Closed
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have an operation with that takes in an enum as query string parameter, and returns it back in the response.
In the parameter section, the enum is just defined as string with no information about what valid values are
"parameters": [
{
"name": "e",
"in": "query",
"schema": {
"type": "string"
}
}
],
In the response the enum is referenced and it's possible to figure out valid values
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EnumWithNoFlags"
}
}
}
}
}
Expected Behavior
The query parameter should use a reference to the enum schema.
Steps To Reproduce
https://github.com/dnv-kimbell/openapi-inlineschema
Exceptions (if any)
No response
.NET Version
9.0 RC1
Anything else?
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
martincostello commentedon Sep 21, 2024
Just spotted this one myself with version
9.0.100-rc.2.24468.2
of the SDK and9.0.0-rc.2.24470.14
of the M.A.OpenApi library.With martincostello/openapi-extensions@5742a21 I get an empty enum for
CarType
:captainsafia commentedon Sep 22, 2024
The behavior that I find surprising here is that the schemas generated for the response and the query parameter are different. The schema generated by the query parameter uses a
type: string
with no enum list configured, whereas the schema configured for the response contains the correct enum listing. The difference in behavior between the two is the actual source of the issue.Upon further debugging, the issue seemed to only manifest for endpoints that used controller actions (as opposed to minimal APIs) which is particularly strange given that the schema generation logic is shared between the two.
Some further debugging reveals that this might be an issue with the ApiExplorer layer for MVC because the
ApiParameterDescription
generates a default type ofstring
for this argument:Based on the logic here. My suspicion gravitated towards the recent changes we made to ModelMetadata to support native AoT since the referenced method interacts with the
IsParsable
andIsConvertibleType
properties that we recently modified as a result of this work although that doesn't appear to be the case.It seems like the actual root cause is some code that we added in 46b5580 that set the parameter type of simple types (including those that can be parsed from an enum) to
string
to support the introduction ofTryParse
binding support in MVC. Ultimately, that appears to be the issue.Anyhow, I've figured out a bug fix for this that I hope to include in .NET 9 but figured I'd monologue a bit about the root case here for posterities sake.
Fix enum handling for MVC actions to close #57979
Fix up OpenAPI schema handling and support concurrent requests (#58024)
Fix up OpenAPI schema handling and support concurrent requests (#58024)
captainsafia commentedon Sep 26, 2024
@dnv-kimbell The fix for this has landed in nightly package version
9.0.0-rtm.24476.2
.You'll need to use the following
PackageReference
:And make sure that you have a reference to the nightly dotnet9 feed in your
nuget.config
file:Can you let me know if that works for you?
dnv-kimbell commentedon Sep 27, 2024
When I try that package, I get a reference to the enum from the query section, both with and without flags, so it seems to be working as expected.
captainsafia commentedon Sep 27, 2024
@dnv-kimbell Great! Thanks for verifying. Closing this bug as fixed.
Fix up OpenAPI schema handling and support concurrent requests (#58024)…
Fix up OpenAPI schema handling and support concurrent requests (#58024)…