Node.js项目调试会话在端口localhost:1337上运行,Swagger项目编辑在127.0.0.1:63208上运行
使用下面的Swagger YAML
,POST请求在没有正文内容的情况下正常工作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
responses:
'200':
description: OK
'403':
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
但是当我按下面添加身体对象时
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
'403':
description: Authentication failed
default:
description: error payload
definitions:
RegisterUser:
type: object
properties:
name:
type: string
password:
type: string
email:
type: string
Swagger显示 响应 ERROR服务器未找到或发生错误 头 未定义 体
交叉原始请求似乎不是问题,因为没有正文的POST工作正常。使用
允许所有跨源请求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');