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

Support x-examples vendor extension for requests #227

Merged
merged 4 commits into from
Mar 13, 2017

Conversation

brendo
Copy link
Contributor

@brendo brendo commented Mar 9, 2017

This PR adds a vendor extension of x-examples which allows developers to specify an example for requests.

Right now a JSON example is automatically generated from the schema and this is an awesome feature most of the time, however we have a couple of cases where it would be ideal if we could specify an example (dealing with rather large schema 😞 ).

The value of x-examples is the same as the Example object from the specification, even though application/json (or something JSON-like with #225) is the only "valid" mime type for the time being.

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Mar 10, 2017

Hey@brendo! Have you just merged your other PR #225 into this?
If yes, close please #225. I am going to merge this and release a new version in the next 2-3hrs

@brendo
Copy link
Contributor Author

brendo commented Mar 10, 2017

Damn, sorry I did! That was unintentional but if you're happy with both feel free to merge this and I'll close the other!

@RomanHotsiy RomanHotsiy merged commit 9e02838 into Redocly:master Mar 13, 2017
@RomanHotsiy
Copy link
Member

RomanHotsiy commented Mar 13, 2017

@brendo I have merged your PR. Thanks!
Do you need a fresh package to be released ?

@brendo brendo deleted the support-x-examples-request branch March 13, 2017 08:49
@brendo
Copy link
Contributor Author

brendo commented Mar 13, 2017

Do you need a fresh package to be released ?

Only if it suits you, I'm running off a branch from here for now 👍

@sgilroy
Copy link

sgilroy commented Mar 15, 2017

@brendo Can you provide an example of how to use x-examples? Looks like this might be a good solution for me. Thanks!

@brendo
Copy link
Contributor Author

brendo commented Mar 15, 2017

Sure @sgilroy, here's an example:

...
"/session": {
  "post": {
    "summary": "Create a session token.",
    "description": "Returns a session token that can authenticate Temando Platform requests. \n\nRequest a session token using `bearerToken` and `accountId`, or `email` and `password`.",
    "operationId": "Authenticate",
    "tags": [
      "Session"
    ],
    "consumes": [
      "application/vnd.api+json"
    ],
    "produces": [
      "application/vnd.api+json"
    ],
    "security": [],
    "parameters": [
      {
        "name": "credentials",
        "in": "body",
        "schema": {
          "$ref": "#/definitions/SessionRequest"
        },
        "x-examples": {
          "application/vnd.api+json": {
            "data": {
              "type": "session",
              "attributes": {
                "accountId": "sample-account-id-here",
                "bearerToken": "bearer-token-from-account-creation",
                "scope": "client"
              }
            }
          }
        }
      }
    ],
    "responses": {
      "201": {
        "description": "Credentials accepted and session token created.",
        "schema": {
          "$ref": "#/definitions/SessionResponse"
        },
        "examples": {
          "application/vnd.api+json": {
            "data": {
              "id": "edb3cd92-ab8c-4133-8997-ef8408015fc6",
              "type": "session",
              "attributes": {
                "session": "<redacted>",
                "expiry": 1488185868834
              }
            }
          }
        }
      },
      "401": {
        "description": "Authentication failed.",
        "schema": {
          "$ref": "#/definitions/Error"
        }
      },
      "403": {
        "description": "Expired credentials.",
        "schema": {
          "$ref": "#/definitions/Error"
        }
      },
      "500": {
        "description": "Unexpected error",
        "schema": {
          "$ref": "#/definitions/Error"
        }
      }
    }
  }
},
...

@sgilroy
Copy link

sgilroy commented Mar 15, 2017

@brendo Thanks! Looking forward to seeing this supported in a release in the near future.

@bdentino
Copy link

This looks great! Any update on when it will be available in a release?

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Mar 29, 2017

@bdentino yes, today 🎉
Will let you know once I'm done

@RomanHotsiy
Copy link
Member

@bdentino available in the version 1.12.0

@bdentino
Copy link

You're awesome! Thanks!

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

Successfully merging this pull request may close these issues.

4 participants