/// <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(); }
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(); }
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteStartObject(); writer.WriteProperty("page", PageParameterName); writer.WriteProperty("pageSize", PageSizeParameterName); 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(); }
/// <inheritdoc /> public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (RemovalDate.HasValue || Date.HasValue || !string.IsNullOrEmpty(Version) || !string.IsNullOrEmpty(Description)) { writer.WriteStartObject(); if (RemovalDate.HasValue) { writer.WriteProperty(nameof(RemovalDate).ToFirstCharacterLowerCase(), RemovalDate.Value); } if (Date.HasValue) { writer.WriteProperty(nameof(Date).ToFirstCharacterLowerCase(), Date.Value); } if (!string.IsNullOrEmpty(Version)) { writer.WriteProperty(nameof(Version).ToFirstCharacterLowerCase(), Version); } if (!string.IsNullOrEmpty(Description)) { writer.WriteProperty(nameof(Description).ToFirstCharacterLowerCase(), Description); } 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>Writes the specified writer.</summary> /// <param name="writer">The writer.</param> /// <param name="specVersion">The spec version.</param> public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteStartObject(); writer.WriteProperty("name", this.enumType.Name); writer.WriteProperty("modelAsString", this.enumModeling == OasEnumModeling.AsString); writer.WritePropertyName("values"); var items = Enum.GetValues(enumType); writer.WriteStartArray(); foreach (var item in items) { var summary = OasDocHelpers.GetFieldDocumentationSummary(enumType, item.ToString(), this.commentDocs); writer.WriteStartObject(); writer.WriteProperty("value", this.namingPolicy.ConvertName(item.ToString())); writer.WriteProperty("name", this.namingPolicy.ConvertName(item.ToString())); if (!string.IsNullOrWhiteSpace(summary)) { writer.WriteProperty("description", summary); } writer.WriteEndObject(); } writer.WriteEndArray(); 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="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="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(); }
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteStartObject(); writer.WriteProperty("baz", Baz); writer.WriteProperty("bar", Bar); writer.WriteEndObject(); }
public void Write(IOpenApiWriter writer) { writer.WriteStartObject(); writer.WriteProperty("baz", Baz); writer.WriteProperty("bar", Bar); writer.WriteEndObject(); }
/// <summary> /// Writes this endpoint description to an OpenAPI document. /// </summary> /// <param name="writer">The write to write to.</param> /// <param name="specVersion">The OpenAPI Spec version to use.</param> protected virtual void WriteBody(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { if (!string.IsNullOrEmpty(Kind)) { writer.WriteProperty("kind", Kind); } writer.WriteProperty("uri", Uri); writer.WriteProperty("description", Description); }
/// <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> /// Writes this endpoint description to an OpenAPI document. /// </summary> /// <param name="writer">The write to write to.</param> /// <param name="specVersion">The OpenAPI Spec version to use.</param> protected virtual void WriteBody(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { if (!string.IsNullOrEmpty(Type)) { writer.WriteProperty("type", Type); } writer.WriteProperty("description", Description); writer.WriteProperty("uri", Uri); writer.WriteOptionalMap("children", Children, specVersion); }
private static void WriteOAuthFlowForV2(IOpenApiWriter writer, string flowValue, OpenApiOAuthFlow flow) { // flow writer.WriteProperty(OpenApiConstants.Flow, flowValue); // authorizationUrl writer.WriteProperty(OpenApiConstants.AuthorizationUrl, flow.AuthorizationUrl?.ToString()); // tokenUrl writer.WriteProperty(OpenApiConstants.TokenUrl, flow.TokenUrl?.ToString()); // scopes writer.WriteOptionalMap(OpenApiConstants.Scopes, flow.Scopes, (w, s) => w.WriteValue(s)); }
private static void WriteHostInfoV2(IOpenApiWriter writer, IList <OpenApiServer> servers) { if (servers == null || !servers.Any()) { return; } // Arbitrarily choose the first server given that V2 only allows // one host, port, and base path. var firstServer = servers.First(); // Divide the URL in the Url property into host and basePath required in OpenAPI V2 // The Url property cannotcontain path templating to be valid for V2 serialization. var firstServerUrl = new Uri(firstServer.Url); // host writer.WriteProperty( OpenApiConstants.Host, firstServerUrl.GetComponents(UriComponents.Host | UriComponents.Port, UriFormat.SafeUnescaped)); // basePath if (firstServerUrl.AbsolutePath != "/") { writer.WriteProperty(OpenApiConstants.BasePath, firstServerUrl.AbsolutePath); } // Consider all schemes of the URLs in the server list that have the same // host, port, and base path as the first server. var schemes = servers.Select( s => { Uri.TryCreate(s.Url, UriKind.RelativeOrAbsolute, out var url); return(url); }) .Where( u => Uri.Compare( u, firstServerUrl, UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0) .Select(u => u.Scheme) .Distinct() .ToList(); // schemes writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes, (w, s) => w.WriteValue(s)); }
/// <summary> /// Serialize <see cref="OpenApiReference"/> to Open Api v2.0. /// </summary> public void SerializeAsV2(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } if (Type == ReferenceType.Tag) { // Write the string value only writer.WriteValue(ReferenceV2); return; } if (Type == ReferenceType.SecurityScheme) { // Write the string as property name writer.WritePropertyName(ReferenceV2); return; } writer.WriteStartObject(); // $ref writer.WriteProperty(OpenApiConstants.DollarRef, ReferenceV2); writer.WriteEndObject(); }
protected override void WriteBody(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { base.WriteBody(writer, specVersion); writer.WriteOptionalObject("schema", Schema, specVersion); writer.WriteProperty("separator", Separator); }
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { NullGuard.NotNull(writer, nameof(writer)) .NotNull(specVersion, nameof(specVersion)); writer.WriteStartObject(); writer.WriteProperty(nameof(ErrorCode), ErrorCode.ToString()); if (string.IsNullOrWhiteSpace(ErrorType) == false) { writer.WriteProperty(nameof(ErrorType), ErrorType); } if (string.IsNullOrWhiteSpace(ErrorMessage) == false) { writer.WriteProperty(nameof(ErrorMessage), ErrorMessage); } 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(); }
/// <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> /// Write the boolean property. /// </summary> /// <param name="writer">The writer.</param> /// <param name="name">The property name.</param> /// <param name="value">The property value.</param> /// <param name="defaultValue">The default value.</param> public static void WriteBooleanProperty(this IOpenApiWriter writer, string name, bool value, bool?defaultValue) { if (defaultValue != null && value == defaultValue.Value) { return; } writer.WriteProperty(name, () => writer.WriteValue(value)); }
/// <summary> /// Write a primitive property. /// </summary> /// <param name="writer">The writer.</param> /// <param name="name">The property name.</param> /// <param name="value">The property value.</param> public static void WriteProperty <T>(this IOpenApiWriter writer, string name, T?value) where T : struct { if (value == null) { return; } writer.WriteProperty(name, value.Value); }
/// <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(); }
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(); }
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(); }
/// <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(); }
/// <inheritdoc /> public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } writer.WriteStartObject(); if (!string.IsNullOrEmpty(NextLinkName)) { writer.WriteProperty(nameof(NextLinkName).ToFirstCharacterLowerCase(), NextLinkName); } if (!string.IsNullOrEmpty(OperationName)) { writer.WriteProperty(nameof(OperationName).ToFirstCharacterLowerCase(), OperationName); } writer.WriteProperty(nameof(ItemName).ToFirstCharacterLowerCase(), ItemName); writer.WriteEndObject(); }
public void Write(IOpenApiWriter writer) { writer.WriteStartObject(); if (!string.IsNullOrWhiteSpace(Credentials)) { writer.WriteProperty("credentials", Credentials); } writer.WritePropertyName("responses"); { writer.WriteStartObject(); writer.WritePropertyName("default"); { writer.WriteStartObject(); writer.WriteProperty("statusCode", "200"); writer.WriteEndObject(); } writer.WriteEndObject(); } writer.WriteProperty("uri", LambdaUri); writer.WriteProperty("passthroughBehavior", "when_no_templates"); writer.WriteProperty("httpMethod", HttpMethod); writer.WriteProperty("type", "aws"); writer.WriteEndObject(); }