openapi - Swagger Annotations for dynamic query parameters - Stack Overflow

admin2025-04-17  4

I want to define a dynamic query parameters, meaning that the key is only known by the client. The value should always be a string. E.g. ?dynamic1=123124&dynamic2=asdasd

It's possible to define this in OpenAPI spec like this:

      parameters:
      - name: filters
        in: query
        description: Filters to apply to the search
        style: form
        explode: true
        schema:
          type: object
          additionalProperties:
            type: string

I tried several things, but the closest that I could do with Swagger Annotations was this.

@Parameter(in = ParameterIn.QUERY, name = "filters", description = "Filters to apply to the search",
    style = ParameterStyle.FORM, explode = Explode.TRUE,
    schema = @Schema(implementation = Map.class, additionalPropertiesSchema = String.class))

But this still results in the additionalProperties type being object:

      parameters:
      - name: filters
        in: query
        description: Filters to apply to the search
        style: form
        explode: true
        schema:
          type: object
          additionalProperties:
            type: object

Is there a way to use the Annotations to achieve the correct yaml representation?

转载请注明原文地址:http://anycun.com/QandA/1744834582a88271.html