-
Notifications
You must be signed in to change notification settings - Fork 246
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
v2 - Primitive parsing for strings as DateTimes is too greedy #2137
Comments
@baywet what are your thoughts here? |
This is something we've faced in the kiota serialization layers as well.
what to use the deserialize method instead But I don't think we need such a level of complexity here. We can probably drop the first to conditional blocks and add more cases to this block What do you think of this approach @captainsafia ? |
@baywet Why are we parsing the string at all? Since we dropped the OpenApiAny primitives, we should not be inferring any types beyond JSON primitives. |
That was my thought as well. My assumption here was so we can call the "correct" serialization method (we need the right type). But it does seem superfluous to me as well. |
My vote is to get rid of all that type casting beyond JSON types. |
From looking at the blame for the file, before a fix I implemented there probably to unblock some of the migration work, it looks like @MaggieKimani1 implemented most of it. Maybe she could share additional context we don't have? |
@darrelmiller @baywet I think at the time I was just refactoring the whole codebase to replace the parsing logic with the JSON node "equivalent" and failed to get rid of the type casting code for the primitives since we no longer need it. Doing a PR that corrects this asap. |
Both @mikekistler and I have observed this bug while interacting with the new JsonNode-based example APIs in v2. The current logic tries to eagerly parse string JsonNodes as date times and write them as such when emitting the final document:
OpenAPI.NET/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs
Lines 118 to 144 in e917e4c
This can cause some rather unintended behaviors. For example, the current implementation casts example strings that are designated as a
DateOnly
time toDateTime
based types. The current implementation will also errenously capture certain string examples (like a float3.14
) as dates.The following code:
Produces:
When I would expect it to produce:
The text was updated successfully, but these errors were encountered: