-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Limit the depth of properties documented by Swashbuckle for [ProducesResponseType] annotations #615
Comments
Are you referring to the Swagger JSON document, or the example/model that's displayed in the swagger-ui? If it's the latter, you have some options. Your example isn't even valid JSON, so that's clearly not possible. But, you can switch to "Model" mode, which shows a model description instead of an example, and you can also limit the expand depth for that model description: app.UseSwaggerUI(c =>
{
c.DefaultModelRendering(ModelRendering.Model);
c.DefaultModelExpandDepth(1);
}); |
Ah sorry for no being specific - the output was just a copy of the data shown in the swagger UI as the output for the method - not the JSON itself. Although your suggestion makes the UI much better and is a definite improvement, I want to achieve the same result but without including the objects in the JSON itself. The JSON is already 160kb and will get much bigger - it is a really large schema. I am finding that the UI can take a while to update for methods with large output models Example JSON at https://pastebin.com/VLr5guYX |
By design, Swashbuckle treats the code as truth! So, it documents the entire API surface area, including all serializable properties on models. If your API surface area is too complex to document, then I might contend that it's going to be difficult to use, and might encourage a simpler design. Of course it's not my place to dictate how you design your API but I will say that SB's fundamental goal is to automatically document API's based on the surface area that can be inferred from code - routes, controllers, actions methods and models. If you find you need to start fighting this, then it may not be the right tool for your specific use-case. With all that said, a final suggestion would be to wire up a |
@domaindrivendev |
The only workaround I came up with, is to filter the virtual properties of my db models (witch defines my db relations), or remove their body with a simple string. This is how it can be done:
It is nice to have the virtual body for 1 depth level, or at least define them like empty arrays or objects, but this kind of filtering can only replace them with a simple string. Finally you have to add your schema filter in configuration like this:
I would be glad if I see any edition to filter, to have a better result. |
I put up a stackoverflow question with no luck, so hoping someone can point me in the right direction :)
https://stackoverflow.com/questions/48987127/limit-the-depth-of-properties-documented-by-swashbuckle-for-producesresponsetyp
I am annotating like this;
Which is fine, but MyType has many reference properties which in turn have referenced properties etc. This results in a massive document like this (but WAY bigger)
How can I create a operation/schema/document filter that limits the depth of recursion to just the top level, and just uses the type name for reference properties?
e.g.
The text was updated successfully, but these errors were encountered: