After creating the swagger schema, the patch type definition looks different and the generated client fails to compile.
Is there a new behavior for the patch methods? Or are there new generator settings where we can handle the patch type?
V5.6.3
"patch": {
...
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Operation"
},
"nullable": true
}
}
}
},
...
V6:
"patch": {
...
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValueDtoJsonPatchDocument"
}
}
}
},
...
Difficult to troubleshoot this without more info. Could you please create a minimal app (i.e. start from empty project) that repro's the issue so I can pull it down and troubleshoot? Thanks
I have attached a simplified sample of our implementation which creates and saves the swagger file in the project folder ./Swagger/service_v1.json. There you can see that there is defined a custom type for patch but this one doesn't exists somewhere.
"patch": {
"tags": [
"WeatherForecast"
],
"summary": "PatchWeatherForecast",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "date-time"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WeatherForecastJsonPatchDocument"
}
}
}
},
I have encountered the same issue today upgrading from 5.6.3 to 6.1.1. I will have to wait until this is fixed before moving to the latest version.
I was able to fix the schema by doing the following MapType to basically mimic what version 5.6.3 was doing before.
options.MapType(typeof(JsonPatchDocument<>), () =>
{
return new OpenApiSchema
{
Type = "array",
Items = new OpenApiSchema
{
Type = "object",
Properties =
{
["value"] = new OpenApiSchema { Nullable = true },
["path"] = new OpenApiSchema { Type = "string", Nullable = true },
["op"] = new OpenApiSchema { Type = "string", Nullable = true },
["from"] = new OpenApiSchema { Type = "string", Nullable = true },
},
AdditionalPropertiesAllowed = false
}
};
});
Investigate further and confirmed this is a bug. The code was (incorrectly) assuming that ParameterInfo.ParameterType and the corresponding ModelMetadata.ModelType generated by the _ApiExplorer_ would always have the same value and could be used interchangeably. However, in some special cases incl. IJsonPatchDocument, _ApiExplorer_ will alter ModelMetadata.ModelType to reflect serialization behavior. So, the fix was to favor ModelMetadata.ModelType as per 95cb4d370e08e54eb04cf14e7e6388ca974a686e
Released with 6.1.2
Most helpful comment
Investigate further and confirmed this is a bug. The code was (incorrectly) assuming that
ParameterInfo.ParameterTypeand the correspondingModelMetadata.ModelTypegenerated by the _ApiExplorer_ would always have the same value and could be used interchangeably. However, in some special cases incl.IJsonPatchDocument, _ApiExplorer_ will alterModelMetadata.ModelTypeto reflect serialization behavior. So, the fix was to favorModelMetadata.ModelTypeas per 95cb4d370e08e54eb04cf14e7e6388ca974a686e