Closed
Description
A produced request body in OAS looks like:
"requestBody": {
"description": "The attributes and relationships of the node to create.",
"content": {
"application/vnd.api+json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/nodePostRequestDocument"
}
]
}
}
}
}
which means the request body is optional.
When generating a C# client using NSwag with:
<Options>/GenerateNullableReferenceTypes:true /GenerateOptionalPropertiesAsNullable:true</Options>
It generates the next method:
public virtual System.Threading.Tasks.Task<NodePrimaryResponseDocument> PostNodeAsync(NodePostRequestDocument? body)
This is incorrect because request bodies are never optional in JSON:API.
This can be fixed by generating the OAS file as below:
"requestBody": {
"description": "The attributes and relationships of the node to create.",
"required": true, // <<<<<<<<<<<<<<
"content": {
...
}
}
}
which produces the correct method:
public virtual System.Threading.Tasks.Task<NodePrimaryResponseDocument> PostNodeAsync(NodePostRequestDocument body)