I use Swagger UI to display API documentation. By default, it displays the "Models" section at the bottom:
How to hide it?
I use Swagger UI to display API documentation. By default, it displays the "Models" section at the bottom:
How to hide it?
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
.
// index.html
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
defaultModelsExpandDepth: -1, // <-------
Swagger UI also has many other configuration options that control API documentation rendering.
For .Net Core 3.0 just Add c.DefaultModelsExpandDepth(-1); on your Startup.cs
// Startup.cs
app.UseSwaggerUI(c =>
{
c.DefaultModelsExpandDepth(-1); // Disable swagger schemas at bottom
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Your API V1");
});
In Docket bean just add
new
Docket(DocumentationType.SWAGGER_2).ignoredParameterTypes(YourClass.class,YourAnother.class)
I hope its helpful
Using Spring Boot:
@Bean
public UiConfiguration uiConfiguration() {
return UiConfigurationBuilder//
.builder()//
.defaultModelsExpandDepth(-1)//
.build();//
}
If using Django add this inside your settings.py
:
SWAGGER_SETTINGS = {
'DEFAULT_MODEL_DEPTH':-1
}
Although not the exact results you are looking for but i find it perfect to just disable the properties of the model you don't want via:
<?php
// src/AppBundle/Entity/User.php
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
...
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"api"}},
* "denormalization_context"={"groups"={"api"}}
* },
...
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"api","user:read"})
*/
protected $id;
/**
* @var \DateTime
*/
private $disabledProperty;
This way you will get a model just with the props you exposed via the group api
.
Hope this helps someone :)