diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiEdmTypeSchemaGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiEdmTypeSchemaGenerator.cs index 4989eac6..47a59f82 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiEdmTypeSchemaGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiEdmTypeSchemaGenerator.cs @@ -420,10 +420,9 @@ private static OpenApiSchema CreateEnumTypeSchema(this ODataContext context, IEd Debug.Assert(typeReference != null); OpenApiSchema schema = new OpenApiSchema(); - schema.Nullable = typeReference.IsNullable; schema.Reference = null; - if (context.Settings.OpenApiSpecVersion >= OpenApiSpecVersion.OpenApi3_0) + if (typeReference.IsNullable && context.Settings.OpenApiSpecVersion >= OpenApiSpecVersion.OpenApi3_0) { schema.AnyOf = new List { @@ -435,6 +434,11 @@ private static OpenApiSchema CreateEnumTypeSchema(this ODataContext context, IEd Type = ReferenceType.Schema, Id = typeReference.Definition.FullTypeName() } + }, + new OpenApiSchema + { + Type = "object", + Nullable = true } }; } @@ -448,6 +452,7 @@ private static OpenApiSchema CreateEnumTypeSchema(this ODataContext context, IEd Id = typeReference.Definition.FullTypeName() }; schema.UnresolvedReference = true; + schema.Nullable = typeReference.IsNullable; } return schema; @@ -459,7 +464,6 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex Debug.Assert(typeReference != null); OpenApiSchema schema = new OpenApiSchema(); - schema.Nullable = typeReference.IsNullable; // AnyOf will only be valid openApi for version 3 // otherwise the reference should be set directly @@ -478,6 +482,11 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex Type = ReferenceType.Schema, Id = typeReference.Definition.FullTypeName() } + }, + new OpenApiSchema + { + Type = "object", + Nullable = true } }; } @@ -490,7 +499,8 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex Type = ReferenceType.Schema, Id = typeReference.Definition.FullTypeName() }; - schema.UnresolvedReference = true; + schema.UnresolvedReference = true; + schema.Nullable = typeReference.IsNullable; } return schema; @@ -502,10 +512,9 @@ private static OpenApiSchema CreateTypeDefinitionSchema(this ODataContext contex Debug.Assert(reference != null); OpenApiSchema schema = new OpenApiSchema(); - schema.Nullable = reference.IsNullable; schema.Reference = null; - if (context.Settings.OpenApiSpecVersion >= OpenApiSpecVersion.OpenApi3_0) + if (reference.IsNullable && context.Settings.OpenApiSpecVersion >= OpenApiSpecVersion.OpenApi3_0) { schema.AnyOf = new List { @@ -517,6 +526,11 @@ private static OpenApiSchema CreateTypeDefinitionSchema(this ODataContext contex Type = ReferenceType.Schema, Id = reference.Definition.FullTypeName() } + }, + new OpenApiSchema + { + Type = "object", + Nullable = true } }; } @@ -530,6 +544,7 @@ private static OpenApiSchema CreateTypeDefinitionSchema(this ODataContext contex Id = reference.Definition.FullTypeName() }; schema.UnresolvedReference = true; + schema.Nullable = reference.IsNullable; } diff --git a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj index 8ea1462f..9d33b1c3 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -29,6 +29,7 @@ - Fixes request body and response representation for ref POST and PUT operations #228 - Adds discriminator object to complex types which have derived types #233 - Adds @odata.type property and makes this a required property in schemas that have discriminator objects #243 +- Represent nullable references within anyOf correctly #190 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiEdmTypeSchemaGeneratorTest.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiEdmTypeSchemaGeneratorTest.cs index d9570594..b5c6d133 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiEdmTypeSchemaGeneratorTest.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiEdmTypeSchemaGeneratorTest.cs @@ -81,9 +81,12 @@ public void CreateEdmTypeSchemaReturnSchemaForNullableCollectionComplexType(Open ""anyOf"": [ { ""$ref"": ""#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportLocation"" + }, + { + ""type"": ""object"", + ""nullable"": true } - ], - ""nullable"": true + ] } }".ChangeLineBreaks(), json); } @@ -185,26 +188,40 @@ public void CreateEdmTypeSchemaReturnSchemaForEnumType(bool isNullable, OpenApiS // & Assert Assert.NotNull(schema); - // Although the schema will be set - // for openApiV2 nullable will not be serialized - Assert.Equal(isNullable, schema.Nullable); - + if (specVersion == OpenApiSpecVersion.OpenApi2_0) { Assert.NotNull(schema.Reference); Assert.Null(schema.AnyOf); Assert.Equal(ReferenceType.Schema, schema.Reference.Type); Assert.Equal(enumType.FullTypeName(), schema.Reference.Id); + Assert.Equal(isNullable, schema.Nullable); } else { - Assert.Null(schema.Reference); - Assert.NotNull(schema.AnyOf); - Assert.NotEmpty(schema.AnyOf); - var anyOf = Assert.Single(schema.AnyOf); - Assert.NotNull(anyOf.Reference); - Assert.Equal(ReferenceType.Schema, anyOf.Reference.Type); - Assert.Equal(enumType.FullTypeName(), anyOf.Reference.Id); + + if (isNullable) + { + Assert.NotNull(schema.AnyOf); + Assert.NotEmpty(schema.AnyOf); + Assert.Null(schema.Reference); + Assert.Equal(2, schema.AnyOf.Count); + var anyOfRef = schema.AnyOf.FirstOrDefault(); + Assert.NotNull(anyOfRef.Reference); + Assert.Equal(ReferenceType.Schema, anyOfRef.Reference.Type); + Assert.Equal(enumType.FullTypeName(), anyOfRef.Reference.Id); + var anyOfNull = schema.AnyOf.Skip(1).FirstOrDefault(); + Assert.NotNull(anyOfNull.Type); + Assert.Equal("object", anyOfNull.Type); + Assert.True(anyOfNull.Nullable); + } + else + { + Assert.Null(schema.AnyOf); + Assert.NotNull(schema.Reference); + Assert.Equal(ReferenceType.Schema, schema.Reference.Type); + Assert.Equal(enumType.FullTypeName(), schema.Reference.Id); + } } } @@ -242,7 +259,8 @@ public void CreateEdmTypeSchemaReturnSchemaForComplexType(bool isNullable, OpenA Assert.Null(schema.Reference); Assert.NotNull(schema.AnyOf); Assert.NotEmpty(schema.AnyOf); - var anyOf = Assert.Single(schema.AnyOf); + Assert.Equal(2, schema.AnyOf.Count); + var anyOf = schema.AnyOf.FirstOrDefault(); Assert.NotNull(anyOf.Reference); Assert.Equal(ReferenceType.Schema, anyOf.Reference.Type); Assert.Equal(complex.FullTypeName(), anyOf.Reference.Id); @@ -283,10 +301,14 @@ public void CreateEdmTypeSchemaReturnSchemaForEntityType(bool isNullable, OpenAp Assert.Null(schema.Reference); Assert.NotNull(schema.AnyOf); Assert.NotEmpty(schema.AnyOf); - var anyOf = Assert.Single(schema.AnyOf); - Assert.NotNull(anyOf.Reference); - Assert.Equal(ReferenceType.Schema, anyOf.Reference.Type); - Assert.Equal(entity.FullTypeName(), anyOf.Reference.Id); + var anyOfRef = schema.AnyOf.FirstOrDefault(); + Assert.NotNull(anyOfRef.Reference); + Assert.Equal(ReferenceType.Schema, anyOfRef.Reference.Type); + Assert.Equal(entity.FullTypeName(), anyOfRef.Reference.Id); + var anyOfNull = schema.AnyOf.Skip(1).FirstOrDefault(); + Assert.NotNull(anyOfNull.Type); + Assert.Equal("object", anyOfNull.Type); + Assert.True(anyOfNull.Nullable); } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiResponseGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiResponseGeneratorTests.cs index 0b73f15a..43407cc6 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiResponseGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiResponseGeneratorTests.cs @@ -225,10 +225,6 @@ public void CreateResponseForEdmFunctionReturnCorrectResponses(bool isFunctionIm Assert.NotNull(response.Content); OpenApiMediaType mediaType = response.Content["application/json"]; - // For either version, nullable should be set - // and the serializer will ignore for v2 - Assert.True(mediaType.Schema.Nullable); - // openApi version 2 should have not use nullable if (specVersion == OpenApiSpecVersion.OpenApi2_0) { @@ -236,14 +232,22 @@ public void CreateResponseForEdmFunctionReturnCorrectResponses(bool isFunctionIm Assert.Null(mediaType.Schema.AnyOf); Assert.NotNull(mediaType.Schema.Reference); Assert.Equal("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", mediaType.Schema.Reference.Id); + Assert.True(mediaType.Schema.Nullable); } else { Assert.NotNull(mediaType.Schema); Assert.Null(mediaType.Schema.Reference); Assert.NotNull(mediaType.Schema.AnyOf); - var anyOf = Assert.Single(mediaType.Schema.AnyOf); - Assert.Equal("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", anyOf.Reference.Id); + Assert.Equal(2, mediaType.Schema.AnyOf.Count); + var anyOfRef = mediaType.Schema.AnyOf.FirstOrDefault(); + Assert.NotNull(anyOfRef); + Assert.Equal("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", anyOfRef.Reference.Id); + var anyOfNull = mediaType.Schema.AnyOf.Skip(1).FirstOrDefault(); + Assert.NotNull(anyOfNull.Type); + Assert.Equal("object", anyOfNull.Type); + Assert.True(anyOfNull.Nullable); + } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs index cf356cb6..c1bd4f4e 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs @@ -259,26 +259,35 @@ public void CreateStructuredTypePropertiesSchemaWithCustomAttributeReturnsCorrec ""anyOf"": [ { ""$ref"": ""#/components/schemas/microsoft.graph.userInsightsSettings"" + }, + { + ""type"": ""object"", + ""nullable"": true } ], - ""nullable"": true, ""x-ms-isHidden"": ""true"" }, ""regionalAndLanguageSettings"": { ""anyOf"": [ { ""$ref"": ""#/components/schemas/microsoft.graph.regionalAndLanguageSettings"" + }, + { + ""type"": ""object"", + ""nullable"": true } - ], - ""nullable"": true + ] }, ""shiftPreferences"": { ""anyOf"": [ { ""$ref"": ""#/components/schemas/microsoft.graph.shiftPreferences"" + }, + { + ""type"": ""object"", + ""nullable"": true } - ], - ""nullable"": true + ] } } } @@ -687,7 +696,7 @@ public void CreatePropertySchemaForNonNullableEnumPropertyReturnSchema(OpenApiSp IEdmEnumType enumType = model.SchemaElements.OfType().First(e => e.Name == "Color"); EdmEntityType entitType = new EdmEntityType("NS", "Entity"); - IEdmProperty property = new EdmStructuralProperty(entitType, "ColorEnumValue", new EdmEnumTypeReference(enumType, false), "yellow"); + IEdmProperty property = new EdmStructuralProperty(entitType, "ColorEnumValue", new EdmEnumTypeReference(enumType, false)); // Act var schema = context.CreatePropertySchema(property); @@ -705,12 +714,7 @@ public void CreatePropertySchemaForNonNullableEnumPropertyReturnSchema(OpenApiSp else { Assert.Equal(@"{ - ""anyOf"": [ - { - ""$ref"": ""#/components/schemas/DefaultNs.Color"" - } - ], - ""default"": ""yellow"" + ""$ref"": ""#/components/schemas/DefaultNs.Color"" }".ChangeLineBreaks(), json); } } @@ -749,10 +753,13 @@ public void CreatePropertySchemaForNullableEnumPropertyReturnSchema(OpenApiSpecV ""anyOf"": [ { ""$ref"": ""#/components/schemas/DefaultNs.Color"" + }, + { + ""type"": ""object"", + ""nullable"": true } ], - ""default"": ""yellow"", - ""nullable"": true + ""default"": ""yellow"" }".ChangeLineBreaks(), json); } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.json b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.json index cf54a0c0..3bb1438d 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.json @@ -4458,9 +4458,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.App.DTO.DocumentTagRelDto" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "Revisions": { @@ -4705,9 +4708,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "example": { @@ -5045,9 +5051,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "Tags": { @@ -5056,34 +5065,46 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "Library": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "LastRevisionFile": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.DocumentFile.DocumentFile" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "SourceDocument": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "SourceDocumentChildren": { "type": "array", @@ -5225,9 +5246,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "example": { @@ -5292,17 +5316,23 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "Tag": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Tags.Tag" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "example": { @@ -5546,25 +5576,34 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "Type": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "SourceFolder": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "Documents": { "type": "array", @@ -5734,17 +5773,23 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "ParentLibraryTypes": { "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "MasterLibraryTypeChildren": { "type": "array", @@ -5995,9 +6040,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -6257,9 +6305,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "example": { diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.yaml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.yaml index fe8da422..83f3bb19 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.yaml @@ -3171,7 +3171,8 @@ components: items: anyOf: - $ref: '#/components/schemas/Siterra.Documents.App.DTO.DocumentTagRelDto' - nullable: true + - type: object + nullable: true Revisions: type: array items: @@ -3362,7 +3363,8 @@ components: Document: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - type: object + nullable: true example: Id: integer (identifier) Number: integer @@ -3637,25 +3639,30 @@ components: items: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass' - nullable: true + - type: object + nullable: true Tags: type: array items: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel' - nullable: true + - type: object + nullable: true Library: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library' - nullable: true + - type: object + nullable: true LastRevisionFile: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.DocumentFile.DocumentFile' - nullable: true + - type: object + nullable: true SourceDocument: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - type: object + nullable: true SourceDocumentChildren: type: array items: @@ -3765,7 +3772,8 @@ components: Document: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - type: object + nullable: true example: ClassInstance: integer ClassId: integer @@ -3817,11 +3825,13 @@ components: Document: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - type: object + nullable: true Tag: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Tags.Tag' - nullable: true + - type: object + nullable: true example: DocumentId: integer TagId: integer @@ -4021,15 +4031,18 @@ components: LibraryParent: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library' - nullable: true + - type: object + nullable: true Type: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType' - nullable: true + - type: object + nullable: true SourceFolder: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library' - nullable: true + - type: object + nullable: true Documents: type: array items: @@ -4162,11 +4175,13 @@ components: MasterLibraryType: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType' - nullable: true + - type: object + nullable: true ParentLibraryTypes: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType' - nullable: true + - type: object + nullable: true MasterLibraryTypeChildren: type: array items: @@ -4361,7 +4376,8 @@ components: items: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel' - nullable: true + - type: object + nullable: true example: Id: integer (identifier) DomainId: integer @@ -4552,7 +4568,8 @@ components: Document: anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - type: object + nullable: true example: Id: integer (identifier) Number: integer diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json index 9e342934..1168c031 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json @@ -1356,9 +1356,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -1388,9 +1391,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -8130,9 +8136,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -8185,9 +8194,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -8254,9 +8266,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -9160,9 +9175,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -9675,9 +9693,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -16791,9 +16812,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -16849,9 +16873,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -16930,9 +16957,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -16979,9 +17009,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -17522,9 +17555,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -26120,9 +26156,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -26185,9 +26224,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -26266,9 +26308,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -27338,9 +27383,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -27937,9 +27985,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -28763,11 +28814,7 @@ "nullable": true }, "Gender": { - "anyOf": [ - { - "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender" - } - ] + "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender" }, "Age": { "anyOf": [ @@ -28794,34 +28841,32 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } }, "HomeAddress": { "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location" - } - ], - "nullable": true - }, - "FavoriteFeature": { - "anyOf": [ + }, { - "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature" + "type": "object", + "nullable": true } ] }, + "FavoriteFeature": { + "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature" + }, "Features": { "type": "array", "items": { - "anyOf": [ - { - "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature" - } - ] + "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature" } }, "Friends": { @@ -28834,10 +28879,13 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } ], - "description": "The best friend.", - "nullable": true + "description": "The best friend." }, "Trips": { "type": "array", @@ -28880,9 +28928,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportLocation" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } }, @@ -28898,9 +28949,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.City" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } }, @@ -28938,10 +28992,13 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "type": "object", + "nullable": true } ], - "description": "The person to contact in case of a crisis at this location.", - "nullable": true + "description": "The person to contact in case of a crisis at this location." } } } @@ -29074,9 +29131,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "Description": { "type": "string", @@ -29120,25 +29180,34 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "From": { "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "To": { "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] } } } @@ -29198,9 +29267,12 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location" + }, + { + "type": "object", + "nullable": true } - ], - "nullable": true + ] }, "DirectReports": { "type": "array", diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml index 39ab5445..d85fa536 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml @@ -905,7 +905,8 @@ paths: schema: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' x-ms-docs-operation-type: functionImport @@ -925,7 +926,8 @@ paths: schema: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' x-ms-docs-operation-type: functionImport @@ -5692,7 +5694,8 @@ paths: schema: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -5730,7 +5733,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -5776,7 +5780,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -6414,7 +6419,8 @@ paths: hire: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true required: true responses: '204': @@ -6782,7 +6788,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -11732,7 +11739,8 @@ paths: schema: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' x-ms-docs-operation-type: function @@ -11771,7 +11779,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -11825,7 +11834,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' x-ms-docs-operation-type: action @@ -11855,7 +11865,8 @@ paths: hire: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true required: true responses: '204': @@ -12233,7 +12244,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' x-ms-docs-operation-type: function @@ -18287,7 +18299,8 @@ paths: schema: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -18332,7 +18345,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -18386,7 +18400,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -19139,7 +19154,8 @@ paths: hire: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true required: true responses: '204': @@ -19565,7 +19581,8 @@ paths: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - type: object + nullable: true default: $ref: '#/components/responses/error' deprecated: true @@ -20154,8 +20171,7 @@ components: type: string nullable: true Gender: - anyOf: - - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender' + $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender' Age: anyOf: - type: integer @@ -20172,19 +20188,19 @@ components: items: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' - nullable: true + - type: object + nullable: true HomeAddress: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' - nullable: true + - type: object + nullable: true FavoriteFeature: - anyOf: - - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature' + $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature' Features: type: array items: - anyOf: - - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature' + $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature' Friends: type: array items: @@ -20192,8 +20208,9 @@ components: BestFriend: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' + - type: object + nullable: true description: The best friend. - nullable: true Trips: type: array items: @@ -20223,7 +20240,8 @@ components: Location: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportLocation' - nullable: true + - type: object + nullable: true Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location: title: Location type: object @@ -20234,7 +20252,8 @@ components: City: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.City' - nullable: true + - type: object + nullable: true Microsoft.OData.Service.Sample.TrippinInMemory.Models.City: title: City type: object @@ -20259,8 +20278,9 @@ components: EmergencyAuthority: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' + - type: object + nullable: true description: The person to contact in case of a crisis at this location. - nullable: true Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation: allOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' @@ -20348,7 +20368,8 @@ components: OccursAt: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation' - nullable: true + - type: object + nullable: true Description: type: string nullable: true @@ -20373,15 +20394,18 @@ components: Airline: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline' - nullable: true + - type: object + nullable: true From: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport' - nullable: true + - type: object + nullable: true To: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport' - nullable: true + - type: object + nullable: true Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee: allOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' @@ -20411,7 +20435,8 @@ components: BossOffice: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' - nullable: true + - type: object + nullable: true DirectReports: type: array items: