diff --git a/src/Microsoft.OpenApi.Readers/YamlReaders/MapNode.cs b/src/Microsoft.OpenApi.Readers/YamlReaders/MapNode.cs index 4b3d531f4..88737a140 100644 --- a/src/Microsoft.OpenApi.Readers/YamlReaders/MapNode.cs +++ b/src/Microsoft.OpenApi.Readers/YamlReaders/MapNode.cs @@ -70,11 +70,11 @@ public string GetScalarValue(ValueNode key) return scalarNode.Value; } - public T GetReferencedObject(string refPointer) where T : IReference + public T GetReferencedObject(string refPointer) where T : IOpenApiReference { return (T)this.Context.GetReferencedObject(refPointer); } - public T CreateOrReferenceDomainObject(Func factory) where T: IReference + public T CreateOrReferenceDomainObject(Func factory) where T: IOpenApiReference { T domainObject; var refPointer = GetReferencePointer(); // What should the DOM of a reference look like? diff --git a/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV2Builder.cs b/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV2Builder.cs index 0e87d2c5e..789b47bf5 100644 --- a/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV2Builder.cs +++ b/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV2Builder.cs @@ -27,7 +27,7 @@ internal static class OpenApiV2Builder - private static void MakeServers(List servers, ParsingContext context) + private static void MakeServers(IList servers, ParsingContext context) { string host = context.GetTempStorage("host"); string basePath = context.GetTempStorage("basePath"); @@ -47,7 +47,7 @@ private static void MakeServers(List servers, ParsingContext cont public static PatternFieldMap OpenApiPatternFields = new PatternFieldMap { // We have no semantics to verify X- nodes, therefore treat them as just values. - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiDocument LoadOpenApi(RootNode rootNode) @@ -84,7 +84,7 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) public static PatternFieldMap InfoPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; @@ -115,7 +115,7 @@ public static OpenApiInfo LoadInfo(ParseNode node) public static PatternFieldMap ContactPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiContact LoadContact(ParseNode node) @@ -139,7 +139,7 @@ public static OpenApiContact LoadContact(ParseNode node) public static PatternFieldMap LicensePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; internal static OpenApiLicense LoadLicense(ParseNode node) @@ -164,7 +164,7 @@ internal static OpenApiLicense LoadLicense(ParseNode node) public static PatternFieldMap PathsPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("/"), (o,k,n)=> o.Add(k, OpenApiV2Builder.LoadPathItem(n) ) }, - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiPaths LoadPaths(ParseNode node) @@ -190,7 +190,7 @@ public static OpenApiPaths LoadPaths(ParseNode node) private static PatternFieldMap PathItemPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, { (s)=> "get,put,post,delete,patch,options,head,patch".Contains(s), (o,k,n)=> o.AddOperation(OperationTypeExtensions.ParseOperationType(k), OpenApiV2Builder.LoadOperation(n) ) } }; @@ -228,7 +228,7 @@ public static OpenApiPathItem LoadPathItem(ParseNode node) private static PatternFieldMap OperationPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; internal static OpenApiOperation LoadOperation(ParseNode node) @@ -418,7 +418,7 @@ private static void ProcessIn(OpenApiParameter o, ParseNode n) private static PatternFieldMap ParameterPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; @@ -465,7 +465,7 @@ public static OpenApiParameter LoadParameter(ParseNode node) private static PatternFieldMap ResponsePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; public static OpenApiResponse LoadResponse(ParseNode node) @@ -523,7 +523,7 @@ private static void ProcessProduces(OpenApiResponse response, ParsingContext con private static PatternFieldMap HeaderPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; @@ -555,7 +555,7 @@ public static OpenApiHeader LoadHeader(ParseNode node) private static PatternFieldMap ExamplePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiExample LoadExample(ParseNode node) @@ -643,7 +643,7 @@ internal static OpenApiTag LoadTag(ParseNode n) private static PatternFieldMap SchemaPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; @@ -689,7 +689,7 @@ public static OpenApiSchema LoadSchema(ParseNode node) private static PatternFieldMap SecuritySchemePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node) @@ -790,9 +790,9 @@ private static string GetReferenceTypeName(ReferenceType referenceType) } - public static IReference LoadReference(OpenApiReference reference, object rootNode) + public static IOpenApiReference LoadReference(OpenApiReference reference, object rootNode) { - IReference referencedObject = null; + IOpenApiReference referencedObject = null; ParseNode node = ((RootNode)rootNode).Find(GetPointer(reference)); if (node == null && reference.ReferenceType != ReferenceType.Tags ) return null; diff --git a/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV3Builder.cs b/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV3Builder.cs index 6653688ea..b921ceb86 100644 --- a/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV3Builder.cs +++ b/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV3Builder.cs @@ -22,7 +22,7 @@ internal static class OpenApiV3Builder public static PatternFieldMap OpenApiPatternFields = new PatternFieldMap { // We have no semantics to verify X- nodes, therefore treat them as just values. - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiDocument LoadOpenApi(RootNode rootNode) @@ -56,10 +56,9 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) public static PatternFieldMap InfoPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; - public static OpenApiInfo LoadInfo(ParseNode node) { var mapNode = node.CheckMapNode("Info"); @@ -85,7 +84,7 @@ public static OpenApiInfo LoadInfo(ParseNode node) public static PatternFieldMap ContactPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiContact LoadContact(ParseNode node) @@ -109,7 +108,7 @@ public static OpenApiContact LoadContact(ParseNode node) public static PatternFieldMap LicensePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; internal static OpenApiLicense LoadLicense(ParseNode node) @@ -136,7 +135,7 @@ internal static OpenApiLicense LoadLicense(ParseNode node) private static PatternFieldMap ServerPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiServer LoadServer(ParseNode node) @@ -163,7 +162,7 @@ public static OpenApiServer LoadServer(ParseNode node) private static PatternFieldMap ServerVariablePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiServerVariable LoadServerVariable(ParseNode node) @@ -195,7 +194,7 @@ public static OpenApiServerVariable LoadServerVariable(ParseNode node) public static PatternFieldMap ComponentsPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiComponents LoadComponents(ParseNode node) @@ -219,7 +218,7 @@ public static OpenApiComponents LoadComponents(ParseNode node) public static PatternFieldMap PathsPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("/"), (o,k,n)=> o.Add(k, LoadPathItem(n) ) }, - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiPaths LoadPaths(ParseNode node) @@ -248,7 +247,7 @@ public static OpenApiPaths LoadPaths(ParseNode node) private static PatternFieldMap PathItemPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, { (s)=> "get,put,post,delete,patch,options,head,patch,trace".Contains(s), (o,k,n)=> o.AddOperation(OperationTypeExtensions.ParseOperationType(k), LoadOperation(n) ) } }; @@ -287,7 +286,7 @@ public static OpenApiPathItem LoadPathItem(ParseNode node) private static PatternFieldMap OperationPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; internal static OpenApiOperation LoadOperation(ParseNode node) @@ -350,7 +349,7 @@ public static OpenApiExternalDocs LoadExternalDocs(ParseNode node) private static PatternFieldMap ParameterPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; @@ -384,7 +383,7 @@ public static OpenApiParameter LoadParameter(ParseNode node) private static PatternFieldMap RequestBodyPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; public static OpenApiRequestBody LoadRequestBody(ParseNode node) @@ -414,7 +413,7 @@ public static OpenApiRequestBody LoadRequestBody(ParseNode node) private static PatternFieldMap MediaTypePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiMediaType LoadMediaType(ParseNode node) @@ -453,7 +452,7 @@ public static OpenApiMediaType LoadMediaType(ParseNode node) private static PatternFieldMap ResponsePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; public static OpenApiResponse LoadResponse(ParseNode node) @@ -512,10 +511,9 @@ public static OpenApiCallback LoadCallback(ParseNode node) private static PatternFieldMap LinkPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; - public static OpenApiLink LoadLink(ParseNode node) { var mapNode = node.CheckMapNode("link"); @@ -547,7 +545,7 @@ public static OpenApiLink LoadLink(ParseNode node) private static PatternFieldMap HeaderPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }, }; @@ -575,7 +573,7 @@ public static OpenApiHeader LoadHeader(ParseNode node) private static PatternFieldMap ExamplePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiExample LoadExample(ParseNode node) @@ -676,7 +674,7 @@ internal static OpenApiTag LoadTag(ParseNode n) private static PatternFieldMap SchemaPatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiSchema LoadSchema(string schema) @@ -727,7 +725,7 @@ public static OpenApiSchema LoadSchema(ParseNode node) private static PatternFieldMap SecuritySchemePatternFields = new PatternFieldMap { - { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } + { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) } }; public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node) @@ -764,9 +762,9 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node) #endregion - public static IReference LoadReference(OpenApiReference pointer, object rootNode) + public static IOpenApiReference LoadReference(OpenApiReference pointer, object rootNode) { - IReference referencedObject = null; + IOpenApiReference referencedObject = null; var node = ((RootNode)rootNode).Find(pointer.GetLocalPointer()); if (node == null && pointer.ReferenceType != ReferenceType.Tags) return null; diff --git a/src/Microsoft.OpenApi.Readers/YamlReaders/ParseNode.cs b/src/Microsoft.OpenApi.Readers/YamlReaders/ParseNode.cs index 48a112464..843f13acf 100644 --- a/src/Microsoft.OpenApi.Readers/YamlReaders/ParseNode.cs +++ b/src/Microsoft.OpenApi.Readers/YamlReaders/ParseNode.cs @@ -49,7 +49,7 @@ public virtual Dictionary CreateMap(Func map) { throw new OpenApiException("Cannot create map"); } - public virtual Dictionary CreateMapWithReference(string refpointer, Func map) where T : class, IReference + public virtual Dictionary CreateMapWithReference(string refpointer, Func map) where T : class, IOpenApiReference { throw new OpenApiException("Cannot create map from reference"); } diff --git a/src/Microsoft.OpenApi.Readers/YamlReaders/ParsingContext.cs b/src/Microsoft.OpenApi.Readers/YamlReaders/ParsingContext.cs index 760897287..401491162 100644 --- a/src/Microsoft.OpenApi.Readers/YamlReaders/ParsingContext.cs +++ b/src/Microsoft.OpenApi.Readers/YamlReaders/ParsingContext.cs @@ -15,9 +15,9 @@ public class ParsingContext : ILog private readonly Stack previousPointers = new Stack(); - private IReferenceService referenceService; + private IOpenApiReferenceService referenceService; - private readonly Dictionary referenceStore = new Dictionary(); + private readonly Dictionary referenceStore = new Dictionary(); private readonly Dictionary tempStorage = new Dictionary(); @@ -37,15 +37,15 @@ public string GetLocation() return "#/" + string.Join("/", currentLocation.Reverse().ToArray()); } - public IReference GetReferencedObject(string pointer) + public IOpenApiReference GetReferencedObject(string pointer) { var reference = referenceService.ParseReference(pointer); return GetReferencedObject(reference); } - public IReference GetReferencedObject(OpenApiReference reference) + public IOpenApiReference GetReferencedObject(OpenApiReference reference) { - IReference returnValue = null; + IOpenApiReference returnValue = null; referenceStore.TryGetValue(reference.ToString(), out returnValue); if (returnValue == null) @@ -83,7 +83,7 @@ public T GetTempStorage(string key) where T : class return null; } - public void SetReferenceService(IReferenceService referenceService) + public void SetReferenceService(IOpenApiReferenceService referenceService) { this.referenceService = referenceService; } diff --git a/src/Microsoft.OpenApi.Readers/YamlReaders/ReferenceService.cs b/src/Microsoft.OpenApi.Readers/YamlReaders/ReferenceService.cs index aeff55918..0bef85fc7 100644 --- a/src/Microsoft.OpenApi.Readers/YamlReaders/ReferenceService.cs +++ b/src/Microsoft.OpenApi.Readers/YamlReaders/ReferenceService.cs @@ -3,9 +3,9 @@ namespace Microsoft.OpenApi.Readers.YamlReaders { - internal class ReferenceService : IReferenceService + internal class ReferenceService : IOpenApiReferenceService { - public Func loadReference { get; set; } + public Func loadReference { get; set; } public Func parseReference { get; set; } private object rootNode; @@ -14,7 +14,7 @@ public ReferenceService(object rootNode) { this.rootNode = rootNode; } - public IReference LoadReference(OpenApiReference reference) + public IOpenApiReference LoadReference(OpenApiReference reference) { var referenceObject = this.loadReference(reference,this.rootNode); if (referenceObject == null) diff --git a/src/Microsoft.OpenApi/IOpenApiExtension.cs b/src/Microsoft.OpenApi/Abstracts/IOpenApiElement.cs similarity index 65% rename from src/Microsoft.OpenApi/IOpenApiExtension.cs rename to src/Microsoft.OpenApi/Abstracts/IOpenApiElement.cs index 6dbc58070..265bab2e7 100644 --- a/src/Microsoft.OpenApi/IOpenApiExtension.cs +++ b/src/Microsoft.OpenApi/Abstracts/IOpenApiElement.cs @@ -1,12 +1,15 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- namespace Microsoft.OpenApi { - public interface IOpenApiExtension + /// + /// Represents an Open API element. + /// + public interface IOpenApiElement { } } diff --git a/src/Microsoft.OpenApi/Abstracts/IOpenApiExtension.cs b/src/Microsoft.OpenApi/Abstracts/IOpenApiExtension.cs new file mode 100644 index 000000000..4b078bee0 --- /dev/null +++ b/src/Microsoft.OpenApi/Abstracts/IOpenApiExtension.cs @@ -0,0 +1,21 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Represents an Extensible Open API element. + /// + public interface IOpenApiExtension : IOpenApiElement + { + /// + /// Specification extensions. + /// + IDictionary Extensions { get; set; } + } +} diff --git a/src/Microsoft.OpenApi/IReference.cs b/src/Microsoft.OpenApi/Abstracts/IOpenApiReference.cs similarity index 57% rename from src/Microsoft.OpenApi/IReference.cs rename to src/Microsoft.OpenApi/Abstracts/IOpenApiReference.cs index 11ef32372..48e86fcec 100644 --- a/src/Microsoft.OpenApi/IReference.cs +++ b/src/Microsoft.OpenApi/Abstracts/IOpenApiReference.cs @@ -1,13 +1,19 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- namespace Microsoft.OpenApi { - public interface IReference + /// + /// Represents an Open API element is referencable. + /// + public interface IOpenApiReference : IOpenApiElement { + /// + /// Reference object. + /// OpenApiReference Pointer { get; set; } } } diff --git a/src/Microsoft.OpenApi/IReferenceService.cs b/src/Microsoft.OpenApi/Abstracts/IOpenApiReferenceService.cs similarity index 67% rename from src/Microsoft.OpenApi/IReferenceService.cs rename to src/Microsoft.OpenApi/Abstracts/IOpenApiReferenceService.cs index 0108b3f7c..a0baea3a6 100644 --- a/src/Microsoft.OpenApi/IReferenceService.cs +++ b/src/Microsoft.OpenApi/Abstracts/IOpenApiReferenceService.cs @@ -1,14 +1,14 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- namespace Microsoft.OpenApi { - public interface IReferenceService + public interface IOpenApiReferenceService { - IReference LoadReference(OpenApiReference reference); + IOpenApiReference LoadReference(OpenApiReference reference); OpenApiReference ParseReference(string pointer); } } diff --git a/src/Microsoft.OpenApi/GenericOpenApiExtension.cs b/src/Microsoft.OpenApi/GenericOpenApiExtension.cs deleted file mode 100644 index 05dbc77c0..000000000 --- a/src/Microsoft.OpenApi/GenericOpenApiExtension.cs +++ /dev/null @@ -1,17 +0,0 @@ -//--------------------------------------------------------------------- -// -// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. -// -//--------------------------------------------------------------------- - -namespace Microsoft.OpenApi -{ - public class GenericOpenApiExtension : IOpenApiExtension - { - string node; - public GenericOpenApiExtension(string n) - { - this.node = n; - } - } -} diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 792f10d79..1a837a7cc 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -11,12 +11,12 @@ namespace Microsoft.OpenApi /// /// Callback Object: A map of possible out-of band callbacks related to the parent operation. /// - public class OpenApiCallback : IReference + public class OpenApiCallback : IOpenApiReference, IOpenApiExtension { public Dictionary PathItems { get; set; } = new Dictionary(); public OpenApiReference Pointer { get; set; } - public Dictionary Extensions { get; set; } + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 3946ff562..f03a45ac3 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -11,18 +11,18 @@ namespace Microsoft.OpenApi /// /// Components Object. /// - public class OpenApiComponents + public class OpenApiComponents : IOpenApiExtension { - public Dictionary Schemas { get; set; } = new Dictionary(); - public Dictionary Responses { get; set; } = new Dictionary(); - public Dictionary Parameters { get; set; } = new Dictionary(); - public Dictionary Examples { get; set; } = new Dictionary(); - public Dictionary RequestBodies { get; set; } = new Dictionary(); - public Dictionary Headers { get; set; } = new Dictionary(); - public Dictionary SecuritySchemes { get; set; } = new Dictionary(); - public Dictionary Links { get; set; } = new Dictionary(); - public Dictionary Callbacks { get; set; } = new Dictionary(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Schemas { get; set; } = new Dictionary(); + public IDictionary Responses { get; set; } = new Dictionary(); + public IDictionary Parameters { get; set; } = new Dictionary(); + public IDictionary Examples { get; set; } = new Dictionary(); + public IDictionary RequestBodies { get; set; } = new Dictionary(); + public IDictionary Headers { get; set; } = new Dictionary(); + public IDictionary SecuritySchemes { get; set; } = new Dictionary(); + public IDictionary Links { get; set; } = new Dictionary(); + public IDictionary Callbacks { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } public bool IsEmpty() { @@ -34,9 +34,7 @@ public bool IsEmpty() || this.Headers.Count > 0 || this.SecuritySchemes.Count > 0 || this.Links.Count > 0 - || this.Callbacks.Count > 0 - || this.Extensions.Count > 0); - + || this.Callbacks.Count > 0); } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index e8f216fa3..2e92320a0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi /// /// Contact Object. /// - public class OpenApiContact + public class OpenApiContact : IOpenApiExtension { /// /// The identifying name of the contact person/organization. @@ -33,6 +33,6 @@ public class OpenApiContact /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } = new Dictionary(); } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 97a728641..606801d9b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi /// /// Describes an Open API Document. See: https://swagger.io/specification /// - public class OpenApiDocument + public class OpenApiDocument : IOpenApiExtension { string version; public string Version { get { return version; } @@ -29,13 +29,13 @@ public class OpenApiDocument public OpenApiInfo Info { get; set; } = new OpenApiInfo(); - public List Servers { get; set; } = new List(); - public List SecurityRequirements { get; set; } + public IList Servers { get; set; } = new List(); + public IList SecurityRequirements { get; set; } public OpenApiPaths Paths { get; set; } = new OpenApiPaths(); public OpenApiComponents Components { get; set; } = new OpenApiComponents(); - public List Tags { get; set; } = new List(); + public IList Tags { get; set; } = new List(); public OpenApiExternalDocs ExternalDocs { get; set; } = new OpenApiExternalDocs(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } private static Regex versionRegex = new Regex(@"\d+\.\d+\.\d+"); @@ -45,6 +45,5 @@ public void CreatePath(string key, Action configure) configure(pathItem); Paths.Add(key, pathItem); } - } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 12604ba7f..7f2c0b092 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi /// /// Example Object. /// - public class OpenApiExample : IReference + public class OpenApiExample : IOpenApiReference, IOpenApiExtension { /// /// Short description for the example. @@ -31,7 +31,7 @@ public class OpenApiExample : IReference /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } public OpenApiReference Pointer { diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index d4219fbf9..7095f8602 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -5,13 +5,14 @@ //--------------------------------------------------------------------- using System; +using System.Collections.Generic; namespace Microsoft.OpenApi { /// /// ExternalDocs object. /// - public class OpenApiExternalDocs + public class OpenApiExternalDocs : IOpenApiExtension { /// /// REQUIRED.The URL for the target documentation. Value MUST be in the format of a URL. @@ -22,5 +23,10 @@ public class OpenApiExternalDocs /// A short description of the target documentation. /// public Uri Url { get; set; } + + /// + /// This object MAY be extended with Specification Extensions. + /// + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 3d6aaa354..8423d3db0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi /// Header Object. /// The Header Object follows the structure of the Parameter Object /// - public class OpenApiHeader : IReference + public class OpenApiHeader : IOpenApiReference, IOpenApiExtension { public OpenApiReference Pointer { get; set; } public string Description { get; set; } @@ -24,9 +24,9 @@ public class OpenApiHeader : IReference public bool AllowReserved { get; set; } public OpenApiSchema Schema { get; set; } public string Example { get; set; } - public List Examples { get; set; } - public Dictionary Content { get; set; } + public IList Examples { get; set; } + public IDictionary Content { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index d2189fb01..1936b8b54 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi /// /// Open API Info Object, it provides the metadata about the Open API. /// - public class OpenApiInfo + public class OpenApiInfo : IOpenApiExtension { /// /// REQUIRED. The title of the application. @@ -60,7 +60,7 @@ public string TermsOfService /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } = new Dictionary(); private static Regex versionRegex = new Regex(@"\d+\.\d+\.\d+"); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 4eb4f6ee6..be280f2f3 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi /// /// License Object. /// - public class OpenApiLicense + public class OpenApiLicense : IOpenApiExtension { // /// REQUIRED.The license name used for the API. @@ -27,6 +27,6 @@ public class OpenApiLicense /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } = new Dictionary(); } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 2f80f21b7..acef64ef2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi /// /// Link Object. /// - public class OpenApiLink : IReference + public class OpenApiLink : IOpenApiReference, IOpenApiExtension { public string Href { get; set; } public string OperationId { get; set; } @@ -19,11 +19,9 @@ public class OpenApiLink : IReference public RuntimeExpression RequestBody { get; set; } public string Description { get; set; } - public Dictionary Extensions { get; set; } - - public OpenApiReference Pointer { get; set; } + public IDictionary Extensions { get; set; } - + public OpenApiReference Pointer { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index ede7c0df7..fcf6aa7c3 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -11,12 +11,12 @@ namespace Microsoft.OpenApi /// /// Media Type Object. /// - public class OpenApiMediaType + public class OpenApiMediaType : IOpenApiExtension { public OpenApiSchema Schema { get; set; } - public Dictionary Examples { get; set; } + public IDictionary Examples { get; set; } public string Example { get; set; } - public Dictionary Extensions { get; set; } + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 622e0995a..11b01de2b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -12,23 +12,23 @@ namespace Microsoft.OpenApi /// /// Operation Object. /// - public class OpenApiOperation + public class OpenApiOperation : IOpenApiExtension { - public List Tags { get; set; } = new List(); + public IList Tags { get; set; } = new List(); public string Summary { get; set; } public string Description { get; set; } public OpenApiExternalDocs ExternalDocs { get; set; } public string OperationId { get; set; } - public List Parameters { get; set; } = new List(); + public IList Parameters { get; set; } = new List(); public OpenApiRequestBody RequestBody { get; set; } - public Dictionary Responses { get; set; } = new Dictionary(); - public Dictionary Callbacks { get; set; } = new Dictionary(); + public IDictionary Responses { get; set; } = new Dictionary(); + public IDictionary Callbacks { get; set; } = new Dictionary(); public const bool DeprecatedDefault = false; public bool Deprecated { get; set; } = DeprecatedDefault; - public List Security { get; set; } = new List(); - public List Servers { get; set; } = new List(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IList Security { get; set; } = new List(); + public IList Servers { get; set; } = new List(); + public IDictionary Extensions { get; set; } public void CreateResponse(string key, Action configure) { diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 55a24b141..474a34fc3 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -19,7 +19,7 @@ public enum InEnum /// /// Parameter Object. /// - public class OpenApiParameter : IReference + public class OpenApiParameter : IOpenApiReference, IOpenApiExtension { public OpenApiReference Pointer { get; set; } public string Name { get; set; } @@ -56,11 +56,9 @@ public bool Required public bool Explode { get; set; } public bool AllowReserved { get; set; } public OpenApiSchema Schema { get; set; } - public List Examples { get; set; } = new List(); + public IList Examples { get; set; } = new List(); public string Example { get; set; } - public Dictionary Content { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); - - + public IDictionary Content { get; set; } + public IDictionary Extensions { get; set; } } - } \ No newline at end of file +} diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 71d26ef56..0d8803790 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -13,17 +13,17 @@ namespace Microsoft.OpenApi /// /// Path Item Object: to describe the operations available on a single path. /// - public class OpenApiPathItem + public class OpenApiPathItem : IOpenApiExtension { public string Summary { get; set; } public string Description { get; set; } - public IReadOnlyDictionary Operations { get { return operations; } } + public IDictionary Operations { get { return operations; } } private Dictionary operations = new Dictionary(); - public List Servers { get; set; } = new List(); - public List Parameters { get; set; } = new List(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IList Servers { get; set; } = new List(); + public IList Parameters { get; set; } = new List(); + public IDictionary Extensions { get; set; } public void CreateOperation(OperationType operationType, Action configure) { diff --git a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs index a9b2d5387..61886d2be 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs @@ -12,12 +12,12 @@ namespace Microsoft.OpenApi /// /// Paths object. /// - public class OpenApiPaths : IDictionary + public class OpenApiPaths : IDictionary, IOpenApiExtension { public OpenApiPathItem this[string key] { get => this.PathItems[key]; set => this.PathItems[key] = value; } private IDictionary PathItems { get; set; } = new Dictionary(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } public ICollection Keys => this.PathItems.Keys; diff --git a/src/Microsoft.OpenApi/Models/OpenApiReference.cs b/src/Microsoft.OpenApi/Models/OpenApiReference.cs index 64fa8ed23..bd724b357 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiReference.cs @@ -22,7 +22,7 @@ public enum ReferenceType Tags } - public class OpenApiReference + public class OpenApiReference : IOpenApiElement { public ReferenceType ReferenceType { get; set; } public string TypeName { get; set; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 2c8c6e072..b7ed7dafa 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -12,13 +12,13 @@ namespace Microsoft.OpenApi /// /// Request Body Object /// - public class OpenApiRequestBody : IReference + public class OpenApiRequestBody : IOpenApiReference, IOpenApiExtension { public OpenApiReference Pointer { get; set; } public string Description { get; set; } public Boolean Required { get; set; } - public Dictionary Content { get; set; } - public Dictionary Extensions { get; set; } + public IDictionary Content { get; set; } + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 8ee0faed3..707717391 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -12,13 +12,13 @@ namespace Microsoft.OpenApi /// /// Response object. /// - public class OpenApiResponse : IReference + public class OpenApiResponse : IOpenApiReference, IOpenApiExtension { public string Description { get; set; } - public Dictionary Content { get; set; } - public Dictionary Headers { get; set; } - public Dictionary Links { get; set; } - public Dictionary Extensions { get; set; } + public IDictionary Content { get; set; } + public IDictionary Headers { get; set; } + public IDictionary Links { get; set; } + public IDictionary Extensions { get; set; } public OpenApiReference Pointer { diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 44eadb57e..4f1eb9d1d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi /// /// Schema Object. /// - public class OpenApiSchema : IReference + public class OpenApiSchema : IOpenApiReference, IOpenApiExtension { public string Title { get; set; } public string Type { get; set; } @@ -28,28 +28,36 @@ public class OpenApiSchema : IReference public string Default { get; set; } public bool ReadOnly { get; set; } public bool WriteOnly { get; set; } - public List AllOf { get; set; } - public List OneOf { get; set; } - public List AnyOf { get; set; } + public IList AllOf { get; set; } + public IList OneOf { get; set; } + public IList AnyOf { get; set; } public OpenApiSchema Not { get; set; } public string[] Required { get; set; } public OpenApiSchema Items { get; set; } public int? MaxItems { get; set; } public int? MinItems { get; set; } public bool UniqueItems { get; set; } - public Dictionary Properties { get; set; } + public IDictionary Properties { get; set; } public int? MaxProperties { get; set; } public int? MinProperties { get; set; } public bool AdditionalPropertiesAllowed { get; set; } public OpenApiSchema AdditionalProperties { get; set; } public string Example { get; set; } - public List Enum { get; set; } = new List(); + public IList Enum { get; set; } = new List(); public bool Nullable { get; set; } public OpenApiExternalDocs ExternalDocs { get; set; } public bool Deprecated { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); + /// + /// Adds additional metadata to describe the XML representation of this property. + /// + public OpenApiXml Xml { get; set; } + + /// + /// Specification Extensions. + /// + public IDictionary Extensions { get; set; } public OpenApiReference Pointer { diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs index abb6b4ba2..3273fe2ea 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi /// /// Security Requirement Object /// - public class OpenApiSecurityRequirement + public class OpenApiSecurityRequirement : IOpenApiElement { public Dictionary> Schemes { get; set; } = new Dictionary>(); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index cc32aa0be..0bdbd4769 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi /// /// Security Scheme Object. /// - public class OpenApiSecurityScheme : IReference + public class OpenApiSecurityScheme : IOpenApiReference, IOpenApiExtension { public string Key { get; set; } public string Type { get; set; } @@ -25,9 +25,9 @@ public class OpenApiSecurityScheme : IReference public string Flow { get; set; } public Uri AuthorizationUrl { get; set; } public Uri TokenUrl { get; set; } - public Dictionary Scopes { get; set; } + public IDictionary Scopes { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } public OpenApiReference Pointer { diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index f4be8d780..df2bf585a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -11,12 +11,12 @@ namespace Microsoft.OpenApi /// /// Server Object: an object representing a Server. /// - public class OpenApiServer + public class OpenApiServer : IOpenApiExtension { public string Description { get; set; } public string Url { get; set; } - public Dictionary Variables { get; set; } = new Dictionary(); + public IDictionary Variables { get; set; } = new Dictionary(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 471e622c1..d26f5e23d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -11,12 +11,12 @@ namespace Microsoft.OpenApi /// /// Server Variable Object. /// - public class OpenApiServerVariable + public class OpenApiServerVariable : IOpenApiExtension { public string Description { get; set; } public string Default { get; set; } public List Enum { get; set; } = new List(); - public Dictionary Extensions { get; set; } = new Dictionary(); + public IDictionary Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 090db16a4..d671ae1e9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -4,12 +4,14 @@ // //--------------------------------------------------------------------- +using System.Collections.Generic; + namespace Microsoft.OpenApi { /// /// Tag Object. /// - public class OpenApiTag : IReference + public class OpenApiTag : IOpenApiReference, IOpenApiExtension { /// /// The name of the tag. @@ -26,7 +28,12 @@ public class OpenApiTag : IReference /// public OpenApiExternalDocs ExternalDocs { get; set; } - OpenApiReference IReference.Pointer + /// + /// This object MAY be extended with Specification Extensions. + /// + public IDictionary Extensions { get; set; } + + OpenApiReference IOpenApiReference.Pointer { get; set; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs new file mode 100644 index 000000000..a593b60c4 --- /dev/null +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -0,0 +1,49 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// XML Object. + /// + public class OpenApiXml : IOpenApiExtension + { + /// + /// Replaces the name of the element/attribute used for the described schema property. + /// + public string Name { get; set; } + + /// + /// The URI of the namespace definition. + /// + public Uri Namespace { get; set; } + + /// + /// The prefix to be used for the name + /// + public string Prefix { get; set; } + + /// + /// Declares whether the property definition translates to an attribute instead of an element. + /// Default value is false. + /// + public bool Attribute { get; set; } + + /// + /// Signifies whether the array is wrapped. + /// Default value is false. + /// + public bool Wrapped { get; set; } + + /// + /// Specification Extensions. + /// + public IDictionary Extensions { get; set; } + } +} diff --git a/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs index da0aa2ed7..cbd9fb8d1 100644 --- a/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs @@ -12,23 +12,23 @@ public abstract class OpenApiVisitorBase { public virtual void Visit(OpenApiDocument doc) { } public virtual void Visit(OpenApiInfo info) { } - public virtual void Visit(List servers) { } + public virtual void Visit(IList servers) { } public virtual void Visit(OpenApiServer server) { } public virtual void Visit(OpenApiPaths paths) { } public virtual void Visit(OpenApiPathItem pathItem) { } public virtual void Visit(OpenApiServerVariable serverVariable) { } - public virtual void Visit(IReadOnlyDictionary operations) { } + public virtual void Visit(IDictionary operations) { } public virtual void Visit(OpenApiOperation operation) { } - public virtual void Visit(List parameters) { } + public virtual void Visit(IList parameters) { } public virtual void Visit(OpenApiParameter parameter) { } public virtual void Visit(OpenApiRequestBody requestBody) { } - public virtual void Visit(IReadOnlyDictionary responses) { } + public virtual void Visit(IDictionary responses) { } public virtual void Visit(OpenApiResponse response) { } - public virtual void Visit(Dictionary content) { } + public virtual void Visit(IDictionary content) { } public virtual void Visit(OpenApiMediaType mediaType) { } - public virtual void Visit(Dictionary example) { } + public virtual void Visit(IDictionary example) { } public virtual void Visit(OpenApiSchema example) { } - public virtual void Visit(Dictionary links) { } + public virtual void Visit(IDictionary links) { } public virtual void Visit(OpenApiLink link) { } } } diff --git a/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs b/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs index 9533e6e18..de513e5aa 100644 --- a/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs +++ b/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs @@ -80,7 +80,7 @@ public void Walk(OpenApiDocument doc) } } - private void WalkContent(Dictionary content) + private void WalkContent(IDictionary content) { if (content == null) return; diff --git a/src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiReferenceWriterExtensions.cs similarity index 65% rename from src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs rename to src/Microsoft.OpenApi/Writers/OpenApiReferenceWriterExtensions.cs index 65fd5541b..ca6721795 100644 --- a/src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiReferenceWriterExtensions.cs @@ -1,26 +1,23 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- namespace Microsoft.OpenApi.Writers { - using Microsoft.OpenApi; - - public static class IReferenceExtensions + public static class OpenApiReferenceWriterExtensions { - public static bool IsReference(this IReference reference) + public static bool IsReference(this IOpenApiReference reference) { return reference.Pointer != null; } - public static void WriteRef(this IReference reference, IOpenApiWriter writer) + public static void WriteRef(this IOpenApiReference reference, IOpenApiWriter writer) { writer.WriteStartObject(); writer.WriteStringProperty("$ref", reference.Pointer.ToString()); writer.WriteEndObject(); } - } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs index 2602f58c8..ad4fa0538 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs @@ -116,7 +116,6 @@ public void TestRequestBody() Assert.Equal("body", (string)bodyparam["in"]); Assert.Equal("string", (string)bodyparam["schema"]["type"]); Assert.Equal("100", (string)bodyparam["schema"]["maxLength"]); - } [Fact] diff --git a/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs b/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs index ebf977a85..24b85002a 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs @@ -25,7 +25,6 @@ public void CheckPetStoreApiInfo() [Fact] public void ParseCompleteHeaderOpenApi() { - var stream = this.GetType().Assembly.GetManifestResourceStream(typeof(InfoTests), "Samples.CompleteHeader.yaml"); var openApiDoc = new OpenApiStreamReader().Read(stream, out var context);