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

Feature Request: Example parameter values #100

Closed
gmr opened this issue Sep 2, 2016 · 3 comments
Closed

Feature Request: Example parameter values #100

gmr opened this issue Sep 2, 2016 · 3 comments

Comments

@gmr
Copy link

gmr commented Sep 2, 2016

I know this is somewhat bleeding into the open-api spec itself, so I understand if this is too much scope creep, but I'd love to be able to provide example values for parameter values. The examples are great for responses, but for requests, the auto-built examples built off of type are good, but utilitarian.

So for example, I could set a x-example attribute for a parameter in a schema I could turn this:

screen shot 2016-09-02 at 9 45 49 am

to

screen shot 2016-09-02 at 9 47 40 am

Does that seem reasonable? I tried to go down the x-code-snippets route but it wasn't quite the same as what I was trying to achieve.

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Sep 2, 2016

@gmr, this is actually supported by both OpenAPI spec and ReDoc :)

You can use example field on Schema Object.

So you can specify example on property level (see example in our demo spec or even on schema level):

{
  "type": "object",
  "properties": {
    // ...
  },
  "example": {
     "user": "gmr",
     "notes": " this is a example note",
     "bin": "9656534-32429432-34329432-bbc3234"
  }
}

Does it solve your problem?

@gmr
Copy link
Author

gmr commented Sep 2, 2016

Ah my bad, I missed the example attribute, or conflated it with examples for responses.

@gmr gmr closed this as completed Sep 2, 2016
@cbautista1002
Copy link

Thanks guys!

But for anyone who stumbles across this post and is hoping to add the example to each individual property - you can do that with example:

{
  "type": "object",
  "properties": {
    "user": {
      "type": "string",
      "description": "the user name",
      "example": "gmr"
    }
  }
}

I prefer this approach because it keeps the example right next to the definition and it avoids duplicating the field names.

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

3 participants