Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Swashbuckle to Ignore Namespace in Models

On the generated swagger page in the Model section, how does one get Swashbuckle to not report the whole namespace, but just the model?

MyNamespace.SubFolder.MyModel

to

MyModel

like image 663
ΩmegaMan Avatar asked May 24 '18 15:05

ΩmegaMan


People also ask

How do you set swashbuckle to ignore property on a model?

If you mark field/property as internal or protected or private , it will be ignored automatically by swashbuckle in swagger documentation. Update: Obviously, those properties/fields won't be populated in request/response.

How do you not show property in Swagger?

Using @ApiParam. @ApiParam is also a Swagger annotation that we can use to specify metadata related to request parameters. We can set the hidden property to true in order to hide any property.

How do I hide models in Swagger UI?

To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index. html . Note the option name uses plural Model*s* not Model . Swagger UI also has many other configuration options that control API documentation rendering.

How do I hide the schema in Swagger net core?

How to do it? add this property in your Swagger UI Options defaultModelsExpandDepth: -1 for hide schema section and for more reference refer this swagger.io/docs/open-source-tools/swagger-ui/usage/… Can you please add your swagger ui configuration settings in your question.


1 Answers

You should be able to define custom schema id's either through an ISchemaFilter or create your own "schema id strategy" read: Customizing Schema Id's

services.AddSwaggerGen(c =>
{
    ...
    c.CustomSchemaIds((type) => type.FullName);
};

You could create a base model class that contains a name property (remember to [JsonIgnore]) use that property for the strategy.

like image 199
VisualBean Avatar answered Sep 20 '22 19:09

VisualBean