Open
Description
I want to have my custom parameter at the end of parameters list in the swagger.json.
The example what I want to see:
"parameters": [
{
"in": "path",
"name": "Id",
"required": true,
"type": "integer",
"format": "int32"
},
{
"in": "body",
"name": "body",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/MyCustomClass"
}
}
},
{
"in": "header",
"name": "key",
"description": "The key.",
"type": "string"
},
],
I used the following code :
in Program.cs:
app.UseSwagger(p => p.SerializeAsV2 = true);
public class AddRequiredParameter: IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
var stringOpenApiSchema = context.SchemaGenerator.GenerateSchema(typeof(string), context.SchemaRepository);
operation.Parameters.Add(new OpenApiParameter
{
Name = "key",
In = ParameterLocation.Header,
Schema = stringOpenApiSchema,
Required = false,
Description = "The key."
});
operation.Security = new List<OpenApiSecurityRequirement>();
}
}
But now I have only the key
parameter is placed before the body
parameter:
"parameters": [
{
"in": "path",
"name": "Id",
"required": true,
"type": "integer",
"format": "int32"
},
{
"in": "header",
"name": "key",
"description": "The key.",
"type": "string"
},
{
"in": "body",
"name": "body",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/MyCustomClass"
}
}
}
],
The problem I have is that the client's code generator changes the order of parameters because I used an old implementation of Swashbuckle for .NET 4.8, which placed the key parameter at the end.
Now, I just want to preserve as much as possible and maintain the same order of parameters.
Metadata
Metadata
Assignees
Labels
No labels