OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Expand Style Examples

Open charjr opened this issue 2 years ago • 3 comments
trafficstars

Looking at the Style Examples I cannot see what style I should use in the following instance:

A parameter in: query of type: array such that I could accept the following query string: ?param[]=X&param[]=Y

If someone could enlighten me on this (and any other examples you can think of that might be missing) I would be happy to make a PR that adds them.

charjr avatar Apr 16 '23 14:04 charjr

Is that querystring format defined somewhere?

MikeRalphson avatar Apr 16 '23 14:04 MikeRalphson

@MikeRalphson

It seems I can't find an RFC for that format, it's simply how PHP formats and parses query strings. i.e. http_build_query().

charjr avatar Apr 17 '23 09:04 charjr

@charjr I believe [] must be part of the parameter's name, other than that it's a standard exploded form-style array. Exploded form is the default style for query parameters.

# ?param[]=X&param[]=Y

parameters:
  - in: query
    name: 'param[]'  # <-----
    schema:
      type: array
      items:
        type: string
      example: [X, Y]

    style: form    # 'style' and 'explode' can be omitted here
    explode: true  # because these are the default values

hkosova avatar May 02 '24 14:05 hkosova

Looks like this has been answered, so I'm going to close this - please open a new issue if there are remaining questions.

Note that [ and ] are technically not allowed in URLs (except in IPv6 literals), but that doesn't seem to stop people using them 🤦 and I guess it mostly works? I'll be addressing this in the PR for #3759 so no need to track it here.

handrews avatar May 24 '24 20:05 handrews