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

WithSummary and WithDescription deson't work in minimal api #45082

Closed
mehdihadeli opened this issue Nov 14, 2022 · 15 comments
Closed

WithSummary and WithDescription deson't work in minimal api #45082

mehdihadeli opened this issue Nov 14, 2022 · 15 comments
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels External This is an issue in a component not contained in this repository. It is open for tracking purposes. feature-openapi

Comments

@mehdihadeli
Copy link

Hi,
I have a minimal api in .net 7, I used WithSummary() and WithDescription() bur it doesn't generate anything in swagger ui!

app.MapGet("/api/v{version:apiVersion}/weatherforecast/byid", () => { return new List<string>(); })
    .WithApiVersionSet(weatherforecasts)
    .HasApiVersion(1.0)
    .HasApiVersion(2.0)
    .WithName("weatherforecast-byid")
    .WithTags("WeatherForecast")
    .WithSummary("summary002")
    .WithDescription("description002");
@captainsafia
Copy link
Member

@mehdihadeli This is a dupe of #40753 and is blocked on domaindrivendev/Swashbuckle.AspNetCore#2414 being merged.

As an alternative, I'd recommend using the WithOpenApi extension method which has more flexibility for setting values.

app.MapGet("/api/v{version:apiVersion}/weatherforecast/byid", () => { return new List<string>(); }
  .WithOpenApi(operation => new(operation)
  {
    Summary = "Summary",
    Description = "Description"
  });

@captainsafia captainsafia added feature-openapi area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 14, 2022
@ghost
Copy link

ghost commented Nov 14, 2022

Hi @mehdihadeli. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@mehdihadeli
Copy link
Author

mehdihadeli commented Nov 14, 2022

@captainsafia Thanks for your response.
When I use WithOpenApi, with minimal api versioning with .WithApiVersionSet(CustomersConfigs.VersionSet).HasApiVersion(1.0) I get error.

app.MapGet("/api/v{version:apiVersion}/weatherforecast/byid", () => { return new List<string>(); }
 .WithApiVersionSet("weatherforecast")
 .HasApiVersion(1.0)
  .WithOpenApi(operation => new(operation)
  {
    Summary = "Summary",
    Description = "Description"
  });

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 14, 2022
@captainsafia
Copy link
Member

@mehdihadeli What's the error you get?

The WithApiVersionSet returns a custom version of the IEndpointConventionBuilder type that might not interop with the generic constraint on the builder type that exists in WithOpenApi method. Try calling WithOpenApi before WithApiVersionSet.

@captainsafia captainsafia added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Nov 15, 2022
@ghost
Copy link

ghost commented Nov 15, 2022

Hi @mehdihadeli. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@mehdihadeli
Copy link
Author

@captainsafia When I put WithOpenApi() after HasVersion and WithApiVesionSet I get this error

app.MapGet("/api/v{version:apiVersion}/weatherforecast/byid", () => { return new List<string>(); }
 .WithApiVersionSet("weatherforecast")
 .HasApiVersion(1.0)
  .WithOpenApi(operation => new(operation)
  {
    Summary = "Summary",
    Description = "Description"
  });
Unhandled exception. System.NotImplementedException: The method or operation is not implemented.
   at Microsoft.AspNetCore.Builder.IEndpointConventionBuilder.Finally(Action`1 finallyConvention)
   at Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi[TBuilder](TBuilder builder, Func`2 configureOperation)
   at Program.<Main>$(String[] args) in C:\Users\MehdiHadeli\Desktop\versoining\Program.cs:line 43

but when I move the WithOpenApi in the first, it works!

app.MapGet("/api/v{version:apiVersion}/weatherforecast/byid", () => { return new List<string>(); }
  .WithOpenApi(operation => new(operation)
  {
    Summary = "Summary",
    Description = "Description"
  })
 .WithApiVersionSet("weatherforecast")
 .HasApiVersion(1.0);

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 15, 2022
@captainsafia
Copy link
Member

Unhandled exception. System.NotImplementedException: The method or operation is not implemented.
at Microsoft.AspNetCore.Builder.IEndpointConventionBuilder.Finally(Action1 finallyConvention) at Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi[TBuilder](TBuilder builder, Func2 configureOperation)

Aha! @commonsensesoftware I think you might have to update the builders in Asp.Versioning to implement the new Finally method.

@captainsafia captainsafia removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Nov 15, 2022
@commonsensesoftware
Copy link

Thanks @captainsafia.

@mehdihadeli Which version are you using? 7.0.0-preview.1 with official .NET 7 support was just released. It definitely implements Finally (I needed it). I don't expect the configuration used in .NET 6.0 to change post-preview, but some of the more succinct setup that removes some of the clunkiness might. Feel free to post API Versioning issues in its repo.

@captainsafia captainsafia added this to the .NET 8 Planning milestone Nov 15, 2022
@ghost
Copy link

ghost commented Nov 15, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia captainsafia added the External This is an issue in a component not contained in this repository. It is open for tracking purposes. label Nov 15, 2022
@mehdihadeli
Copy link
Author

mehdihadeli commented Nov 16, 2022

@commonsensesoftware Hi,
No, it is .Net 7.0.0 stable version.
Do you need a sample code? I can make it in a GitHub repo.

@commonsensesoftware
Copy link

@mehdihadeli Apologies, I wasn't clear. Yes, ASP.NET Core and .NET 7 have been released. As this is a major version change, there can be breaking changes. The addition of Finally, unfortunately, breaks API Versioning as written for .NET 6. API Versioning has released 7.0.0-preview.1 that should be compatible with .NET 7 and address the issue you are facing. Be aware as a preview there may be some additional changes, but I don't expect much. I'm marching toward an official release as soon as possible.

@mehdihadeli
Copy link
Author

mehdihadeli commented Nov 16, 2022

@commonsensesoftware Thanks for your response. I'm waiting for fixing this issue in next minor versions of .net 7 :)
Maybe the title of this issue should be changed also for supporting WithOpenAPi in any order

@mehdihadeli
Copy link
Author

@commonsensesoftware WithOpenApi() method with Asp.Versioning.Http/7.0.0-preview.1 and .Net 7 with any orders (before or after other operations) works great.
Thanks :)

@captainsafia
Copy link
Member

Thanks! Closing this issue out now.

There's a PR out on Swashbuckle to support the summary and description methods that's waiting on merge and release.

Other than that, I think everything is resolved here.

@mehdihadeli
Copy link
Author

@captainsafia Thanks

@ghost ghost locked as resolved and limited conversation to collaborators Dec 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels External This is an issue in a component not contained in this repository. It is open for tracking purposes. feature-openapi
Projects
None yet
Development

No branches or pull requests

3 participants