diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index d698bd5b2..93c39a738 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -664,18 +664,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d { var rootNode = OpenApiUrlTreeNode.Create(document, "main"); - writer.WriteLine(@" - - - - - - -"); + writer.WriteLine( + """ + + + + + + + + + """); writer.WriteLine("

" + document.Info.Title + "

"); writer.WriteLine(); writer.WriteLine($"

API Description: {sourceUrl}

"); @@ -686,6 +689,7 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d { writer.WriteLine($"{style.Key.Replace("_", " ", StringComparison.OrdinalIgnoreCase)}"); } + writer.WriteLine(""); writer.WriteLine("
"); writer.WriteLine(""); @@ -693,18 +697,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d writer.WriteLine(""); // Write script tag to include JS library for rendering markdown - writer.WriteLine(@""); + writer.WriteLine( + """ + + """); // Write script tag to include JS library for rendering mermaid writer.WriteLine(" { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs index 71489d39f..c80c05a4f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs @@ -13,13 +13,14 @@ public class OpenApiContactTests [Fact] public void ParseStringContactFragmentShouldSucceed() { - var input = @" -{ - ""name"": ""API Support"", - ""url"": ""http://www.swagger.io/support"", - ""email"": ""support@swagger.io"" -} -"; + var input = + """ + { + "name": "API Support", + "url": "http://www.swagger.io/support", + "email": "support@swagger.io" + } + """; var reader = new OpenApiStringReader(); var diagnostic = new OpenApiDiagnostic(); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs index 4acdb583f..1d01c6a33 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs @@ -22,26 +22,24 @@ public class OpenApiDocumentTests { private const string SampleFolderPath = "V2Tests/Samples/"; - - - [Fact] public void ShouldThrowWhenReferenceTypeIsInvalid() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -paths: - '/': - get: - responses: - '200': - description: ok - schema: - $ref: '#/defi888nition/does/notexist' -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + paths: + '/': + get: + responses: + '200': + description: ok + schema: + $ref: '#/defi888nition/does/notexist' + """; var reader = new OpenApiStringReader(); var doc = reader.Read(input, out var diagnostic); @@ -54,21 +52,22 @@ public void ShouldThrowWhenReferenceTypeIsInvalid() [Fact] public void ShouldThrowWhenReferenceDoesNotExist() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -paths: - '/': - get: - produces: ['application/json'] - responses: - '200': - description: ok - schema: - $ref: '#/definitions/doesnotexist' -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + paths: + '/': + get: + produces: ['application/json'] + responses: + '200': + description: ok + schema: + $ref: '#/definitions/doesnotexist' + """; var reader = new OpenApiStringReader(); @@ -91,23 +90,24 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); var openApiDoc = new OpenApiStringReader().Read( - @" -swagger: 2.0 -info: - title: Simple Document - version: 0.9.1 - x-extension: 2.335 -definitions: - sampleSchema: - type: object - properties: - sampleProperty: - type: double - minimum: 100.54 - maximum: 60000000.35 - exclusiveMaximum: true - exclusiveMinimum: false -paths: {}", + """ + swagger: 2.0 + info: + title: Simple Document + version: 0.9.1 + x-extension: 2.335 + definitions: + sampleSchema: + type: object + properties: + sampleProperty: + type: double + minimum: 100.54 + maximum: 60000000.35 + exclusiveMaximum: true + exclusiveMinimum: false + paths: {} + """, out var context); openApiDoc.Should().BeEquivalentTo( diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs index 5037007a2..f809219e7 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs @@ -11,13 +11,14 @@ public class OpenApiServerTests [Fact] public void NoServer() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { }); @@ -30,15 +31,16 @@ public void NoServer() [Fact] public void JustSchemeNoDefault() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -schemes: - - http -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + schemes: + - http + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { }); @@ -51,14 +53,15 @@ public void JustSchemeNoDefault() [Fact] public void JustHostNoDefault() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -host: www.foo.com -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + host: www.foo.com + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { }); @@ -73,16 +76,17 @@ public void JustHostNoDefault() [Fact] public void NoBasePath() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -host: www.foo.com -schemes: - - http -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + host: www.foo.com + schemes: + - http + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://www.foo.com/spec.yaml") @@ -98,14 +102,15 @@ public void NoBasePath() [Fact] public void JustBasePathNoDefault() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -basePath: /baz -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + basePath: /baz + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { }); @@ -120,15 +125,16 @@ public void JustBasePathNoDefault() [Fact] public void JustSchemeWithCustomHost() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -schemes: - - http -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + schemes: + - http + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://bing.com/foo") @@ -144,15 +150,16 @@ public void JustSchemeWithCustomHost() [Fact] public void JustSchemeWithCustomHostWithEmptyPath() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -schemes: - - http -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + schemes: + - http + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://bing.com") @@ -168,14 +175,15 @@ public void JustSchemeWithCustomHostWithEmptyPath() [Fact] public void JustBasePathWithCustomHost() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -basePath: /api -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + basePath: /api + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://bing.com") @@ -191,14 +199,15 @@ public void JustBasePathWithCustomHost() [Fact] public void JustHostWithCustomHost() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -host: www.example.com -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + host: www.example.com + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://bing.com") @@ -214,14 +223,15 @@ public void JustHostWithCustomHost() [Fact] public void JustHostWithCustomHostWithApi() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -host: prod.bing.com -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + host: prod.bing.com + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://dev.bing.com/api/description.yaml") @@ -237,16 +247,17 @@ public void JustHostWithCustomHostWithApi() [Fact] public void MultipleServers() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -schemes: - - http - - https -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + schemes: + - http + - https + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://dev.bing.com/api") @@ -263,14 +274,15 @@ public void MultipleServers() [Fact] public void LocalHostWithCustomHost() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -host: localhost:23232 -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + host: localhost:23232 + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://bing.com") @@ -286,14 +298,15 @@ public void LocalHostWithCustomHost() [Fact] public void InvalidHostShouldYieldError() { - var input = @" -swagger: 2.0 -info: - title: test - version: 1.0.0 -host: http://test.microsoft.com -paths: {} -"; + var input = + """ + swagger: 2.0 + info: + title: test + version: 1.0.0 + host: http://test.microsoft.com + paths: {} + """; var reader = new OpenApiStringReader(new OpenApiReaderSettings { BaseUrl = new Uri("https://bing.com") diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs index be78f942b..7e4cfad75 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs @@ -13,13 +13,14 @@ public class OpenApiContactTests [Fact] public void ParseStringContactFragmentShouldSucceed() { - var input = @" -{ - ""name"": ""API Support"", - ""url"": ""http://www.swagger.io/support"", - ""email"": ""support@swagger.io"" -} -"; + var input = + """ + { + "name": "API Support", + "url": "http://www.swagger.io/support", + "email": "support@swagger.io" + } + """; var reader = new OpenApiStringReader(); var diagnostic = new OpenApiDiagnostic(); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index 85a686e49..b4f1a16ff 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -84,12 +84,14 @@ public OpenApiDocumentTests(ITestOutputHelper output) public void ParseDocumentFromInlineStringShouldSucceed() { var openApiDoc = new OpenApiStringReader().Read( - @" -openapi : 3.0.0 -info: - title: Simple Document - version: 0.9.1 -paths: {}", + """ + + openapi : 3.0.0 + info: + title: Simple Document + version: 0.9.1 + paths: {} + """, out var context); openApiDoc.Should().BeEquivalentTo( @@ -119,23 +121,24 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); var openApiDoc = new OpenApiStringReader().Read( - @" -openapi : 3.0.0 -info: - title: Simple Document - version: 0.9.1 -components: - schemas: - sampleSchema: - type: object - properties: - sampleProperty: - type: double - minimum: 100.54 - maximum: 60000000.35 - exclusiveMaximum: true - exclusiveMinimum: false -paths: {}", + """ + openapi : 3.0.0 + info: + title: Simple Document + version: 0.9.1 + components: + schemas: + sampleSchema: + type: object + properties: + sampleProperty: + type: double + minimum: 100.54 + maximum: 60000000.35 + exclusiveMaximum: true + exclusiveMinimum: false + paths: {} + """, out var context); openApiDoc.Should().BeEquivalentTo( diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index 54553d5a5..087a61fef 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -74,12 +74,14 @@ public void ParsePrimitiveSchemaFragmentShouldSucceed() [Fact] public void ParsePrimitiveStringSchemaFragmentShouldSucceed() { - var input = @" -{ ""type"": ""integer"", -""format"": ""int64"", -""default"": 88 -} -"; + var input = + """ + { + "type": "integer", + "format": "int64", + "default": 88 + } + """; var reader = new OpenApiStringReader(); var diagnostic = new OpenApiDiagnostic(); @@ -101,11 +103,13 @@ public void ParsePrimitiveStringSchemaFragmentShouldSucceed() [Fact] public void ParseExampleStringFragmentShouldSucceed() { - var input = @" -{ - ""foo"": ""bar"", - ""baz"": [ 1,2] -}"; + var input = + """ + { + "foo": "bar", + "baz": [ 1,2] + } + """; var reader = new OpenApiStringReader(); var diagnostic = new OpenApiDiagnostic(); @@ -130,11 +134,13 @@ public void ParseExampleStringFragmentShouldSucceed() [Fact] public void ParseEnumFragmentShouldSucceed() { - var input = @" -[ - ""foo"", - ""baz"" -]"; + var input = + """ + [ + "foo", + "baz" + ] + """; var reader = new OpenApiStringReader(); var diagnostic = new OpenApiDiagnostic(); @@ -205,13 +211,14 @@ public void ParseSimpleSchemaShouldSucceed() [Fact] public void ParsePathFragmentShouldSucceed() { - var input = @" -summary: externally referenced path item -get: - responses: - '200': - description: Ok -"; + var input = + """ + summary: externally referenced path item + get: + responses: + '200': + description: Ok + """; var reader = new OpenApiStringReader(); var diagnostic = new OpenApiDiagnostic(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs index 46a6bb772..879e89cef 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs @@ -286,41 +286,44 @@ public void SerializeBasicComponentsAsYamlWorks() public void SerializeAdvancedComponentsAsJsonV3Works() { // Arrange - var expected = @"{ - ""schemas"": { - ""schema1"": { - ""properties"": { - ""property2"": { - ""type"": ""integer"" - }, - ""property3"": { - ""maxLength"": 15, - ""type"": ""string"" - } - } - } - }, - ""securitySchemes"": { - ""securityScheme1"": { - ""type"": ""oauth2"", - ""description"": ""description1"", - ""flows"": { - ""implicit"": { - ""authorizationUrl"": ""https://example.com/api/oauth"", - ""scopes"": { - ""operation1:object1"": ""operation 1 on object 1"", - ""operation2:object2"": ""operation 2 on object 2"" - } - } - } - }, - ""securityScheme2"": { - ""type"": ""openIdConnect"", - ""description"": ""description1"", - ""openIdConnectUrl"": ""https://example.com/openIdConnect"" - } - } -}"; + var expected = + """ + { + "schemas": { + "schema1": { + "properties": { + "property2": { + "type": "integer" + }, + "property3": { + "maxLength": 15, + "type": "string" + } + } + } + }, + "securitySchemes": { + "securityScheme1": { + "type": "oauth2", + "description": "description1", + "flows": { + "implicit": { + "authorizationUrl": "https://example.com/api/oauth", + "scopes": { + "operation1:object1": "operation 1 on object 1", + "operation2:object2": "operation 2 on object 2" + } + } + } + }, + "securityScheme2": { + "type": "openIdConnect", + "description": "description1", + "openIdConnectUrl": "https://example.com/openIdConnect" + } + } + } + """; // Act var actual = AdvancedComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -335,47 +338,50 @@ public void SerializeAdvancedComponentsAsJsonV3Works() public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works() { // Arrange - var expected = @"{ - ""schemas"": { - ""schema1"": { - ""properties"": { - ""property2"": { - ""type"": ""integer"" - }, - ""property3"": { - ""$ref"": ""#/components/schemas/schema2"" - } - } - }, - ""schema2"": { - ""properties"": { - ""property2"": { - ""type"": ""integer"" - } - } - } - }, - ""securitySchemes"": { - ""securityScheme1"": { - ""type"": ""oauth2"", - ""description"": ""description1"", - ""flows"": { - ""implicit"": { - ""authorizationUrl"": ""https://example.com/api/oauth"", - ""scopes"": { - ""operation1:object1"": ""operation 1 on object 1"", - ""operation2:object2"": ""operation 2 on object 2"" - } - } - } - }, - ""securityScheme2"": { - ""type"": ""openIdConnect"", - ""description"": ""description1"", - ""openIdConnectUrl"": ""https://example.com/openIdConnect"" - } - } -}"; + var expected = + """ + { + "schemas": { + "schema1": { + "properties": { + "property2": { + "type": "integer" + }, + "property3": { + "$ref": "#/components/schemas/schema2" + } + } + }, + "schema2": { + "properties": { + "property2": { + "type": "integer" + } + } + } + }, + "securitySchemes": { + "securityScheme1": { + "type": "oauth2", + "description": "description1", + "flows": { + "implicit": { + "authorizationUrl": "https://example.com/api/oauth", + "scopes": { + "operation1:object1": "operation 1 on object 1", + "operation2:object2": "operation 2 on object 2" + } + } + } + }, + "securityScheme2": { + "type": "openIdConnect", + "description": "description1", + "openIdConnectUrl": "https://example.com/openIdConnect" + } + } + } + """; // Act var actual = AdvancedComponentsWithReference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -390,28 +396,31 @@ public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works() public void SerializeAdvancedComponentsAsYamlV3Works() { // Arrange - var expected = @"schemas: - schema1: - properties: - property2: - type: integer - property3: - maxLength: 15 - type: string -securitySchemes: - securityScheme1: - type: oauth2 - description: description1 - flows: - implicit: - authorizationUrl: https://example.com/api/oauth - scopes: - operation1:object1: operation 1 on object 1 - operation2:object2: operation 2 on object 2 - securityScheme2: - type: openIdConnect - description: description1 - openIdConnectUrl: https://example.com/openIdConnect"; + var expected = + """ + schemas: + schema1: + properties: + property2: + type: integer + property3: + maxLength: 15 + type: string + securitySchemes: + securityScheme1: + type: oauth2 + description: description1 + flows: + implicit: + authorizationUrl: https://example.com/api/oauth + scopes: + operation1:object1: operation 1 on object 1 + operation2:object2: operation 2 on object 2 + securityScheme2: + type: openIdConnect + description: description1 + openIdConnectUrl: https://example.com/openIdConnect + """; // Act var actual = AdvancedComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -426,31 +435,34 @@ public void SerializeAdvancedComponentsAsYamlV3Works() public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works() { // Arrange - var expected = @"schemas: - schema1: - properties: - property2: - type: integer - property3: - $ref: '#/components/schemas/schema2' - schema2: - properties: - property2: - type: integer -securitySchemes: - securityScheme1: - type: oauth2 - description: description1 - flows: - implicit: - authorizationUrl: https://example.com/api/oauth - scopes: - operation1:object1: operation 1 on object 1 - operation2:object2: operation 2 on object 2 - securityScheme2: - type: openIdConnect - description: description1 - openIdConnectUrl: https://example.com/openIdConnect"; + var expected = + """ + schemas: + schema1: + properties: + property2: + type: integer + property3: + $ref: '#/components/schemas/schema2' + schema2: + properties: + property2: + type: integer + securitySchemes: + securityScheme1: + type: oauth2 + description: description1 + flows: + implicit: + authorizationUrl: https://example.com/api/oauth + scopes: + operation1:object1: operation 1 on object 1 + operation2:object2: operation 2 on object 2 + securityScheme2: + type: openIdConnect + description: description1 + openIdConnectUrl: https://example.com/openIdConnect + """; // Act var actual = AdvancedComponentsWithReference.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -465,27 +477,30 @@ public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works() public void SerializeBrokenComponentsAsJsonV3Works() { // Arrange - var expected = @"{ - ""schemas"": { - ""schema1"": { - ""type"": ""string"" - }, - ""schema2"": null, - ""schema3"": null, - ""schema4"": { - ""type"": ""string"", - ""allOf"": [ - null, - null, - { - ""type"": ""string"" - }, - null, - null - ] - } - } -}"; + var expected = + """ + { + "schemas": { + "schema1": { + "type": "string" + }, + "schema2": null, + "schema3": null, + "schema4": { + "type": "string", + "allOf": [ + null, + null, + { + "type": "string" + }, + null, + null + ] + } + } + } + """; // Act var actual = BrokenComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -500,19 +515,22 @@ public void SerializeBrokenComponentsAsJsonV3Works() public void SerializeBrokenComponentsAsYamlV3Works() { // Arrange - var expected = @"schemas: - schema1: - type: string - schema2: - schema3: - schema4: - type: string - allOf: - - - - - - type: string - - - - "; + var expected = + """ + schemas: + schema1: + type: string + schema2: + schema3: + schema4: + type: string + allOf: + - + - + - type: string + - + - + """; // Act var actual = BrokenComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -527,14 +545,17 @@ public void SerializeBrokenComponentsAsYamlV3Works() public void SerializeTopLevelReferencingComponentsAsYamlV3Works() { // Arrange - var expected = @"schemas: - schema1: - $ref: '#/components/schemas/schema2' - schema2: - type: object - properties: - property1: - type: string"; + var expected = + """ + schemas: + schema1: + $ref: '#/components/schemas/schema2' + schema2: + type: object + properties: + property1: + type: string + """; // Act var actual = TopLevelReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -549,8 +570,11 @@ public void SerializeTopLevelReferencingComponentsAsYamlV3Works() public void SerializeTopLevelSelfReferencingComponentsAsYamlV3Works() { // Arrange - var expected = @"schemas: - schema1: { }"; + var expected = + """ + schemas: + schema1: { } + """; // Act var actual = TopLevelSelfReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -565,17 +589,20 @@ public void SerializeTopLevelSelfReferencingComponentsAsYamlV3Works() public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works() { // Arrange - var expected = @"schemas: - schema1: - type: object - properties: - property1: - type: string - schema2: - type: object - properties: - property1: - type: string"; + var expected = + """ + schemas: + schema1: + type: object + properties: + property1: + type: string + schema2: + type: object + properties: + property1: + type: string + """; // Act var actual = TopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs index 1a99241d1..d1ffab249 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs @@ -54,12 +54,14 @@ public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"{ - ""name"": ""API Support"", - ""url"": ""http://www.example.com/support"", - ""email"": ""support@example.com"", - ""x-internal-id"": 42 -}"; + """ + { + "name": "API Support", + "url": "http://www.example.com/support", + "email": "support@example.com", + "x-internal-id": 42 + } + """; // Act var actual = AdvanceContact.SerializeAsJson(version); @@ -77,10 +79,12 @@ public void SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"name: API Support -url: http://www.example.com/support -email: support@example.com -x-internal-id: 42"; + """ + name: API Support + url: http://www.example.com/support + email: support@example.com + x-internal-id: 42 + """; // Act var actual = AdvanceContact.SerializeAsYaml(version); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index becc91d97..4fb3686fa 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1410,18 +1410,21 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV2JsonWorks(bool produ public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Works() { // Arrange - var expected = @"swagger: '2.0' -info: - version: 1.0.0 -paths: { } -definitions: - schema1: - $ref: '#/definitions/schema2' - schema2: - type: object - properties: - property1: - type: string"; + var expected = + """ + swagger: '2.0' + info: + version: 1.0.0 + paths: { } + definitions: + schema1: + $ref: '#/definitions/schema2' + schema2: + type: object + properties: + property1: + type: string + """; // Act var actual = SimpleDocumentWithTopLevelReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); @@ -1436,12 +1439,15 @@ public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Work public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3Works() { // Arrange - var expected = @"swagger: '2.0' -info: - version: 1.0.0 -paths: { } -definitions: - schema1: { }"; + var expected = + """ + swagger: '2.0' + info: + version: 1.0.0 + paths: { } + definitions: + schema1: { } + """; // Act var actual = SimpleDocumentWithTopLevelSelfReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); @@ -1456,21 +1462,24 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3 public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works() { // Arrange - var expected = @"swagger: '2.0' -info: - version: 1.0.0 -paths: { } -definitions: - schema1: - type: object - properties: - property1: - type: string - schema2: - type: object - properties: - property1: - type: string"; + var expected = + """ + swagger: '2.0' + info: + version: 1.0.0 + paths: { } + definitions: + schema1: + type: object + properties: + property1: + type: string + schema2: + type: object + properties: + property1: + type: string + """; // Act var actual = SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); @@ -1541,11 +1550,13 @@ public void SerializeRelativePathAsV2JsonWorks() { // Arrange var expected = - @"swagger: '2.0' -info: - version: 1.0.0 -basePath: /server1 -paths: { }"; + """ + swagger: '2.0' + info: + version: 1.0.0 + basePath: /server1 + paths: { } + """; var doc = new OpenApiDocument { Info = new OpenApiInfo { Version = "1.0.0" }, @@ -1572,12 +1583,14 @@ public void SerializeRelativePathWithHostAsV2JsonWorks() { // Arrange var expected = - @"swagger: '2.0' -info: - version: 1.0.0 -host: //example.org -basePath: /server1 -paths: { }"; + """ + swagger: '2.0' + info: + version: 1.0.0 + host: //example.org + basePath: /server1 + paths: { } + """; var doc = new OpenApiDocument { Info = new OpenApiInfo { Version = "1.0.0" }, @@ -1604,11 +1617,13 @@ public void SerializeRelativeRootPathWithHostAsV2JsonWorks() { // Arrange var expected = - @"swagger: '2.0' -info: - version: 1.0.0 -host: //example.org -paths: { }"; + """ + swagger: '2.0' + info: + version: 1.0.0 + host: //example.org + paths: { } + """; var doc = new OpenApiDocument { Info = new OpenApiInfo { Version = "1.0.0" }, @@ -1683,15 +1698,18 @@ private static OpenApiDocument ParseInputFile(string filePath) public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat() { // Arrange - var expected = @"swagger: '2.0' -info: { } -paths: - /foo: - get: - parameters: - - in: query - type: string - responses: { }"; + var expected = + """ + swagger: '2.0' + info: { } + paths: + /foo: + get: + parameters: + - in: query + type: string + responses: { } + """; var doc = new OpenApiDocument { @@ -1735,27 +1753,30 @@ public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFo public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() { // Arrange - var expected = @"openapi: 3.0.1 -info: - title: magic style - version: 1.0.0 -paths: - /foo: - get: - parameters: - - name: id - in: query - schema: - type: object - additionalProperties: - type: integer - responses: - '200': - description: foo - content: - text/plain: - schema: - type: string"; + var expected = + """ + openapi: 3.0.1 + info: + title: magic style + version: 1.0.0 + paths: + /foo: + get: + parameters: + - name: id + in: query + schema: + type: object + additionalProperties: + type: integer + responses: + '200': + description: foo + content: + text/plain: + schema: + type: string + """; var doc = new OpenApiDocument { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs index 24bfca242..9f273f280 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs @@ -40,12 +40,14 @@ public void SerializeAdvanceEncodingAsV3JsonWorks() { // Arrange var expected = - @"{ - ""contentType"": ""image/png, image/jpeg"", - ""style"": ""simple"", - ""explode"": true, - ""allowReserved"": true -}"; + """ + { + "contentType": "image/png, image/jpeg", + "style": "simple", + "explode": true, + "allowReserved": true + } + """; // Act var actual = AdvanceEncoding.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -61,10 +63,12 @@ public void SerializeAdvanceEncodingAsV3YamlWorks() { // Arrange var expected = - @"contentType: 'image/png, image/jpeg' -style: simple -explode: true -allowReserved: true"; + """ + contentType: 'image/png, image/jpeg' + style: simple + explode: true + allowReserved: true + """; // Act var actual = AdvanceEncoding.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs index 7d37fc9a4..a9ba66e88 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs @@ -41,10 +41,12 @@ public void SerializeAdvanceExDocsAsV3JsonWorks() { // Arrange var expected = - @"{ - ""description"": ""Find more info here"", - ""url"": ""https://example.com"" -}"; + """ + { + "description": "Find more info here", + "url": "https://example.com" + } + """; // Act var actual = AdvanceExDocs.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -60,8 +62,10 @@ public void SerializeAdvanceExDocsAsV3YamlWorks() { // Arrange var expected = - @"description: Find more info here -url: https://example.com"; + """ + description: Find more info here + url: https://example.com + """; // Act var actual = AdvanceExDocs.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs index b2395a9ed..a28ea2598 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs @@ -43,10 +43,12 @@ public static IEnumerable BasicInfoJsonExpected() yield return new object[] { specVersion, - @"{ - ""title"": ""Sample Pet Store App"", - ""version"": ""1.0"" -}" + """ + { + "title": "Sample Pet Store App", + "version": "1.0" + } + """ }; } } @@ -72,8 +74,10 @@ public static IEnumerable BasicInfoYamlExpected() yield return new object[] { specVersion, - @"title: Sample Pet Store App -version: '1.0'" + """ + title: Sample Pet Store App + version: '1.0' + """ }; } } @@ -99,24 +103,26 @@ public static IEnumerable AdvanceInfoJsonExpect() yield return new object[] { specVersion, - @"{ - ""title"": ""Sample Pet Store App"", - ""description"": ""This is a sample server for a pet store."", - ""termsOfService"": ""http://example.com/terms/"", - ""contact"": { - ""name"": ""API Support"", - ""url"": ""http://www.example.com/support"", - ""email"": ""support@example.com"", - ""x-internal-id"": 42 - }, - ""license"": { - ""name"": ""Apache 2.0"", - ""url"": ""http://www.apache.org/licenses/LICENSE-2.0.html"", - ""x-copyright"": ""Abc"" - }, - ""version"": ""1.1.1"", - ""x-updated"": ""metadata"" -}" + """ + { + "title": "Sample Pet Store App", + "description": "This is a sample server for a pet store.", + "termsOfService": "http://example.com/terms/", + "contact": { + "name": "API Support", + "url": "http://www.example.com/support", + "email": "support@example.com", + "x-internal-id": 42 + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html", + "x-copyright": "Abc" + }, + "version": "1.1.1", + "x-updated": "metadata" + } + """ }; } } @@ -142,20 +148,22 @@ public static IEnumerable AdvanceInfoYamlExpect() yield return new object[] { specVersion, - @"title: Sample Pet Store App -description: This is a sample server for a pet store. -termsOfService: http://example.com/terms/ -contact: - name: API Support - url: http://www.example.com/support - email: support@example.com - x-internal-id: 42 -license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - x-copyright: Abc -version: '1.1.1' -x-updated: metadata" + """ + title: Sample Pet Store App + description: This is a sample server for a pet store. + termsOfService: http://example.com/terms/ + contact: + name: API Support + url: http://www.example.com/support + email: support@example.com + x-internal-id: 42 + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + x-copyright: Abc + version: '1.1.1' + x-updated: metadata + """ }; } } @@ -184,8 +192,10 @@ public void InfoVersionShouldAcceptDateStyledAsVersions() }; var expected = - @"title: Sample Pet Store App -version: '2017-03-01'"; + """ + title: Sample Pet Store App + version: '2017-03-01' + """; // Act var actual = info.Serialize(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs index 46717ecec..1f5bb1d5b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs @@ -37,9 +37,11 @@ public void SerializeBasicLicenseAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"{ - ""name"": ""Apache 2.0"" -}"; + """ + { + "name": "Apache 2.0" + } + """; // Act var actual = BasicLicense.SerializeAsJson(version); @@ -74,11 +76,13 @@ public void SerializeAdvanceLicenseAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"{ - ""name"": ""Apache 2.0"", - ""url"": ""http://www.apache.org/licenses/LICENSE-2.0.html"", - ""x-copyright"": ""Abc"" -}"; + """ + { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html", + "x-copyright": "Abc" + } + """; // Act var actual = AdvanceLicense.SerializeAsJson(version); @@ -96,9 +100,11 @@ public void SerializeAdvanceLicenseAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"name: Apache 2.0 -url: http://www.apache.org/licenses/LICENSE-2.0.html -x-copyright: Abc"; + """ + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + x-copyright: Abc + """; // Act var actual = AdvanceLicense.SerializeAsYaml(version); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs index c59da1e86..161be20d9 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs @@ -147,17 +147,19 @@ public void SerializeAdvanceMediaTypeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""example"": 42, - ""encoding"": { - ""testEncoding"": { - ""contentType"": ""image/png, image/jpeg"", - ""style"": ""simple"", - ""explode"": true, - ""allowReserved"": true - } - } -}"; + """ + { + "example": 42, + "encoding": { + "testEncoding": { + "contentType": "image/png, image/jpeg", + "style": "simple", + "explode": true, + "allowReserved": true + } + } + } + """; // Act var actual = AdvanceMediaType.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -173,13 +175,15 @@ public void SerializeAdvanceMediaTypeAsV3YamlWorks() { // Arrange var expected = - @"example: 42 -encoding: - testEncoding: - contentType: 'image/png, image/jpeg' - style: simple - explode: true - allowReserved: true"; + """ + example: 42 + encoding: + testEncoding: + contentType: 'image/png, image/jpeg' + style: simple + explode: true + allowReserved: true + """; // Act var actual = AdvanceMediaType.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -195,24 +199,26 @@ public void SerializeMediaTypeWithObjectExampleAsV3YamlWorks() { // Arrange var expected = - @"example: - versions: - - status: Status1 - id: v1 - links: - - href: http://example.com/1 - rel: sampleRel1 - - status: Status2 - id: v2 - links: - - href: http://example.com/2 - rel: sampleRel2 -encoding: - testEncoding: - contentType: 'image/png, image/jpeg' - style: simple - explode: true - allowReserved: true"; + """ + example: + versions: + - status: Status1 + id: v1 + links: + - href: http://example.com/1 + rel: sampleRel1 + - status: Status2 + id: v2 + links: + - href: http://example.com/2 + rel: sampleRel2 + encoding: + testEncoding: + contentType: 'image/png, image/jpeg' + style: simple + explode: true + allowReserved: true + """; // Act var actual = MediaTypeWithObjectExample.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -228,40 +234,42 @@ public void SerializeMediaTypeWithObjectExampleAsV3JsonWorks() { // Arrange var expected = - @"{ - ""example"": { - ""versions"": [ - { - ""status"": ""Status1"", - ""id"": ""v1"", - ""links"": [ - { - ""href"": ""http://example.com/1"", - ""rel"": ""sampleRel1"" - } - ] - }, - { - ""status"": ""Status2"", - ""id"": ""v2"", - ""links"": [ - { - ""href"": ""http://example.com/2"", - ""rel"": ""sampleRel2"" - } - ] - } - ] - }, - ""encoding"": { - ""testEncoding"": { - ""contentType"": ""image/png, image/jpeg"", - ""style"": ""simple"", - ""explode"": true, - ""allowReserved"": true - } - } -}"; + """ + { + "example": { + "versions": [ + { + "status": "Status1", + "id": "v1", + "links": [ + { + "href": "http://example.com/1", + "rel": "sampleRel1" + } + ] + }, + { + "status": "Status2", + "id": "v2", + "links": [ + { + "href": "http://example.com/2", + "rel": "sampleRel2" + } + ] + } + ] + }, + "encoding": { + "testEncoding": { + "contentType": "image/png, image/jpeg", + "style": "simple", + "explode": true, + "allowReserved": true + } + } + } + """; // Act var actual = MediaTypeWithObjectExample.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -277,13 +285,15 @@ public void SerializeMediaTypeWithXmlExampleAsV3YamlWorks() { // Arrange var expected = - @"example: 123 -encoding: - testEncoding: - contentType: 'image/png, image/jpeg' - style: simple - explode: true - allowReserved: true"; + """ + example: 123 + encoding: + testEncoding: + contentType: 'image/png, image/jpeg' + style: simple + explode: true + allowReserved: true + """; // Act var actual = MediaTypeWithXmlExample.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -298,17 +308,20 @@ public void SerializeMediaTypeWithXmlExampleAsV3YamlWorks() public void SerializeMediaTypeWithXmlExampleAsV3JsonWorks() { // Arrange - var expected = @"{ - ""example"": ""123"", - ""encoding"": { - ""testEncoding"": { - ""contentType"": ""image/png, image/jpeg"", - ""style"": ""simple"", - ""explode"": true, - ""allowReserved"": true - } - } -}"; + var expected = + """ + { + "example": "123", + "encoding": { + "testEncoding": { + "contentType": "image/png, image/jpeg", + "style": "simple", + "explode": true, + "allowReserved": true + } + } + } + """; // Act var actual = MediaTypeWithXmlExample.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -323,26 +336,29 @@ public void SerializeMediaTypeWithXmlExampleAsV3JsonWorks() public void SerializeMediaTypeWithObjectExamplesAsV3YamlWorks() { // Arrange - var expected = @"examples: - object1: - value: - versions: - - status: Status1 - id: v1 - links: - - href: http://example.com/1 - rel: sampleRel1 - - status: Status2 - id: v2 - links: - - href: http://example.com/2 - rel: sampleRel2 -encoding: - testEncoding: - contentType: 'image/png, image/jpeg' - style: simple - explode: true - allowReserved: true"; + var expected = + """ + examples: + object1: + value: + versions: + - status: Status1 + id: v1 + links: + - href: http://example.com/1 + rel: sampleRel1 + - status: Status2 + id: v2 + links: + - href: http://example.com/2 + rel: sampleRel2 + encoding: + testEncoding: + contentType: 'image/png, image/jpeg' + style: simple + explode: true + allowReserved: true + """; // Act var actual = MediaTypeWithObjectExamples.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -358,44 +374,47 @@ public void SerializeMediaTypeWithObjectExamplesAsV3YamlWorks() public void SerializeMediaTypeWithObjectExamplesAsV3JsonWorks() { // Arrange - var expected = @"{ - ""examples"": { - ""object1"": { - ""value"": { - ""versions"": [ - { - ""status"": ""Status1"", - ""id"": ""v1"", - ""links"": [ - { - ""href"": ""http://example.com/1"", - ""rel"": ""sampleRel1"" - } - ] - }, - { - ""status"": ""Status2"", - ""id"": ""v2"", - ""links"": [ - { - ""href"": ""http://example.com/2"", - ""rel"": ""sampleRel2"" - } - ] - } - ] - } - } - }, - ""encoding"": { - ""testEncoding"": { - ""contentType"": ""image/png, image/jpeg"", - ""style"": ""simple"", - ""explode"": true, - ""allowReserved"": true - } - } -}"; + var expected = + """ + { + "examples": { + "object1": { + "value": { + "versions": [ + { + "status": "Status1", + "id": "v1", + "links": [ + { + "href": "http://example.com/1", + "rel": "sampleRel1" + } + ] + }, + { + "status": "Status2", + "id": "v2", + "links": [ + { + "href": "http://example.com/2", + "rel": "sampleRel2" + } + ] + } + ] + } + } + }, + "encoding": { + "testEncoding": { + "contentType": "image/png, image/jpeg", + "style": "simple", + "explode": true, + "allowReserved": true + } + } + } + """; // Act var actual = MediaTypeWithObjectExamples.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs index 80040f566..cd46ae02a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs @@ -50,9 +50,11 @@ public void SerializeBasicOAuthFlowAsV3JsonWorks() { // Arrange var expected = - @"{ - ""scopes"": { } -}"; + """ + { + "scopes": { } + } + """; // Act var actual = BasicOAuthFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -84,13 +86,15 @@ public void SerializePartialOAuthFlowAsV3JsonWorks() { // Arrange var expected = - @"{ - ""authorizationUrl"": ""http://example.com/authorization"", - ""scopes"": { - ""scopeName3"": ""description3"", - ""scopeName4"": ""description4"" - } -}"; + """ + { + "authorizationUrl": "http://example.com/authorization", + "scopes": { + "scopeName3": "description3", + "scopeName4": "description4" + } + } + """; // Act var actual = PartialOAuthFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -106,15 +110,17 @@ public void SerializeCompleteOAuthFlowAsV3JsonWorks() { // Arrange var expected = - @"{ - ""authorizationUrl"": ""http://example.com/authorization"", - ""tokenUrl"": ""http://example.com/token"", - ""refreshUrl"": ""http://example.com/refresh"", - ""scopes"": { - ""scopeName3"": ""description3"", - ""scopeName4"": ""description4"" - } -}"; + """ + { + "authorizationUrl": "http://example.com/authorization", + "tokenUrl": "http://example.com/token", + "refreshUrl": "http://example.com/refresh", + "scopes": { + "scopeName3": "description3", + "scopeName4": "description4" + } + } + """; // Act var actual = CompleteOAuthFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs index 7d4882bbb..9860a926a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs @@ -96,15 +96,17 @@ public void SerializeOAuthFlowsWithSingleFlowAsV3JsonWorks() { // Arrange var expected = - @"{ - ""implicit"": { - ""authorizationUrl"": ""http://example.com/authorization"", - ""scopes"": { - ""scopeName1"": ""description1"", - ""scopeName2"": ""description2"" - } - } -}"; + """ + { + "implicit": { + "authorizationUrl": "http://example.com/authorization", + "scopes": { + "scopeName1": "description1", + "scopeName2": "description2" + } + } + } + """; // Act var actual = OAuthFlowsWithSingleFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -120,23 +122,25 @@ public void SerializeOAuthFlowsWithMultipleFlowsAsV3JsonWorks() { // Arrange var expected = - @"{ - ""implicit"": { - ""authorizationUrl"": ""http://example.com/authorization"", - ""scopes"": { - ""scopeName1"": ""description1"", - ""scopeName2"": ""description2"" - } - }, - ""password"": { - ""tokenUrl"": ""http://example.com/token"", - ""refreshUrl"": ""http://example.com/refresh"", - ""scopes"": { - ""scopeName3"": ""description3"", - ""scopeName4"": ""description4"" - } - } -}"; + """ + { + "implicit": { + "authorizationUrl": "http://example.com/authorization", + "scopes": { + "scopeName1": "description1", + "scopeName2": "description2" + } + }, + "password": { + "tokenUrl": "http://example.com/token", + "refreshUrl": "http://example.com/refresh", + "scopes": { + "scopeName3": "description3", + "scopeName4": "description4" + } + } + } + """; // Act var actual = OAuthFlowsWithMultipleFlows.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs index 11d8dc517..6c6bd6f76 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs @@ -307,9 +307,12 @@ public OpenApiOperationTests(ITestOutputHelper output) public void SerializeBasicOperationAsV3JsonWorks() { // Arrange - var expected = @"{ - ""responses"": { } -}"; + var expected = + """ + { + "responses": { } + } + """; // Act var actual = _basicOperation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -324,61 +327,64 @@ public void SerializeBasicOperationAsV3JsonWorks() public void SerializeOperationWithBodyAsV3JsonWorks() { // Arrange - var expected = @"{ - ""summary"": ""summary1"", - ""description"": ""operationDescription"", - ""externalDocs"": { - ""description"": ""externalDocsDescription"", - ""url"": ""http://external.com"" - }, - ""operationId"": ""operationId1"", - ""parameters"": [ - { - ""name"": ""parameter1"", - ""in"": ""path"" - }, - { - ""name"": ""parameter2"", - ""in"": ""header"" - } - ], - ""requestBody"": { - ""description"": ""description2"", - ""content"": { - ""application/json"": { - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - }, - ""required"": true - }, - ""responses"": { - ""200"": { - ""$ref"": ""#/components/responses/response1"" - }, - ""400"": { - ""description"": null, - ""content"": { - ""application/json"": { - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - } - } - }, - ""servers"": [ - { - ""url"": ""http://server.com"", - ""description"": ""serverDescription"" - } - ] -}"; + var expected = + """ + { + "summary": "summary1", + "description": "operationDescription", + "externalDocs": { + "description": "externalDocsDescription", + "url": "http://external.com" + }, + "operationId": "operationId1", + "parameters": [ + { + "name": "parameter1", + "in": "path" + }, + { + "name": "parameter2", + "in": "header" + } + ], + "requestBody": { + "description": "description2", + "content": { + "application/json": { + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + }, + "required": true + }, + "responses": { + "200": { + "$ref": "#/components/responses/response1" + }, + "400": { + "description": null, + "content": { + "application/json": { + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + } + } + }, + "servers": [ + { + "url": "http://server.com", + "description": "serverDescription" + } + ] + } + """; // Act var actual = _operationWithBody.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -393,74 +399,77 @@ public void SerializeOperationWithBodyAsV3JsonWorks() public void SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() { // Arrange - var expected = @"{ - ""tags"": [ - ""tagName1"", - ""tagId1"" - ], - ""summary"": ""summary1"", - ""description"": ""operationDescription"", - ""externalDocs"": { - ""description"": ""externalDocsDescription"", - ""url"": ""http://external.com"" - }, - ""operationId"": ""operationId1"", - ""parameters"": [ - { - ""name"": ""parameter1"", - ""in"": ""path"" - }, - { - ""name"": ""parameter2"", - ""in"": ""header"" - } - ], - ""requestBody"": { - ""description"": ""description2"", - ""content"": { - ""application/json"": { - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - }, - ""required"": true - }, - ""responses"": { - ""200"": { - ""$ref"": ""#/components/responses/response1"" - }, - ""400"": { - ""description"": null, - ""content"": { - ""application/json"": { - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - } - } - }, - ""security"": [ - { - ""securitySchemeId1"": [ ], - ""securitySchemeId2"": [ - ""scopeName1"", - ""scopeName2"" - ] - } - ], - ""servers"": [ - { - ""url"": ""http://server.com"", - ""description"": ""serverDescription"" - } - ] -}"; + var expected = + """ + { + "tags": [ + "tagName1", + "tagId1" + ], + "summary": "summary1", + "description": "operationDescription", + "externalDocs": { + "description": "externalDocsDescription", + "url": "http://external.com" + }, + "operationId": "operationId1", + "parameters": [ + { + "name": "parameter1", + "in": "path" + }, + { + "name": "parameter2", + "in": "header" + } + ], + "requestBody": { + "description": "description2", + "content": { + "application/json": { + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + }, + "required": true + }, + "responses": { + "200": { + "$ref": "#/components/responses/response1" + }, + "400": { + "description": null, + "content": { + "application/json": { + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + } + } + }, + "security": [ + { + "securitySchemeId1": [ ], + "securitySchemeId2": [ + "scopeName1", + "scopeName2" + ] + } + ], + "servers": [ + { + "url": "http://server.com", + "description": "serverDescription" + } + ] + } + """; // Act var actual = _advancedOperationWithTagsAndSecurity.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -475,9 +484,12 @@ public void SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() public void SerializeBasicOperationAsV2JsonWorks() { // Arrange - var expected = @"{ - ""responses"": { } -}"; + var expected = + """ + { + "responses": { } + } + """; // Act var actual = _basicOperation.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -492,68 +504,71 @@ public void SerializeBasicOperationAsV2JsonWorks() public void SerializeOperationWithFormDataAsV3JsonWorks() { // Arrange - var expected = @"{ - ""summary"": ""Updates a pet in the store with form data"", - ""description"": """", - ""operationId"": ""updatePetWithForm"", - ""parameters"": [ - { - ""name"": ""petId"", - ""in"": ""path"", - ""description"": ""ID of pet that needs to be updated"", - ""required"": true, - ""schema"": { - ""type"": ""string"" - } - } - ], - ""requestBody"": { - ""content"": { - ""application/x-www-form-urlencoded"": { - ""schema"": { - ""required"": [ - ""name"" - ], - ""properties"": { - ""name"": { - ""type"": ""string"", - ""description"": ""Updated name of the pet"" - }, - ""status"": { - ""type"": ""string"", - ""description"": ""Updated status of the pet"" - } - } - } - }, - ""multipart/form-data"": { - ""schema"": { - ""required"": [ - ""name"" - ], - ""properties"": { - ""name"": { - ""type"": ""string"", - ""description"": ""Updated name of the pet"" - }, - ""status"": { - ""type"": ""string"", - ""description"": ""Updated status of the pet"" - } - } - } - } - } - }, - ""responses"": { - ""200"": { - ""description"": ""Pet updated."" - }, - ""405"": { - ""description"": ""Invalid input"" - } - } -}"; + var expected = + """ + { + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet that needs to be updated", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/x-www-form-urlencoded": { + "schema": { + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "description": "Updated name of the pet" + }, + "status": { + "type": "string", + "description": "Updated status of the pet" + } + } + } + }, + "multipart/form-data": { + "schema": { + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "description": "Updated name of the pet" + }, + "status": { + "type": "string", + "description": "Updated status of the pet" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Pet updated." + }, + "405": { + "description": "Invalid input" + } + } + } + """; // Act var actual = _operationWithFormData.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -568,45 +583,48 @@ public void SerializeOperationWithFormDataAsV3JsonWorks() public void SerializeOperationWithFormDataAsV2JsonWorks() { // Arrange - var expected = @"{ - ""summary"": ""Updates a pet in the store with form data"", - ""description"": """", - ""operationId"": ""updatePetWithForm"", - ""consumes"": [ - ""application/x-www-form-urlencoded"", - ""multipart/form-data"" - ], - ""parameters"": [ - { - ""in"": ""path"", - ""name"": ""petId"", - ""description"": ""ID of pet that needs to be updated"", - ""required"": true, - ""type"": ""string"" - }, - { - ""in"": ""formData"", - ""name"": ""name"", - ""description"": ""Updated name of the pet"", - ""required"": true, - ""type"": ""string"" - }, - { - ""in"": ""formData"", - ""name"": ""status"", - ""description"": ""Updated status of the pet"", - ""type"": ""string"" - } - ], - ""responses"": { - ""200"": { - ""description"": ""Pet updated."" - }, - ""405"": { - ""description"": ""Invalid input"" - } - } -}"; + var expected = + """ + { + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "consumes": [ + "application/x-www-form-urlencoded", + "multipart/form-data" + ], + "parameters": [ + { + "in": "path", + "name": "petId", + "description": "ID of pet that needs to be updated", + "required": true, + "type": "string" + }, + { + "in": "formData", + "name": "name", + "description": "Updated name of the pet", + "required": true, + "type": "string" + }, + { + "in": "formData", + "name": "status", + "description": "Updated status of the pet", + "type": "string" + } + ], + "responses": { + "200": { + "description": "Pet updated." + }, + "405": { + "description": "Invalid input" + } + } + } + """; // Act var actual = _operationWithFormData.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -621,58 +639,61 @@ public void SerializeOperationWithFormDataAsV2JsonWorks() public void SerializeOperationWithBodyAsV2JsonWorks() { // Arrange - var expected = @"{ - ""summary"": ""summary1"", - ""description"": ""operationDescription"", - ""externalDocs"": { - ""description"": ""externalDocsDescription"", - ""url"": ""http://external.com"" - }, - ""operationId"": ""operationId1"", - ""consumes"": [ - ""application/json"" - ], - ""produces"": [ - ""application/json"" - ], - ""parameters"": [ - { - ""in"": ""path"", - ""name"": ""parameter1"" - }, - { - ""in"": ""header"", - ""name"": ""parameter2"" - }, - { - ""in"": ""body"", - ""name"": ""body"", - ""description"": ""description2"", - ""required"": true, - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - ], - ""responses"": { - ""200"": { - ""$ref"": ""#/responses/response1"" - }, - ""400"": { - ""description"": null, - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - }, - ""schemes"": [ - ""http"" - ] -}"; + var expected = + """ + { + "summary": "summary1", + "description": "operationDescription", + "externalDocs": { + "description": "externalDocsDescription", + "url": "http://external.com" + }, + "operationId": "operationId1", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "path", + "name": "parameter1" + }, + { + "in": "header", + "name": "parameter2" + }, + { + "in": "body", + "name": "body", + "description": "description2", + "required": true, + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + ], + "responses": { + "200": { + "$ref": "#/responses/response1" + }, + "400": { + "description": null, + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + }, + "schemes": [ + "http" + ] + } + """; // Act var actual = _operationWithBody.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -687,71 +708,74 @@ public void SerializeOperationWithBodyAsV2JsonWorks() public void SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks() { // Arrange - var expected = @"{ - ""tags"": [ - ""tagName1"", - ""tagId1"" - ], - ""summary"": ""summary1"", - ""description"": ""operationDescription"", - ""externalDocs"": { - ""description"": ""externalDocsDescription"", - ""url"": ""http://external.com"" - }, - ""operationId"": ""operationId1"", - ""consumes"": [ - ""application/json"" - ], - ""produces"": [ - ""application/json"" - ], - ""parameters"": [ - { - ""in"": ""path"", - ""name"": ""parameter1"" - }, - { - ""in"": ""header"", - ""name"": ""parameter2"" - }, - { - ""in"": ""body"", - ""name"": ""body"", - ""description"": ""description2"", - ""required"": true, - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - ], - ""responses"": { - ""200"": { - ""$ref"": ""#/responses/response1"" - }, - ""400"": { - ""description"": null, - ""schema"": { - ""maximum"": 10, - ""minimum"": 5, - ""type"": ""number"" - } - } - }, - ""schemes"": [ - ""http"" - ], - ""security"": [ - { - ""securitySchemeId1"": [ ], - ""securitySchemeId2"": [ - ""scopeName1"", - ""scopeName2"" - ] - } - ] -}"; + var expected = + """ + { + "tags": [ + "tagName1", + "tagId1" + ], + "summary": "summary1", + "description": "operationDescription", + "externalDocs": { + "description": "externalDocsDescription", + "url": "http://external.com" + }, + "operationId": "operationId1", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "path", + "name": "parameter1" + }, + { + "in": "header", + "name": "parameter2" + }, + { + "in": "body", + "name": "body", + "description": "description2", + "required": true, + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + ], + "responses": { + "200": { + "$ref": "#/responses/response1" + }, + "400": { + "description": null, + "schema": { + "maximum": 10, + "minimum": 5, + "type": "number" + } + } + }, + "schemes": [ + "http" + ], + "security": [ + { + "securitySchemeId1": [ ], + "securitySchemeId2": [ + "scopeName1", + "scopeName2" + ] + } + ] + } + """; // Act var actual = _advancedOperationWithTagsAndSecurity.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -766,9 +790,12 @@ public void SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks() public void SerializeOperationWithNullCollectionAsV2JsonWorks() { // Arrange - var expected = @"{ - ""responses"": { } -}"; + var expected = + """ + { + "responses": { } + } + """; var operation = new OpenApiOperation { Parameters = null, diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs index 2a2c65202..8ffb122ef 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs @@ -211,10 +211,13 @@ public void WhenStyleAndInIsNullTheDefaultValueOfStyleShouldBeSimple(ParameterLo public void SerializeBasicParameterAsV3JsonWorks() { // Arrange - var expected = @"{ - ""name"": ""name1"", - ""in"": ""path"" -}"; + var expected = + """ + { + "name": "name1", + "in": "path" + } + """; // Act var actual = BasicParameter.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -229,33 +232,36 @@ public void SerializeBasicParameterAsV3JsonWorks() public void SerializeAdvancedParameterAsV3JsonWorks() { // Arrange - var expected = @"{ - ""name"": ""name1"", - ""in"": ""path"", - ""description"": ""description1"", - ""required"": true, - ""style"": ""simple"", - ""explode"": true, - ""schema"": { - ""title"": ""title2"", - ""oneOf"": [ - { - ""type"": ""number"", - ""format"": ""double"" - }, - { - ""type"": ""string"" - } - ], - ""description"": ""description2"" - }, - ""examples"": { - ""test"": { - ""summary"": ""summary3"", - ""description"": ""description3"" - } - } -}"; + var expected = + """ + { + "name": "name1", + "in": "path", + "description": "description1", + "required": true, + "style": "simple", + "explode": true, + "schema": { + "title": "title2", + "oneOf": [ + { + "type": "number", + "format": "double" + }, + { + "type": "string" + } + ], + "description": "description2" + }, + "examples": { + "test": { + "summary": "summary3", + "description": "description3" + } + } + } + """; // Act var actual = AdvancedPathParameterWithSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -270,13 +276,16 @@ public void SerializeAdvancedParameterAsV3JsonWorks() public void SerializeAdvancedParameterAsV2JsonWorks() { // Arrange - var expected = @"{ - ""in"": ""path"", - ""name"": ""name1"", - ""description"": ""description1"", - ""required"": true, - ""format"": ""double"" -}"; + var expected = + """ + { + "in": "path", + "name": "name1", + "description": "description1", + "required": true, + "format": "double" + } + """; // Act var actual = AdvancedPathParameterWithSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs index b9edd2a32..5b7426fca 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs @@ -90,9 +90,12 @@ public void SerializeSchemaReferenceAsJsonV3Works() { // Arrange var reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Pet" }; - var expected = @"{ - ""$ref"": ""#/components/schemas/Pet"" -}"; + var expected = + """ + { + "$ref": "#/components/schemas/Pet" + } + """; // Act var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -132,9 +135,12 @@ public void SerializeSchemaReferenceAsJsonV2Works() Id = "Pet" }; - var expected = @"{ - ""$ref"": ""#/definitions/Pet"" -}".MakeLineBreaksEnvironmentNeutral(); + var expected = + """ + { + "$ref": "#/definitions/Pet" + } + """.MakeLineBreaksEnvironmentNeutral(); // Act var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -172,9 +178,12 @@ public void SerializeExternalReferenceAsJsonV2Works() Id = "Pets" }; - var expected = @"{ - ""$ref"": ""main.json#/definitions/Pets"" -}"; + var expected = + """ + { + "$ref": "main.json#/definitions/Pets" + } + """; // Act var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -210,9 +219,12 @@ public void SerializeExternalReferenceAsJsonV3Works() // Arrange var reference = new OpenApiReference { ExternalResource = "main.json", Type = ReferenceType.Schema,Id = "Pets" }; - var expected = @"{ - ""$ref"": ""main.json#/components/schemas/Pets"" -}"; + var expected = + """ + { + "$ref": "main.json#/components/schemas/Pets" + } + """; // Act var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs index 0010e8cb6..373305603 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs @@ -126,9 +126,13 @@ public void SerializeBasicResponseWorks( OpenApiFormat format) { // Arrange - var expected = format == OpenApiFormat.Json ? @"{ - ""description"": null -}" : @"description: "; + var expected = format == OpenApiFormat.Json ? + """ + { + "description": null + } + """ : + @"description: "; // Act var actual = BasicResponse.Serialize(version, format); @@ -143,35 +147,37 @@ public void SerializeBasicResponseWorks( public void SerializeAdvancedResponseAsV3JsonWorks() { // Arrange - var expected = @"{ - ""description"": ""A complex object array response"", - ""headers"": { - ""X-Rate-Limit-Limit"": { - ""description"": ""The number of allowed requests in the current period"", - ""schema"": { - ""type"": ""integer"" - } - }, - ""X-Rate-Limit-Reset"": { - ""description"": ""The number of seconds left in the current period"", - ""schema"": { - ""type"": ""integer"" - } - } - }, - ""content"": { - ""text/plain"": { - ""schema"": { - ""type"": ""array"", - ""items"": { - ""$ref"": ""#/components/schemas/customType"" - } - }, - ""example"": ""Blabla"", - ""myextension"": ""myextensionvalue"" - } - } -}"; + var expected = """ + { + "description": "A complex object array response", + "headers": { + "X-Rate-Limit-Limit": { + "description": "The number of allowed requests in the current period", + "schema": { + "type": "integer" + } + }, + "X-Rate-Limit-Reset": { + "description": "The number of seconds left in the current period", + "schema": { + "type": "integer" + } + } + }, + "content": { + "text/plain": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/customType" + } + }, + "example": "Blabla", + "myextension": "myextensionvalue" + } + } + } + """; // Act var actual = AdvancedResponse.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -187,24 +193,26 @@ public void SerializeAdvancedResponseAsV3YamlWorks() { // Arrange var expected = - @"description: A complex object array response -headers: - X-Rate-Limit-Limit: - description: The number of allowed requests in the current period - schema: - type: integer - X-Rate-Limit-Reset: - description: The number of seconds left in the current period - schema: - type: integer -content: - text/plain: - schema: - type: array - items: - $ref: '#/components/schemas/customType' - example: Blabla - myextension: myextensionvalue"; + """ + description: A complex object array response + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + text/plain: + schema: + type: array + items: + $ref: '#/components/schemas/customType' + example: Blabla + myextension: myextensionvalue + """; // Act var actual = AdvancedResponse.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -219,29 +227,32 @@ public void SerializeAdvancedResponseAsV3YamlWorks() public void SerializeAdvancedResponseAsV2JsonWorks() { // Arrange - var expected = @"{ - ""description"": ""A complex object array response"", - ""schema"": { - ""type"": ""array"", - ""items"": { - ""$ref"": ""#/definitions/customType"" - } - }, - ""examples"": { - ""text/plain"": ""Blabla"" - }, - ""myextension"": ""myextensionvalue"", - ""headers"": { - ""X-Rate-Limit-Limit"": { - ""description"": ""The number of allowed requests in the current period"", - ""type"": ""integer"" - }, - ""X-Rate-Limit-Reset"": { - ""description"": ""The number of seconds left in the current period"", - ""type"": ""integer"" - } - } -}"; + var expected = + """ + { + "description": "A complex object array response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/customType" + } + }, + "examples": { + "text/plain": "Blabla" + }, + "myextension": "myextensionvalue", + "headers": { + "X-Rate-Limit-Limit": { + "description": "The number of allowed requests in the current period", + "type": "integer" + }, + "X-Rate-Limit-Reset": { + "description": "The number of seconds left in the current period", + "type": "integer" + } + } + } + """; // Act var actual = AdvancedResponse.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -257,21 +268,23 @@ public void SerializeAdvancedResponseAsV2YamlWorks() { // Arrange var expected = - @"description: A complex object array response -schema: - type: array - items: - $ref: '#/definitions/customType' -examples: - text/plain: Blabla -myextension: myextensionvalue -headers: - X-Rate-Limit-Limit: - description: The number of allowed requests in the current period - type: integer - X-Rate-Limit-Reset: - description: The number of seconds left in the current period - type: integer"; + """ + description: A complex object array response + schema: + type: array + items: + $ref: '#/definitions/customType' + examples: + text/plain: Blabla + myextension: myextensionvalue + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + type: integer + """; // Act var actual = AdvancedResponse.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index d59c026e3..7965ef527 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -245,19 +245,22 @@ public void SerializeBasicSchemaAsV3JsonWorks() public void SerializeAdvancedSchemaNumberAsV3JsonWorks() { // Arrange - var expected = @"{ - ""title"": ""title1"", - ""multipleOf"": 3, - ""maximum"": 42, - ""minimum"": 10, - ""exclusiveMinimum"": true, - ""type"": ""integer"", - ""default"": 15, - ""nullable"": true, - ""externalDocs"": { - ""url"": ""http://example.com/externalDocs"" - } -}"; + var expected = + """ + { + "title": "title1", + "multipleOf": 3, + "maximum": 42, + "minimum": 10, + "exclusiveMinimum": true, + "type": "integer", + "default": 15, + "nullable": true, + "externalDocs": { + "url": "http://example.com/externalDocs" + } + } + """; // Act var actual = AdvancedSchemaNumber.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -272,41 +275,44 @@ public void SerializeAdvancedSchemaNumberAsV3JsonWorks() public void SerializeAdvancedSchemaObjectAsV3JsonWorks() { // Arrange - var expected = @"{ - ""title"": ""title1"", - ""properties"": { - ""property1"": { - ""properties"": { - ""property2"": { - ""type"": ""integer"" - }, - ""property3"": { - ""maxLength"": 15, - ""type"": ""string"" - } - } - }, - ""property4"": { - ""properties"": { - ""property5"": { - ""properties"": { - ""property6"": { - ""type"": ""boolean"" - } - } - }, - ""property7"": { - ""minLength"": 2, - ""type"": ""string"" - } - } - } - }, - ""nullable"": true, - ""externalDocs"": { - ""url"": ""http://example.com/externalDocs"" - } -}"; + var expected = + """ + { + "title": "title1", + "properties": { + "property1": { + "properties": { + "property2": { + "type": "integer" + }, + "property3": { + "maxLength": 15, + "type": "string" + } + } + }, + "property4": { + "properties": { + "property5": { + "properties": { + "property6": { + "type": "boolean" + } + } + }, + "property7": { + "minLength": 2, + "type": "string" + } + } + } + }, + "nullable": true, + "externalDocs": { + "url": "http://example.com/externalDocs" + } + } + """; // Act var actual = AdvancedSchemaObject.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -321,44 +327,47 @@ public void SerializeAdvancedSchemaObjectAsV3JsonWorks() public void SerializeAdvancedSchemaWithAllOfAsV3JsonWorks() { // Arrange - var expected = @"{ - ""title"": ""title1"", - ""allOf"": [ - { - ""title"": ""title2"", - ""properties"": { - ""property1"": { - ""type"": ""integer"" - }, - ""property2"": { - ""maxLength"": 15, - ""type"": ""string"" - } - } - }, - { - ""title"": ""title3"", - ""properties"": { - ""property3"": { - ""properties"": { - ""property4"": { - ""type"": ""boolean"" - } - } - }, - ""property5"": { - ""minLength"": 2, - ""type"": ""string"" - } - }, - ""nullable"": true - } - ], - ""nullable"": true, - ""externalDocs"": { - ""url"": ""http://example.com/externalDocs"" - } -}"; + var expected = + """ + { + "title": "title1", + "allOf": [ + { + "title": "title2", + "properties": { + "property1": { + "type": "integer" + }, + "property2": { + "maxLength": 15, + "type": "string" + } + } + }, + { + "title": "title3", + "properties": { + "property3": { + "properties": { + "property4": { + "type": "boolean" + } + } + }, + "property5": { + "minLength": 2, + "type": "string" + } + }, + "nullable": true + } + ], + "nullable": true, + "externalDocs": { + "url": "http://example.com/externalDocs" + } + } + """; // Act var actual = AdvancedSchemaWithAllOf.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -448,15 +457,18 @@ public void SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInChildre var v2Schema = outputStringWriter.GetStringBuilder().ToString().MakeLineBreaksEnvironmentNeutral(); - var expectedV2Schema = @"{ - ""format"": ""decimal"", - ""allOf"": [ - { - ""format"": ""decimal"", - ""type"": ""number"" - } - ] -}".MakeLineBreaksEnvironmentNeutral(); + var expectedV2Schema = + """ + { + "format": "decimal", + "allOf": [ + { + "format": "decimal", + "type": "number" + } + ] + } + """.MakeLineBreaksEnvironmentNeutral(); // Assert Assert.Equal(expectedV2Schema, v2Schema); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs index 7d630c5f6..220837531 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs @@ -100,18 +100,20 @@ public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV3JsonWork { // Arrange var expected = - @"{ - ""scheme1"": [ - ""scope1"", - ""scope2"", - ""scope3"" - ], - ""scheme2"": [ - ""scope4"", - ""scope5"" - ], - ""scheme3"": [ ] -}"; + """ + { + "scheme1": [ + "scope1", + "scope2", + "scope3" + ], + "scheme2": [ + "scope4", + "scope5" + ], + "scheme3": [ ] + } + """; // Act var actual = @@ -128,18 +130,20 @@ public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV2JsonWork { // Arrange var expected = - @"{ - ""scheme1"": [ - ""scope1"", - ""scope2"", - ""scope3"" - ], - ""scheme2"": [ - ""scope4"", - ""scope5"" - ], - ""scheme3"": [ ] -}"; + """ + { + "scheme1": [ + "scope1", + "scope2", + "scope3" + ], + "scheme2": [ + "scope4", + "scope5" + ], + "scheme3": [ ] + } + """; // Act var actual = SecurityRequirementWithReferencedSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); @@ -156,14 +160,16 @@ public void { // Arrange var expected = - @"{ - ""scheme1"": [ - ""scope1"", - ""scope2"", - ""scope3"" - ], - ""scheme3"": [ ] -}"; + """ + { + "scheme1": [ + "scope1", + "scope2", + "scope3" + ], + "scheme3": [ ] + } + """; // Act var actual = @@ -181,14 +187,16 @@ public void { // Arrange var expected = - @"{ - ""scheme1"": [ - ""scope1"", - ""scope2"", - ""scope3"" - ], - ""scheme3"": [ ] -}"; + """ + { + "scheme1": [ + "scope1", + "scope2", + "scope3" + ], + "scheme3": [ ] + } + """; // Act var actual = diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs index 44a388d90..acb4323f1 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs @@ -133,12 +133,14 @@ public void SerializeApiKeySecuritySchemeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""type"": ""apiKey"", - ""description"": ""description1"", - ""name"": ""parameterName"", - ""in"": ""query"" -}"; + """ + { + "type": "apiKey", + "description": "description1", + "name": "parameterName", + "in": "query" + } + """; // Act var actual = ApiKeySecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -154,10 +156,12 @@ public void SerializeApiKeySecuritySchemeAsV3YamlWorks() { // Arrange var expected = - @"type: apiKey -description: description1 -name: parameterName -in: query"; + """ + type: apiKey + description: description1 + name: parameterName + in: query + """; // Act var actual = ApiKeySecurityScheme.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); @@ -173,11 +177,13 @@ public void SerializeHttpBasicSecuritySchemeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""type"": ""http"", - ""description"": ""description1"", - ""scheme"": ""basic"" -}"; + """ + { + "type": "http", + "description": "description1", + "scheme": "basic" + } + """; // Act var actual = HttpBasicSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -193,12 +199,14 @@ public void SerializeHttpBearerSecuritySchemeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""type"": ""http"", - ""description"": ""description1"", - ""scheme"": ""bearer"", - ""bearerFormat"": ""JWT"" -}"; + """ + { + "type": "http", + "description": "description1", + "scheme": "bearer", + "bearerFormat": "JWT" + } + """; // Act var actual = HttpBearerSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -214,19 +222,21 @@ public void SerializeOAuthSingleFlowSecuritySchemeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""type"": ""oauth2"", - ""description"": ""description1"", - ""flows"": { - ""implicit"": { - ""authorizationUrl"": ""https://example.com/api/oauth"", - ""scopes"": { - ""operation1:object1"": ""operation 1 on object 1"", - ""operation2:object2"": ""operation 2 on object 2"" - } - } - } -}"; + """ + { + "type": "oauth2", + "description": "description1", + "flows": { + "implicit": { + "authorizationUrl": "https://example.com/api/oauth", + "scopes": { + "operation1:object1": "operation 1 on object 1", + "operation2:object2": "operation 2 on object 2" + } + } + } + } + """; // Act var actual = OAuth2SingleFlowSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -242,35 +252,37 @@ public void SerializeOAuthMultipleFlowSecuritySchemeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""type"": ""oauth2"", - ""description"": ""description1"", - ""flows"": { - ""implicit"": { - ""authorizationUrl"": ""https://example.com/api/oauth"", - ""scopes"": { - ""operation1:object1"": ""operation 1 on object 1"", - ""operation2:object2"": ""operation 2 on object 2"" - } - }, - ""clientCredentials"": { - ""tokenUrl"": ""https://example.com/api/token"", - ""refreshUrl"": ""https://example.com/api/refresh"", - ""scopes"": { - ""operation1:object1"": ""operation 1 on object 1"", - ""operation2:object2"": ""operation 2 on object 2"" - } - }, - ""authorizationCode"": { - ""authorizationUrl"": ""https://example.com/api/oauth"", - ""tokenUrl"": ""https://example.com/api/token"", - ""scopes"": { - ""operation1:object1"": ""operation 1 on object 1"", - ""operation2:object2"": ""operation 2 on object 2"" - } - } - } -}"; + """ + { + "type": "oauth2", + "description": "description1", + "flows": { + "implicit": { + "authorizationUrl": "https://example.com/api/oauth", + "scopes": { + "operation1:object1": "operation 1 on object 1", + "operation2:object2": "operation 2 on object 2" + } + }, + "clientCredentials": { + "tokenUrl": "https://example.com/api/token", + "refreshUrl": "https://example.com/api/refresh", + "scopes": { + "operation1:object1": "operation 1 on object 1", + "operation2:object2": "operation 2 on object 2" + } + }, + "authorizationCode": { + "authorizationUrl": "https://example.com/api/oauth", + "tokenUrl": "https://example.com/api/token", + "scopes": { + "operation1:object1": "operation 1 on object 1", + "operation2:object2": "operation 2 on object 2" + } + } + } + } + """; // Act var actual = OAuth2MultipleFlowSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -286,11 +298,13 @@ public void SerializeOpenIdConnectSecuritySchemeAsV3JsonWorks() { // Arrange var expected = - @"{ - ""type"": ""openIdConnect"", - ""description"": ""description1"", - ""openIdConnectUrl"": ""https://example.com/openIdConnect"" -}"; + """ + { + "type": "openIdConnect", + "description": "description1", + "openIdConnectUrl": "https://example.com/openIdConnect" + } + """; // Act var actual = OpenIdConnectSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs index e4d4f36fb..a249591ab 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs @@ -51,10 +51,12 @@ public void SerializeBasicServerAsV3JsonWorks() { // Arrange var expected = - @"{ - ""url"": ""https://example.com/server1"", - ""description"": ""description1"" -}"; + """ + { + "url": "https://example.com/server1", + "description": "description1" + } + """; // Act var actual = BasicServer.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -70,27 +72,29 @@ public void SerializeAdvancedServerAsV3JsonWorks() { // Arrange var expected = - @"{ - ""url"": ""https://{username}.example.com:{port}/{basePath}"", - ""description"": ""description1"", - ""variables"": { - ""username"": { - ""default"": ""unknown"", - ""description"": ""variableDescription1"" - }, - ""port"": { - ""default"": ""8443"", - ""description"": ""variableDescription2"", - ""enum"": [ - ""443"", - ""8443"" - ] - }, - ""basePath"": { - ""default"": ""v1"" - } - } -}"; + """ + { + "url": "https://{username}.example.com:{port}/{basePath}", + "description": "description1", + "variables": { + "username": { + "default": "unknown", + "description": "variableDescription1" + }, + "port": { + "default": "8443", + "description": "variableDescription2", + "enum": [ + "443", + "8443" + ] + }, + "basePath": { + "default": "v1" + } + } + } + """; // Act var actual = AdvancedServer.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs index 9d50f76f6..89e341aac 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs @@ -44,14 +44,16 @@ public void SerializeAdvancedServerVariableAsV3JsonWorks() { // Arrange var expected = - @"{ - ""default"": ""8443"", - ""description"": ""test description"", - ""enum"": [ - ""8443"", - ""443"" - ] -}"; + """ + { + "default": "8443", + "description": "test description", + "enum": [ + "8443", + "443" + ] + } + """; // Act var actual = AdvancedServerVariable.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); @@ -67,11 +69,13 @@ public void SerializeAdvancedServerVariableAsV3YamlWorks() { // Arrange var expected = - @"default: '8443' -description: test description -enum: - - '8443' - - '443'"; + """ + default: '8443' + description: test description + enum: + - '8443' + - '443' + """; // Act var actual = AdvancedServerVariable.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs index 66c0dfd70..ceb8620e8 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs @@ -160,12 +160,14 @@ public void SerializeAdvancedTagAsV3YamlWithoutReferenceWorks() var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); var writer = new OpenApiYamlWriter(outputStringWriter); var expected = - @"name: pet -description: Pets operations -externalDocs: - description: Find more info here - url: https://example.com -x-tag-extension: "; + """ + name: pet + description: Pets operations + externalDocs: + description: Find more info here + url: https://example.com + x-tag-extension: + """; // Act AdvancedTag.SerializeAsV3WithoutReference(writer); @@ -185,12 +187,14 @@ public void SerializeAdvancedTagAsV2YamlWithoutReferenceWorks() var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); var writer = new OpenApiYamlWriter(outputStringWriter); var expected = - @"name: pet -description: Pets operations -externalDocs: - description: Find more info here - url: https://example.com -x-tag-extension: "; + """ + name: pet + description: Pets operations + externalDocs: + description: Find more info here + url: https://example.com + x-tag-extension: + """; // Act AdvancedTag.SerializeAsV2WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs index 9e79c5211..ebc303fb9 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs @@ -54,14 +54,16 @@ public void SerializeAdvancedXmlAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"{ - ""name"": ""animal"", - ""namespace"": ""http://swagger.io/schema/sample"", - ""prefix"": ""sample"", - ""attribute"": true, - ""wrapped"": true, - ""x-xml-extension"": 7 -}"; + """ + { + "name": "animal", + "namespace": "http://swagger.io/schema/sample", + "prefix": "sample", + "attribute": true, + "wrapped": true, + "x-xml-extension": 7 + } + """; // Act var actual = AdvancedXml.SerializeAsJson(version); @@ -79,12 +81,14 @@ public void SerializeAdvancedXmlAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = - @"name: animal -namespace: http://swagger.io/schema/sample -prefix: sample -attribute: true -wrapped: true -x-xml-extension: 7"; + """ + name: animal + namespace: http://swagger.io/schema/sample + prefix: sample + attribute: true + wrapped: true + x-xml-extension: 7 + """; // Act var actual = AdvancedXml.SerializeAsYaml(version); diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs index 13f70f1e9..facefb4a9 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs @@ -39,23 +39,27 @@ public static IEnumerable WriteStringListAsYamlShouldMatchExpectedTest "string7", "string8" }, - @"- string1 -- string2 -- string3 -- string4 -- string5 -- string6 -- string7 -- string8" + """ + - string1 + - string2 + - string3 + - string4 + - string5 + - string6 + - string7 + - string8 + """ }; yield return new object[] { new[] {"string1", "string1", "string1", "string1"}, - @"- string1 -- string1 -- string1 -- string1" + """ + - string1 + - string1 + - string1 + - string1 + """ }; } @@ -99,10 +103,12 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesSi ["property3"] = "value3", ["property4"] = "value4" }, - @"property1: value1 -property2: value2 -property3: value3 -property4: value4" + """ + property1: value1 + property2: value2 + property3: value3 + property4: value4 + """ }; // Simple map with duplicate value @@ -115,10 +121,12 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesSi ["property3"] = "value1", ["property4"] = "value1" }, - @"property1: value1 -property2: value1 -property3: value1 -property4: value1" + """ + property1: value1 + property2: value1 + property3: value1 + property4: value1 + """ }; } @@ -137,11 +145,13 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesCo }, ["property4"] = "value4" }, - @"property1: { } -property2: [ ] -property3: - - { } -property4: value4" + """ + property1: { } + property2: [ ] + property3: + - { } + property4: value4 + """ }; // Number, boolean, and null handling @@ -161,17 +171,19 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesCo ["property10"] = "null", ["property11"] = "", }, - @"property1: '10.0' -property2: '10' -property3: '-5' -property4: 10.0 -property5: 10 -property6: -5 -property7: true -property8: 'true' -property9: -property10: 'null' -property11: ''" + """ + property1: '10.0' + property2: '10' + property3: '-5' + property4: 10.0 + property5: 10 + property6: -5 + property7: true + property8: 'true' + property9: + property10: 'null' + property11: '' + """ }; // DateTime @@ -183,9 +195,11 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesCo ["property2"] = new DateTimeOffset(new DateTime(1970, 01, 01), TimeSpan.FromHours(3)), ["property3"] = new DateTime(2018, 04, 03), }, - @"property1: '1970-01-01T00:00:00.0000000' -property2: '1970-01-01T00:00:00.0000000+03:00' -property3: '2018-04-03T00:00:00.0000000'" + """ + property1: '1970-01-01T00:00:00.0000000' + property2: '1970-01-01T00:00:00.0000000+03:00' + property3: '2018-04-03T00:00:00.0000000' + """ }; // Nested map @@ -204,12 +218,14 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesCo }, ["property4"] = "value4" }, - @"property1: - innerProperty1: innerValue1 -property2: value2 -property3: - innerProperty3: innerValue3 -property4: value4" + """ + property1: + innerProperty1: innerValue1 + property2: value2 + property3: + innerProperty3: innerValue3 + property4: value4 + """ }; // Nested map and list @@ -238,17 +254,19 @@ public static IEnumerable WriteMapAsYamlShouldMatchExpectedTestCasesCo }, ["property4"] = "value4" }, - @"property1: { } -property2: [ ] -property3: - - { } - - string1 - - innerProperty1: [ ] - innerProperty2: string2 - innerProperty3: - - - - string3 -property4: value4" + """ + property1: { } + property2: [ ] + property3: + - { } + - string1 + - innerProperty1: [ ] + innerProperty2: string2 + innerProperty3: + - + - string3 + property4: value4 + """ }; } @@ -356,21 +374,23 @@ public void WriteInlineSchema() var doc = CreateDocWithSimpleSchemaToInline(); var expected = -@"openapi: 3.0.1 -info: - title: Demo - version: 1.0.0 -paths: - /: - get: - responses: - '200': - description: OK - content: - application/json: - schema: - type: object -components: { }"; + """ + openapi: 3.0.1 + info: + title: Demo + version: 1.0.0 + paths: + /: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + components: { } + """; var outputString = new StringWriter(CultureInfo.InvariantCulture); var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true } ); @@ -393,20 +413,22 @@ public void WriteInlineSchemaV2() var doc = CreateDocWithSimpleSchemaToInline(); var expected = -@"swagger: '2.0' -info: - title: Demo - version: 1.0.0 -paths: - /: - get: - produces: - - application/json - responses: - '200': - description: OK - schema: - type: object"; + """ + swagger: '2.0' + info: + title: Demo + version: 1.0.0 + paths: + /: + get: + produces: + - application/json + responses: + '200': + description: OK + schema: + type: object + """; var outputString = new StringWriter(CultureInfo.InvariantCulture); var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true }); @@ -483,39 +505,41 @@ public void WriteInlineRecursiveSchema() var doc = CreateDocWithRecursiveSchemaReference(); var expected = -@"openapi: 3.0.1 -info: - title: Demo - version: 1.0.0 -paths: - /: - get: - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - children: - $ref: '#/components/schemas/thing' - related: - type: integer -components: - schemas: - thing: - type: object - properties: - children: - type: object - properties: - children: - $ref: '#/components/schemas/thing' - related: - type: integer - related: - type: integer"; + """ + openapi: 3.0.1 + info: + title: Demo + version: 1.0.0 + paths: + /: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + children: + $ref: '#/components/schemas/thing' + related: + type: integer + components: + schemas: + thing: + type: object + properties: + children: + type: object + properties: + children: + $ref: '#/components/schemas/thing' + related: + type: integer + related: + type: integer + """; // Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles. var outputString = new StringWriter(CultureInfo.InvariantCulture); @@ -598,38 +622,40 @@ public void WriteInlineRecursiveSchemav2() var doc = CreateDocWithRecursiveSchemaReference(); var expected = -@"swagger: '2.0' -info: - title: Demo - version: 1.0.0 -paths: - /: - get: - produces: - - application/json - responses: - '200': - description: OK - schema: - type: object - properties: - children: - $ref: '#/definitions/thing' - related: - type: integer -definitions: - thing: - type: object - properties: - children: - type: object - properties: - children: - $ref: '#/definitions/thing' - related: - type: integer - related: - type: integer"; + """ + swagger: '2.0' + info: + title: Demo + version: 1.0.0 + paths: + /: + get: + produces: + - application/json + responses: + '200': + description: OK + schema: + type: object + properties: + children: + $ref: '#/definitions/thing' + related: + type: integer + definitions: + thing: + type: object + properties: + children: + type: object + properties: + children: + $ref: '#/definitions/thing' + related: + type: integer + related: + type: integer + """; // Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles. var outputString = new StringWriter(CultureInfo.InvariantCulture);