Closed andyslack closed 3 years ago
If it's possible in standard OpenAPI, it should be possible with this, but I'm not sure what it would look like. I will poke around
I'm not sure exactly what you are looking for but you might be able to use @bodyComponent
Hi @bourdakos1
Lets say I want to POST some JSON to an endpoint, e.g.
https://api.juicyllama.com/#tag/Webhook/paths/~1webhook/post
I can show the example response:
* @responseContent {Webhook} 201.application/json
* @responseExample {WebhookExample} 201.application/json.WebhookExample
Full comment:
/**
* POST /webhook
* @queryParam {string} app_id - Your application ID
* @queryParam {string} app_api_key - Your application API Key
* @queryParam {string} admin_api_key - Your applications admin API Key
* @bodyContent {WebhookPost} application/json
* @bodyRequired
* @tag Webhook
* @summary Create Webhook
* @description Create a new item
* @response 201 - Created
* @responseContent {Webhook} 201.application/json
* @responseExample {WebhookExample} 201.application/json.WebhookExample
* @response 400 - Bad request - Check you are passing all the required params
* @response 401 - Authorization
* @response 500 - Unexpected error.
*/
As you can see I included the bodyContent {WebhookPost} but I cannot see how to add the JSON example or the values to the YAML.
Here are my entries from the YAML file:
Schemas:
Webhook:
type: object
properties:
webhook_id:
type: integer
description: The record ID.
app_id:
type: integer
description: Your App ID.
url:
type: string
description: The url of your webhook
resources:
type: array
description: The resources the webhook will fire on
created_at:
type: datetime
description: The datetime the item was created
updated_at:
type: datetime
description: The datetime the item was last updated
WebhookPost:
type: object
required:
- url
- resources
properties:
url:
type: string
description: The url of your webhook
resources:
type: array
description: The resources the webhook will fire on
examples:
WebhookExample:
value: {
"webhook_id": 1,
"app_id": 1,
"url": "http://test.com/webhooks/example",
"resources": [
"post",
"wall"
],
"created_at": "2000-01-01 00:00:00",
"updated_at": "2000-01-01 00:00:00"
}
I hope this clarifies what I am looking to achieve.
Using @bodyContent {WebhookPost} application/json
only injects the schema and doesn't support an example:
requestBody:
content:
application/json:
schema: <{WebhookPost} get's injected here>
example: <this doesn't get set>
you can use @bodyComponent {WebhookPostBody}
instead for more control. Under the hood it looks like this:
requestBody:
$ref: <{WebhookPostBody} get's injected here>
example body component:
components:
requestBodies:
WebhookPostBody:
description: xxxx
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookPost'
examples:
$ref: '#/components/examples/Webhook'
Amazing, I managed to get this working after a little jiggery pokery. Thank you SO much for your help!
Awesome! No problem 😊
Hi There,
Is there a way to include an example Request sample?
I am including example response but would be great to show an example request, so rather than:
It could be something like: