Skip to content

Adds nullable to double schema conversions #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public static OpenApiSchema CreateSchema(this ODataContext context, IEdmPrimitiv
case EdmPrimitiveTypeKind.Double: // double
schema.OneOf = new List<OpenApiSchema>
{
new OpenApiSchema { Type = Constants.NumberType, Format = "double" },
new OpenApiSchema { Type = Constants.StringType },
new OpenApiSchema { Type = Constants.NumberType, Format = "double", Nullable = true },
new OpenApiSchema { Type = Constants.StringType, Nullable = true },
new OpenApiSchema
{
UnresolvedReference = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@

schemas[Constants.ReferenceNumericName] = new()
{
Enum = new List<IOpenApiAny>
{
Type = Constants.StringType,
Nullable = true,
Enum =
[
new OpenApiString("-INF"),
new OpenApiString("INF"),
new OpenApiString("NaN")
}
]
};

if (context.Settings.EnableODataAnnotationReferencesForResponses)
Expand Down Expand Up @@ -631,7 +633,7 @@
// properties
foreach (var property in structuredType.Properties())
{
// IOpenApiAny item;

Check warning on line 636 in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
IEdmTypeReference propertyType = property.Type;

IOpenApiAny item = GetTypeNameForExample(context, propertyType);
Expand Down Expand Up @@ -757,7 +759,7 @@
// The type 'System.Double' is not supported in Open API document.
case EdmPrimitiveTypeKind.Double:
/*
{

Check warning on line 762 in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
double result;
if (Double.TryParse(property.DefaultValueString, out result))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<TargetFrameworks>net8.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>2.0.0-preview.2</Version>
<Version>2.0.0-preview.3</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
Expand All @@ -25,6 +25,7 @@
- Cleaned up obsolete APIs
- Changed target framework to net8.0
- Adds support for retrieving collection of enum values from UpdateMethod property of UpdateRestrictions annotation #564
- Adds nullable to double schema conversions #581
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,10 +1105,12 @@ public void NonNullableDoublePropertyWithDefaultStringWorks()
""oneOf"": [
{
""type"": ""number"",
""format"": ""double""
""format"": ""double"",
""nullable"": true
},
{
""type"": ""string""
""type"": ""string"",
""nullable"": true
},
{
""$ref"": ""#/components/schemas/ReferenceNumeric""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ definitions:
- '-INF'
- INF
- NaN
type: string
parameters:
top:
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,9 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string",
"nullable": true
}
},
"responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ components:
- '-INF'
- INF
- NaN
type: string
nullable: true
responses:
error:
description: error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ definitions:
- '-INF'
- INF
- NaN
type: string
parameters:
top:
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string",
"nullable": true
}
},
"responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ components:
- '-INF'
- INF
- NaN
type: string
nullable: true
responses:
error:
description: error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6118,7 +6118,8 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4436,6 +4436,7 @@ definitions:
- '-INF'
- INF
- NaN
type: string
parameters:
top:
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6835,7 +6835,9 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string",
"nullable": true
}
},
"responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4921,6 +4921,8 @@ components:
- '-INF'
- INF
- NaN
type: string
nullable: true
responses:
error:
description: error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31561,7 +31561,8 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21393,6 +21393,7 @@ definitions:
- '-INF'
- INF
- NaN
type: string
parameters:
top:
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1397,10 +1397,12 @@
"oneOf": [
{
"type": "number",
"format": "double"
"format": "double",
"nullable": true
},
{
"type": "string"
"type": "string",
"nullable": true
},
{
"$ref": "#/components/schemas/ReferenceNumeric"
Expand All @@ -1416,10 +1418,12 @@
"oneOf": [
{
"type": "number",
"format": "double"
"format": "double",
"nullable": true
},
{
"type": "string"
"type": "string",
"nullable": true
},
{
"$ref": "#/components/schemas/ReferenceNumeric"
Expand Down Expand Up @@ -35293,7 +35297,9 @@
"-INF",
"INF",
"NaN"
]
],
"type": "string",
"nullable": true
}
},
"responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ paths:
oneOf:
- type: number
format: double
nullable: true
- type: string
nullable: true
- $ref: '#/components/schemas/ReferenceNumeric'
- name: lon
in: path
Expand All @@ -923,7 +925,9 @@ paths:
oneOf:
- type: number
format: double
nullable: true
- type: string
nullable: true
- $ref: '#/components/schemas/ReferenceNumeric'
responses:
'200':
Expand Down Expand Up @@ -23713,6 +23717,8 @@ components:
- '-INF'
- INF
- NaN
type: string
nullable: true
responses:
error:
description: error
Expand Down
Loading