Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI path prefix isn't prefixed onto resources #588

Open
Ober3550 opened this issue Jun 20, 2024 · 2 comments
Open

OpenAPI path prefix isn't prefixed onto resources #588

Ober3550 opened this issue Jun 20, 2024 · 2 comments
Assignees
Labels

Comments

@Ober3550
Copy link

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).

@outofcoffee
Copy link
Owner

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?

@Ober3550
Copy link
Author

Ober3550 commented Jun 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants