/// <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 out contents of OpenApiArray to passed writer /// </summary> /// <param name="writer">Instance of JSON or YAML writer.</param> public void Write(IOpenApiWriter writer) { writer.WriteStartArray(); foreach (var item in this) { writer.WriteAny(item); } writer.WriteEndArray(); }
/// <summary> /// Write out contents of OpenApiArray to passed writer /// </summary> /// <param name="writer">Instance of JSON or YAML writer.</param> /// <param name="specVersion">Version of the OpenAPI specification that that will be output.</param> public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteStartArray(); foreach (var item in this) { writer.WriteAny(item); } writer.WriteEndArray(); }
/// <summary> /// Serialize OpenApiObject to writer /// </summary> /// <param name="writer"></param> public void Write(IOpenApiWriter writer) { writer.WriteStartObject(); foreach (var item in this) { writer.WritePropertyName(item.Key); writer.WriteAny(item.Value); } writer.WriteEndObject(); }
/// <summary> /// Write <see cref="RuntimeExpressionAnyWrapper"/> /// </summary> public void WriteValue(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } if (_any != null) { writer.WriteAny(_any); } else if (_expression != null) { writer.WriteValue(_expression.Expression); } }
/// <summary> /// Write the specification extensions /// </summary> /// <param name="writer">The Open API writer.</param> /// <param name="extensions">The specification extensions.</param> public static void WriteExtensions(this IOpenApiWriter writer, IDictionary <string, IOpenApiAny> extensions) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } if (extensions != null) { foreach (var item in extensions) { writer.WritePropertyName(item.Key); writer.WriteAny(item.Value); } } }
/// <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(); }
private static void WriteArray(this IOpenApiWriter writer, OpenApiArray array) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } if (array == null) { throw Error.ArgumentNull(nameof(array)); } writer.WriteStartArray(); foreach (var item in array) { writer.WriteAny(item); } writer.WriteEndArray(); }
private static void WriteObject(this IOpenApiWriter writer, OpenApiObject entity) { if (writer == null) { throw Error.ArgumentNull(nameof(writer)); } if (entity == null) { throw Error.ArgumentNull(nameof(entity)); } writer.WriteStartObject(); foreach (var item in entity) { writer.WritePropertyName(item.Key); writer.WriteAny(item.Value); } writer.WriteEndObject(); }
/// <summary> /// Write out null representation /// </summary> /// <param name="writer"></param> /// <param name="specVersion">Version of the OpenAPI specification that that will be output.</param> public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteAny(this); }
/// <summary> /// Write out null representation /// </summary> /// <param name="writer"></param> public void Write(IOpenApiWriter writer) { writer.WriteAny(this); }