Reputation: 3057
I am using node-swagger. It's working fine. I want to post json body without defining the schema in details. For example below I don't want to specify object properties. Is there any way to do this?
/pets:
post:
description: Add new
parameters:
- name: id
in: body
description: data to post
required: true
type: object
responses:
'200':
description: A list of pets
schema:
type : string
It's not rendering the textarea to post json data.
Upvotes: 3
Views: 9952
Reputation: 171
Based on Open API 3 spec, for an empty body request, you should have a requestBody
section like the following:
requestBody:
required: true
description: blabla.
content:
application/json:
schema:
type: object
nullable: true
Upvotes: 0
Reputation: 15296
If you are using swagger-ui-express
and swagger-jsdoc
and don't wan to use definitions you can directly define in YAML on endpoint like this.
/**
* @swagger
* /pets:
* post:
* description: Add new
* produces:
* - application/json
* parameters:
* - name: id
* description: data to post
* in: body
* required: true
* schema:
* type: object
* responses:
* 201:
* description: Pet created
*/
Upvotes: 1
Reputation: 2991
Try this YAML:
---
swagger: '2.0'
info:
version: 0.0.0
title: Simple API
paths:
/:
post:
produces:
- application/json
parameters:
- in: body
name: id
required: true
schema:
"$ref": "#/definitions/inBody"
responses:
201:
description: Added
definitions:
inBody:
type: object
Upvotes: 5