Node.js project debug session running on port localhost:1337 and Swagger project edit running on 127.0.0.1:63208
POST request works fine without body content using below Swagger YAML
swagger: "2.0"
info:
version: "1.0.0"
title: some title
host: localhost:1337
basePath: /api
schemes:
- http
consumes:
- application/json
produces:
- applicaiton/json
paths:
/auth/register:
get:
description: some description
parameters:
- name: body
in: body
description: ID of pet to use
required: true
schema:
$ref: '#/definitions/RegisterUser'
responses:
'200':
description: OK
'304':
description: Authentication failed
default:
description: error payload
post:
description: Register a new user
responses:
'200':
description: OK
'304':
description: Authentication failed
default:
description: error payload
definitions:
RegisterUser:
type: object
properties:
userName:
type: string
password:
type: string
email:
type: string
But when i add body object as below
swagger: "2.0"
info:
version: "1.0.0"
title: some title
host: localhost:1337
basePath: /api
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/auth/register:
get:
description: some description
responses:
'200':
description: OK
'304':
description: Authentication failed
default:
description: error payload
post:
description: Register a new user
parameters:
- in: body
name: RegisterUser
description: The movie you want update with.
required: false
schema:
$ref: '#/definitions/RegisterUser'
responses:
'200':
description: OK
'304':
description: Authentication failed
default:
description: error payload
definitions:
RegisterUser:
type: object
properties:
name:
type: string
password:
type: string
email:
type: string
Swagger displays Response ERROR Server not found or an error occurred Headers undefined Body
Cross origin requests doesn't seem to be the issue as POST without body is working. All cross origin requests are allowed using
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Host, Accept, Accept-Encoding, Accept-Language, Cache-Control, Connection, Content-Type, Origin, Referer, User-Agent, Content-Length');
via Arvind Singh
No comments:
Post a Comment