Skip to content
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

[Bug]: Commit #3133 breaks Enums and Structure #3163

Closed
ymg2006 opened this issue Nov 21, 2024 · 8 comments · Fixed by #3164
Closed

[Bug]: Commit #3133 breaks Enums and Structure #3163

ymg2006 opened this issue Nov 21, 2024 · 8 comments · Fixed by #3164
Labels
Milestone

Comments

@ymg2006
Copy link

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 why the contribution is not separated in multiple pullrequests?

@ymg2006 ymg2006 added the bug label Nov 21, 2024
@ymg2006
Copy link
Author

ymg2006 commented Nov 21, 2024

c# code to reproduce
public class CreateOrEditUnprocessedDto
{
[Required]
public TransactionTypeEnum Type { get; set; }

[Required]
public long FiscalYearId { get; set; }
}

public enum TransactionTypeEnum
{
Credit = 1,
Debit = 2
}

public async Task<bool> CreateOrEditAsync([FromForm] CreateOrEditUnprocessedDto input, CancellationToken cancellationToken = default)
{
return true;
}

@martincostello
Copy link
Collaborator

martincostello commented Nov 21, 2024

Please provide an example of the C# code that produces the incorrect OpenAPI document. The more information we have, the easier you make it for people to fix issues, and do so accurately.

@ymg2006
Copy link
Author

ymg2006 commented Nov 21, 2024

Please provide an example of the C# code the produces the incorrect OpenAPI document. The more information we have, the easier you make it for people to fix issues, and do so accurately.

I was making it, Should I make a full c# app for it or this examlpe is enough?

@jgarciadelanoceda
Copy link
Contributor

I tested it in the Basic Website ( This behaviour and it was working). I need to take a look at these. I will do asap

@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Nov 21, 2024

Please provide a configuration of your swagger config because I tested it here https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/test%2FSwashbuckle.AspNetCore.IntegrationTests%2FSwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Basic_DotNet_6.verified.txt#L668-L726

Which version of aspnetcore you are using also would be nice

Also does the representation of the OpenApi affect your tests using Swagger-ui?

@ymg2006
Copy link
Author

ymg2006 commented Nov 21, 2024

Please provide a configuration of your swagger config because I tested it here https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/test%2FSwashbuckle.AspNetCore.IntegrationTests%2FSwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Basic_DotNet_6.verified.txt#L668-L726

Which version of aspnetcore you are using also would be nice

Also does the representation of the OpenApi affect your tests using Swagger-ui?

.net 8
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo() { Title = "My API", Version = AppVersionHelper.Version });
});
image
Yes, there is no Type Enum at the swagger ui too.

@jgarciadelanoceda
Copy link
Contributor

Thank you very much for the issue!.
In the PR I could see that the schema was OK for dotnet6, but nod for dotnet8 :(, due to the integration of the ApiDescription of aspnetcore

@IhnatKlimchuk
Copy link
Contributor

@martincostello can you please trigger release pipeline with that fix for nuget? 7.0.1 maybe?

@martincostello martincostello added this to the v7.1.0 milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants