Summary
I would like to hide properties from the generated documentation model for PUT/POST requests.
More Detail
I would like to create a nicely documented API for a system I'm working on. I would like to use Swashbuckle/Swagger to automatically generate the documentation. I am using Entity Framework to define the relationship between objects in the system.
Here is an example relationship between objects.
User.cs
public class User
{
public int Id { get; set; }
public string ExternalReference { get; set; }
public string Name { get; set; }
public ICollection<Post> Posts { get; }
}
Post.cs
public class Post
{
public int Id { get; set; }
public string ExternalReference { get; set; }
public string Content { get; set; }
public int UserId { get; set; }
public User User { get; set; }
}
The following example value is generated for my GET /api/posts/{id} endpoint.
GET /api/posts/{id}
{
"id": 0,
"externalReference": "string",
"content": "string",
"userId": 0,
"user": {
"id": 0,
"externalReference": "string",
"name": "string",
"posts": [
null
]
}
}
This is what I would like to see, it's relevant to potentially return the User object as well.
The following is the example value generated for my POST /api/posts endpoint
POST /api/posts
{
"id": 0,
"externalReference": "string",
"content": "string",
"userId": 0,
"user": {
"id": 0,
"externalReference": "string",
"name": "string"
}
}
In my mind at least I feel the user section of the example isn't relevant for POST or PUT only the userId property is. The generated example value isn't too bad in this simple example, but if I start having objects with multiple relationships I feel it can get messy.
The question again
Is there an elegant way of supressing relational objects from the generated swagger documentation ONLY for PUT/POST methods?
