question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arbitrary query parameter names?

See original GitHub issue

I’m pretty new to openapi, so apologies if this has been asked before. I haven’t been able to find a similar question anywhere.

I’m working creating an openapi.yml for an existing API we have at my workplace.

For better or worse, the API supports arbitrary query parameter names. Values are always supplied. These pairs are interpreted as tag name/value pairs of particular resources (computational resources). Here are a few examples (with some name simplifications) of how the API can be invoked:

GET /resources?state=active&tagName1=tagValue1&tagName2=tagValue2

GET /resources?tagName6=tagValue6

GET /resources?state=active

Both the tagNameNs and tagValueN’s are user-supplied and arbitrary, but have to conform to be “identifier names” (no spaces, alphanumeric, must not start with a digit).

The only query parameter with a fixed, known name is state.

Is there some way of expressing this notion in openapi?

I appreciate this is pretty unusual, and perhaps the description might be the only means to express this.

For reference here’s a section of my openapi.yml file for this endpoint.

openapi: 3.0.0
info:
  title: Service
  description: Endpoints
  version: 1.0.0
paths:
  /resources:
    get:
      parameters:
        - in: query
          name: state
          schema:
            type: string
            enum:
              - active
              - inactive
        - in: query
         # TODO - how to describe tagNameN/tagValueN here?
      responses:
        '200':
          description: "All resources successfully obtained."

Any insights or advice appreciated.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
hkosovacommented, Jun 18, 2021

@danieljacobs1 Free-form query parameters can be defined as a single parameter whose value is a dictionary and that uses style: form + explode: true (this is the default serialization style for query parameters). The parameter name can be arbitrary, it does not appear in the URL but may be used by code generators.

Both the tagNameNs and tagValueN’s are user-supplied and arbitrary, but have to conform to be “identifier names” (no spaces, alphanumeric, must not start with a digit).

The name format can be defined in OAS 3.1 using patternProperties or propertyNames. Make sure to use the ^ and $ anchors in regexes because regexes are not implicitly anchored.

patternProperties example:

        - in: query
          name: tags  # Arbitrary name
          schema:
            type: object
            patternProperties:
              # Parameter names
              '^[A-Za-z][A-Za-z0-9]*$':
                # Parameter values
                type: string
                pattern: '^[A-Za-z][A-Za-z0-9]*$'
            additionalProperties: false
            example:
              tagName1: tagValue1
              tagName2: tagValue2

propertyNames example:

        - in: query
          name: tags  # Arbitrary name
          schema:
            type: object
            propertyNames:
              pattern: '^[A-Za-z][A-Za-z0-9]*$'  # Parameter names
            additionalProperties:     # Schema for parameter values
              type: string
              pattern: '^[A-Za-z][A-Za-z0-9]*$'
            example:
              tagName1: tagValue1
              tagName2: tagValue2

OAS 3.0 also supports free-form query parameters, but does not have a way to limit their names.

        - in: query
          name: tags  # Arbitrary name
          schema:
            type: object
            additionalProperties:  # Schema for parameter values
              type: string
              pattern: '^[A-Za-z][A-Za-z0-9]*$'
            example:
              tagName1: tagValue1
              tagName2: tagValue2
1reaction
danieljacobs1commented, Dec 14, 2022

Sorry for being so very slow getting back on this. @hkosova your screenshot looks exactly like what I was looking for. Thank you! I’ll close this issue. Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to document dynamic query parameter names in ...
where the query parameter names are dynamic and will be received from the client. I'm using the latest Swagger API. swagger · swagger-editor ......
Read more >
A Beginner's Guide to URL Parameters - SEMrush
In this comprehensive guide, we explore the ins and outs of URL parameters. Discover now how to use query strings without hurting your ......
Read more >
Query parameter data types and performance - CYBERTEC
What are query parameters? SELECT val FROM large WHERE id = $1; Here, $1 is a placeholder for an arbitrary value. Such a...
Read more >
Query parameter targeting - Optimize Resource Hub
Every character in your query parameter, from beginning to end, must be an exact match of the entered value for the condition to...
Read more >
Running parameterized queries | BigQuery - Google Cloud
Query parameters can be used as substitutes for arbitrary expressions. Parameters cannot be used as substitutes for identifiers, column names, table names, or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found