Nswag: Improvements for the Models part in Swagger UI

Created on 20 Jun 2018  路  6Comments  路  Source: RicoSuter/NSwag

In the new Version of NSwag/Swagger there is a new part with all the Models used in the REST API.

This is really a good functionality but there are multiple improvements which would make it more usefull:

  • Sorting possibility: At the moment they seem to be randomly listed
  • Grouping possibility
  • If you have mutiple Dataobject with the same name, but in different namespaces they are numbered e.g. Customer, Customer2, Customer3... It should be possible the decorate them with a namespace instead.

Is there already a way to do that?

help wanted NSwag.AspNet NSwag.AspNetCore enhancement

All 6 comments

We need to add the missing settings here:

https://github.com/RSuter/NSwag/blob/master/src/NSwag.AspNetCore/SwaggerUi3Settings.cs#L53

and here:

https://github.com/RSuter/NSwag/blob/master/src/NSwag.AspNetCore/SwaggerUi3/index.html

(or just serve this .html file yourself :-)

I think you can change the schema names with a custom schema name generator: https://github.com/RSuter/NSwag/wiki#customizations

Maybe we need a more flexible way to extend this, maybe just inject js/css code?

I have tested your proposal, means added in

https://github.com/RSuter/NSwag/blob/master/src/NSwag.AspNetCore/SwaggerUi3Settings.cs

public string ApisSorter { get; set; } = "none";
public string OperationsSorter { get; set; } = "none";
...
html = html.Replace("{ApisSorter}", ApisSorter);
html = html.Replace("{OperationsSorter}", OperationsSorter);

https://github.com/RSuter/NSwag/blob/master/src/NSwag.AspNetCore/SwaggerUi3/index.html

apisSorter: "{ApisSorter}",
operationsSorter: "{OperationsSorter}",

...and this worked perfectly.

Is "none" a working default?

The Swagger documentation is there not quite clear, but during my tests it worked.
So I also had a look into the code and saw that the sorters are stored in a collection by the accoding tag ("alpha", "method"). So "none" is as good as any other string not member of the defined tags.

Using a custom schema name generator is working fine for us.

Was this page helpful?
0 / 5 - 0 ratings