Reputation: 807
I would like to modify the Swagger schema object names that are auto generated for my MVC application.
For example, I have number of entities like EmployeeModel
or CompanyModel
objects that are accessible via our REST endpoints
However, it's not necessary or desired that the Swagger definition contains the word "Model" after each entity name. They should be known only as Employee or Company -- see example in screen shot.
Upvotes: 1
Views: 2076
Reputation: 930
What library are you using to build you swagger shema? Take a look at Swashbuckle . This allows to build swagger shema automatically for your app (by using xml-documentation) and is flexible for customization. See "Modifying Generated Schemas" in documentation.
Upvotes: 0
Reputation: 2263
You have to use the SchemaId function available in your SwaggerConfig.cs
file in the EnableSwagger
method as follows:
c.SchemaId(t =>
{
c.SchemaId(t => t.FullName.EndsWith("Model") ? t.FullName.Replace("Model", String.Empty) : t.FullName);
});
This methods allows you to override Swashbuckle default behavior and set complex type names properly.
My sample addresses directly the removela of the "Model" part of your boject names, but could be using more complex setup.
Upvotes: 2