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 fc12eb0d..09da523b 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -30,7 +30,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs index 14bd3156..ff62e212 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs @@ -391,40 +391,48 @@ public async Task CreateStructuredTypePropertiesSchemaWithCustomAttributeReturns "anyOf": [ { "$ref": "#/components/schemas/microsoft.graph.userInsightsSettings" + }, + { + "enum": [null] } ], "description": "The user's settings for the visibility of meeting hour insights, and insights derived between a user and other items in Microsoft 365, such as documents or sites. Get userInsightsSettings through this navigation property.", - "nullable": true, "x-ms-navigationProperty": true }, "contactMergeSuggestions": { "anyOf": [ { "$ref": "#/components/schemas/microsoft.graph.contactMergeSuggestions" + }, + { + "enum": [null] } ], "description": "The user's settings for the visibility of merge suggestion for the duplicate contacts in the user's contact list.", - "nullable": true, "x-ms-navigationProperty": true }, "regionalAndLanguageSettings": { "anyOf": [ { "$ref": "#/components/schemas/microsoft.graph.regionalAndLanguageSettings" + }, + { + "enum": [null] } ], "description": "The user's preferences for languages, regional locale and date/time formatting.", - "nullable": true, "x-ms-navigationProperty": true }, "shiftPreferences": { "anyOf": [ { "$ref": "#/components/schemas/microsoft.graph.shiftPreferences" + }, + { + "enum": [null] } ], "description": "The shift preferences for the user.", - "nullable": true, "x-ms-navigationProperty": true } } @@ -916,10 +924,14 @@ public async Task CreatePropertySchemaForNullableEnumPropertyReturnSchema(OpenAp "anyOf": [ { "$ref": "#/components/schemas/DefaultNs.Color" + }, + { + "enum": [ + null + ] } ], - "default": "yellow", - "nullable": true + "default": "yellow" } """, OpenApiSpecVersion.OpenApi3_1 => 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 100f7dc2..b00992a6 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 @@ -5011,13 +5011,16 @@ "format": "int32" }, "Document": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true } }, @@ -5358,33 +5361,42 @@ } }, "Library": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "LastRevisionFile": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.DocumentFile.DocumentFile" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "SourceDocument": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "SourceDocumentChildren": { @@ -5526,13 +5538,16 @@ "type": "boolean" }, "Document": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true } }, @@ -5595,23 +5610,29 @@ "format": "date-time" }, "Document": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "Tag": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Tags.Tag" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true } }, @@ -5852,33 +5873,42 @@ "format": "int32" }, "LibraryParent": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "Type": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "SourceFolder": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "Documents": { @@ -6049,23 +6079,29 @@ "type": "boolean" }, "MasterLibraryType": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "ParentLibraryTypes": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "MasterLibraryTypeChildren": { @@ -6573,13 +6609,16 @@ "nullable": true }, "Document": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true } }, @@ -7473,4 +7512,4 @@ "x-ms-docs-toc-type": "page" } ] -} \ No newline at end of file +} 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 b6da54bd..715d8e71 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 @@ -3526,10 +3526,10 @@ components: type: number format: int32 Document: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - enum: + - null x-ms-navigationProperty: true example: Id: 0 @@ -3804,22 +3804,22 @@ components: items: $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel' Library: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library' - nullable: true + - enum: + - null x-ms-navigationProperty: true LastRevisionFile: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.DocumentFile.DocumentFile' - nullable: true + - enum: + - null x-ms-navigationProperty: true SourceDocument: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - enum: + - null x-ms-navigationProperty: true SourceDocumentChildren: type: array @@ -3930,10 +3930,10 @@ components: IsPrimary: type: boolean Document: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - enum: + - null x-ms-navigationProperty: true example: ClassInstance: 0 @@ -3984,16 +3984,16 @@ components: type: string format: date-time Document: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - enum: + - null x-ms-navigationProperty: true Tag: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Tags.Tag' - nullable: true + - enum: + - null x-ms-navigationProperty: true example: DocumentId: 0 @@ -4191,22 +4191,22 @@ components: type: number format: int32 LibraryParent: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library' - nullable: true + - enum: + - null x-ms-navigationProperty: true Type: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType' - nullable: true + - enum: + - null x-ms-navigationProperty: true SourceFolder: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.Library' - nullable: true + - enum: + - null x-ms-navigationProperty: true Documents: type: array @@ -4341,16 +4341,16 @@ components: HasChanged: type: boolean MasterLibraryType: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType' - nullable: true + - enum: + - null x-ms-navigationProperty: true ParentLibraryTypes: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Library.LibraryType' - nullable: true + - enum: + - null x-ms-navigationProperty: true MasterLibraryTypeChildren: type: array @@ -4735,10 +4735,10 @@ components: format: date-time nullable: true Document: - type: object anyOf: - $ref: '#/components/schemas/Siterra.Documents.BusinessLogic.Entities.Document.Document' - nullable: true + - enum: + - null x-ms-navigationProperty: true example: Id: 0 @@ -5372,4 +5372,4 @@ tags: - name: Tasks.RevisionDto x-ms-docs-toc-type: page - name: Tasks.DocumentTagRelDto - x-ms-docs-toc-type: page \ No newline at end of file + x-ms-docs-toc-type: page 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 828daac9..33b971d7 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json @@ -1413,13 +1413,16 @@ "content": { "application/json": { "schema": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } } @@ -1446,13 +1449,16 @@ "content": { "application/json": { "schema": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } } @@ -11680,13 +11686,16 @@ "type": "object", "properties": { "hire": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } } @@ -16955,13 +16964,16 @@ "type": "object", "properties": { "hire": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } } @@ -30704,13 +30716,16 @@ "type": "object", "properties": { "hire": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } } @@ -33721,13 +33736,16 @@ } }, "HomeAddress": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] }, "FavoriteFeature": { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature" @@ -33752,14 +33770,17 @@ "x-ms-navigationProperty": true }, "BestFriend": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "enum": [ + null + ] } ], "description": "The best friend.", - "nullable": true, "x-ms-navigationProperty": true }, "Trips": { @@ -33804,9 +33825,13 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportLocation" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } }, @@ -33819,13 +33844,16 @@ "nullable": true }, "City": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.City" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } }, @@ -33860,14 +33888,17 @@ "$ref": "#/components/schemas/Edm.GeographyPoint" }, "EmergencyAuthority": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" + }, + { + "enum": [ + null + ] } ], "description": "The person to contact in case of a crisis at this location.", - "nullable": true, "x-ms-navigationProperty": true } } @@ -34005,9 +34036,13 @@ "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] }, "Description": { "type": "string", @@ -34048,33 +34083,42 @@ "nullable": true }, "Airline": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "From": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true }, "To": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport" + }, + { + "enum": [ + null + ] } ], - "nullable": true, "x-ms-navigationProperty": true } } @@ -34137,13 +34181,16 @@ ] }, "BossOffice": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] }, "DirectReports": { "type": "array", @@ -34479,13 +34526,16 @@ "content": { "application/json": { "schema": { - "type": "object", "anyOf": [ { "$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline" + }, + { + "enum": [ + null + ] } - ], - "nullable": true + ] } } } @@ -35051,4 +35101,4 @@ "x-ms-docs-toc-type": "container" } ] -} \ No newline at end of file +} 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 19ef166e..c7eb92a8 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml @@ -910,10 +910,10 @@ paths: content: application/json: schema: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport' - nullable: true + - enum: + - null default: $ref: '#/components/responses/error' x-ms-docs-operation-type: functionImport @@ -931,10 +931,10 @@ paths: content: application/json: schema: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - enum: + - null default: $ref: '#/components/responses/error' x-ms-docs-operation-type: functionImport @@ -7778,10 +7778,10 @@ paths: type: object properties: hire: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - enum: + - null responses: '204': description: Success @@ -11288,10 +11288,10 @@ paths: type: object properties: hire: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - enum: + - null responses: '204': description: Success @@ -20526,10 +20526,10 @@ paths: type: object properties: hire: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' - nullable: true + - enum: + - null responses: '204': description: Success @@ -22561,10 +22561,10 @@ components: items: $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' HomeAddress: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' - nullable: true + - enum: + - null FavoriteFeature: $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Feature' Features: @@ -22582,11 +22582,11 @@ components: description: Friends of person x-ms-navigationProperty: true BestFriend: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' + - enum: + - null description: The best friend. - nullable: true x-ms-navigationProperty: true Trips: type: array @@ -22618,7 +22618,8 @@ components: Location: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportLocation' - nullable: true + - enum: + - null Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location: title: Location type: object @@ -22627,10 +22628,10 @@ components: type: string nullable: true City: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.City' - nullable: true + - enum: + - null Microsoft.OData.Service.Sample.TrippinInMemory.Models.City: title: City type: object @@ -22653,11 +22654,11 @@ components: Loc: $ref: '#/components/schemas/Edm.GeographyPoint' EmergencyAuthority: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person' + - enum: + - null description: The person to contact in case of a crisis at this location. - nullable: true x-ms-navigationProperty: true Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation: allOf: @@ -22750,7 +22751,8 @@ components: OccursAt: anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation' - nullable: true + - enum: + - null Description: type: string nullable: true @@ -22773,22 +22775,22 @@ components: type: string nullable: true Airline: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline' - nullable: true + - enum: + - null x-ms-navigationProperty: true From: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport' - nullable: true + - enum: + - null x-ms-navigationProperty: true To: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport' - nullable: true + - enum: + - null x-ms-navigationProperty: true Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee: allOf: @@ -22822,10 +22824,10 @@ components: - type: string nullable: true BossOffice: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location' - nullable: true + - enum: + - null DirectReports: type: array items: @@ -23040,10 +23042,10 @@ components: content: application/json: schema: - type: object anyOf: - $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline' - nullable: true + - enum: + - null GetFriendsTripsResponse: description: Success content: @@ -23398,4 +23400,4 @@ tags: - name: People.Person.Actions x-ms-docs-toc-type: container - name: ResetDataSource - x-ms-docs-toc-type: container \ No newline at end of file + x-ms-docs-toc-type: container