You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a toy API that exists for testing ASP.NET Core functionality, and one of the resources describes times and acts like a clock.
The schema for the response of this endpoint is below:
"TimeResponse": {
"type": "object",
"properties": {
"timestamp": {
"type": "string",
"description": "The timestamp for the response for which the times are generated.",
"format": "date-time"
},
"rfc1123": {
"type": "string",
"description": "The current UTC date and time in RFC1123 format."
},
"unix": {
"type": "integer",
"description": "The number of seconds since the UNIX epoch.",
"format": "int64"
},
"universalSortable": {
"type": "string",
"description": "The current UTC date and time in universal sortable format."
},
"universalFull": {
"type": "string",
"description": "The current UTC date and time in universal full format."
}
},
"description": "Represents the response from the /time API resource."
}
This response explicitly has:
One date-time for ISO-8601
One int64 for Unix timestamps
Three string properties that are string representations of dates that do not conform to ISO-8601
It also contains the following JSON example for the schema:
[
Data and type mismatch found. [#/paths/~1time/get/responses/200/content/application~1json/example/rfc1123],
Data and type mismatch found. [#/paths/~1time/get/responses/200/content/application~1json/example/unix],
Data and type mismatch found. [#/paths/~1time/get/responses/200/content/application~1json/example/universalSortable],
Data and type mismatch found. [#/paths/~1time/get/responses/200/content/application~1json/example/universalFull]
]
For the three "date-ish" values, this is because this line of code treats the value as an OpenApiDateTime as it happens to parse as a DateTimeOffset:
Hi @martincostello, thanks for pointing out this issue.
This is clearly a regression bug as a result of trying to fix this issue #1526.
Let me look into it.
PS: This issue will go away in V2 as we're getting rid of the strongly typed structure during parsing examples as we'll treat them as their JSON compatible values.
Describe the bug
I have a toy API that exists for testing ASP.NET Core functionality, and one of the resources describes times and acts like a clock.
The schema for the response of this endpoint is below:
This response explicitly has:
date-time
for ISO-8601int64
for Unix timestampsstring
properties that are string representations of dates that do not conform to ISO-8601It also contains the following JSON example for the schema:
The example is valid for the moment in time that it describes.
If the schema is validated according to the validation rules with code such as the below, it generates 4 validation warnings:
For the three "date-ish" values, this is because this line of code treats the value as an
OpenApiDateTime
as it happens to parse as aDateTimeOffset
:OpenAPI.NET/src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs
Lines 64 to 73 in 6899d5f
This then fires the validation warning here as the type test fails:
OpenAPI.NET/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs
Lines 256 to 266 in 306dda2
For the
int64
value, because the value is less thanint.MaxValue + 1
, this code treats the value as anint32
:OpenAPI.NET/src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs
Lines 138 to 146 in 6899d5f
This then causes the type test to fail in a similar fashion:
OpenAPI.NET/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs
Lines 148 to 158 in 306dda2
OpenApi File To Reproduce
openapi.json
Expected behavior
The example is valid according to the schema, so should not generate any validation warnings.
Screenshots/Code Snippets
N/A
Additional context
Found through use of Kiota to generate a typed C# client for the OpenAPI schema as part of dotnet/aspnetcore#56318 (comment).
The text was updated successfully, but these errors were encountered: