From 9cd1efeed37e6c7b9cd257cec0959e4a72ba34d7 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 13 Oct 2017 17:33:14 -0700 Subject: [PATCH] Modify the Open Api object class name & add the copyright head --- .../OpenApiV2Reader.cs | 182 ++++++++--------- .../OpenApiV3Reader.cs | 186 +++++++++--------- .../ReferenceService.cs | 10 +- src/Microsoft.OpenApi.Workbench/MainModel.cs | 2 - src/Microsoft.OpenApi/Callback.cs | 19 -- src/Microsoft.OpenApi/Components.cs | 37 ---- src/Microsoft.OpenApi/Contact.cs | 15 -- src/Microsoft.OpenApi/DomainParseException.cs | 16 -- src/Microsoft.OpenApi/Example.cs | 26 --- src/Microsoft.OpenApi/ExternalDocs.cs | 12 -- .../GenericOpenApiExtension.cs | 10 +- src/Microsoft.OpenApi/Header.cs | 27 --- src/Microsoft.OpenApi/IOpenApiExtension.cs | 10 +- src/Microsoft.OpenApi/IReference.cs | 9 +- src/Microsoft.OpenApi/IReferenceService.cs | 9 +- src/Microsoft.OpenApi/Info.cs | 36 ---- src/Microsoft.OpenApi/JsonPointer.cs | 12 +- src/Microsoft.OpenApi/License.cs | 17 -- src/Microsoft.OpenApi/Link.cs | 25 --- src/Microsoft.OpenApi/MediaType.cs | 20 -- src/Microsoft.OpenApi/OpenApiCallback.cs | 22 +++ src/Microsoft.OpenApi/OpenApiComponents.cs | 42 ++++ src/Microsoft.OpenApi/OpenApiContact.cs | 38 ++++ src/Microsoft.OpenApi/OpenApiDiscriminator.cs | 15 ++ src/Microsoft.OpenApi/OpenApiDocument.cs | 34 ++-- src/Microsoft.OpenApi/OpenApiExample.cs | 41 ++++ src/Microsoft.OpenApi/OpenApiException.cs | 22 +++ src/Microsoft.OpenApi/OpenApiExternalDocs.cs | 26 +++ src/Microsoft.OpenApi/OpenApiHeader.cs | 32 +++ src/Microsoft.OpenApi/OpenApiInfo.cs | 67 +++++++ src/Microsoft.OpenApi/OpenApiLicense.cs | 32 +++ src/Microsoft.OpenApi/OpenApiLink.cs | 29 +++ src/Microsoft.OpenApi/OpenApiMediaType.cs | 22 +++ src/Microsoft.OpenApi/OpenApiOperation.cs | 40 ++++ .../{Parameter.cs => OpenApiParameter.cs} | 26 ++- src/Microsoft.OpenApi/OpenApiPathItem.cs | 46 +++++ .../{Paths.cs => OpenApiPaths.cs} | 32 +-- src/Microsoft.OpenApi/OpenApiReference.cs | 13 +- src/Microsoft.OpenApi/OpenApiRequestBody.cs | 24 +++ src/Microsoft.OpenApi/OpenApiResponse.cs | 39 ++++ .../{Schema.cs => OpenApiSchema.cs} | 36 ++-- .../OpenApiSecurityRequirement.cs | 18 ++ ...rityScheme.cs => OpenApiSecurityScheme.cs} | 22 ++- src/Microsoft.OpenApi/OpenApiServer.cs | 22 +++ .../OpenApiServerVariable.cs | 22 +++ src/Microsoft.OpenApi/OpenApiTag.cs | 29 +++ src/Microsoft.OpenApi/Operation.cs | 33 ---- src/Microsoft.OpenApi/OperationType.cs | 8 +- src/Microsoft.OpenApi/PathItem.cs | 41 ---- src/Microsoft.OpenApi/RequestBody.cs | 18 -- src/Microsoft.OpenApi/Response.cs | 32 --- src/Microsoft.OpenApi/RuntimeExpression.cs | 8 +- src/Microsoft.OpenApi/SecurityRequirement.cs | 13 -- src/Microsoft.OpenApi/Server.cs | 17 -- src/Microsoft.OpenApi/ServerVariable.cs | 18 -- src/Microsoft.OpenApi/Sevices/OpenAPIDiff.cs | 19 +- .../Sevices/OpenApiValidator.cs | 12 +- .../Sevices/OpenApiVisitorBase.cs | 46 +++-- .../Sevices/OpenApiWalker.cs | 10 +- src/Microsoft.OpenApi/Tag.cs | 18 -- .../Writers/IOpenApiWriter.cs | 7 +- .../Writers/IParseNodeWriter.cs | 8 +- .../Writers/IReferenceExtensions.cs | 8 +- .../Writers/JsonParseNodeWriter.cs | 8 +- .../Writers/OpenApiV2Writer.cs | 79 ++++---- .../Writers/OpenApiV3Writer.cs | 82 ++++---- .../Writers/WriterExtensions.cs | 13 +- .../Writers/YamlParseNodeWriter.cs | 8 +- .../BasicTests.cs | 2 +- .../CallbackTests.cs | 10 +- .../DownGradeTests.cs | 52 ++--- .../FixtureTests.cs | 4 +- .../InfoTests.cs | 4 +- .../ParameterTests.cs | 12 +- test/Microsoft.OpenApi.Tests/ExampleTests.cs | 4 +- 75 files changed, 1177 insertions(+), 888 deletions(-) delete mode 100644 src/Microsoft.OpenApi/Callback.cs delete mode 100644 src/Microsoft.OpenApi/Components.cs delete mode 100644 src/Microsoft.OpenApi/Contact.cs delete mode 100644 src/Microsoft.OpenApi/DomainParseException.cs delete mode 100644 src/Microsoft.OpenApi/Example.cs delete mode 100644 src/Microsoft.OpenApi/ExternalDocs.cs delete mode 100644 src/Microsoft.OpenApi/Header.cs delete mode 100644 src/Microsoft.OpenApi/Info.cs delete mode 100644 src/Microsoft.OpenApi/License.cs delete mode 100644 src/Microsoft.OpenApi/Link.cs delete mode 100644 src/Microsoft.OpenApi/MediaType.cs create mode 100644 src/Microsoft.OpenApi/OpenApiCallback.cs create mode 100644 src/Microsoft.OpenApi/OpenApiComponents.cs create mode 100644 src/Microsoft.OpenApi/OpenApiContact.cs create mode 100644 src/Microsoft.OpenApi/OpenApiDiscriminator.cs create mode 100644 src/Microsoft.OpenApi/OpenApiExample.cs create mode 100644 src/Microsoft.OpenApi/OpenApiException.cs create mode 100644 src/Microsoft.OpenApi/OpenApiExternalDocs.cs create mode 100644 src/Microsoft.OpenApi/OpenApiHeader.cs create mode 100644 src/Microsoft.OpenApi/OpenApiInfo.cs create mode 100644 src/Microsoft.OpenApi/OpenApiLicense.cs create mode 100644 src/Microsoft.OpenApi/OpenApiLink.cs create mode 100644 src/Microsoft.OpenApi/OpenApiMediaType.cs create mode 100644 src/Microsoft.OpenApi/OpenApiOperation.cs rename src/Microsoft.OpenApi/{Parameter.cs => OpenApiParameter.cs} (65%) create mode 100644 src/Microsoft.OpenApi/OpenApiPathItem.cs rename src/Microsoft.OpenApi/{Paths.cs => OpenApiPaths.cs} (51%) create mode 100644 src/Microsoft.OpenApi/OpenApiRequestBody.cs create mode 100644 src/Microsoft.OpenApi/OpenApiResponse.cs rename src/Microsoft.OpenApi/{Schema.cs => OpenApiSchema.cs} (62%) create mode 100644 src/Microsoft.OpenApi/OpenApiSecurityRequirement.cs rename src/Microsoft.OpenApi/{SecurityScheme.cs => OpenApiSecurityScheme.cs} (60%) create mode 100644 src/Microsoft.OpenApi/OpenApiServer.cs create mode 100644 src/Microsoft.OpenApi/OpenApiServerVariable.cs create mode 100644 src/Microsoft.OpenApi/OpenApiTag.cs delete mode 100644 src/Microsoft.OpenApi/Operation.cs delete mode 100644 src/Microsoft.OpenApi/PathItem.cs delete mode 100644 src/Microsoft.OpenApi/RequestBody.cs delete mode 100644 src/Microsoft.OpenApi/Response.cs delete mode 100644 src/Microsoft.OpenApi/SecurityRequirement.cs delete mode 100644 src/Microsoft.OpenApi/Server.cs delete mode 100644 src/Microsoft.OpenApi/ServerVariable.cs delete mode 100644 src/Microsoft.OpenApi/Tag.cs diff --git a/src/Microsoft.OpenApi.Readers/OpenApiV2Reader.cs b/src/Microsoft.OpenApi.Readers/OpenApiV2Reader.cs index 527c1fbef..dc4eb29d2 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiV2Reader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiV2Reader.cs @@ -31,7 +31,7 @@ public static class OpenApiV2Reader - private static void MakeServers(List servers, ParsingContext context) + private static void MakeServers(List servers, ParsingContext context) { string host = context.GetTempStorage("host"); string basePath = context.GetTempStorage("basePath"); @@ -41,7 +41,7 @@ private static void MakeServers(List servers, ParsingContext context) { foreach (var scheme in schemes) { - var server = new Server(); + var server = new OpenApiServer(); server.Url = scheme + "://" + (host ?? "example.org/") + (basePath ?? "/"); servers.Add(server); } @@ -76,27 +76,27 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) #region InfoObject - public static FixedFieldMap InfoFixedFields = new FixedFieldMap + public static FixedFieldMap InfoFixedFields = new FixedFieldMap { { "title", (o,n) => { o.Title = n.GetScalarValue(); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "termsOfService", (o,n) => { o.TermsOfService = n.GetScalarValue(); } }, { "contact", (o,n) => { o.Contact = LoadContact(n); } }, { "license", (o,n) => { o.License = LoadLicense(n); } }, - { "version", (o,n) => { o.Version = n.GetScalarValue(); } } + { "version", (o,n) => { o.Version = new Version(n.GetScalarValue()); } } }; - public static PatternFieldMap InfoPatternFields = new PatternFieldMap + public static PatternFieldMap InfoPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Info LoadInfo(ParseNode node) + public static OpenApiInfo LoadInfo(ParseNode node) { var mapNode = node.CheckMapNode("Info"); - var info = new Info(); + var info = new OpenApiInfo(); var required = new List() { "title", "version" }; ParseMap(mapNode, info, InfoFixedFields, InfoPatternFields, required); @@ -111,21 +111,21 @@ public static Info LoadInfo(ParseNode node) #region ContactObject - public static FixedFieldMap ContactFixedFields = new FixedFieldMap { + public static FixedFieldMap ContactFixedFields = new FixedFieldMap { { "name", (o,n) => { o.Name = n.GetScalarValue(); } }, { "url", (o,n) => { o.Url = new Uri(n.GetScalarValue()); } }, { "email", (o,n) => { o.Email = n.GetScalarValue(); } }, }; - public static PatternFieldMap ContactPatternFields = new PatternFieldMap + public static PatternFieldMap ContactPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Contact LoadContact(ParseNode node) + public static OpenApiContact LoadContact(ParseNode node) { var mapNode = node as MapNode; - var contact = new Contact(); + var contact = new OpenApiContact(); ParseMap(mapNode, contact, ContactFixedFields,ContactPatternFields); @@ -136,21 +136,21 @@ public static Contact LoadContact(ParseNode node) #region LicenseObject - public static FixedFieldMap LicenseFixedFields = new FixedFieldMap { + public static FixedFieldMap LicenseFixedFields = new FixedFieldMap { { "name", (o,n) => { o.Name = n.GetScalarValue(); } }, { "url", (o,n) => { o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, }; - public static PatternFieldMap LicensePatternFields = new PatternFieldMap + public static PatternFieldMap LicensePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - internal static License LoadLicense(ParseNode node) + internal static OpenApiLicense LoadLicense(ParseNode node) { - var mapNode = node.CheckMapNode("License"); + var mapNode = node.CheckMapNode("OpenApiLicense"); - var license = new License(); + var license = new OpenApiLicense(); ParseMap(mapNode, license, LicenseFixedFields, LicensePatternFields); @@ -161,21 +161,21 @@ internal static License LoadLicense(ParseNode node) #region PathsObject - public static FixedFieldMap PathsFixedFields = new FixedFieldMap + public static FixedFieldMap PathsFixedFields = new FixedFieldMap { }; - public static PatternFieldMap PathsPatternFields = new PatternFieldMap + public static PatternFieldMap PathsPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("/"), (o,k,n)=> o.Add(k, OpenApiV2Reader.LoadPathItem(n) ) }, { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Paths LoadPaths(ParseNode node) + public static OpenApiPaths LoadPaths(ParseNode node) { MapNode mapNode = node.CheckMapNode("Paths"); - Paths domainObject = new Paths(); + OpenApiPaths domainObject = new OpenApiPaths(); ParseMap(mapNode, domainObject, PathsFixedFields, PathsPatternFields); @@ -185,14 +185,14 @@ public static Paths LoadPaths(ParseNode node) #region PathItemObject - private static FixedFieldMap PathItemFixedFields = new FixedFieldMap + private static FixedFieldMap PathItemFixedFields = new FixedFieldMap { { "$ref", (o,n) => { /* Not supported yet */} }, { "parameters", (o,n) => { o.Parameters = n.CreateList(OpenApiV2Reader.LoadParameter); } }, }; - private static PatternFieldMap PathItemPatternFields = new PatternFieldMap + private static PatternFieldMap PathItemPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, { (s)=> "get,put,post,delete,patch,options,head,patch".Contains(s), @@ -200,11 +200,11 @@ public static Paths LoadPaths(ParseNode node) }; - public static PathItem LoadPathItem(ParseNode node) + public static OpenApiPathItem LoadPathItem(ParseNode node) { var mapNode = node.CheckMapNode("PathItem"); - var pathItem = new PathItem(); + var pathItem = new OpenApiPathItem(); ParseMap(mapNode, pathItem, PathItemFixedFields, PathItemPatternFields); @@ -215,7 +215,7 @@ public static PathItem LoadPathItem(ParseNode node) #region OperationObject - private static FixedFieldMap OperationFixedFields = new FixedFieldMap + private static FixedFieldMap OperationFixedFields = new FixedFieldMap { { "tags", (o,n) => o.Tags = n.CreateSimpleList((v) => ReferenceService.LoadTagByReference(v.Context,v.GetScalarValue()))}, { "summary", (o,n) => { o.Summary = n.GetScalarValue(); } }, @@ -230,28 +230,28 @@ public static PathItem LoadPathItem(ParseNode node) { "security", (o,n) => { o.Security = n.CreateList(LoadSecurityRequirement); } }, }; - private static PatternFieldMap OperationPatternFields = new PatternFieldMap + private static PatternFieldMap OperationPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - internal static Operation LoadOperation(ParseNode node) + internal static OpenApiOperation LoadOperation(ParseNode node) { - var mapNode = node.CheckMapNode("Operation"); + var mapNode = node.CheckMapNode("OpenApiOperation"); - Operation operation = new Operation(); + OpenApiOperation operation = new OpenApiOperation(); ParseMap(mapNode, operation, OperationFixedFields, OperationPatternFields); - // Build request body based on information determined while parsing Operation - var bodyParameter = node.Context.GetTempStorage("bodyParameter"); + // Build request body based on information determined while parsing OpenApiOperation + var bodyParameter = node.Context.GetTempStorage("bodyParameter"); if (bodyParameter != null) { operation.RequestBody = CreateRequestBody(node.Context, bodyParameter); } else { - var formParameters = node.Context.GetTempStorage>("formParameters"); + var formParameters = node.Context.GetTempStorage>("formParameters"); if (formParameters != null) { operation.RequestBody = CreateFormBody(formParameters); @@ -262,36 +262,36 @@ internal static Operation LoadOperation(ParseNode node) return operation; } - private static RequestBody CreateFormBody(List formParameters) + private static OpenApiRequestBody CreateFormBody(List formParameters) { - var mediaType = new MediaType() + var mediaType = new OpenApiMediaType() { - Schema = new Schema() + Schema = new OpenApiSchema() { Properties = formParameters.ToDictionary(k => k.Name, v => v.Schema) } }; - var formBody = new RequestBody() + var formBody = new OpenApiRequestBody() { - Content = new Dictionary() { + Content = new Dictionary() { { "application/x-www-form-urlencoded", mediaType } } }; return formBody; } - private static RequestBody CreateRequestBody(ParsingContext context, Parameter bodyParameter) + private static OpenApiRequestBody CreateRequestBody(ParsingContext context, OpenApiParameter bodyParameter) { var consumes = context.GetTempStorage>("operationproduces") ?? context.GetTempStorage>("globalproduces") ?? new List() { "application/json" }; - var requestBody = new RequestBody() + var requestBody = new OpenApiRequestBody() { Description = bodyParameter.Description, Required = bodyParameter.Required, - Content = consumes.ToDictionary(k => k, v => new MediaType() + Content = consumes.ToDictionary(k => k, v => new OpenApiMediaType() { Schema = bodyParameter.Schema // Should we clone this? }) @@ -304,23 +304,23 @@ private static RequestBody CreateRequestBody(ParsingContext context, Parameter b #region ExternalDocsObject - private static FixedFieldMap ExternalDocsFixedFields = new FixedFieldMap + private static FixedFieldMap ExternalDocsFixedFields = new FixedFieldMap { // $ref { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "url", (o,n) => { o.Url = new Uri(n.GetScalarValue()); } }, }; - private static PatternFieldMap ExternalDocsPatternFields = new PatternFieldMap + private static PatternFieldMap ExternalDocsPatternFields = new PatternFieldMap { }; - public static ExternalDocs LoadExternalDocs(ParseNode node) + public static OpenApiExternalDocs LoadExternalDocs(ParseNode node) { var mapNode = node.CheckMapNode("externalDocs"); - var externalDocs = new ExternalDocs(); + var externalDocs = new OpenApiExternalDocs(); ParseMap(mapNode, externalDocs, ExternalDocsFixedFields, ExternalDocsPatternFields); @@ -331,7 +331,7 @@ public static ExternalDocs LoadExternalDocs(ParseNode node) #region ParameterObject - private static FixedFieldMap ParameterFixedFields = new FixedFieldMap + private static FixedFieldMap ParameterFixedFields = new FixedFieldMap { { "name", (o,n) => { o.Name = n.GetScalarValue(); } }, { "in", (o,n) => { ProcessIn(o,n); } }, @@ -355,7 +355,7 @@ public static ExternalDocs LoadExternalDocs(ParseNode node) { "schema", (o,n) => { o.Schema = LoadSchema(n); } }, }; - private static void LoadStyle(Parameter p, string v) + private static void LoadStyle(OpenApiParameter p, string v) { switch (v) { @@ -377,25 +377,25 @@ private static void LoadStyle(Parameter p, string v) } } - private static Schema GetOrCreateSchema(Parameter p) + private static OpenApiSchema GetOrCreateSchema(OpenApiParameter p) { if (p.Schema == null) { - p.Schema = new Schema(); + p.Schema = new OpenApiSchema(); } return p.Schema; } - private static Schema GetOrCreateSchema(Header p) + private static OpenApiSchema GetOrCreateSchema(OpenApiHeader p) { if (p.Schema == null) { - p.Schema = new Schema(); + p.Schema = new OpenApiSchema(); } return p.Schema; } - private static void ProcessIn(Parameter o, ParseNode n) + private static void ProcessIn(OpenApiParameter o, ParseNode n) { string value = n.GetScalarValue(); @@ -405,10 +405,10 @@ private static void ProcessIn(Parameter o, ParseNode n) n.Context.SetTempStorage("bodyParameter",o); break; case "form": - var formParameters = n.Context.GetTempStorage>("formParameters"); + var formParameters = n.Context.GetTempStorage>("formParameters"); if (formParameters == null) { - formParameters = new List(); + formParameters = new List(); n.Context.SetTempStorage("formParameters", formParameters); } formParameters.Add(o); @@ -420,27 +420,27 @@ private static void ProcessIn(Parameter o, ParseNode n) } - private static PatternFieldMap ParameterPatternFields = new PatternFieldMap + private static PatternFieldMap ParameterPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - public static Parameter LoadParameter(ParseNode node) + public static OpenApiParameter LoadParameter(ParseNode node) { var mapNode = node.CheckMapNode("parameter"); var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } - var parameter = new Parameter(); + var parameter = new OpenApiParameter(); ParseMap(mapNode, parameter, ParameterFixedFields, ParameterPatternFields); - var schema = node.Context.GetTempStorage("schema"); + var schema = node.Context.GetTempStorage("schema"); if (schema != null) { parameter.Schema = schema; @@ -449,7 +449,7 @@ public static Parameter LoadParameter(ParseNode node) if (parameter.In == 0) { - return null; // Don't include Form or Body parameters in Operation.Parameters list + return null; // Don't include Form or Body parameters in OpenApiOperation.Parameters list } return parameter; @@ -458,7 +458,7 @@ public static Parameter LoadParameter(ParseNode node) #region ResponseObject - private static FixedFieldMap ResponseFixedFields = new FixedFieldMap + private static FixedFieldMap ResponseFixedFields = new FixedFieldMap { { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "headers", (o,n) => { o.Headers = n.CreateMap(LoadHeader); } }, @@ -467,16 +467,16 @@ public static Parameter LoadParameter(ParseNode node) }; - private static PatternFieldMap ResponsePatternFields = new PatternFieldMap + private static PatternFieldMap ResponsePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - public static Response LoadResponse(ParseNode node) + public static OpenApiResponse LoadResponse(ParseNode node) { var mapNode = node.CheckMapNode("response"); - var response = new Response(); + var response = new OpenApiResponse(); foreach (var property in mapNode) { property.ParseField(response, ResponseFixedFields, ResponsePatternFields); @@ -487,21 +487,21 @@ public static Response LoadResponse(ParseNode node) return response; } - private static void ProcessProduces(Response response, ParsingContext context) + private static void ProcessProduces(OpenApiResponse response, ParsingContext context) { var produces = context.GetTempStorage>("operationproduces") ?? context.GetTempStorage>("globalproduces") ?? new List() { "application/json" }; - response.Content = new Dictionary(); + response.Content = new Dictionary(); foreach (var mt in produces) { - var schema = context.GetTempStorage("operationschema"); - MediaType mediaType = null; + var schema = context.GetTempStorage("operationschema"); + OpenApiMediaType mediaType = null; if (schema != null) { - mediaType = new MediaType() + mediaType = new OpenApiMediaType() { Schema = schema }; @@ -514,7 +514,7 @@ private static void ProcessProduces(Response response, ParsingContext context) #endregion #region HeaderObject - private static FixedFieldMap
HeaderFixedFields = new FixedFieldMap
+ private static FixedFieldMap HeaderFixedFields = new FixedFieldMap { { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "required", (o,n) => { o.Required = bool.Parse(n.GetScalarValue()); } }, @@ -526,22 +526,22 @@ private static void ProcessProduces(Response response, ParsingContext context) }; - private static PatternFieldMap
HeaderPatternFields = new PatternFieldMap
+ private static PatternFieldMap HeaderPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - public static Header LoadHeader(ParseNode node) + public static OpenApiHeader LoadHeader(ParseNode node) { var mapNode = node.CheckMapNode("header"); - var header = new Header(); + var header = new OpenApiHeader(); foreach (var property in mapNode) { property.ParseField(header, HeaderFixedFields, HeaderPatternFields); } - var schema = node.Context.GetTempStorage("schema"); + var schema = node.Context.GetTempStorage("schema"); if (schema != null) { header.Schema = schema; @@ -554,19 +554,19 @@ public static Header LoadHeader(ParseNode node) #endregion #region ExampleObject - private static FixedFieldMap ExampleFixedFields = new FixedFieldMap + private static FixedFieldMap ExampleFixedFields = new FixedFieldMap { }; - private static PatternFieldMap ExamplePatternFields = new PatternFieldMap + private static PatternFieldMap ExamplePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Example LoadExample(ParseNode node) + public static OpenApiExample LoadExample(ParseNode node) { var mapNode = node.CheckMapNode("Example"); - var example = new Example(); + var example = new OpenApiExample(); foreach (var property in mapNode) { property.ParseField(example, ExampleFixedFields, ExamplePatternFields); @@ -579,11 +579,11 @@ public static Example LoadExample(ParseNode node) #endregion #region TagObject - internal static Tag LoadTag(ParseNode n) + internal static OpenApiTag LoadTag(ParseNode n) { var mapNode = n.CheckMapNode("tag"); - var obj = new Tag(); + var obj = new OpenApiTag(); foreach (var node in mapNode) { @@ -607,7 +607,7 @@ internal static Tag LoadTag(ParseNode n) #region SchemaObject - private static FixedFieldMap SchemaFixedFields = new FixedFieldMap + private static FixedFieldMap SchemaFixedFields = new FixedFieldMap { { "title", (o,n) => { o.Title = n.GetScalarValue(); } }, { "multipleOf", (o,n) => { o.MultipleOf = decimal.Parse(n.GetScalarValue()); } }, @@ -646,23 +646,23 @@ internal static Tag LoadTag(ParseNode n) }; - private static PatternFieldMap SchemaPatternFields = new PatternFieldMap + private static PatternFieldMap SchemaPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Schema LoadSchema(ParseNode node) + public static OpenApiSchema LoadSchema(ParseNode node) { MapNode mapNode = node.CheckMapNode("schema"); var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } - var domainObject = new Schema(); + var domainObject = new OpenApiSchema(); foreach (var propertyNode in mapNode) { @@ -677,7 +677,7 @@ public static Schema LoadSchema(ParseNode node) #region SecuritySchemeObject - private static FixedFieldMap SecuritySchemeFixedFields = new FixedFieldMap + private static FixedFieldMap SecuritySchemeFixedFields = new FixedFieldMap { { "type", (o,n) => { o.Type = n.GetScalarValue(); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, @@ -692,16 +692,16 @@ public static Schema LoadSchema(ParseNode node) { "scopes", (o,n) => { o.Scopes= n.CreateSimpleMap(v => v.GetScalarValue() ); } }, }; - private static PatternFieldMap SecuritySchemePatternFields = new PatternFieldMap + private static PatternFieldMap SecuritySchemePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static SecurityScheme LoadSecurityScheme(ParseNode node) + public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node) { var mapNode = node.CheckMapNode("securityScheme"); - var securityScheme = new SecurityScheme(); + var securityScheme = new OpenApiSecurityScheme(); foreach (var property in mapNode) { property.ParseField(securityScheme, SecuritySchemeFixedFields, SecuritySchemePatternFields); @@ -713,12 +713,12 @@ public static SecurityScheme LoadSecurityScheme(ParseNode node) #endregion #region SecurityRequirement - public static SecurityRequirement LoadSecurityRequirement(ParseNode node) + public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node) { var mapNode = node.CheckMapNode("security"); - var obj = new SecurityRequirement(); + var obj = new OpenApiSecurityRequirement(); foreach (var property in mapNode) { @@ -828,7 +828,7 @@ public static IReference LoadReference(OpenApiReference reference, object rootNo } else { - return new Tag() { Name = reference.TypeName }; + return new OpenApiTag() { Name = reference.TypeName }; } break; diff --git a/src/Microsoft.OpenApi.Readers/OpenApiV3Reader.cs b/src/Microsoft.OpenApi.Readers/OpenApiV3Reader.cs index 1b7eebfb3..c40d7363d 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiV3Reader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiV3Reader.cs @@ -46,27 +46,27 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) #region InfoObject - public static FixedFieldMap InfoFixedFields = new FixedFieldMap + public static FixedFieldMap InfoFixedFields = new FixedFieldMap { { "title", (o,n) => { o.Title = n.GetScalarValue(); } }, - { "version", (o,n) => { o.Version = n.GetScalarValue(); } }, + { "version", (o,n) => { o.Version = new Version(n.GetScalarValue()); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "termsOfService", (o,n) => { o.TermsOfService = n.GetScalarValue(); } }, { "contact", (o,n) => { o.Contact = LoadContact(n); } }, { "license", (o,n) => { o.License = LoadLicense(n); } } }; - public static PatternFieldMap InfoPatternFields = new PatternFieldMap + public static PatternFieldMap InfoPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Info LoadInfo(ParseNode node) + public static OpenApiInfo LoadInfo(ParseNode node) { var mapNode = node.CheckMapNode("Info"); - var info = new Info(); + var info = new OpenApiInfo(); var required = new List() { "title", "version" }; ParseMap(mapNode, info, InfoFixedFields, InfoPatternFields, required); @@ -79,21 +79,21 @@ public static Info LoadInfo(ParseNode node) #region ContactObject - public static FixedFieldMap ContactFixedFields = new FixedFieldMap { + public static FixedFieldMap ContactFixedFields = new FixedFieldMap { { "name", (o,n) => { o.Name = n.GetScalarValue(); } }, { "email", (o,n) => { o.Email = n.GetScalarValue(); } }, { "url", (o,n) => { o.Url = new Uri(n.GetScalarValue()); } }, }; - public static PatternFieldMap ContactPatternFields = new PatternFieldMap + public static PatternFieldMap ContactPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Contact LoadContact(ParseNode node) + public static OpenApiContact LoadContact(ParseNode node) { var mapNode = node as MapNode; - var contact = new Contact(); + var contact = new OpenApiContact(); ParseMap(mapNode, contact, ContactFixedFields,ContactPatternFields); @@ -104,21 +104,21 @@ public static Contact LoadContact(ParseNode node) #region LicenseObject - public static FixedFieldMap LicenseFixedFields = new FixedFieldMap { + public static FixedFieldMap LicenseFixedFields = new FixedFieldMap { { "name", (o,n) => { o.Name = n.GetScalarValue(); } }, { "url", (o,n) => { o.Url = new Uri(n.GetScalarValue()); } }, }; - public static PatternFieldMap LicensePatternFields = new PatternFieldMap + public static PatternFieldMap LicensePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - internal static License LoadLicense(ParseNode node) + internal static OpenApiLicense LoadLicense(ParseNode node) { var mapNode = node.CheckMapNode("License"); - var license = new License(); + var license = new OpenApiLicense(); ParseMap(mapNode, license, LicenseFixedFields, LicensePatternFields); @@ -129,23 +129,23 @@ internal static License LoadLicense(ParseNode node) #region ServerObject - private static FixedFieldMap ServerFixedFields = new FixedFieldMap + private static FixedFieldMap ServerFixedFields = new FixedFieldMap { { "url", (o,n) => { o.Url= n.GetScalarValue(); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "variables", (o,n) => { o.Variables = n.CreateMap(LoadServerVariable); } } }; - private static PatternFieldMap ServerPatternFields = new PatternFieldMap + private static PatternFieldMap ServerPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) } }; - public static Server LoadServer(ParseNode node) + public static OpenApiServer LoadServer(ParseNode node) { var mapNode = node.CheckMapNode("server"); - var server = new Server(); + var server = new OpenApiServer(); ParseMap(mapNode, server, ServerFixedFields, ServerPatternFields); @@ -156,23 +156,23 @@ public static Server LoadServer(ParseNode node) #region ServerVariable - private static FixedFieldMap ServerVariableFixedFields = new FixedFieldMap + private static FixedFieldMap ServerVariableFixedFields = new FixedFieldMap { { "enum", (o,n) => { o.Enum = n.CreateSimpleList((s)=> s.GetScalarValue()); } }, { "default", (o,n) => { o.Default = n.GetScalarValue(); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, }; - private static PatternFieldMap ServerVariablePatternFields = new PatternFieldMap + private static PatternFieldMap ServerVariablePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) } }; - public static ServerVariable LoadServerVariable(ParseNode node) + public static OpenApiServerVariable LoadServerVariable(ParseNode node) { var mapNode = node.CheckMapNode("serverVariable"); - var serverVariable = new ServerVariable(); + var serverVariable = new OpenApiServerVariable(); ParseMap(mapNode, serverVariable, ServerVariableFixedFields, ServerVariablePatternFields); @@ -183,7 +183,7 @@ public static ServerVariable LoadServerVariable(ParseNode node) #region ComponentsObject - public static FixedFieldMap ComponentsFixedFields = new FixedFieldMap { + public static FixedFieldMap ComponentsFixedFields = new FixedFieldMap { { "schemas", (o,n) => { o.Schemas = n.CreateMap(LoadSchema); } }, { "responses", (o,n) => o.Responses = n.CreateMap(LoadResponse) }, { "parameters", (o,n) => o.Parameters = n.CreateMap(LoadParameter) }, @@ -195,15 +195,15 @@ public static ServerVariable LoadServerVariable(ParseNode node) { "callbacks", (o,n) => o.Callbacks = n.CreateMap(LoadCallback) }, }; - public static PatternFieldMap ComponentsPatternFields = new PatternFieldMap + public static PatternFieldMap ComponentsPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Components LoadComponents(ParseNode node) + public static OpenApiComponents LoadComponents(ParseNode node) { var mapNode = node.CheckMapNode("components"); - var components = new Components(); + var components = new OpenApiComponents(); ParseMap(mapNode, components, ComponentsFixedFields, ComponentsPatternFields); @@ -214,21 +214,21 @@ public static Components LoadComponents(ParseNode node) #region PathsObject - public static FixedFieldMap PathsFixedFields = new FixedFieldMap + public static FixedFieldMap PathsFixedFields = new FixedFieldMap { }; - public static PatternFieldMap PathsPatternFields = new PatternFieldMap + 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())) } }; - public static Paths LoadPaths(ParseNode node) + public static OpenApiPaths LoadPaths(ParseNode node) { var mapNode = node.CheckMapNode("Paths"); - Paths domainObject = new Paths(); + OpenApiPaths domainObject = new OpenApiPaths(); ParseMap(mapNode, domainObject, PathsFixedFields, PathsPatternFields); @@ -238,7 +238,7 @@ public static Paths LoadPaths(ParseNode node) #region PathItemObject - private static FixedFieldMap PathItemFixedFields = new FixedFieldMap + private static FixedFieldMap PathItemFixedFields = new FixedFieldMap { // $ref { "summary", (o,n) => { o.Summary = n.GetScalarValue(); } }, @@ -248,7 +248,7 @@ public static Paths LoadPaths(ParseNode node) }; - private static PatternFieldMap PathItemPatternFields = new PatternFieldMap + private static PatternFieldMap PathItemPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, { (s)=> "get,put,post,delete,patch,options,head,patch,trace".Contains(s), @@ -256,11 +256,11 @@ public static Paths LoadPaths(ParseNode node) }; - public static PathItem LoadPathItem(ParseNode node) + public static OpenApiPathItem LoadPathItem(ParseNode node) { var mapNode = node.CheckMapNode("PathItem"); - var pathItem = new PathItem(); + var pathItem = new OpenApiPathItem(); ParseMap(mapNode, pathItem, PathItemFixedFields, PathItemPatternFields); @@ -271,7 +271,7 @@ public static PathItem LoadPathItem(ParseNode node) #region OperationObject - private static FixedFieldMap OperationFixedFields = new FixedFieldMap + private static FixedFieldMap OperationFixedFields = new FixedFieldMap { { "tags", (o,n) => o.Tags = n.CreateSimpleList((v) => ReferenceService.LoadTagByReference(v.Context,v.GetScalarValue()))}, { "summary", (o,n) => { o.Summary = n.GetScalarValue(); } }, @@ -287,16 +287,16 @@ public static PathItem LoadPathItem(ParseNode node) { "servers", (o,n) => { o.Servers = n.CreateList(LoadServer); }}, }; - private static PatternFieldMap OperationPatternFields = new PatternFieldMap + private static PatternFieldMap OperationPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - internal static Operation LoadOperation(ParseNode node) + internal static OpenApiOperation LoadOperation(ParseNode node) { var mapNode = node.CheckMapNode("Operation"); - Operation operation = new Operation(); + OpenApiOperation operation = new OpenApiOperation(); ParseMap(mapNode, operation, OperationFixedFields, OperationPatternFields); @@ -307,23 +307,23 @@ internal static Operation LoadOperation(ParseNode node) #region ExternalDocsObject - private static FixedFieldMap ExternalDocsFixedFields = new FixedFieldMap + private static FixedFieldMap ExternalDocsFixedFields = new FixedFieldMap { // $ref { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "url", (o,n) => { o.Url = new Uri(n.GetScalarValue()); } }, }; - private static PatternFieldMap ExternalDocsPatternFields = new PatternFieldMap + private static PatternFieldMap ExternalDocsPatternFields = new PatternFieldMap { }; - public static ExternalDocs LoadExternalDocs(ParseNode node) + public static OpenApiExternalDocs LoadExternalDocs(ParseNode node) { var mapNode = node.CheckMapNode("externalDocs"); - var externalDocs = new ExternalDocs(); + var externalDocs = new OpenApiExternalDocs(); ParseMap(mapNode, externalDocs, ExternalDocsFixedFields, ExternalDocsPatternFields); @@ -334,7 +334,7 @@ public static ExternalDocs LoadExternalDocs(ParseNode node) #region ParameterObject - private static FixedFieldMap ParameterFixedFields = new FixedFieldMap + private static FixedFieldMap ParameterFixedFields = new FixedFieldMap { { "name", (o,n) => { o.Name = n.GetScalarValue(); } }, { "in", (o,n) => { o.In = (InEnum)Enum.Parse(typeof(InEnum), n.GetScalarValue()); } }, @@ -350,23 +350,23 @@ public static ExternalDocs LoadExternalDocs(ParseNode node) { "example", (o,n) => { o.Example = n.GetScalarValue(); } }, }; - private static PatternFieldMap ParameterPatternFields = new PatternFieldMap + private static PatternFieldMap ParameterPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - public static Parameter LoadParameter(ParseNode node) + public static OpenApiParameter LoadParameter(ParseNode node) { var mapNode = node.CheckMapNode("parameter"); var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } - var parameter = new Parameter(); + var parameter = new OpenApiParameter(); var required = new List() { "name", "in" }; ParseMap(mapNode, parameter, ParameterFixedFields, ParameterPatternFields,required); @@ -375,25 +375,25 @@ public static Parameter LoadParameter(ParseNode node) } #endregion - #region RequestBody + #region OpenApiRequestBody - private static FixedFieldMap RequestBodyFixedFields = new FixedFieldMap + private static FixedFieldMap RequestBodyFixedFields = new FixedFieldMap { { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "content", (o,n) => { o.Content = n.CreateMap(LoadMediaType); } }, { "required", (o,n) => { o.Required = bool.Parse(n.GetScalarValue()); } }, }; - private static PatternFieldMap RequestBodyPatternFields = new PatternFieldMap + private static PatternFieldMap RequestBodyPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) }, }; - public static RequestBody LoadRequestBody(ParseNode node) + public static OpenApiRequestBody LoadRequestBody(ParseNode node) { var mapNode = node.CheckMapNode("requestBody"); - var requestBody = new RequestBody(); + var requestBody = new OpenApiRequestBody(); foreach (var property in mapNode) { property.ParseField(requestBody, RequestBodyFixedFields, RequestBodyPatternFields); @@ -406,7 +406,7 @@ public static RequestBody LoadRequestBody(ParseNode node) #region MediaTypeObject - private static FixedFieldMap MediaTypeFixedFields = new FixedFieldMap + private static FixedFieldMap MediaTypeFixedFields = new FixedFieldMap { { "schema", (o,n) => { o.Schema = LoadSchema(n); } }, { "examples", (o,n) => { o.Examples = n.CreateMap(LoadExample); } }, @@ -414,18 +414,18 @@ public static RequestBody LoadRequestBody(ParseNode node) //Encoding }; - private static PatternFieldMap MediaTypePatternFields = new PatternFieldMap + private static PatternFieldMap MediaTypePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) } }; - public static MediaType LoadMediaType(ParseNode node) + public static OpenApiMediaType LoadMediaType(ParseNode node) { var mapNode = node.CheckMapNode("contentType"); if (mapNode.Count() == 0) return null; - var contentType = new MediaType(); + var contentType = new OpenApiMediaType(); ParseMap(mapNode, contentType, MediaTypeFixedFields, MediaTypePatternFields); @@ -445,7 +445,7 @@ public static MediaType LoadMediaType(ParseNode node) #region ResponseObject - private static FixedFieldMap ResponseFixedFields = new FixedFieldMap + private static FixedFieldMap ResponseFixedFields = new FixedFieldMap { { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "headers", (o,n) => { o.Headers = n.CreateMap(LoadHeader); } }, @@ -453,17 +453,17 @@ public static MediaType LoadMediaType(ParseNode node) { "links", (o,n) => { o.Links = n.CreateMap(LoadLink); } } }; - private static PatternFieldMap ResponsePatternFields = new PatternFieldMap + private static PatternFieldMap ResponsePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - public static Response LoadResponse(ParseNode node) + public static OpenApiResponse LoadResponse(ParseNode node) { var mapNode = node.CheckMapNode("response"); var required = new List() { "description" }; - var response = new Response(); + var response = new OpenApiResponse(); ParseMap(mapNode, response, ResponseFixedFields, ResponsePatternFields, required); return response; @@ -472,27 +472,27 @@ public static Response LoadResponse(ParseNode node) #endregion #region CallbackObject - private static FixedFieldMap CallbackFixedFields = new FixedFieldMap + private static FixedFieldMap CallbackFixedFields = new FixedFieldMap { }; - private static PatternFieldMap CallbackPatternFields = new PatternFieldMap + private static PatternFieldMap CallbackPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("$"), (o,k,n)=> o.PathItems.Add(new RuntimeExpression(k), LoadPathItem(n) ) } }; - public static Callback LoadCallback(ParseNode node) + public static OpenApiCallback LoadCallback(ParseNode node) { var mapNode = node.CheckMapNode("callback"); var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } - var domainObject = new Callback(); + var domainObject = new OpenApiCallback(); ParseMap(mapNode, domainObject, CallbackFixedFields, CallbackPatternFields); @@ -503,7 +503,7 @@ public static Callback LoadCallback(ParseNode node) #region LinkObject - private static FixedFieldMap LinkFixedFields = new FixedFieldMap + private static FixedFieldMap LinkFixedFields = new FixedFieldMap { { "href", (o,n) => { o.Href = n.GetScalarValue(); } }, { "operationId", (o,n) => { o.OperationId = n.GetScalarValue(); } }, @@ -512,21 +512,21 @@ public static Callback LoadCallback(ParseNode node) { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, }; - private static PatternFieldMap LinkPatternFields = new PatternFieldMap + private static PatternFieldMap LinkPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, n.GetScalarValue()) }, }; - public static Link LoadLink(ParseNode node) + public static OpenApiLink LoadLink(ParseNode node) { var mapNode = node.CheckMapNode("link"); - var link = new Link(); + var link = new OpenApiLink(); var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } ParseMap(mapNode, link, LinkFixedFields, LinkPatternFields); @@ -537,7 +537,7 @@ public static Link LoadLink(ParseNode node) #endregion #region HeaderObject - private static FixedFieldMap
HeaderFixedFields = new FixedFieldMap
+ private static FixedFieldMap HeaderFixedFields = new FixedFieldMap { { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "required", (o,n) => { o.Required = bool.Parse(n.GetScalarValue()); } }, @@ -547,16 +547,16 @@ public static Link LoadLink(ParseNode node) { "schema", (o,n) => { o.Schema = LoadSchema(n); } } }; - private static PatternFieldMap
HeaderPatternFields = new PatternFieldMap
+ private static PatternFieldMap HeaderPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) }, }; - public static Header LoadHeader(ParseNode node) + public static OpenApiHeader LoadHeader(ParseNode node) { var mapNode = node.CheckMapNode("header"); - var header = new Header(); + var header = new OpenApiHeader(); foreach (var property in mapNode) { property.ParseField(header, HeaderFixedFields, HeaderPatternFields); @@ -568,30 +568,30 @@ public static Header LoadHeader(ParseNode node) #endregion #region ExampleObject - private static FixedFieldMap ExampleFixedFields = new FixedFieldMap + private static FixedFieldMap ExampleFixedFields = new FixedFieldMap { { "summary", (o,n) => { o.Summary= n.GetScalarValue(); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, { "value", (o,n) => { o.Value = n.GetScalarValue(); } }, }; - private static PatternFieldMap ExamplePatternFields = new PatternFieldMap + private static PatternFieldMap ExamplePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Example LoadExample(ParseNode node) + public static OpenApiExample LoadExample(ParseNode node) { var mapNode = node.CheckMapNode("Example"); var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } - var example = new Example(); + var example = new OpenApiExample(); foreach (var property in mapNode) { property.ParseField(example, ExampleFixedFields, ExamplePatternFields); @@ -604,11 +604,11 @@ public static Example LoadExample(ParseNode node) #endregion #region TagObject - internal static Tag LoadTag(ParseNode n) + internal static OpenApiTag LoadTag(ParseNode n) { var mapNode = n.CheckMapNode("tag"); - var obj = new Tag(); + var obj = new OpenApiTag(); foreach (var node in mapNode) { @@ -632,7 +632,7 @@ internal static Tag LoadTag(ParseNode n) #region SchemaObject - private static FixedFieldMap SchemaFixedFields = new FixedFieldMap + private static FixedFieldMap SchemaFixedFields = new FixedFieldMap { { "title", (o,n) => { o.Title = n.GetScalarValue(); } }, { "multipleOf", (o,n) => { o.MultipleOf = decimal.Parse(n.GetScalarValue()); } }, @@ -676,17 +676,17 @@ internal static Tag LoadTag(ParseNode n) }; - private static PatternFieldMap SchemaPatternFields = new PatternFieldMap + private static PatternFieldMap SchemaPatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static Schema LoadSchema(string schema) + public static OpenApiSchema LoadSchema(string schema) { return LoadSchema(MapNode.Create(schema)); } - public static Schema LoadSchema(ParseNode node) + public static OpenApiSchema LoadSchema(ParseNode node) { var mapNode = node.CheckMapNode("schema"); @@ -694,10 +694,10 @@ public static Schema LoadSchema(ParseNode node) var refpointer = mapNode.GetReferencePointer(); if (refpointer != null) { - return mapNode.GetReferencedObject(refpointer); + return mapNode.GetReferencedObject(refpointer); } - var domainObject = new Schema(); + var domainObject = new OpenApiSchema(); foreach (var propertyNode in mapNode) { @@ -712,7 +712,7 @@ public static Schema LoadSchema(ParseNode node) #region SecuritySchemeObject - private static FixedFieldMap SecuritySchemeFixedFields = new FixedFieldMap + private static FixedFieldMap SecuritySchemeFixedFields = new FixedFieldMap { { "type", (o,n) => { o.Type = n.GetScalarValue(); } }, { "description", (o,n) => { o.Description = n.GetScalarValue(); } }, @@ -727,16 +727,16 @@ public static Schema LoadSchema(ParseNode node) { "scopes", (o,n) => { o.Scopes= n.CreateMap(v => v.GetScalarValue() ); } }, }; - private static PatternFieldMap SecuritySchemePatternFields = new PatternFieldMap + private static PatternFieldMap SecuritySchemePatternFields = new PatternFieldMap { { (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new GenericOpenApiExtension(n.GetScalarValue())) } }; - public static SecurityScheme LoadSecurityScheme(ParseNode node) + public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node) { var mapNode = node.CheckMapNode("securityScheme"); - var securityScheme = new SecurityScheme(); + var securityScheme = new OpenApiSecurityScheme(); foreach (var property in mapNode) { property.ParseField(securityScheme, SecuritySchemeFixedFields, SecuritySchemePatternFields); @@ -748,12 +748,12 @@ public static SecurityScheme LoadSecurityScheme(ParseNode node) #endregion #region SecurityRequirement - public static SecurityRequirement LoadSecurityRequirement(ParseNode node) + public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node) { var mapNode = node.CheckMapNode("security"); - var obj = new SecurityRequirement(); + var obj = new OpenApiSecurityRequirement(); foreach (var property in mapNode) { @@ -810,7 +810,7 @@ public static IReference LoadReference(OpenApiReference pointer, object rootNode } else { - return new Tag() { Name = pointer.TypeName }; + return new OpenApiTag() { Name = pointer.TypeName }; } break; diff --git a/src/Microsoft.OpenApi.Readers/ReferenceService.cs b/src/Microsoft.OpenApi.Readers/ReferenceService.cs index 6e4b11a12..da1ccdc1b 100644 --- a/src/Microsoft.OpenApi.Readers/ReferenceService.cs +++ b/src/Microsoft.OpenApi.Readers/ReferenceService.cs @@ -31,10 +31,10 @@ public OpenApiReference ParseReference(string pointer) return this.parseReference(pointer); } - public static SecurityScheme LoadSecuritySchemeByReference(ParsingContext context, string schemeName) + public static OpenApiSecurityScheme LoadSecuritySchemeByReference(ParsingContext context, string schemeName) { - var schemeObject = (SecurityScheme)context.GetReferencedObject(new OpenApiReference() + var schemeObject = (OpenApiSecurityScheme)context.GetReferencedObject(new OpenApiReference() { ReferenceType = ReferenceType.SecurityScheme, TypeName = schemeName @@ -44,14 +44,14 @@ public static SecurityScheme LoadSecuritySchemeByReference(ParsingContext contex } - public static Tag LoadTagByReference(ParsingContext context, string tagName) + public static OpenApiTag LoadTagByReference(ParsingContext context, string tagName) { - var tagObject = (Tag)context.GetReferencedObject($"#/tags/{tagName}"); + var tagObject = (OpenApiTag)context.GetReferencedObject($"#/tags/{tagName}"); if (tagObject == null) { - tagObject = new Tag() { Name = tagName }; + tagObject = new OpenApiTag() { Name = tagName }; } return tagObject; } diff --git a/src/Microsoft.OpenApi.Workbench/MainModel.cs b/src/Microsoft.OpenApi.Workbench/MainModel.cs index 3894ec765..4a9f80baa 100644 --- a/src/Microsoft.OpenApi.Workbench/MainModel.cs +++ b/src/Microsoft.OpenApi.Workbench/MainModel.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; using Microsoft.OpenApi; using Microsoft.OpenApi.Writers; using Microsoft.OpenApi.Readers; diff --git a/src/Microsoft.OpenApi/Callback.cs b/src/Microsoft.OpenApi/Callback.cs deleted file mode 100644 index cd039f841..000000000 --- a/src/Microsoft.OpenApi/Callback.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - - public class Callback : IReference - { - public Dictionary PathItems { get; set; } = new Dictionary(); - - public OpenApiReference Pointer { get; set; } - - public Dictionary Extensions { get; set; } - - - - - } -} diff --git a/src/Microsoft.OpenApi/Components.cs b/src/Microsoft.OpenApi/Components.cs deleted file mode 100644 index 86a2353ce..000000000 --- a/src/Microsoft.OpenApi/Components.cs +++ /dev/null @@ -1,37 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - - public class Components - { - 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 bool IsEmpty() - { - return !(this.Schemas.Count > 0 - || this.Responses.Count > 0 - || this.Parameters.Count > 0 - || this.Examples.Count > 0 - || this.RequestBodies.Count > 0 - || this.Headers.Count > 0 - || this.SecuritySchemes.Count > 0 - || this.Links.Count > 0 - || this.Callbacks.Count > 0 - || this.Extensions.Count > 0); - - } - - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Contact.cs b/src/Microsoft.OpenApi/Contact.cs deleted file mode 100644 index 46f47e549..000000000 --- a/src/Microsoft.OpenApi/Contact.cs +++ /dev/null @@ -1,15 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - - public class Contact - { - public string Name { get; set; } - public Uri Url { get; set; } - public string Email { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/DomainParseException.cs b/src/Microsoft.OpenApi/DomainParseException.cs deleted file mode 100644 index a06ac9a83..000000000 --- a/src/Microsoft.OpenApi/DomainParseException.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace Microsoft.OpenApi -{ - public class OpenApiException : Exception - { - public string Pointer { get; set; } - public OpenApiException(string message) : base(message) - { - - } - - } - - -} diff --git a/src/Microsoft.OpenApi/Example.cs b/src/Microsoft.OpenApi/Example.cs deleted file mode 100644 index f05fe50d3..000000000 --- a/src/Microsoft.OpenApi/Example.cs +++ /dev/null @@ -1,26 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public class Example : IReference - { - public string Summary { get; set; } - public string Description { get; set; } - - public string Value { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); - - public OpenApiReference Pointer - { - get; set; - } - } - - - -} diff --git a/src/Microsoft.OpenApi/ExternalDocs.cs b/src/Microsoft.OpenApi/ExternalDocs.cs deleted file mode 100644 index 9aaad6a89..000000000 --- a/src/Microsoft.OpenApi/ExternalDocs.cs +++ /dev/null @@ -1,12 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - - public class ExternalDocs - { - public string Description { get; set; } - public Uri Url { get; set; } - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/GenericOpenApiExtension.cs b/src/Microsoft.OpenApi/GenericOpenApiExtension.cs index bef7f4119..05dbc77c0 100644 --- a/src/Microsoft.OpenApi/GenericOpenApiExtension.cs +++ b/src/Microsoft.OpenApi/GenericOpenApiExtension.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- namespace Microsoft.OpenApi { diff --git a/src/Microsoft.OpenApi/Header.cs b/src/Microsoft.OpenApi/Header.cs deleted file mode 100644 index 8d79a2dc3..000000000 --- a/src/Microsoft.OpenApi/Header.cs +++ /dev/null @@ -1,27 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Text; - using System.Threading.Tasks; - - public class Header : IReference - { - public OpenApiReference Pointer { get; set; } - public string Description { get; set; } - public bool Required { get; set; } - public bool Deprecated { get; set; } - public bool AllowEmptyValue { get; set; } - public string Style { get; set; } - public bool Explode { get; set; } - public bool AllowReserved { get; set; } - public Schema Schema { get; set; } - public string Example { get; set; } - public List Examples { get; set; } - public Dictionary Content { get; set; } - - public Dictionary Extensions { get; set; } = new Dictionary(); - - } -} diff --git a/src/Microsoft.OpenApi/IOpenApiExtension.cs b/src/Microsoft.OpenApi/IOpenApiExtension.cs index 1d625991c..6dbc58070 100644 --- a/src/Microsoft.OpenApi/IOpenApiExtension.cs +++ b/src/Microsoft.OpenApi/IOpenApiExtension.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- namespace Microsoft.OpenApi { diff --git a/src/Microsoft.OpenApi/IReference.cs b/src/Microsoft.OpenApi/IReference.cs index 147a8a8d0..11ef32372 100644 --- a/src/Microsoft.OpenApi/IReference.cs +++ b/src/Microsoft.OpenApi/IReference.cs @@ -1,6 +1,11 @@ -namespace Microsoft.OpenApi -{ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OpenApi +{ public interface IReference { OpenApiReference Pointer { get; set; } diff --git a/src/Microsoft.OpenApi/IReferenceService.cs b/src/Microsoft.OpenApi/IReferenceService.cs index b76eba0d9..0108b3f7c 100644 --- a/src/Microsoft.OpenApi/IReferenceService.cs +++ b/src/Microsoft.OpenApi/IReferenceService.cs @@ -1,4 +1,9 @@ - +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + namespace Microsoft.OpenApi { public interface IReferenceService @@ -6,6 +11,4 @@ public interface IReferenceService IReference LoadReference(OpenApiReference reference); OpenApiReference ParseReference(string pointer); } - - } diff --git a/src/Microsoft.OpenApi/Info.cs b/src/Microsoft.OpenApi/Info.cs deleted file mode 100644 index 5df298e1b..000000000 --- a/src/Microsoft.OpenApi/Info.cs +++ /dev/null @@ -1,36 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System.Collections.Generic; - using System; - using System.Linq; - using System.Text.RegularExpressions; - - public class Info - { - public string Title { get; set; } = "[Title Required]"; - public string Description { get; set; } - public string TermsOfService - { - get { return this.termsOfService; } - set - { - if (!Uri.IsWellFormedUriString(value, UriKind.RelativeOrAbsolute)) - { - throw new OpenApiException("`info.termsOfService` MUST be a URL"); - }; - this.termsOfService = value; - } - } - string termsOfService; - public Contact Contact { get; set; } - public License License { get; set; } - public string Version { get; set; } = "1.0"; - public Dictionary Extensions { get; set; } = new Dictionary(); - - private static Regex versionRegex = new Regex(@"\d+\.\d+\.\d+"); - - - } - -} diff --git a/src/Microsoft.OpenApi/JsonPointer.cs b/src/Microsoft.OpenApi/JsonPointer.cs index 8581ff107..a509d640d 100644 --- a/src/Microsoft.OpenApi/JsonPointer.cs +++ b/src/Microsoft.OpenApi/JsonPointer.cs @@ -1,10 +1,14 @@ - +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; +using System.Linq; namespace Microsoft.OpenApi { - using System; - using System.Linq; - public class JsonPointer { private readonly string[] _Tokens; diff --git a/src/Microsoft.OpenApi/License.cs b/src/Microsoft.OpenApi/License.cs deleted file mode 100644 index bd6f58cf1..000000000 --- a/src/Microsoft.OpenApi/License.cs +++ /dev/null @@ -1,17 +0,0 @@ - - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - - public class License - { - public string Name { get; set; } - public Uri Url { get; set; } - public Dictionary Extensions { get; set; } = new Dictionary(); - - - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Link.cs b/src/Microsoft.OpenApi/Link.cs deleted file mode 100644 index 3dec5866d..000000000 --- a/src/Microsoft.OpenApi/Link.cs +++ /dev/null @@ -1,25 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public class Link : IReference - { - public string Href { get; set; } - public string OperationId { get; set; } - public Dictionary Parameters { get; set; } - public RuntimeExpression RequestBody { get; set; } - - public string Description { get; set; } - public Dictionary Extensions { get; set; } - - public OpenApiReference Pointer { get; set; } - - - - } -} diff --git a/src/Microsoft.OpenApi/MediaType.cs b/src/Microsoft.OpenApi/MediaType.cs deleted file mode 100644 index 18b8b3a76..000000000 --- a/src/Microsoft.OpenApi/MediaType.cs +++ /dev/null @@ -1,20 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public class MediaType - { - public Schema Schema { get; set; } - public Dictionary Examples { get; set; } - public string Example { get; set; } - - public Dictionary Extensions { get; set; } - - - } -} diff --git a/src/Microsoft.OpenApi/OpenApiCallback.cs b/src/Microsoft.OpenApi/OpenApiCallback.cs new file mode 100644 index 000000000..64742835c --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiCallback.cs @@ -0,0 +1,22 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Callback Object: A map of possible out-of band callbacks related to the parent operation. + /// + public class OpenApiCallback : IReference + { + public Dictionary PathItems { get; set; } = new Dictionary(); + + public OpenApiReference Pointer { get; set; } + + public Dictionary Extensions { get; set; } + } +} diff --git a/src/Microsoft.OpenApi/OpenApiComponents.cs b/src/Microsoft.OpenApi/OpenApiComponents.cs new file mode 100644 index 000000000..3946ff562 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiComponents.cs @@ -0,0 +1,42 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Components Object. + /// + public class OpenApiComponents + { + 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 bool IsEmpty() + { + return !(this.Schemas.Count > 0 + || this.Responses.Count > 0 + || this.Parameters.Count > 0 + || this.Examples.Count > 0 + || this.RequestBodies.Count > 0 + || this.Headers.Count > 0 + || this.SecuritySchemes.Count > 0 + || this.Links.Count > 0 + || this.Callbacks.Count > 0 + || this.Extensions.Count > 0); + + } + } +} diff --git a/src/Microsoft.OpenApi/OpenApiContact.cs b/src/Microsoft.OpenApi/OpenApiContact.cs new file mode 100644 index 000000000..e8f216fa3 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiContact.cs @@ -0,0 +1,38 @@ +//--------------------------------------------------------------------- +// +// 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 +{ + /// + /// Contact Object. + /// + public class OpenApiContact + { + /// + /// The identifying name of the contact person/organization. + /// + public string Name { get; set; } + + /// + /// The URL pointing to the contact information. MUST be in the format of a URL. + /// + public Uri Url { get; set; } + + /// + /// The email address of the contact person/organization. + /// MUST be in the format of an email address. + /// + public string Email { get; set; } + + /// + /// This object MAY be extended with Specification Extensions. + /// + public Dictionary Extensions { get; set; } = new Dictionary(); + } +} diff --git a/src/Microsoft.OpenApi/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/OpenApiDiscriminator.cs new file mode 100644 index 000000000..15f418ae5 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiDiscriminator.cs @@ -0,0 +1,15 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +namespace Microsoft.OData.OpenAPI +{ + /// + /// Discriminator object. + /// + internal class OpenApiDiscriminator + { + } +} diff --git a/src/Microsoft.OpenApi/OpenApiDocument.cs b/src/Microsoft.OpenApi/OpenApiDocument.cs index 187ec5c69..97a728641 100644 --- a/src/Microsoft.OpenApi/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/OpenApiDocument.cs @@ -1,13 +1,19 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Text.RegularExpressions; -using System.Collections; namespace Microsoft.OpenApi { - public class OpenApiDocument + /// + /// Describes an Open API Document. See: https://swagger.io/specification + /// + public class OpenApiDocument { string version; public string Version { get { return version; } @@ -22,20 +28,20 @@ public class OpenApiDocument } } // Swagger - public Info Info { get; set; } = new Info(); - public List Servers { get; set; } = new List(); - public List SecurityRequirements { get; set; } - public Paths Paths { get; set; } = new Paths(); - public Components Components { get; set; } = new Components(); - public List Tags { get; set; } = new List(); - public ExternalDocs ExternalDocs { get; set; } = new ExternalDocs(); + public OpenApiInfo Info { get; set; } = new OpenApiInfo(); + public List Servers { get; set; } = new List(); + public List 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 OpenApiExternalDocs ExternalDocs { get; set; } = new OpenApiExternalDocs(); public Dictionary Extensions { get; set; } = new Dictionary(); private static Regex versionRegex = new Regex(@"\d+\.\d+\.\d+"); - public void CreatePath(string key, Action configure) + public void CreatePath(string key, Action configure) { - var pathItem = new PathItem(); + var pathItem = new OpenApiPathItem(); configure(pathItem); Paths.Add(key, pathItem); } diff --git a/src/Microsoft.OpenApi/OpenApiExample.cs b/src/Microsoft.OpenApi/OpenApiExample.cs new file mode 100644 index 000000000..12604ba7f --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiExample.cs @@ -0,0 +1,41 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Example Object. + /// + public class OpenApiExample : IReference + { + /// + /// Short description for the example. + /// + public string Summary { get; set; } + + /// + /// Long description for the example. + /// + public string Description { get; set; } + + /// + /// Embedded literal example. + /// + public string Value { get; set; } + + /// + /// This object MAY be extended with Specification Extensions. + /// + public Dictionary Extensions { get; set; } = new Dictionary(); + + public OpenApiReference Pointer + { + get; set; + } + } +} diff --git a/src/Microsoft.OpenApi/OpenApiException.cs b/src/Microsoft.OpenApi/OpenApiException.cs new file mode 100644 index 000000000..01c546da8 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiException.cs @@ -0,0 +1,22 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; + +namespace Microsoft.OpenApi +{ + public class OpenApiException : Exception + { + public string Pointer { get; set; } + public OpenApiException(string message) : base(message) + { + + } + + } + + +} diff --git a/src/Microsoft.OpenApi/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/OpenApiExternalDocs.cs new file mode 100644 index 000000000..d4219fbf9 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiExternalDocs.cs @@ -0,0 +1,26 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; + +namespace Microsoft.OpenApi +{ + /// + /// ExternalDocs object. + /// + public class OpenApiExternalDocs + { + /// + /// REQUIRED.The URL for the target documentation. Value MUST be in the format of a URL. + /// + public string Description { get; set; } + + /// + /// A short description of the target documentation. + /// + public Uri Url { get; set; } + } +} diff --git a/src/Microsoft.OpenApi/OpenApiHeader.cs b/src/Microsoft.OpenApi/OpenApiHeader.cs new file mode 100644 index 000000000..3d6aaa354 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiHeader.cs @@ -0,0 +1,32 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Header Object. + /// The Header Object follows the structure of the Parameter Object + /// + public class OpenApiHeader : IReference + { + public OpenApiReference Pointer { get; set; } + public string Description { get; set; } + public bool Required { get; set; } + public bool Deprecated { get; set; } + public bool AllowEmptyValue { get; set; } + public string Style { get; set; } + public bool Explode { get; set; } + 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 Dictionary Extensions { get; set; } = new Dictionary(); + } +} diff --git a/src/Microsoft.OpenApi/OpenApiInfo.cs b/src/Microsoft.OpenApi/OpenApiInfo.cs new file mode 100644 index 000000000..d2189fb01 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiInfo.cs @@ -0,0 +1,67 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Microsoft.OpenApi +{ + /// + /// Open API Info Object, it provides the metadata about the Open API. + /// + public class OpenApiInfo + { + /// + /// REQUIRED. The title of the application. + /// + public string Title { get; set; } = "[Title Required]"; + + /// + /// A short description of the application. + /// + public string Description { get; set; } + + /// + /// REQUIRED. The version of the OpenAPI document. + /// + public Version Version { get; set; } = new Version(1, 0); + + /// + /// A URL to the Terms of Service for the API. MUST be in the format of a URL. + /// + public string TermsOfService + { + get { return this.termsOfService; } + set + { + if (!Uri.IsWellFormedUriString(value, UriKind.RelativeOrAbsolute)) + { + throw new OpenApiException("`info.termsOfService` MUST be a URL"); + }; + this.termsOfService = value; + } + } + string termsOfService; + + /// + /// The contact information for the exposed API. + /// + public OpenApiContact Contact { get; set; } + + /// + /// The license information for the exposed API. + /// + public OpenApiLicense License { get; set; } + + /// + /// This object MAY be extended with Specification Extensions. + /// + public Dictionary Extensions { get; set; } = new Dictionary(); + + private static Regex versionRegex = new Regex(@"\d+\.\d+\.\d+"); + } +} diff --git a/src/Microsoft.OpenApi/OpenApiLicense.cs b/src/Microsoft.OpenApi/OpenApiLicense.cs new file mode 100644 index 000000000..4eb4f6ee6 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiLicense.cs @@ -0,0 +1,32 @@ +//--------------------------------------------------------------------- +// +// 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 +{ + /// + /// License Object. + /// + public class OpenApiLicense + { + // + /// REQUIRED.The license name used for the API. + /// + public string Name { get; set; } + + /// + /// The URL pointing to the contact information. MUST be in the format of a URL. + /// + public Uri Url { get; set; } + + /// + /// This object MAY be extended with Specification Extensions. + /// + public Dictionary Extensions { get; set; } = new Dictionary(); + } +} diff --git a/src/Microsoft.OpenApi/OpenApiLink.cs b/src/Microsoft.OpenApi/OpenApiLink.cs new file mode 100644 index 000000000..2f80f21b7 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiLink.cs @@ -0,0 +1,29 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Link Object. + /// + public class OpenApiLink : IReference + { + public string Href { get; set; } + public string OperationId { get; set; } + public Dictionary Parameters { get; set; } + public RuntimeExpression RequestBody { get; set; } + + public string Description { get; set; } + public Dictionary Extensions { get; set; } + + public OpenApiReference Pointer { get; set; } + + + + } +} diff --git a/src/Microsoft.OpenApi/OpenApiMediaType.cs b/src/Microsoft.OpenApi/OpenApiMediaType.cs new file mode 100644 index 000000000..ede7c0df7 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiMediaType.cs @@ -0,0 +1,22 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Media Type Object. + /// + public class OpenApiMediaType + { + public OpenApiSchema Schema { get; set; } + public Dictionary Examples { get; set; } + public string Example { get; set; } + + public Dictionary Extensions { get; set; } + } +} diff --git a/src/Microsoft.OpenApi/OpenApiOperation.cs b/src/Microsoft.OpenApi/OpenApiOperation.cs new file mode 100644 index 000000000..622e0995a --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiOperation.cs @@ -0,0 +1,40 @@ +//--------------------------------------------------------------------- +// +// 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 +{ + /// + /// Operation Object. + /// + public class OpenApiOperation + { + public List 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 OpenApiRequestBody RequestBody { get; set; } + public Dictionary Responses { get; set; } = new Dictionary(); + public Dictionary 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 void CreateResponse(string key, Action configure) + { + var response = new OpenApiResponse(); + configure(response); + Responses.Add(key, response); + } + } +} diff --git a/src/Microsoft.OpenApi/Parameter.cs b/src/Microsoft.OpenApi/OpenApiParameter.cs similarity index 65% rename from src/Microsoft.OpenApi/Parameter.cs rename to src/Microsoft.OpenApi/OpenApiParameter.cs index 994fe0c82..55a24b141 100644 --- a/src/Microsoft.OpenApi/Parameter.cs +++ b/src/Microsoft.OpenApi/OpenApiParameter.cs @@ -1,11 +1,14 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Linq; +//--------------------------------------------------------------------- +// +// 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 +{ public enum InEnum { path = 1, @@ -13,7 +16,10 @@ public enum InEnum header = 3 } - public class Parameter : IReference + /// + /// Parameter Object. + /// + public class OpenApiParameter : IReference { public OpenApiReference Pointer { get; set; } public string Name { get; set; } @@ -49,10 +55,10 @@ public bool Required public string Style { get; set; } public bool Explode { get; set; } public bool AllowReserved { get; set; } - public Schema Schema { get; set; } - public List Examples { get; set; } = new List(); + public OpenApiSchema Schema { get; set; } + public List Examples { get; set; } = new List(); public string Example { get; set; } - public Dictionary Content { get; set; } + public Dictionary Content { get; set; } public Dictionary Extensions { get; set; } = new Dictionary(); diff --git a/src/Microsoft.OpenApi/OpenApiPathItem.cs b/src/Microsoft.OpenApi/OpenApiPathItem.cs new file mode 100644 index 000000000..71d26ef56 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiPathItem.cs @@ -0,0 +1,46 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.OpenApi +{ + /// + /// Path Item Object: to describe the operations available on a single path. + /// + public class OpenApiPathItem + { + public string Summary { get; set; } + public string Description { get; set; } + + public IReadOnlyDictionary 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 void CreateOperation(OperationType operationType, Action configure) + { + var operation = new OpenApiOperation(); + configure(operation); + AddOperation(operationType, operation); + } + + public void AddOperation(OperationType operationType, OpenApiOperation operation) + { + var successResponse = operation.Responses.Keys.Where(k => k.StartsWith("2")).Any(); + if (!successResponse) + { + throw new OpenApiException("An operation requires a successful response"); + } + + this.operations.Add(operationType.GetOperationTypeName(), operation); + } + } +} diff --git a/src/Microsoft.OpenApi/Paths.cs b/src/Microsoft.OpenApi/OpenApiPaths.cs similarity index 51% rename from src/Microsoft.OpenApi/Paths.cs rename to src/Microsoft.OpenApi/OpenApiPaths.cs index f018e6cce..a9b2d5387 100644 --- a/src/Microsoft.OpenApi/Paths.cs +++ b/src/Microsoft.OpenApi/OpenApiPaths.cs @@ -1,30 +1,38 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + using System.Collections; using System.Collections.Generic; namespace Microsoft.OpenApi { - public class Paths : IDictionary + /// + /// Paths object. + /// + public class OpenApiPaths : IDictionary { - public PathItem this[string key] { get => this.PathItems[key]; set => this.PathItems[key] = value; } + public OpenApiPathItem this[string key] { get => this.PathItems[key]; set => this.PathItems[key] = value; } - private IDictionary PathItems { get; set; } = new Dictionary(); + private IDictionary PathItems { get; set; } = new Dictionary(); public Dictionary Extensions { get; set; } = new Dictionary(); public ICollection Keys => this.PathItems.Keys; - public ICollection Values => this.PathItems.Values; + public ICollection Values => this.PathItems.Values; public int Count => this.PathItems.Count; public bool IsReadOnly => this.PathItems.IsReadOnly; - public void Add(string key, PathItem value) + public void Add(string key, OpenApiPathItem value) { PathItems.Add(key, value); } - public void Add(KeyValuePair item) + public void Add(KeyValuePair item) { PathItems.Add(item); } @@ -34,7 +42,7 @@ public void Clear() this.PathItems.Clear(); } - public bool Contains(KeyValuePair item) + public bool Contains(KeyValuePair item) { return this.PathItems.Contains(item); } @@ -44,7 +52,7 @@ public bool ContainsKey(string key) return this.PathItems.ContainsKey(key); } - public void CopyTo(KeyValuePair[] array, int arrayIndex) + public void CopyTo(KeyValuePair[] array, int arrayIndex) { this.PathItems.CopyTo(array, arrayIndex); } @@ -55,12 +63,12 @@ public bool Remove(string key) return this.PathItems.Remove(key); } - public bool Remove(KeyValuePair item) + public bool Remove(KeyValuePair item) { return this.PathItems.Remove(item); } - public bool TryGetValue(string key, out PathItem value) + public bool TryGetValue(string key, out OpenApiPathItem value) { return this.PathItems.TryGetValue(key, out value); } @@ -75,7 +83,7 @@ IEnumerator IEnumerable.GetEnumerator() return this.PathItems.GetEnumerator(); } - IEnumerator> IEnumerable>.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { return this.PathItems.GetEnumerator(); } diff --git a/src/Microsoft.OpenApi/OpenApiReference.cs b/src/Microsoft.OpenApi/OpenApiReference.cs index 4a3f1eb23..64fa8ed23 100644 --- a/src/Microsoft.OpenApi/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/OpenApiReference.cs @@ -1,8 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; namespace Microsoft.OpenApi { @@ -19,6 +21,7 @@ public enum ReferenceType Link, Tags } + public class OpenApiReference { public ReferenceType ReferenceType { get; set; } diff --git a/src/Microsoft.OpenApi/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/OpenApiRequestBody.cs new file mode 100644 index 000000000..2c8c6e072 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiRequestBody.cs @@ -0,0 +1,24 @@ +//--------------------------------------------------------------------- +// +// 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 +{ + /// + /// Request Body Object + /// + public class OpenApiRequestBody : IReference + { + 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; } + } +} diff --git a/src/Microsoft.OpenApi/OpenApiResponse.cs b/src/Microsoft.OpenApi/OpenApiResponse.cs new file mode 100644 index 000000000..8ee0faed3 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiResponse.cs @@ -0,0 +1,39 @@ +//--------------------------------------------------------------------- +// +// 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 +{ + /// + /// Response object. + /// + public class OpenApiResponse : IReference + { + 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 OpenApiReference Pointer + { + get; set; + } + + public void CreateContent(string mediatype, Action configure) + { + var m = new OpenApiMediaType(); + configure(m); + if (Content == null) { + Content = new Dictionary(); + } + + Content.Add(mediatype, m); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Schema.cs b/src/Microsoft.OpenApi/OpenApiSchema.cs similarity index 62% rename from src/Microsoft.OpenApi/Schema.cs rename to src/Microsoft.OpenApi/OpenApiSchema.cs index 2d829fc7a..44eadb57e 100644 --- a/src/Microsoft.OpenApi/Schema.cs +++ b/src/Microsoft.OpenApi/OpenApiSchema.cs @@ -1,12 +1,17 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + using System.Collections.Generic; -using System.Linq; namespace Microsoft.OpenApi { - - public class Schema : IReference - + /// + /// Schema Object. + /// + public class OpenApiSchema : IReference { public string Title { get; set; } public string Type { get; set; } @@ -23,25 +28,25 @@ public class Schema : 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 Schema Not { get; set; } + public List AllOf { get; set; } + public List OneOf { get; set; } + public List AnyOf { get; set; } + public OpenApiSchema Not { get; set; } public string[] Required { get; set; } - public Schema Items { 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 Dictionary Properties { get; set; } public int? MaxProperties { get; set; } public int? MinProperties { get; set; } public bool AdditionalPropertiesAllowed { get; set; } - public Schema AdditionalProperties { get; set; } + public OpenApiSchema AdditionalProperties { get; set; } public string Example { get; set; } public List Enum { get; set; } = new List(); public bool Nullable { get; set; } - public ExternalDocs ExternalDocs { get; set; } + public OpenApiExternalDocs ExternalDocs { get; set; } public bool Deprecated { get; set; } public Dictionary Extensions { get; set; } = new Dictionary(); @@ -51,8 +56,5 @@ public OpenApiReference Pointer get; set; } - - - } -} \ No newline at end of file +} diff --git a/src/Microsoft.OpenApi/OpenApiSecurityRequirement.cs b/src/Microsoft.OpenApi/OpenApiSecurityRequirement.cs new file mode 100644 index 000000000..abb6b4ba2 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiSecurityRequirement.cs @@ -0,0 +1,18 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Security Requirement Object + /// + public class OpenApiSecurityRequirement + { + public Dictionary> Schemes { get; set; } = new Dictionary>(); + } +} diff --git a/src/Microsoft.OpenApi/SecurityScheme.cs b/src/Microsoft.OpenApi/OpenApiSecurityScheme.cs similarity index 60% rename from src/Microsoft.OpenApi/SecurityScheme.cs rename to src/Microsoft.OpenApi/OpenApiSecurityScheme.cs index 79daa5c49..cc32aa0be 100644 --- a/src/Microsoft.OpenApi/SecurityScheme.cs +++ b/src/Microsoft.OpenApi/OpenApiSecurityScheme.cs @@ -1,10 +1,18 @@ - +//--------------------------------------------------------------------- +// +// 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 { - using System; - using System.Collections.Generic; - - public class SecurityScheme : IReference + /// + /// Security Scheme Object. + /// + public class OpenApiSecurityScheme : IReference { public string Key { get; set; } public string Type { get; set; } @@ -25,7 +33,5 @@ public OpenApiReference Pointer { get; set; } - - } -} \ No newline at end of file +} diff --git a/src/Microsoft.OpenApi/OpenApiServer.cs b/src/Microsoft.OpenApi/OpenApiServer.cs new file mode 100644 index 000000000..f4be8d780 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiServer.cs @@ -0,0 +1,22 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Server Object: an object representing a Server. + /// + public class OpenApiServer + { + public string Description { get; set; } + public string Url { get; set; } + public Dictionary Variables { get; set; } = new Dictionary(); + + public Dictionary Extensions { get; set; } = new Dictionary(); + } +} diff --git a/src/Microsoft.OpenApi/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/OpenApiServerVariable.cs new file mode 100644 index 000000000..471e622c1 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiServerVariable.cs @@ -0,0 +1,22 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.OpenApi +{ + /// + /// Server Variable Object. + /// + public class OpenApiServerVariable + { + public string Description { get; set; } + public string Default { get; set; } + public List Enum { get; set; } = new List(); + + public Dictionary Extensions { get; set; } = new Dictionary(); + } +} diff --git a/src/Microsoft.OpenApi/OpenApiTag.cs b/src/Microsoft.OpenApi/OpenApiTag.cs new file mode 100644 index 000000000..a0e2c42d7 --- /dev/null +++ b/src/Microsoft.OpenApi/OpenApiTag.cs @@ -0,0 +1,29 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +namespace Microsoft.OpenApi +{ + /// + /// Tag Object. + /// + public class OpenApiTag : IReference + { + /// + /// The name of the tag. + /// + public string Name { get; set; } + + /// + /// A short description for the tag. + /// + public string Description { get; set; } + + OpenApiReference IReference.Pointer + { + get; set; + } + } +} diff --git a/src/Microsoft.OpenApi/Operation.cs b/src/Microsoft.OpenApi/Operation.cs deleted file mode 100644 index 5ed181aad..000000000 --- a/src/Microsoft.OpenApi/Operation.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Microsoft.OpenApi -{ - - public class Operation - { - public List Tags { get; set; } = new List(); - public string Summary { get; set; } - public string Description { get; set; } - public ExternalDocs ExternalDocs { get; set; } - public string OperationId { get; set; } - public List Parameters { get; set; } = new List(); - public RequestBody RequestBody { get; set; } - public Dictionary Responses { get; set; } = new Dictionary(); - public Dictionary 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 void CreateResponse(string key, Action configure) - { - var response = new Response(); - configure(response); - Responses.Add(key, response); - } - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/OperationType.cs b/src/Microsoft.OpenApi/OperationType.cs index a2e064c6d..4e35d3628 100644 --- a/src/Microsoft.OpenApi/OperationType.cs +++ b/src/Microsoft.OpenApi/OperationType.cs @@ -1,4 +1,10 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; namespace Microsoft.OpenApi { diff --git a/src/Microsoft.OpenApi/PathItem.cs b/src/Microsoft.OpenApi/PathItem.cs deleted file mode 100644 index d46b4bb7b..000000000 --- a/src/Microsoft.OpenApi/PathItem.cs +++ /dev/null @@ -1,41 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Linq; - - public class PathItem - { - - public string Summary { get; set; } - public string Description { get; set; } - - public IReadOnlyDictionary 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 void CreateOperation(OperationType operationType, Action configure) - { - var operation = new Operation(); - configure(operation); - AddOperation(operationType, operation); - } - - public void AddOperation(OperationType operationType, Operation operation) - { - var successResponse = operation.Responses.Keys.Where(k => k.StartsWith("2")).Any(); - if (!successResponse) - { - throw new OpenApiException("An operation requires a successful response"); - } - - this.operations.Add(operationType.GetOperationTypeName(), operation); - } - - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/RequestBody.cs b/src/Microsoft.OpenApi/RequestBody.cs deleted file mode 100644 index e4113dba4..000000000 --- a/src/Microsoft.OpenApi/RequestBody.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public class RequestBody : IReference - { - 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; } - } -} diff --git a/src/Microsoft.OpenApi/Response.cs b/src/Microsoft.OpenApi/Response.cs deleted file mode 100644 index 31cae1a4c..000000000 --- a/src/Microsoft.OpenApi/Response.cs +++ /dev/null @@ -1,32 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - using System.Collections.Generic; - - public class Response : IReference - { - - 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 OpenApiReference Pointer - { - get; set; - } - - public void CreateContent(string mediatype, Action configure) - { - var m = new MediaType(); - configure(m); - if (Content == null) { - Content = new Dictionary(); - } - - Content.Add(mediatype, m); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/RuntimeExpression.cs b/src/Microsoft.OpenApi/RuntimeExpression.cs index 9e40a7a02..b840be5f5 100644 --- a/src/Microsoft.OpenApi/RuntimeExpression.cs +++ b/src/Microsoft.OpenApi/RuntimeExpression.cs @@ -1,4 +1,10 @@ -namespace Microsoft.OpenApi +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +namespace Microsoft.OpenApi { public class RuntimeExpression { diff --git a/src/Microsoft.OpenApi/SecurityRequirement.cs b/src/Microsoft.OpenApi/SecurityRequirement.cs deleted file mode 100644 index 800cd5511..000000000 --- a/src/Microsoft.OpenApi/SecurityRequirement.cs +++ /dev/null @@ -1,13 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System.Collections.Generic; - using System.Linq; - - public class SecurityRequirement - { - public Dictionary> Schemes { get; set; } = new Dictionary>(); - - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Server.cs b/src/Microsoft.OpenApi/Server.cs deleted file mode 100644 index 11fee8384..000000000 --- a/src/Microsoft.OpenApi/Server.cs +++ /dev/null @@ -1,17 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System.Collections.Generic; - - public class Server - { - public string Description { get; set; } - public string Url { get; set; } - public Dictionary Variables { get; set; } = new Dictionary(); - - public Dictionary Extensions { get; set; } = new Dictionary(); - - - } - -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/ServerVariable.cs b/src/Microsoft.OpenApi/ServerVariable.cs deleted file mode 100644 index cee31a11a..000000000 --- a/src/Microsoft.OpenApi/ServerVariable.cs +++ /dev/null @@ -1,18 +0,0 @@ - - -namespace Microsoft.OpenApi -{ - using System.Collections.Generic; - - public class ServerVariable - { - public string Description { get; set; } - public string Default { get; set; } - public List Enum { get; set; } = new List(); - - public Dictionary Extensions { get; set; } = new Dictionary(); - - - - } -} diff --git a/src/Microsoft.OpenApi/Sevices/OpenAPIDiff.cs b/src/Microsoft.OpenApi/Sevices/OpenAPIDiff.cs index 2d9a1dccf..ad317d066 100644 --- a/src/Microsoft.OpenApi/Sevices/OpenAPIDiff.cs +++ b/src/Microsoft.OpenApi/Sevices/OpenAPIDiff.cs @@ -1,24 +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.Services { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - public static class OpenAPIDiff - { public static List Compare(OpenApiDocument source, OpenApiDocument target) { var diffs = new List(); return diffs; } - - } public class OpenApiDifference { } - } diff --git a/src/Microsoft.OpenApi/Sevices/OpenApiValidator.cs b/src/Microsoft.OpenApi/Sevices/OpenApiValidator.cs index c1f58346e..b92c848d0 100644 --- a/src/Microsoft.OpenApi/Sevices/OpenApiValidator.cs +++ b/src/Microsoft.OpenApi/Sevices/OpenApiValidator.cs @@ -1,8 +1,10 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.OpenApi.Sevices { @@ -15,7 +17,7 @@ public OpenApiValidator() { this.openApiException = new List(); } - public override void Visit(Response response) + public override void Visit(OpenApiResponse response) { if (string.IsNullOrEmpty(response.Description)) { diff --git a/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs index b47175032..da0aa2ed7 100644 --- a/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Sevices/OpenApiVisitorBase.cs @@ -1,28 +1,34 @@ -using System.Collections.Generic; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; namespace Microsoft.OpenApi { public abstract class OpenApiVisitorBase { public virtual void Visit(OpenApiDocument doc) { } - public virtual void Visit(Info info) { } - public virtual void Visit(List servers) { } - public virtual void Visit(Server server) { } - public virtual void Visit(Paths paths) { } - public virtual void Visit(PathItem pathItem) { } - public virtual void Visit(ServerVariable serverVariable) { } - public virtual void Visit(IReadOnlyDictionary operations) { } - public virtual void Visit(Operation operation) { } - public virtual void Visit(List parameters) { } - public virtual void Visit(Parameter parameter) { } - public virtual void Visit(RequestBody requestBody) { } - public virtual void Visit(IReadOnlyDictionary responses) { } - public virtual void Visit(Response response) { } - public virtual void Visit(Dictionary content) { } - public virtual void Visit(MediaType mediaType) { } - public virtual void Visit(Dictionary example) { } - public virtual void Visit(Schema example) { } - public virtual void Visit(Dictionary links) { } - public virtual void Visit(Link link) { } + public virtual void Visit(OpenApiInfo info) { } + public virtual void Visit(List 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(OpenApiOperation operation) { } + public virtual void Visit(List parameters) { } + public virtual void Visit(OpenApiParameter parameter) { } + public virtual void Visit(OpenApiRequestBody requestBody) { } + public virtual void Visit(IReadOnlyDictionary responses) { } + public virtual void Visit(OpenApiResponse response) { } + public virtual void Visit(Dictionary content) { } + public virtual void Visit(OpenApiMediaType mediaType) { } + public virtual void Visit(Dictionary example) { } + public virtual void Visit(OpenApiSchema example) { } + public virtual void Visit(Dictionary links) { } + public virtual void Visit(OpenApiLink link) { } } } diff --git a/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs b/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs index f89cfedbb..9533e6e18 100644 --- a/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs +++ b/src/Microsoft.OpenApi/Sevices/OpenApiWalker.cs @@ -1,4 +1,10 @@ -using System.Collections.Generic; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System.Collections.Generic; namespace Microsoft.OpenApi { @@ -74,7 +80,7 @@ public void Walk(OpenApiDocument doc) } } - private void WalkContent(Dictionary content) + private void WalkContent(Dictionary content) { if (content == null) return; diff --git a/src/Microsoft.OpenApi/Tag.cs b/src/Microsoft.OpenApi/Tag.cs deleted file mode 100644 index 909af840b..000000000 --- a/src/Microsoft.OpenApi/Tag.cs +++ /dev/null @@ -1,18 +0,0 @@ - -namespace Microsoft.OpenApi -{ - using System; - - public class Tag : IReference - { - public string Name { get; set; } - public string Description { get; set; } - - OpenApiReference IReference.Pointer - { - get; set; - } - - - } -} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs b/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs index d190f6675..fdedd79a6 100644 --- a/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs +++ b/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs @@ -1,4 +1,9 @@ - +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + namespace Microsoft.OpenApi.Writers { using System.IO; diff --git a/src/Microsoft.OpenApi/Writers/IParseNodeWriter.cs b/src/Microsoft.OpenApi/Writers/IParseNodeWriter.cs index d0b9c7d4f..7f747fe73 100644 --- a/src/Microsoft.OpenApi/Writers/IParseNodeWriter.cs +++ b/src/Microsoft.OpenApi/Writers/IParseNodeWriter.cs @@ -1,4 +1,10 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; namespace Microsoft.OpenApi.Writers { diff --git a/src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs b/src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs index d444b56a3..ead2ca237 100644 --- a/src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/IReferenceExtensions.cs @@ -1,4 +1,10 @@ -namespace Microsoft.OpenApi.Writers +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +namespace Microsoft.OpenApi.Writers { using Microsoft.OpenApi; diff --git a/src/Microsoft.OpenApi/Writers/JsonParseNodeWriter.cs b/src/Microsoft.OpenApi/Writers/JsonParseNodeWriter.cs index 058289152..b7f2bd303 100644 --- a/src/Microsoft.OpenApi/Writers/JsonParseNodeWriter.cs +++ b/src/Microsoft.OpenApi/Writers/JsonParseNodeWriter.cs @@ -1,4 +1,10 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; using System.Collections.Generic; using System.IO; diff --git a/src/Microsoft.OpenApi/Writers/OpenApiV2Writer.cs b/src/Microsoft.OpenApi/Writers/OpenApiV2Writer.cs index 96194a7a5..1cf5dbc74 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiV2Writer.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiV2Writer.cs @@ -1,12 +1,16 @@ - +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; +using System.IO; +using System.Linq; +using System.Collections.Generic; + namespace Microsoft.OpenApi.Writers { - using System; - using System.IO; - using Microsoft.OpenApi; - using System.Linq; - using System.Collections.Generic; - public class OpenApiV2Writer : IOpenApiWriter { Func defaultWriterFactory = s => new YamlParseNodeWriter(s); @@ -58,7 +62,7 @@ public static void WriteOpenApiDocument(IParseNodeWriter writer, OpenApiDocument } - private static void WriteHostInfo(IParseNodeWriter writer, IList servers) + private static void WriteHostInfo(IParseNodeWriter writer, IList servers) { if (servers == null || servers.Count == 0) return; var firstServer = servers.First(); @@ -75,7 +79,7 @@ private static void WriteHostInfo(IParseNodeWriter writer, IList servers writer.WriteEndList(); } - public static void WriteInfo(IParseNodeWriter writer, Info info) + public static void WriteInfo(IParseNodeWriter writer, OpenApiInfo info) { writer.WriteStartMap(); @@ -84,12 +88,12 @@ public static void WriteInfo(IParseNodeWriter writer, Info info) writer.WriteStringProperty("termsOfService", info.TermsOfService); writer.WriteObject("contact", info.Contact, WriteContact); writer.WriteObject("license", info.License, WriteLicense); - writer.WriteStringProperty("version", info.Version); + writer.WriteStringProperty("version", info.Version.ToString()); writer.WriteEndMap(); } - public static void WriteContact(IParseNodeWriter writer, Contact contact) + public static void WriteContact(IParseNodeWriter writer, OpenApiContact contact) { writer.WriteStartMap(); @@ -101,7 +105,7 @@ public static void WriteContact(IParseNodeWriter writer, Contact contact) writer.WriteEndMap(); } - public static void WriteLicense(IParseNodeWriter writer, License license) + public static void WriteLicense(IParseNodeWriter writer, OpenApiLicense license) { writer.WriteStartMap(); @@ -110,7 +114,7 @@ public static void WriteLicense(IParseNodeWriter writer, License license) writer.WriteEndMap(); } - public static void WriteTag(IParseNodeWriter writer, Tag tag) + public static void WriteTag(IParseNodeWriter writer, OpenApiTag tag) { writer.WriteStartMap(); writer.WriteStringProperty("name", tag.Name); @@ -118,11 +122,11 @@ public static void WriteTag(IParseNodeWriter writer, Tag tag) writer.WriteEndMap(); } - public static void WriteTagRef(IParseNodeWriter writer, Tag tag) + public static void WriteTagRef(IParseNodeWriter writer, OpenApiTag tag) { writer.WriteValue(tag.Name); } - public static void WriteComponents(IParseNodeWriter writer, Components components) + public static void WriteComponents(IParseNodeWriter writer, OpenApiComponents components) { writer.WriteMap("definitions", components.Schemas, WriteSchema); writer.WriteMap("responses", components.Responses, WriteResponse); @@ -131,7 +135,7 @@ public static void WriteComponents(IParseNodeWriter writer, Components component } - public static void WriteExternalDocs(IParseNodeWriter writer, ExternalDocs externalDocs) + public static void WriteExternalDocs(IParseNodeWriter writer, OpenApiExternalDocs externalDocs) { writer.WriteStartMap(); writer.WriteStringProperty("description", externalDocs.Description); @@ -140,7 +144,7 @@ public static void WriteExternalDocs(IParseNodeWriter writer, ExternalDocs exter } - public static void WriteSecurityRequirement(IParseNodeWriter writer, SecurityRequirement securityRequirement) + public static void WriteSecurityRequirement(IParseNodeWriter writer, OpenApiSecurityRequirement securityRequirement) { writer.WriteStartMap(); @@ -163,7 +167,7 @@ public static void WriteSecurityRequirement(IParseNodeWriter writer, SecurityReq } - public static void WritePaths(IParseNodeWriter writer, Paths paths) + public static void WritePaths(IParseNodeWriter writer, OpenApiPaths paths) { foreach (var pathItem in paths) { @@ -172,7 +176,7 @@ public static void WritePaths(IParseNodeWriter writer, Paths paths) } } - public static void WritePathItem(IParseNodeWriter writer, PathItem pathItem) + public static void WritePathItem(IParseNodeWriter writer, OpenApiPathItem pathItem) { writer.WriteStartMap(); writer.WriteStringProperty("x-summary", pathItem.Summary); @@ -199,7 +203,7 @@ public static void WritePathItem(IParseNodeWriter writer, PathItem pathItem) } - public static void WriteOperation(IParseNodeWriter writer, Operation operation) + public static void WriteOperation(IParseNodeWriter writer, OpenApiOperation operation) { writer.WriteStartMap(); writer.WriteList("tags", operation.Tags, WriteTagRef); @@ -209,9 +213,9 @@ public static void WriteOperation(IParseNodeWriter writer, Operation operation) writer.WriteStringProperty("operationId", operation.OperationId); - var parameters = new List(operation.Parameters); + var parameters = new List(operation.Parameters); - Parameter bodyParameter = null; + OpenApiParameter bodyParameter = null; if (operation.RequestBody != null) { writer.WritePropertyName("consumes"); @@ -246,15 +250,15 @@ public static void WriteOperation(IParseNodeWriter writer, Operation operation) writer.WriteEndList(); } - writer.WriteList("parameters", parameters, WriteParameterOrReference); - writer.WriteMap("responses", operation.Responses, WriteResponseOrReference); - writer.WriteBoolProperty("deprecated", operation.Deprecated, Operation.DeprecatedDefault); + writer.WriteList("parameters", parameters, WriteParameterOrReference); + writer.WriteMap("responses", operation.Responses, WriteResponseOrReference); + writer.WriteBoolProperty("deprecated", operation.Deprecated, OpenApiOperation.DeprecatedDefault); writer.WriteList("security", operation.Security, WriteSecurityRequirement); writer.WriteEndMap(); } - public static void WriteParameterOrReference(IParseNodeWriter writer, Parameter parameter) + public static void WriteParameterOrReference(IParseNodeWriter writer, OpenApiParameter parameter) { if (parameter.IsReference()) { @@ -266,7 +270,7 @@ public static void WriteParameterOrReference(IParseNodeWriter writer, Parameter WriteParameter(writer, parameter); } } - public static void WriteParameter(IParseNodeWriter writer, Parameter parameter) + public static void WriteParameter(IParseNodeWriter writer, OpenApiParameter parameter) { writer.WriteStartMap(); writer.WriteStringProperty("name", parameter.Name); @@ -299,7 +303,7 @@ public static void WriteParameter(IParseNodeWriter writer, Parameter parameter) - public static void WriteResponseOrReference(IParseNodeWriter writer, Response response) + public static void WriteResponseOrReference(IParseNodeWriter writer, OpenApiResponse response) { if (response.IsReference()) { @@ -311,7 +315,7 @@ public static void WriteResponseOrReference(IParseNodeWriter writer, Response re } } - public static void WriteResponse(IParseNodeWriter writer, Response response) + public static void WriteResponse(IParseNodeWriter writer, OpenApiResponse response) { writer.WriteStartMap(); @@ -342,7 +346,7 @@ public static void WriteResponse(IParseNodeWriter writer, Response response) } - public static void WriteSchemaOrReference(IParseNodeWriter writer, Schema schema) + public static void WriteSchemaOrReference(IParseNodeWriter writer, OpenApiSchema schema) { if (schema.IsReference()) { @@ -354,7 +358,7 @@ public static void WriteSchemaOrReference(IParseNodeWriter writer, Schema schema } } - public static void WriteSchema(IParseNodeWriter writer, Schema schema) + public static void WriteSchema(IParseNodeWriter writer, OpenApiSchema schema) { writer.WriteStartMap(); @@ -363,7 +367,7 @@ public static void WriteSchema(IParseNodeWriter writer, Schema schema) writer.WriteEndMap(); } - private static void WriteSchemaProperties(IParseNodeWriter writer, Schema schema) + private static void WriteSchemaProperties(IParseNodeWriter writer, OpenApiSchema schema) { writer.WriteStringProperty("title", schema.Title); writer.WriteStringProperty("type", schema.Type); @@ -420,7 +424,7 @@ private static void WriteSchemaProperties(IParseNodeWriter writer, Schema schema writer.WriteList("enum", schema.Enum, (nodeWriter, s) => nodeWriter.WriteValue(s)); } - public static void WriteHeaderOrReference(IParseNodeWriter writer, Header header) + public static void WriteHeaderOrReference(IParseNodeWriter writer, OpenApiHeader header) { if (header.IsReference()) { @@ -432,7 +436,7 @@ public static void WriteHeaderOrReference(IParseNodeWriter writer, Header header } } - public static void WriteHeader(IParseNodeWriter writer, Header header) + public static void WriteHeader(IParseNodeWriter writer, OpenApiHeader header) { writer.WriteStartMap(); @@ -451,7 +455,7 @@ public static void WriteHeader(IParseNodeWriter writer, Header header) - public static void WriteSecurityScheme(IParseNodeWriter writer, SecurityScheme securityScheme) + public static void WriteSecurityScheme(IParseNodeWriter writer, OpenApiSecurityScheme securityScheme) { writer.WriteStartMap(); if (securityScheme.Type == "http") @@ -479,12 +483,9 @@ public static void WriteSecurityScheme(IParseNodeWriter writer, SecurityScheme s writer.WriteEndMap(); } - - - } - internal class BodyParameter : Parameter + internal class BodyParameter : OpenApiParameter { } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiV3Writer.cs b/src/Microsoft.OpenApi/Writers/OpenApiV3Writer.cs index 8f8edf8df..4f2bbaa15 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiV3Writer.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiV3Writer.cs @@ -1,10 +1,14 @@ - +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + namespace Microsoft.OpenApi.Writers { using System; using System.IO; using Microsoft.OpenApi; - using System.Linq; public class OpenApiV3Writer : IOpenApiWriter { @@ -56,7 +60,7 @@ public static void WriteOpenApiDocument(IParseNodeWriter writer, OpenApiDocument } - public static void WriteInfo(IParseNodeWriter writer, Info info) + public static void WriteInfo(IParseNodeWriter writer, OpenApiInfo info) { writer.WriteStartMap(); @@ -65,12 +69,12 @@ public static void WriteInfo(IParseNodeWriter writer, Info info) writer.WriteStringProperty("termsOfService", info.TermsOfService); writer.WriteObject("contact", info.Contact, WriteContact); writer.WriteObject("license", info.License, WriteLicense); - writer.WriteStringProperty("version", info.Version); + writer.WriteStringProperty("version", info.Version.ToString()); writer.WriteEndMap(); } - public static void WriteContact(IParseNodeWriter writer, Contact contact) + public static void WriteContact(IParseNodeWriter writer, OpenApiContact contact) { writer.WriteStartMap(); @@ -82,7 +86,7 @@ public static void WriteContact(IParseNodeWriter writer, Contact contact) writer.WriteEndMap(); } - public static void WriteLicense(IParseNodeWriter writer, License license) + public static void WriteLicense(IParseNodeWriter writer, OpenApiLicense license) { writer.WriteStartMap(); @@ -92,7 +96,7 @@ public static void WriteLicense(IParseNodeWriter writer, License license) writer.WriteEndMap(); } - public static void WriteServer(IParseNodeWriter writer, Server server) + public static void WriteServer(IParseNodeWriter writer, OpenApiServer server) { writer.WriteStartMap(); @@ -103,7 +107,7 @@ public static void WriteServer(IParseNodeWriter writer, Server server) writer.WriteEndMap(); } - public static void WriteTag(IParseNodeWriter writer, Tag tag) + public static void WriteTag(IParseNodeWriter writer, OpenApiTag tag) { writer.WriteStartMap(); writer.WriteStringProperty("name", tag.Name); @@ -111,12 +115,12 @@ public static void WriteTag(IParseNodeWriter writer, Tag tag) writer.WriteEndMap(); } - public static void WriteTagRef(IParseNodeWriter writer, Tag tag) + public static void WriteTagRef(IParseNodeWriter writer, OpenApiTag tag) { writer.WriteValue(tag.Name); } - public static void WriteComponents(IParseNodeWriter writer, Components components) + public static void WriteComponents(IParseNodeWriter writer, OpenApiComponents components) { writer.WriteStartMap(); @@ -133,7 +137,7 @@ public static void WriteComponents(IParseNodeWriter writer, Components component writer.WriteEndMap(); } - public static void WriteServerVariable(IParseNodeWriter writer, ServerVariable variable) + public static void WriteServerVariable(IParseNodeWriter writer, OpenApiServerVariable variable) { writer.WriteStartMap(); @@ -144,7 +148,7 @@ public static void WriteServerVariable(IParseNodeWriter writer, ServerVariable v writer.WriteEndMap(); } - public static void WriteExternalDocs(IParseNodeWriter writer, ExternalDocs externalDocs) + public static void WriteExternalDocs(IParseNodeWriter writer, OpenApiExternalDocs externalDocs) { writer.WriteStartMap(); writer.WriteStringProperty("description", externalDocs.Description); @@ -153,7 +157,7 @@ public static void WriteExternalDocs(IParseNodeWriter writer, ExternalDocs exter } - public static void WriteSecurityRequirement(IParseNodeWriter writer, SecurityRequirement securityRequirement) + public static void WriteSecurityRequirement(IParseNodeWriter writer, OpenApiSecurityRequirement securityRequirement) { writer.WriteStartMap(); @@ -181,7 +185,7 @@ public static void WriteSecurityRequirement(IParseNodeWriter writer, SecurityReq } - public static void WritePaths(IParseNodeWriter writer, Paths paths) + public static void WritePaths(IParseNodeWriter writer, OpenApiPaths paths) { foreach (var pathItem in paths) @@ -191,7 +195,7 @@ public static void WritePaths(IParseNodeWriter writer, Paths paths) } } - public static void WritePathItem(IParseNodeWriter writer, PathItem pathItem) + public static void WritePathItem(IParseNodeWriter writer, OpenApiPathItem pathItem) { writer.WriteStartMap(); writer.WriteStringProperty("summary", pathItem.Summary); @@ -218,7 +222,7 @@ public static void WritePathItem(IParseNodeWriter writer, PathItem pathItem) } - public static void WriteOperation(IParseNodeWriter writer, Operation operation) + public static void WriteOperation(IParseNodeWriter writer, OpenApiOperation operation) { writer.WriteStartMap(); writer.WriteList("tags", operation.Tags, WriteTagRef); @@ -227,18 +231,18 @@ public static void WriteOperation(IParseNodeWriter writer, Operation operation) writer.WriteObject("externalDocs", operation.ExternalDocs, WriteExternalDocs); writer.WriteStringProperty("operationId", operation.OperationId); - writer.WriteList("parameters", operation.Parameters, WriteParameterOrReference); + writer.WriteList("parameters", operation.Parameters, WriteParameterOrReference); writer.WriteObject("requestBody", operation.RequestBody, WriteRequestBodyOrReference); - writer.WriteMap("responses", operation.Responses, WriteResponseOrReference); - writer.WriteMap("callbacks", operation.Callbacks, WriteCallbackOrReference); - writer.WriteBoolProperty("deprecated", operation.Deprecated, Operation.DeprecatedDefault); + writer.WriteMap("responses", operation.Responses, WriteResponseOrReference); + writer.WriteMap("callbacks", operation.Callbacks, WriteCallbackOrReference); + writer.WriteBoolProperty("deprecated", operation.Deprecated, OpenApiOperation.DeprecatedDefault); writer.WriteList("security", operation.Security, WriteSecurityRequirement); writer.WriteList("servers", operation.Servers, WriteServer); writer.WriteEndMap(); } - public static void WriteParameterOrReference(IParseNodeWriter writer, Parameter parameter) + public static void WriteParameterOrReference(IParseNodeWriter writer, OpenApiParameter parameter) { if (parameter.IsReference()) { @@ -250,7 +254,7 @@ public static void WriteParameterOrReference(IParseNodeWriter writer, Parameter WriteParameter(writer, parameter); } } - public static void WriteParameter(IParseNodeWriter writer, Parameter parameter) + public static void WriteParameter(IParseNodeWriter writer, OpenApiParameter parameter) { writer.WriteStartMap(); writer.WriteStringProperty("name", parameter.Name); @@ -269,7 +273,7 @@ public static void WriteParameter(IParseNodeWriter writer, Parameter parameter) writer.WriteEndMap(); } - public static void WriteRequestBodyOrReference(IParseNodeWriter writer, RequestBody requestBody) + public static void WriteRequestBodyOrReference(IParseNodeWriter writer, OpenApiRequestBody requestBody) { if (requestBody.IsReference()) { @@ -281,7 +285,7 @@ public static void WriteRequestBodyOrReference(IParseNodeWriter writer, RequestB } } - public static void WriteRequestBody(IParseNodeWriter writer, RequestBody requestBody) + public static void WriteRequestBody(IParseNodeWriter writer, OpenApiRequestBody requestBody) { writer.WriteStartMap(); @@ -292,7 +296,7 @@ public static void WriteRequestBody(IParseNodeWriter writer, RequestBody request writer.WriteEndMap(); } - public static void WriteResponseOrReference(IParseNodeWriter writer, Response response) + public static void WriteResponseOrReference(IParseNodeWriter writer, OpenApiResponse response) { if (response.IsReference()) { @@ -304,7 +308,7 @@ public static void WriteResponseOrReference(IParseNodeWriter writer, Response re } } - public static void WriteResponse(IParseNodeWriter writer, Response response) + public static void WriteResponse(IParseNodeWriter writer, OpenApiResponse response) { writer.WriteStartMap(); @@ -319,7 +323,7 @@ public static void WriteResponse(IParseNodeWriter writer, Response response) } - public static void WriteSchemaOrReference(IParseNodeWriter writer, Schema schema) + public static void WriteSchemaOrReference(IParseNodeWriter writer, OpenApiSchema schema) { if (schema.IsReference()) { @@ -331,7 +335,7 @@ public static void WriteSchemaOrReference(IParseNodeWriter writer, Schema schema } } - public static void WriteSchema(IParseNodeWriter writer, Schema schema) + public static void WriteSchema(IParseNodeWriter writer, OpenApiSchema schema) { writer.WriteStartMap(); @@ -392,7 +396,7 @@ public static void WriteSchema(IParseNodeWriter writer, Schema schema) writer.WriteEndMap(); } - public static void WriteLinkOrReference(IParseNodeWriter writer, Link link) + public static void WriteLinkOrReference(IParseNodeWriter writer, OpenApiLink link) { if (link.IsReference()) { @@ -404,7 +408,7 @@ public static void WriteLinkOrReference(IParseNodeWriter writer, Link link) } } - public static void WriteLink(IParseNodeWriter writer, Link link) + public static void WriteLink(IParseNodeWriter writer, OpenApiLink link) { writer.WriteStartMap(); @@ -415,7 +419,7 @@ public static void WriteLink(IParseNodeWriter writer, Link link) writer.WriteEndMap(); } - public static void WriteHeaderOrReference(IParseNodeWriter writer, Header header) + public static void WriteHeaderOrReference(IParseNodeWriter writer, OpenApiHeader header) { if (header.IsReference()) { @@ -427,7 +431,7 @@ public static void WriteHeaderOrReference(IParseNodeWriter writer, Header header } } - public static void WriteHeader(IParseNodeWriter writer, Header header) + public static void WriteHeader(IParseNodeWriter writer, OpenApiHeader header) { writer.WriteStartMap(); @@ -446,7 +450,7 @@ public static void WriteHeader(IParseNodeWriter writer, Header header) writer.WriteEndMap(); } - public static void WriteMediaType(IParseNodeWriter writer, MediaType mediaType) + public static void WriteMediaType(IParseNodeWriter writer, OpenApiMediaType mediaType) { writer.WriteStartMap(); @@ -457,7 +461,7 @@ public static void WriteMediaType(IParseNodeWriter writer, MediaType mediaType) writer.WriteEndMap(); } - public static void WriteCallbackOrReference(IParseNodeWriter writer, Callback callback) + public static void WriteCallbackOrReference(IParseNodeWriter writer, OpenApiCallback callback) { if (callback.IsReference()) { @@ -469,17 +473,17 @@ public static void WriteCallbackOrReference(IParseNodeWriter writer, Callback ca } } - public static void WriteCallback(IParseNodeWriter writer, Callback callback) + public static void WriteCallback(IParseNodeWriter writer, OpenApiCallback callback) { writer.WriteStartMap(); foreach(var item in callback.PathItems) { - writer.WriteObject(item.Key.Expression, item.Value, WritePathItem); + writer.WriteObject(item.Key.Expression, item.Value, WritePathItem); } writer.WriteEndMap(); } - public static void WriteExampleOrReference(IParseNodeWriter writer, Example example) + public static void WriteExampleOrReference(IParseNodeWriter writer, OpenApiExample example) { if (example.IsReference()) { @@ -491,7 +495,7 @@ public static void WriteExampleOrReference(IParseNodeWriter writer, Example exam } } - public static void WriteExample(IParseNodeWriter writer, Example example) + public static void WriteExample(IParseNodeWriter writer, OpenApiExample example) { writer.WriteStartMap(); writer.WriteStringProperty("summary", example.Summary); @@ -505,7 +509,7 @@ public static void WriteExample(IParseNodeWriter writer, Example example) } - public static void WriteSecurityScheme(IParseNodeWriter writer, SecurityScheme securityScheme) + public static void WriteSecurityScheme(IParseNodeWriter writer, OpenApiSecurityScheme securityScheme) { writer.WriteStartMap(); writer.WriteStringProperty("type", securityScheme.Type); diff --git a/src/Microsoft.OpenApi/Writers/WriterExtensions.cs b/src/Microsoft.OpenApi/Writers/WriterExtensions.cs index 9e1dcd22a..3ac0d2d4a 100644 --- a/src/Microsoft.OpenApi/Writers/WriterExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/WriterExtensions.cs @@ -1,4 +1,9 @@ - +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + namespace Microsoft.OpenApi.Writers { using Microsoft.OpenApi; @@ -6,10 +11,8 @@ namespace Microsoft.OpenApi.Writers using System.Collections.Generic; using System.IO; using System.Linq; - public static class WriterExtensions { - - - + public static class WriterExtensions + { public static void Save(this OpenApiDocument doc, Stream stream, IOpenApiWriter openApiWriter = null) { if (openApiWriter == null) diff --git a/src/Microsoft.OpenApi/Writers/YamlParseNodeWriter.cs b/src/Microsoft.OpenApi/Writers/YamlParseNodeWriter.cs index a2e897b43..653ad1679 100644 --- a/src/Microsoft.OpenApi/Writers/YamlParseNodeWriter.cs +++ b/src/Microsoft.OpenApi/Writers/YamlParseNodeWriter.cs @@ -1,4 +1,10 @@ -using System; +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- + +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/test/Microsoft.OpenApi.Readers.Tests/BasicTests.cs b/test/Microsoft.OpenApi.Readers.Tests/BasicTests.cs index a802b4291..b14890bc6 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/BasicTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/BasicTests.cs @@ -42,7 +42,7 @@ public void ParseSimplestOpenApiEver() Assert.Equal("1.0.0", openApiDoc.Version); Assert.Equal(0, openApiDoc.Paths.Count()); Assert.Equal("The Api", openApiDoc.Info.Title); - Assert.Equal("0.9.1", openApiDoc.Info.Version); + Assert.Equal("0.9.1", openApiDoc.Info.Version.ToString()); Assert.Equal(0, context.ParseErrors.Count); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs b/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs index 21321ec9c..ad0b36c88 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs @@ -19,8 +19,8 @@ public void LoadSimpleCallback() var stream = this.GetType().Assembly.GetManifestResourceStream("OpenApiTests.Samples.CallbackSample.yaml"); var openApiDoc = OpenApiParser.Parse(stream).OpenApiDocument; - PathItem path = openApiDoc.Paths.First().Value; - Operation subscribeOperation = path.Operations["post"]; + OpenApiPathItem path = openApiDoc.Paths.First().Value; + OpenApiOperation subscribeOperation = path.Operations["post"]; var callback = subscribeOperation.Callbacks["mainHook"]; var pathItem = callback.PathItems.First().Value; @@ -44,14 +44,14 @@ public void LoadSimpleCallbackWithRefs() var callbackPair = operation.Callbacks.First(); Assert.Equal("simplehook", callbackPair.Key); - Callback callback = callbackPair.Value; + OpenApiCallback callback = callbackPair.Value; var pathItemPair = callback.PathItems.First(); Assert.Equal("$request.body(/url)", pathItemPair.Key.Expression); - PathItem pathItem = pathItemPair.Value; + OpenApiPathItem pathItem = pathItemPair.Value; var operationPair = pathItem.Operations.First(); - Operation cboperation = operationPair.Value; + OpenApiOperation cboperation = operationPair.Value; Assert.Equal("post", operationPair.Key); Assert.NotNull(callback); diff --git a/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs index 34a9cde72..55c1f4f69 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/DownGradeTests.cs @@ -44,8 +44,8 @@ public void EmptyTest() public void HostTest() { var openApiDoc = new OpenApiDocument(); - openApiDoc.Servers.Add(new Server() { Url = "http://example.org/api" }); - openApiDoc.Servers.Add(new Server() { Url = "https://example.org/api" }); + openApiDoc.Servers.Add(new OpenApiServer() { Url = "http://example.org/api" }); + openApiDoc.Servers.Add(new OpenApiServer() { Url = "https://example.org/api" }); JObject jObject = ExportV2ToJObject(openApiDoc); @@ -58,19 +58,19 @@ public void HostTest() public void TestConsumes() { var openApiDoc = new OpenApiDocument(); - var pathItem = new PathItem(); - var operation = new Operation + var pathItem = new OpenApiPathItem(); + var operation = new OpenApiOperation { - RequestBody = new RequestBody + RequestBody = new OpenApiRequestBody { - Content = new Dictionary() { - { "application/vnd.collection+json", new MediaType + Content = new Dictionary() { + { "application/vnd.collection+json", new OpenApiMediaType { } } } }, - Responses = new Dictionary { { "200", new Response() { + Responses = new Dictionary { { "200", new OpenApiResponse() { Description = "Success" } } } }; @@ -87,15 +87,15 @@ public void TestConsumes() public void TestRequestBody() { var openApiDoc = new OpenApiDocument(); - var pathItem = new PathItem(); - var operation = new Operation + var pathItem = new OpenApiPathItem(); + var operation = new OpenApiOperation { - RequestBody = new RequestBody + RequestBody = new OpenApiRequestBody { - Content = new Dictionary() { - { "application/vnd.collection+json", new MediaType + Content = new Dictionary() { + { "application/vnd.collection+json", new OpenApiMediaType { - Schema = new Schema + Schema = new OpenApiSchema { Type = "string", MaxLength = 100 @@ -104,7 +104,7 @@ public void TestRequestBody() } } }, - Responses = new Dictionary { { "200", new Response() { + Responses = new Dictionary { { "200", new OpenApiResponse() { Description = "Success" } } } }; @@ -124,13 +124,13 @@ public void TestRequestBody() public void TestProduces() { var openApiDoc = new OpenApiDocument(); - var pathItem = new PathItem(); - var operation = new Operation + var pathItem = new OpenApiPathItem(); + var operation = new OpenApiOperation { - Responses = new Dictionary { { "200", new Response() { + Responses = new Dictionary { { "200", new OpenApiResponse() { Description = "Success", - Content = new Dictionary() { - { "application/vnd.collection+json", new MediaType + Content = new Dictionary() { + { "application/vnd.collection+json", new OpenApiMediaType { } }, @@ -154,20 +154,20 @@ public void TestProduces() public void TestParameter() { var openApiDoc = new OpenApiDocument(); - var pathItem = new PathItem(); - var operation = new Operation + var pathItem = new OpenApiPathItem(); + var operation = new OpenApiOperation { - Parameters = new List { - new Parameter { + Parameters = new List { + new OpenApiParameter { Name = "param1", In = InEnum.query, - Schema = new Schema + Schema = new OpenApiSchema { Type = "string" } } }, - Responses = new Dictionary { { "200", new Response() { + Responses = new Dictionary { { "200", new OpenApiResponse() { Description = "Success" } } } }; diff --git a/test/Microsoft.OpenApi.Readers.Tests/FixtureTests.cs b/test/Microsoft.OpenApi.Readers.Tests/FixtureTests.cs index 9895d1860..731c75245 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/FixtureTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/FixtureTests.cs @@ -28,7 +28,7 @@ public void TestBasicInfoObject() Assert.NotNull(info); Assert.Equal("Swagger Sample App", info.Title); - Assert.Equal("1.0.1", info.Version); + Assert.Equal("1.0.1", info.Version.ToString()); Assert.Equal("support@swagger.io", info.Contact.Email); Assert.Equal(0, ctx.ParseErrors.Count); } @@ -45,7 +45,7 @@ public void TestMinimalInfoObject() Assert.NotNull(info); Assert.Equal("Swagger Sample App", info.Title); - Assert.Equal("1.0.1", info.Version); + Assert.Equal("1.0.1", info.Version.ToString()); Assert.Equal(0, ctx.ParseErrors.Count); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs b/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs index 2fe0735ad..c6fd2aafa 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/InfoTests.cs @@ -19,7 +19,7 @@ public void CheckPetStoreApiInfo() var info = openApiDoc.Info; Assert.Equal("Swagger Petstore (Simple)", openApiDoc.Info.Title); Assert.Equal("A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", info.Description); - Assert.Equal("1.0.0", info.Version); + Assert.Equal("1.0.0", info.Version.ToString()); } @@ -36,7 +36,7 @@ public void ParseCompleteHeaderOpenApi() Assert.Equal(0, openApiDoc.Paths.Count()); Assert.Equal("The Api", openApiDoc.Info.Title); - Assert.Equal("0.9.1", openApiDoc.Info.Version); + Assert.Equal("0.9.1", openApiDoc.Info.Version.ToString()); Assert.Equal("This is an api", openApiDoc.Info.Description); Assert.Equal("http://example.org/Dowhatyouwant", openApiDoc.Info.TermsOfService); Assert.Equal("Darrel Miller", openApiDoc.Info.Contact.Name); diff --git a/test/Microsoft.OpenApi.Readers.Tests/ParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/ParameterTests.cs index 59146837b..5d90e736b 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ParameterTests.cs @@ -16,7 +16,7 @@ public class ParameterTests InlineData("foo","foo")] public void SerializeStrings(string value, string expected) { - var parameter = new Parameter() { + var parameter = new OpenApiParameter() { }; @@ -29,7 +29,7 @@ public void SerializeStrings(string value, string expected) InlineData("foo bar", "foo%20bar")] public void SerializeEscapedStrings(string value, string expected) { - var parameter = new Parameter() + var parameter = new OpenApiParameter() { AllowReserved = false }; @@ -44,7 +44,7 @@ public void SerializeEscapedStrings(string value, string expected) InlineData("matrix", "", ";foo")] public void SerializePrefixedStrings(string style,string value, string expected) { - var parameter = new Parameter() + var parameter = new OpenApiParameter() { Name = "foo", Style = style @@ -61,7 +61,7 @@ public void SerializePrefixedStrings(string style,string value, string expected) InlineData("exploded-label", new[] { "a", "b" }, ".a.b")] public void SerializeArrays(string style, string[] value, string expected) { - var parameter = new Parameter() + var parameter = new OpenApiParameter() { Name = "bar", Style = style @@ -84,7 +84,7 @@ public void SerializeArrays(string style, string[] value, string expected) public void SerializeMaps(string style, string expected) { var value = new Dictionary { { "a", "1" }, { "b", "2" } }; - var parameter = new Parameter() + var parameter = new OpenApiParameter() { Name = "bar", Style = style @@ -95,7 +95,7 @@ public void SerializeMaps(string style, string expected) } // Is it possible to write code based on the information in Parameter // to serialize the value like RFC6570 does! - private string SerializeParameterValue(Parameter parameter, object value ) + private string SerializeParameterValue(OpenApiParameter parameter, object value ) { string output; diff --git a/test/Microsoft.OpenApi.Tests/ExampleTests.cs b/test/Microsoft.OpenApi.Tests/ExampleTests.cs index 1b485dd10..346151db8 100644 --- a/test/Microsoft.OpenApi.Tests/ExampleTests.cs +++ b/test/Microsoft.OpenApi.Tests/ExampleTests.cs @@ -17,10 +17,10 @@ public void WriteResponseExample() { var doc = new OpenApiDocument { - Info = new Info() + Info = new OpenApiInfo() { Title = "test", - Version = "1.0" + Version = new Version(1, 0) } };