/// <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> /// 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 <see cref="OpenApiExternalDocs"/> to Open Api v3.0. /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } writer.WriteStartObject(); // contentType writer.WriteProperty(OpenApiConstants.ContentType, ContentType); // headers writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, (w, h) => h.SerializeAsV3(w)); // style writer.WriteProperty(OpenApiConstants.Style, Style?.GetDisplayName()); // explode writer.WriteProperty(OpenApiConstants.Explode, Explode, false); // allowReserved writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false); // extensions writer.WriteExtensions(Extensions); 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(); }
private void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // name writer.WriteProperty(OpenApiConstants.Name, Name); // namespace writer.WriteProperty(OpenApiConstants.Namespace, Namespace?.AbsoluteUri); // prefix writer.WriteProperty(OpenApiConstants.Prefix, Prefix); // attribute writer.WriteProperty(OpenApiConstants.Attribute, Attribute, false); // wrapped writer.WriteProperty(OpenApiConstants.Wrapped, Wrapped, false); // extensions writer.WriteExtensions(Extensions, specVersion); 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> /// 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(); }
/// <summary> /// Serialize <see cref="OpenApiOAuthFlow"/> to Open Api v3.0 /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // authorizationUrl writer.WriteProperty(OpenApiConstants.AuthorizationUrl, AuthorizationUrl?.ToString()); // tokenUrl writer.WriteProperty(OpenApiConstants.TokenUrl, TokenUrl?.ToString()); // refreshUrl writer.WriteProperty(OpenApiConstants.RefreshUrl, RefreshUrl?.ToString()); // scopes writer.WriteRequiredMap(OpenApiConstants.Scopes, Scopes, (w, s) => w.WriteValue(s)); // extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <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="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> /// 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> /// Serialize to OpenAPI V2 document without using reference. /// </summary> public void SerializeAsV2WithoutReference(IOpenApiWriter writer) { if (Type == SecuritySchemeType.Http && Scheme != OpenApiConstants.Basic) { // Bail because V2 does not support non-basic HTTP scheme writer.WriteStartObject(); writer.WriteEndObject(); return; } if (Type == SecuritySchemeType.OpenIdConnect) { // Bail because V2 does not support OpenIdConnect writer.WriteStartObject(); writer.WriteEndObject(); return; } writer.WriteStartObject(); // type switch (Type) { case SecuritySchemeType.Http: writer.WriteProperty(OpenApiConstants.Type, OpenApiConstants.Basic); break; case SecuritySchemeType.OAuth2: // These properties apply to ouauth2 type only. // flow // authorizationUrl // tokenUrl // scopes writer.WriteProperty(OpenApiConstants.Type, Type.GetDisplayName()); WriteOAuthFlowForV2(writer, Flows); break; case SecuritySchemeType.ApiKey: // These properties apply to apiKey type only. // name // in writer.WriteProperty(OpenApiConstants.Type, Type.GetDisplayName()); writer.WriteProperty(OpenApiConstants.Name, Name); writer.WriteProperty(OpenApiConstants.In, In.GetDisplayName()); break; } // description writer.WriteProperty(OpenApiConstants.Description, Description); // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_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(); // path items foreach (var item in PathItems) { writer.WriteRequiredObject(item.Key.Expression, item.Value, (w, p) => p.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(); // 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 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 Open Api v2.0 /// </summary> public void SerializeAsV2(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); foreach (var item in this) { writer.WriteRequiredObject(item.Key, item.Value, (w, p) => p.SerializeAsV2(w)); } 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(); // description writer.WriteProperty(OpenApiConstants.Description, Description); // content writer.WriteRequiredMap(OpenApiConstants.Content, Content, (w, c) => c.SerializeAsV3(w)); // required writer.WriteProperty(OpenApiConstants.Required, Required, false); // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
private void WriteInternal(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // name writer.WriteProperty(OpenApiConstants.Name, Name); // url writer.WriteProperty(OpenApiConstants.Url, Url?.OriginalString); // specification extensions writer.WriteExtensions(Extensions, specVersion); writer.WriteEndObject(); }
private void WriteInternal(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // description writer.WriteProperty(OpenApiConstants.Description, Description); // url writer.WriteProperty(OpenApiConstants.Url, Url?.OriginalString); // extensions writer.WriteExtensions(Extensions); 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="OpenApiComponents"/> to Open Api v3.0. /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // schemas writer.WriteOptionalMap(OpenApiConstants.Schemas, Schemas, (w, s) => s.SerializeAsV3WithoutReference(w)); // responses writer.WriteOptionalMap(OpenApiConstants.Responses, Responses, (w, r) => r.SerializeAsV3WithoutReference(w)); // parameters writer.WriteOptionalMap(OpenApiConstants.Parameters, Parameters, (w, p) => p.SerializeAsV3WithoutReference(w)); // examples writer.WriteOptionalMap(OpenApiConstants.Examples, Examples, (w, e) => e.SerializeAsV3WithoutReference(w)); // requestBodies writer.WriteOptionalMap(OpenApiConstants.RequestBodies, RequestBodies, (w, r) => r.SerializeAsV3WithoutReference(w)); // headers writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, (w, h) => h.SerializeAsV3WithoutReference(w)); // securitySchemes writer.WriteOptionalMap(OpenApiConstants.SecuritySchemes, SecuritySchemes, (w, s) => s.SerializeAsV3WithoutReference(w)); // links writer.WriteOptionalMap(OpenApiConstants.Links, Links, (w, link) => link.SerializeAsV3WithoutReference(w)); // callbacks writer.WriteOptionalMap(OpenApiConstants.Callbacks, Callbacks, (w, c) => c.SerializeAsV3WithoutReference(w)); // extensions writer.WriteExtensions(Extensions); 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(); }
/// <summary> /// Serialize to OpenAPI V3 document without using reference. /// </summary> public void SerializeAsV3WithoutReference(IOpenApiWriter writer) { writer.WriteStartObject(); // description writer.WriteProperty(OpenApiConstants.Description, Description); // headers writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, (w, h) => h.SerializeAsV3(w)); // content writer.WriteOptionalMap(OpenApiConstants.Content, Content, (w, c) => c.SerializeAsV3(w)); // links writer.WriteOptionalMap(OpenApiConstants.Links, Links, (w, l) => l.SerializeAsV3(w)); // extension writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiServer"/> to Open Api v3.0 /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // url writer.WriteProperty(OpenApiConstants.Url, Url); // description writer.WriteProperty(OpenApiConstants.Description, Description); // variables writer.WriteOptionalMap(OpenApiConstants.Variables, Variables, (w, v) => v.SerializeAsV3(w)); // specification extensions writer.WriteExtensions(Extensions); writer.WriteEndObject(); }
/// <summary> /// Serialize <see cref="OpenApiServerVariable"/> to Open Api v3.0 /// </summary> public void SerializeAsV3(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // default writer.WriteProperty(OpenApiConstants.Default, Default); // description writer.WriteProperty(OpenApiConstants.Description, Description); // enums writer.WriteOptionalCollection(OpenApiConstants.Enum, Enum, (w, s) => w.WriteValue(s)); // specification extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0); writer.WriteEndObject(); }
private void WriteInternal(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } writer.WriteStartObject(); // name writer.WriteProperty(OpenApiConstants.Name, Name); // url writer.WriteProperty(OpenApiConstants.Url, Url?.OriginalString); // email writer.WriteProperty(OpenApiConstants.Email, Email); // extensions writer.WriteExtensions(Extensions); 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 Schema?.WriteAsItemsProperties(writer); // example writer.WriteOptionalObject(OpenApiConstants.Example, Example, (w, s) => w.WriteAny(s)); // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0); writer.WriteEndObject(); }