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

Match Example Request to Example Response by name #66

Open
joelbyler opened this issue Apr 14, 2023 · 1 comment
Open

Match Example Request to Example Response by name #66

joelbyler opened this issue Apr 14, 2023 · 1 comment

Comments

@joelbyler
Copy link

I'm not sure if this is a common use case but wanted to ask to see if this would be a useful feature. In my OpenAPI spec I have multiple example requests and corresponding responses for them. Would it make sense to match these by name so that a request which matches an example in the spec will look for a corresponding example response and return that? From my perspective it would be a better option than passing a Prefer header to specify the desired response. Looking for feedback on this idea and if its popular I can attempt a PR.

@joelbyler
Copy link
Author

If you need an example, something like this is what I had in mind

openapi: 3.0.0
info:
  version: 1.0.0
  title: Example API
  description: Example API for GH Issue

paths:
  /widgets:
    post:
      description: Create a New Widget
      requestBody:
        description: Creates and persists a new widget
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                color:
                  type: string
              required:
                - name
            examples:
              successful:
                value:
                  bin: Fred
                  pcn: green
              failure:
                value:
                  color: blue
      responses:
        '200':
          description: Successfully predicted
          content:
            application/json; charset=UTF-8:
              schema:
                type: object
                properties:
                  id:
                    type: number
                  name:
                    type: number
                  color:
                    type: number
                  success:
                    type: boolean
                  message:
                    type: string
              examples:
                successful:
                  value:
                    id: 42
                    cost: 99.99
                    name: Fred
                    color: green
                    success: true
                failure:
                  value:
                    success: false,
                    message: name is a required property of a new widget

So if I send a request with params that match the successful example params it would be great for the successful example response to be sent back. And same for the failure examples.

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

No branches or pull requests

1 participant