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

Support additional attributes from System.ComponentModel namespace #1954

Open
domaindrivendev opened this issue Jan 13, 2021 · 3 comments
Open
Labels
help-wanted A change up for grabs for contributions from the community p2 Medium priority

Comments

@domaindrivendev
Copy link
Owner

domaindrivendev commented Jan 13, 2021

For example:

@domaindrivendev domaindrivendev added this to the Backlog milestone Jan 13, 2021
@domaindrivendev domaindrivendev changed the title Support applicable attributes from System.ComponentModel namespace Support additional attributes from System.ComponentModel namespace Jan 14, 2021
@domaindrivendev domaindrivendev added the p2 Medium priority label Jan 17, 2021
@domaindrivendev domaindrivendev removed this from the Backlog milestone Jan 17, 2021
@mikhail-barg
Copy link

mikhail-barg commented Sep 9, 2022

Is there any progress on this issue? It would be really good to have this because it allows to use framework-defined attributes to annotate classes, without a need to add additional assembly.

Consider the following setup. There's a common library with business objects, having all the descriptions. And there's a number of services using this library, one of those provides web api with CRUD operations over the business objects, but other services have no relation to OpenAPI, and web at all.

So to have the API service display a nice swagger UI it's necessary to add a reference to Swashbuckle.AspNetCore.Annotations to the common library, which would then propagate to all dependent services.

Instead of doing all this, it would be great to just use well-known and supported framework attributes.

@mikhail-barg
Copy link

I've looked through the sources and was quite puzzled because Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator does support RequiredAttribute and DefaultValueAttribute from System.ComponentModel. So it's unclear why not support other ones?

Anyway I've quickly mocked a filter (based on Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter) than reads the remaining attributes. So maybe it would help you in some way to speedup the implementation in the library.

ComponentModelSchemaFilter.cs.txt

@ouvreboite
Copy link
Contributor

@domaindrivendev I’m part of the API team at Criteo, and as such we provide common, generic, models to be used in our various internal and external APIs to have an homogenous input/output/error structure.

As such we currently have to rely an xmlDoc/filters/customSchemaIds to fine tune the description and schemaIds for our generic models. But this require internal teams to correctly reference the correct assembly and inject the correct filters and such. And it’s quite hard to fully enforce that.

So relying on DescriptionAttribute for schema/field description and DisplayNameAttribute for schemaId would be beneficial as those would not require any custom configuration.

If the support of those attributes is still in line with the Swashbuckle roadmap, I would be happy to work on a PR :)

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted A change up for grabs for contributions from the community p2 Medium priority
Projects
None yet
Development

No branches or pull requests

4 participants