0

I have a problem where an OpenAPI 2.0 specification takes a path parameter that is a valid string URI which looks like 1234/models/4321/v1 to form a URL endpoint that looks like: http://localhost/endpoints/1234/models/4321/v1/predict. I've defined the endpoint as the following in my swagger.yaml:

/endpoints/{modelURI}/predict:
    post:
      operationId: predict
      summary: Run inference on the input array.
      consumes:
      - application/json
      produces:
      - application/json
      parameters:
      - name: body
        in: body
        description: The input NDArray
        required: true
        schema:
          $ref: '#/definitions/Prediction'
      - name: modelURI
        in: path
        description: The URI of the model
        required: true
        type: string
        format: uri

The problem is that event though I've specified format: uri Swagger codegen will URL-encode the path parameter in the generated clients and the request will look like http://localhost/endpoints/1234%2Fmodels%2F4321%2Fv1/predict. Lower in our software stack there's an HTTP router which cannot interpret the request because it's expecting a different format. Unfortunately due to legacy software, we cannot easily change the specification.

How can I instead force Swagger to not encode this path parameter? Can I do this through some sort of plugin?

crockpotveggies
  • 12,682
  • 12
  • 70
  • 140
  • Check out the linked questions. Slashes are currently not allowed in path parameters. There's an open feature request at https://github.com/OAI/OpenAPI-Specification/issues/892. – Helen Jun 20 '18 at 10:02
  • This question specifically points to a `format: uri` specification, however because the first link has an accepted answer I'll accept this as a duplicate. Thanks for linking them. – crockpotveggies Jun 20 '18 at 16:35

0 Answers0