public OpenApiDocument LoadDocument(RootNode rootNode) { return(OpenApiV2Deserializer.LoadOpenApi(rootNode)); }
/// <summary> /// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object /// </summary> public bool TryLoadReference(ParsingContext context, OpenApiReference reference, out IOpenApiReferenceable referencedObject) { referencedObject = null; if (reference == null) { return(false); } if (reference.IsExternal) { // TODO: need to read the external document and load the referenced object. throw new NotImplementedException(SRResource.LoadReferencedObjectFromExternalNotImplmented); } if (!reference.Type.HasValue) { throw new ArgumentException("Local reference must have type specified."); } // Special case for Tag if (reference.Type == ReferenceType.Tag) { foreach (var tag in context.Tags) { if (tag.Name == reference.Id) { referencedObject = tag; return(true); } } referencedObject = new OpenApiTag { Name = reference.Id }; return(false); } var jsonPointer = new JsonPointer("#/" + GetReferenceTypeV2Name(reference.Type.Value) + "/" + reference.Id); var node = context.RootNode.Find(jsonPointer); switch (reference.Type) { case ReferenceType.Schema: referencedObject = OpenApiV2Deserializer.LoadSchema(node); break; case ReferenceType.Response: referencedObject = OpenApiV2Deserializer.LoadResponse(node); break; case ReferenceType.Parameter: // TODO: Handle referencing to a "body" parameter in V2 referencedObject = OpenApiV2Deserializer.LoadParameter(node); break; case ReferenceType.SecurityScheme: referencedObject = OpenApiV2Deserializer.LoadSecurityScheme(node); break; default: throw new OpenApiException( string.Format( SRResource.ReferenceV2HasInvalidValue, reference.Type, jsonPointer)); } return(true); }