/// <summary> /// Serialize <see cref="OpenApiMediaType"/> to Open Api v3.0. /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // schema writer.WriteOptionalObject(OpenApiConstants.Schema, Schema, (w, s) => s.SerializeAsV3(w)); // example writer.WriteOptionalObject(OpenApiConstants.Example, Example, (w, e) => w.WriteAny(e)); // examples writer.WriteOptionalMap(OpenApiConstants.Examples, Examples, (w, e) => e.SerializeAsV3(w)); // encoding writer.WriteOptionalMap(OpenApiConstants.Encoding, Encoding, (w, e) => e.SerializeAsV3(w)); // extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiOAuthFlows"/> to Open Api v3.0 /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // implicit writer.WriteOptionalObject(OpenApiConstants.Implicit, Implicit, (w, o) => o.SerializeAsV3(w)); // password writer.WriteOptionalObject(OpenApiConstants.Password, Password, (w, o) => o.SerializeAsV3(w)); // clientCredentials writer.WriteOptionalObject( OpenApiConstants.ClientCredentials, ClientCredentials, (w, o) => o.SerializeAsV3(w)); // authorizationCode writer.WriteOptionalObject( OpenApiConstants.AuthorizationCode, AuthorizationCode, (w, o) => o.SerializeAsV3(w)); // extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
protected override void WriteBody(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { base.WriteBody(writer, specVersion); writer.WriteOptionalObject("schema", Schema, specVersion); writer.WriteOptionalObject("element", Element, specVersion); }
/// <summary> /// Write Open API Info to the given writer. /// </summary> /// <param name="writer">The writer.</param> public virtual void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); // title writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocTitle, Title); // description writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDescription, Description); // termsOfService writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocTermsOfService, TermsOfService?.OriginalString); // contact object writer.WriteOptionalObject(OpenApiConstants.OpenApiDocContact, Contact); // license object writer.WriteOptionalObject(OpenApiConstants.OpenApiDocLicense, License); // version writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocVersion, Version?.ToString()); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); }
private void WriteInternal(IOpenApiWriter writer) { // { for JSON, empty for YAML writer.WriteStartObject(); // operationRef writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocOperationRef, OperationRef); // operationId writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocOperationId, OperationId); // parameters writer.WriteOptionalDictionary(OpenApiConstants.OpenApiDocParameters, Parameters); // requestBody writer.WriteOptionalObject(OpenApiConstants.OpenApiDocRequestBody, RequestBody); // description writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDescription, Description); // server writer.WriteOptionalObject(OpenApiConstants.OpenApiDocServer, Server); // specification extensions writer.WriteDictionary(Extensions); // } for JSON, empty for YAML writer.WriteEndObject(); }
/// <summary> /// Write media type object to the given writer. /// </summary> /// <param name="writer">The writer.</param> public virtual void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); // schema writer.WriteOptionalObject(OpenApiConstants.OpenApiDocSchema, Schema); // example writer.WriteOptionalObject(OpenApiConstants.OpenApiDocExample, Example); // examples writer.WriteOptionalDictionary(OpenApiConstants.OpenApiDocExamples, Examples); // encoding writer.WriteOptionalDictionary(OpenApiConstants.OpenApiDocEncoding, Encoding); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiInfo"/> to Open Api v3.0 /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // title writer.WriteProperty(OpenApiConstants.Title, Title); // description writer.WriteProperty(OpenApiConstants.Description, Description); // termsOfService writer.WriteProperty(OpenApiConstants.TermsOfService, TermsOfService?.OriginalString); // contact object writer.WriteOptionalObject(OpenApiConstants.Contact, Contact, (w, c) => c.SerializeAsV3(w)); // license object writer.WriteOptionalObject(OpenApiConstants.License, License, (w, l) => l.SerializeAsV3(w)); // version writer.WriteProperty(OpenApiConstants.Version, Version); // specification extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Write Any object to the given writer. /// </summary> /// <param name="writer">The writer.</param> public void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); // implicit writer.WriteOptionalObject(OpenApiConstants.OpenApiDocImplicit, Implicit); // password writer.WriteOptionalObject(OpenApiConstants.OpenApiDocPassword, Password); // clientCredentials writer.WriteOptionalObject(OpenApiConstants.OpenApiDocClientCredentials, ClientCredentials); // authorizationCode writer.WriteOptionalObject(OpenApiConstants.OpenApiDocAuthorizationCode, AuthorizationCode); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); }
protected override void WriteBody(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { base.WriteBody(writer, specVersion); writer.WriteOptionalObject("request-schema", RequestSchema, specVersion); writer.WriteOptionalObject("response-schema", ResponseSchema, specVersion); }
private void WriteInternal(IOpenApiWriter writer) { Debug.Assert(writer != null); // { for json, empty for YAML writer.WriteStartObject(); // name writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocName, Name); // in writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocIn, In.ToString()); // description writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDescription, Description); // required if (In == ParameterLocation.path) { writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocRequired, true); } else { writer.WriteBooleanProperty(OpenApiConstants.OpenApiDocRequired, Required, false); } // deprecated writer.WriteBooleanProperty(OpenApiConstants.OpenApiDocDeprecated, Deprecated, false); // allowEmptyValue writer.WriteBooleanProperty(OpenApiConstants.OpenApiDocDeprecated, AllowEmptyValue, false); // style writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocStyle, Style.ToString()); // explode writer.WriteBooleanProperty(OpenApiConstants.OpenApiDocExplode, Explode, false); // allowReserved writer.WriteBooleanProperty(OpenApiConstants.OpenApiDocAllowReserved, AllowReserved, false); // schema writer.WriteOptionalObject(OpenApiConstants.OpenApiDocSchema, Schema); // example writer.WriteOptionalObject(OpenApiConstants.OpenApiDocExample, Example); // examples writer.WriteOptionalDictionary(OpenApiConstants.OpenApiDocExamples, Examples); // content writer.WriteOptionalDictionary(OpenApiConstants.OpenApiDocContent, Content); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiOperation"/> to Open Api v3.0. /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // tags writer.WriteOptionalCollection( OpenApiConstants.Tags, Tags, (w, t) => { t.SerializeAsV2(w); }); // summary writer.WriteProperty(OpenApiConstants.Summary, Summary); // description writer.WriteProperty(OpenApiConstants.Description, Description); // externalDocs writer.WriteOptionalObject(OpenApiConstants.ExternalDocs, ExternalDocs, (w, e) => e.SerializeAsV3(w)); // operationId writer.WriteProperty(OpenApiConstants.OperationId, OperationId); // parameters writer.WriteOptionalCollection(OpenApiConstants.Parameters, Parameters, (w, p) => p.SerializeAsV3(w)); // requestBody writer.WriteOptionalObject(OpenApiConstants.RequestBody, RequestBody, (w, r) => r.SerializeAsV3(w)); // responses writer.WriteRequiredObject(OpenApiConstants.Responses, Responses, (w, r) => r.SerializeAsV3(w)); // callbacks writer.WriteOptionalMap(OpenApiConstants.Callbacks, Callbacks, (w, c) => c.SerializeAsV3(w)); // deprecated writer.WriteProperty(OpenApiConstants.Deprecated, Deprecated, false); // security writer.WriteOptionalCollection(OpenApiConstants.Security, Security, (w, s) => s.SerializeAsV3(w)); // servers writer.WriteOptionalCollection(OpenApiConstants.Servers, Servers, (w, s) => s.SerializeAsV3(w)); // specification extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Write Open API operation object. /// </summary> /// <param name="writer">The Open API Writer.</param> public virtual void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); // summary writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocSummary, Summary); // tags writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocTags, Tags); // description writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDescription, Description); // externalDocs writer.WriteOptionalObject(OpenApiConstants.OpenApiDocExternalDocs, ExternalDocs); // operationId writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocOperationId, OperationId); // parameters writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocParameters, Parameters); // requestBody writer.WriteOptionalObject(OpenApiConstants.OpenApiDocRequestBody, RequestBody); // responses writer.WriteOptionalObject(OpenApiConstants.OpenApiDocResponses, Responses); // callbacks writer.WriteOptionalDictionary(OpenApiConstants.OpenApiDocCallbacks, Callbacks); // deprecated writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDeprecated, Deprecated); // security writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocSecurity, Security); // servers writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocServers, Servers); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V3 document without using reference. /// </summary> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // name writer.WriteProperty(OpenApiConstants.Name, Name); // in writer.WriteProperty(OpenApiConstants.In, In.GetDisplayName()); // description writer.WriteProperty(OpenApiConstants.Description, Description); // required writer.WriteProperty(OpenApiConstants.Required, Required, false); // deprecated writer.WriteProperty(OpenApiConstants.Deprecated, Deprecated, false); // allowEmptyValue writer.WriteProperty(OpenApiConstants.AllowEmptyValue, AllowEmptyValue, false); // style writer.WriteProperty(OpenApiConstants.Style, Style?.GetDisplayName()); // explode writer.WriteProperty(OpenApiConstants.Explode, Explode, false); // allowReserved writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false); // schema writer.WriteOptionalObject(OpenApiConstants.Schema, Schema, (w, s) => s.SerializeAsV3(w)); // example writer.WriteOptionalObject(OpenApiConstants.Example, Example, (w, s) => w.WriteAny(s)); // examples writer.WriteOptionalMap(OpenApiConstants.Examples, Examples, (w, e) => e.SerializeAsV3(w)); // content writer.WriteOptionalMap(OpenApiConstants.Content, Content, (w, c) => c.SerializeAsV3(w)); // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
/// <summary> /// Serialize inline PathItem in OpenAPI V2 /// </summary> /// <param name="writer"></param> public void SerializeAsV2WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // operations except "trace" foreach (var operation in Operations) { if (operation.Key != OperationType.Trace) { writer.WriteOptionalObject( operation.Key.GetDisplayName(), operation.Value, (w, o) => o.SerializeAsV2(w)); } } // parameters writer.WriteOptionalCollection(OpenApiConstants.Parameters, Parameters, (w, p) => p.SerializeAsV2(w)); // write "summary" as extensions writer.WriteProperty(OpenApiConstants.ExtensionFieldNamePrefix + OpenApiConstants.Summary, Summary); // write "description" as extensions writer.WriteProperty( OpenApiConstants.ExtensionFieldNamePrefix + OpenApiConstants.Description, Description); // specification extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0); writer.WriteEndObject(); }
/// <summary> /// Serialize inline PathItem in OpenAPI V3 /// </summary> /// <param name="writer"></param> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // summary writer.WriteProperty(OpenApiConstants.Summary, Summary); // description writer.WriteProperty(OpenApiConstants.Description, Description); // operations foreach (var operation in Operations) { writer.WriteOptionalObject( operation.Key.GetDisplayName(), operation.Value, (w, o) => o.SerializeAsV3(w)); } // servers writer.WriteOptionalCollection(OpenApiConstants.Servers, Servers, (w, s) => s.SerializeAsV3(w)); // parameters writer.WriteOptionalCollection(OpenApiConstants.Parameters, Parameters, (w, p) => p.SerializeAsV3(w)); // specification extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiPathItem"/> to Open Api v3.0 /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // summary writer.WriteProperty(OpenApiConstants.Summary, Summary); // description writer.WriteProperty(OpenApiConstants.Description, Description); // operations foreach (var operation in Operations) { writer.WriteOptionalObject( operation.Key.GetDisplayName(), operation.Value, (w, o) => o.SerializeAsV3(w)); } // servers writer.WriteOptionalCollection(OpenApiConstants.Servers, Servers, (w, s) => s.SerializeAsV3(w)); // parameters writer.WriteOptionalCollection(OpenApiConstants.Parameters, Parameters, (w, p) => p.SerializeAsV3(w)); // specification extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Write Open API tag object. /// </summary> /// <param name="writer">The Open API Writer.</param> public virtual void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for JSON, empty for YAML writer.WriteStartObject(); // name writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocName, Name); // description writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDescription, Description); // External Docs writer.WriteOptionalObject(OpenApiConstants.OpenApiDocExternalDocs, ExternalDocs); // specification extensions writer.WriteDictionary(Extensions); // } for JSON, empty for YAML writer.WriteEndObject(); }
protected override void WriteBody(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { base.WriteBody(writer, specVersion); writer.WriteOptionalObject("schema", Schema, specVersion); writer.WriteProperty("separator", Separator); }
public override void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteStartObject(); foreach (var item in Children) { writer.WriteOptionalObject(item.Key, item.Value, specVersion); } writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V2 document without using reference. /// </summary> public void SerializeAsV2WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // description writer.WriteRequiredProperty(OpenApiConstants.Description, Description); var extensionsClone = new Dictionary <string, IOpenApiExtension>(Extensions); if (Content != null) { var mediatype = Content.FirstOrDefault(); if (mediatype.Value != null) { // schema writer.WriteOptionalObject( OpenApiConstants.Schema, mediatype.Value.Schema, (w, s) => s.SerializeAsV2(w)); // examples if (Content.Values.Any(m => m.Example != null)) { writer.WritePropertyName(OpenApiConstants.Examples); writer.WriteStartObject(); foreach (var mediaTypePair in Content) { if (mediaTypePair.Value.Example != null) { writer.WritePropertyName(mediaTypePair.Key); writer.WriteAny(mediaTypePair.Value.Example); } } writer.WriteEndObject(); } writer.WriteExtensions(mediatype.Value.Extensions, OpenApiSpecVersion.OpenApi2_0); foreach (var key in mediatype.Value.Extensions.Keys) { // The extension will already have been serialized as part of the call above, // so remove it from the cloned collection so we don't write it again. extensionsClone.Remove(key); } } } // headers writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, (w, h) => h.SerializeAsV2(w)); // extension writer.WriteExtensions(extensionsClone, OpenApiSpecVersion.OpenApi2_0); writer.WriteEndObject(); }
/// <summary> /// Write Open API document to the given writer. /// </summary> /// <param name="writer">The writer.</param> public virtual void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); // openapi:3.0.0 writer.WriteRequiredProperty(OpenApiConstants.OpenApiDocOpenApi, OpenApi.ToString()); // info writer.WriteRequiredObject(OpenApiConstants.OpenApiDocInfo, Info); // servers writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocServers, Servers); // paths writer.WriteRequiredObject(OpenApiConstants.OpenApiDocPaths, Paths); // components writer.WriteOptionalObject(OpenApiConstants.OpenApiDocComponents, Components); // security writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocSecurity, Security); // tags writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocTags, Tags); // external docs writer.WriteOptionalObject(OpenApiConstants.OpenApiDocExternalDocs, ExternalDoc); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); // flush writer.Flush(); }
private void WriteInternal(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); // summary writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocSummary, Summary); // description writer.WriteOptionalProperty(OpenApiConstants.OpenApiDocDescription, Description); // get writer.WriteOptionalObject(OpenApiConstants.OpenApiDocGet, Get); // put writer.WriteOptionalObject(OpenApiConstants.OpenApiDocPut, Put); // post writer.WriteOptionalObject(OpenApiConstants.OpenApiDocPost, Post); // delete writer.WriteOptionalObject(OpenApiConstants.OpenApiDocDelete, Delete); // options writer.WriteOptionalObject(OpenApiConstants.OpenApiDocOptions, Options); // head writer.WriteOptionalObject(OpenApiConstants.OpenApiDocHead, Head); // patch writer.WriteOptionalObject(OpenApiConstants.OpenApiDocPatch, Patch); // trace writer.WriteOptionalObject(OpenApiConstants.OpenApiDocTrace, Trace); // servers writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocServers, Servers); // parameters writer.WriteOptionalCollection(OpenApiConstants.OpenApiDocParameters, Parameters); // specification extensions writer.WriteDictionary(Extensions); // } for json, empty for YAML writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiDocument"/> to the latest patch of OpenAPI object V3.0. /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // openapi writer.WriteProperty(OpenApiConstants.OpenApi, "3.0.1"); // info writer.WriteRequiredObject(OpenApiConstants.Info, Info, (w, i) => i.SerializeAsV3(w)); // servers writer.WriteOptionalCollection(OpenApiConstants.Servers, Servers, (w, s) => s.SerializeAsV3(w)); // paths writer.WriteRequiredObject(OpenApiConstants.Paths, Paths, (w, p) => p.SerializeAsV3(w)); // components writer.WriteOptionalObject(OpenApiConstants.Components, Components, (w, c) => c.SerializeAsV3(w)); // security writer.WriteOptionalCollection( OpenApiConstants.Security, SecurityRequirements, (w, s) => s.SerializeAsV3(w)); // tags writer.WriteOptionalCollection(OpenApiConstants.Tags, Tags, (w, t) => t.SerializeAsV3WithoutReference(w)); // external docs writer.WriteOptionalObject(OpenApiConstants.ExternalDocs, ExternalDocs, (w, e) => e.SerializeAsV3(w)); // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiDocument"/> to Open Api v2.0. /// </summary> public void SerializeAsV2(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // swagger writer.WriteProperty(OpenApiConstants.Swagger, "2.0"); // info writer.WriteRequiredObject(OpenApiConstants.Info, Info, (w, i) => i.SerializeAsV2(w)); // host, basePath, schemes, consumes, produces WriteHostInfoV2(writer, Servers); // paths writer.WriteRequiredObject(OpenApiConstants.Paths, Paths, (w, p) => p.SerializeAsV2(w)); // definitions writer.WriteOptionalMap(OpenApiConstants.Definitions, Components?.Schemas, (w, s) => s.SerializeAsV2WithoutReference(w)); // parameters writer.WriteOptionalMap(OpenApiConstants.Parameters, Components?.Parameters, (w, p) => p.SerializeAsV2WithoutReference(w)); // responses writer.WriteOptionalMap(OpenApiConstants.Responses, Components?.Responses, (w, r) => r.SerializeAsV2WithoutReference(w)); // securityDefinitions writer.WriteOptionalMap(OpenApiConstants.SecurityDefinitions, Components?.SecuritySchemes, (w, s) => s.SerializeAsV2WithoutReference(w)); // security writer.WriteOptionalCollection( OpenApiConstants.Security, SecurityRequirements, (w, s) => s.SerializeAsV2(w)); // tags writer.WriteOptionalCollection(OpenApiConstants.Tags, Tags, (w, t) => t.SerializeAsV2WithoutReference(w)); // externalDocs writer.WriteOptionalObject(OpenApiConstants.ExternalDocs, ExternalDocs, (w, e) => e.SerializeAsV2(w)); // extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V3 document without using reference. /// </summary> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // operationRef writer.WriteProperty(OpenApiConstants.OperationRef, OperationRef); // operationId writer.WriteProperty(OpenApiConstants.OperationId, OperationId); // parameters writer.WriteOptionalMap(OpenApiConstants.Parameters, Parameters, (w, p) => p.WriteValue(w)); // requestBody writer.WriteOptionalObject(OpenApiConstants.RequestBody, RequestBody, (w, r) => r.WriteValue(w)); // description writer.WriteProperty(OpenApiConstants.Description, Description); // server writer.WriteOptionalObject(OpenApiConstants.Server, Server, (w, s) => s.SerializeAsV3(w)); writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V2 document without using reference. /// </summary> public void SerializeAsV2WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // description writer.WriteProperty(OpenApiConstants.Description, Description); // required writer.WriteProperty(OpenApiConstants.Required, Required, false); // deprecated writer.WriteProperty(OpenApiConstants.Deprecated, Deprecated, false); // allowEmptyValue writer.WriteProperty(OpenApiConstants.AllowEmptyValue, AllowEmptyValue, false); // style writer.WriteProperty(OpenApiConstants.Style, Style?.GetDisplayName()); // explode writer.WriteProperty(OpenApiConstants.Explode, Explode, false); // allowReserved writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false); // schema writer.WriteOptionalObject(OpenApiConstants.Schema, Schema, (w, s) => s.SerializeAsV2(w)); // example writer.WriteOptionalObject(OpenApiConstants.Example, Example, (w, s) => w.WriteAny(s)); // extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V3 document without using reference. /// </summary> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // type writer.WriteProperty(OpenApiConstants.Type, Type.GetDisplayName()); // description writer.WriteProperty(OpenApiConstants.Description, Description); switch (Type) { case SecuritySchemeType.ApiKey: // These properties apply to apiKey type only. // name // in writer.WriteProperty(OpenApiConstants.Name, Name); writer.WriteProperty(OpenApiConstants.In, In.GetDisplayName()); break; case SecuritySchemeType.Http: // These properties apply to http type only. // scheme // bearerFormat writer.WriteProperty(OpenApiConstants.Scheme, Scheme); writer.WriteProperty(OpenApiConstants.BearerFormat, BearerFormat); break; case SecuritySchemeType.OAuth2: // This property apply to oauth2 type only. // flows writer.WriteOptionalObject(OpenApiConstants.Flows, Flows, (w, o) => o.SerializeAsV3(w)); break; case SecuritySchemeType.OpenIdConnect: // This property apply to openIdConnect only. // openIdConnectUrl writer.WriteProperty(OpenApiConstants.OpenIdConnectUrl, OpenIdConnectUrl?.ToString()); break; } // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V2 document without using reference. /// </summary> public void SerializeAsV2WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // description writer.WriteProperty(OpenApiConstants.Description, Description); if (Content != null) { var mediatype = Content.FirstOrDefault(); if (mediatype.Value != null) { // schema writer.WriteOptionalObject( OpenApiConstants.Schema, mediatype.Value.Schema, (w, s) => s.SerializeAsV2(w)); // examples if (Content.Values.Any(m => m.Example != null)) { writer.WritePropertyName(OpenApiConstants.Examples); writer.WriteStartObject(); foreach (var mediaTypePair in Content) { if (mediaTypePair.Value.Example != null) { writer.WritePropertyName(mediaTypePair.Key); writer.WriteAny(mediaTypePair.Value.Example); } } writer.WriteEndObject(); } } } // headers writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, (w, h) => h.SerializeAsV2(w)); // extension writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0); writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V3 document without using reference. /// </summary> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // name writer.WriteProperty(OpenApiConstants.Name, Name); // description writer.WriteProperty(OpenApiConstants.Description, Description); // external docs writer.WriteOptionalObject(OpenApiConstants.ExternalDocs, ExternalDocs, (w, e) => e.SerializeAsV3(w)); // extensions. writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
/// <summary> /// Serialize to OpenAPI V3 document without using reference. /// </summary> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // summary writer.WriteProperty(OpenApiConstants.Summary, Summary); // description writer.WriteProperty(OpenApiConstants.Description, Description); // value writer.WriteOptionalObject(OpenApiConstants.Value, Value, (w, v) => w.WriteAny(v)); // externalValue writer.WriteProperty(OpenApiConstants.ExternalValue, ExternalValue); // extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }