Skip to content

Fix FromForm without WithOpenApi schemas#3133

Merged
martincostello merged 12 commits intodomaindrivendev:masterfrom
jgarciadelanoceda:issue_3126_WrongForFromForMinimalApi
Nov 12, 2024
Merged

Fix FromForm without WithOpenApi schemas#3133
martincostello merged 12 commits intodomaindrivendev:masterfrom
jgarciadelanoceda:issue_3126_WrongForFromForMinimalApi

Conversation

@jgarciadelanoceda
Copy link
Copy Markdown
Contributor

Fixes #3126.
Also I have found that there was an error for WithOpenApi for FromFormParameters that are enums

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 8, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.55%. Comparing base (0554326) to head (ec2e87f).
Report is 3 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3133      +/-   ##
==========================================
+ Coverage   91.44%   91.55%   +0.10%     
==========================================
  Files          76       76              
  Lines        3121     3125       +4     
  Branches      520      526       +6     
==========================================
+ Hits         2854     2861       +7     
+ Misses        267      264       -3     
Flag Coverage Δ
Linux 81.90% <98.30%> (+0.05%) ⬆️
Windows 91.55% <100.00%> (+0.10%) ⬆️
macOS 91.55% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…hemas similar between MinimalApi and Controllers
@jgarciadelanoceda jgarciadelanoceda marked this pull request as ready for review November 8, 2024 01:52
@jgarciadelanoceda jgarciadelanoceda changed the title Fix the error and also an encountered error for Enums for WithOpenApi… Fix FromForm without WithOpenApi schemas Nov 8, 2024
Comment thread src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs Outdated
Comment thread test/WebSites/Basic/Controllers/FromFormParamsController.cs
Comment thread test/WebSites/Basic/Controllers/FromFormParamsController.cs
@martincostello martincostello added this to the v7.0.0 milestone Nov 8, 2024
@martincostello martincostello added bug fix version-major A change suitable for release in a major version labels Nov 8, 2024
@martincostello
Copy link
Copy Markdown
Collaborator

Thanks - will merge this after #3007.

Javier García de la Noceda Argüelles added 2 commits November 8, 2024 16:10
@jgarciadelanoceda
Copy link
Copy Markdown
Contributor Author

jgarciadelanoceda commented Nov 8, 2024

We may need to create an issue to check the order of filters to avoid this behaviour but I applied here.. I can remove it if you like and address it on other PR.. But I did not know why the Description did not show up. First filter wins?

@martincostello
Copy link
Copy Markdown
Collaborator

First filter wins?

Probably. I did similar things in my new OpenAPI extensions NuGet package to not overwrite things in the OpenAPI document if they already had a value.

@ymg2006
Copy link
Copy Markdown

ymg2006 commented Nov 21, 2024

@jgarciadelanoceda I am writing because this commit removed enums from FromForm.
Here is simple example from v6.9.0 and 7.0.0 output:
v7.0.0: "multipart/form-data": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/TransactionTypeEnum"
},
{
"required": [
"FiscalYearId"
],
"type": "object",
"properties": {
"FiscalYearId": {
"type": "integer",
"format": "int64"
},
"Id": {
"type": "integer",
"format": "int64"
}
}
}
]
}
}
v6.9.0: "multipart/form-data": {
"schema": {
"required": [
"FiscalYearId",
"Type"
],
"type": "object",
"properties": {
"Type": {
"$ref": "#/components/schemas/TransactionTypeEnum"
},
"FiscalYearId": {
"type": "integer",
"format": "int64"
}
}
}
}
This makes nswag to remove Type enum from output api.
createOrEdit(type?: TransactionTypeEnum | undefined, fiscalYearId: number): Observable;
createOrEdit(fiscalYearId: number): Observable;
I don't understand why Enum should be removed from required and moved to allOf, isn't it a type? can't enums be passed optional?
@martincostello Please revert this commit until the contributor fixes issues with it.

@martincostello
Copy link
Copy Markdown
Collaborator

Please create a new issue for this regression with a fully reproducible example, rather than commenting on a complete PR.

The change won't be reverted, we'll just fix-forward.

This was referenced Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix version-major A change suitable for release in a major version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Incorrect swagger.json generation in Minimal API when using FromForm parameters without the WithOpenApi extension method

4 participants