OpenAPI path prefix isn't prefixed onto resources
Ober3550 opened this issue · 2 comments
I understand that the resources under the openapi plugin are actually just rest resources. But our teams are having troubles with the fact that openapi uses "path" but rest uses "basePath" and it seems that the path prefixing isn't very standardised across plugin types. It would be great if we could have a universal path variable that gets applied to all resources in a given imposter config (and any contract definitions loaded in by specFiles).
Hi @Ober3550, thanks for raising this. I agree standardising this would be helpful.
Are you able to share a minimal test case to illustrate the issue?
Given the following swagger and imposter config. You can see that there's 3 ways to prefix a value onto the specFile definition but seemingly none to the rest resources. Additionally the internal binding of the server path prefix means that none of the resources are mapping correctly and the server responds with a "File not found". The particular use case we're trying to achieve is to have multiple services that all combines into one big imposter. But we want a parameter to be able to specify a single prefix to all paths relevant to a particular imposter binding /service-random
We have some ingress routing that we want the swagger /_spec/
page to have with pathing. We can use the server.url to add a path to the page but not to the binding by also adding stripServerPath: true
to the config. This means that the swagger interface sends the path to the imposter service for routing but the binding inside the kube cluster isn't even aware of the extra pathing. e.g.
External/Swagger Interface: https://cluster/service/imposter/endpoint
becomes
Internal Imposter binding: http://imposter/endpoint
# swagger.yaml
openapi: 3.0.0
servers:
- url: http://petstore/petstore1
paths:
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
"200":
description: Expected response to a valid request
content:
application/json:
examples:
catExample:
value: |-
{ "id": 1, "name": "Cat" }
dogExample:
value: |-
{ "id": 2, "name": "Dog" }
#petstore-config.yaml
plugin: openapi
specFile: swagger.yaml # servers.url is prefixed first
basePath: /petstore2 # Then this gets prefixed
path: /petstore3 # Then this gets prefixed
# None of the above get prefixed onto the rest resources below
resources:
- path: /petstore1/petstore2/petstore3/pets/1 # This returns file not found
method: get
response:
exampleName: catExample
- path: /pets/2
method: get
response:
exampleName: dogExample