1
votes

We use ServiceStack 5.11 with Swagger/ OpenApi version enabled. The generated documentation for a POST shows a correct model, which I can click and it appears in the body. That's nice. But the model is also generated as query parameters. How can I disable them? In oher words: How can I disable the rows with the input fields and parametertype query? Why is this auto generated? Is it like it should be and work, too?

Model snippet:

 [Route("/json/reply/Address", "POST", Summary = "update/insert address", Notes = "update/insert address data")]
[DataContract]
public class Address
{
    [DataMember]
    public DtoIdentifier DtoId { get; set; }

    [DataMember]
    public DtoIdentifier TypeCountryId { get; set; }

    [DataMember]
    public string Street { get; set; }

    [DataMember]
    public string HouseNumber { get; set; }

    [DataMember]
    public string Floor { get; set; }

generated docu: generated docu:

1

1 Answers

1
votes

A ServiceStack Service can further populate its Request DTO from the HTTP Request's Path Info, QueryString, FormData and Headers in addition to the HTTP Request Body.

You can customize the Open API Schema returned with the Open API Filters, e.g. to remove all query params from API Requests with a Request Body you can use:

Plugins.Add(new OpenApiFeature {
    OperationFilter = (action, op) => {
        if (HttpUtils.HasRequestBody(action)) {
            op.Parameters.RemoveAll(x => x.In == "query");
        }
    },
});

Alternatively you can disable to auto Request Body from being added with:

Plugins.Add(new OpenApiFeature {
    DisableAutoDtoInBodyParam = true,
});