在 POST 请求 swagger node.js 上缺少 header "content-type"
missing header "content-type" on POST request swagger node.js
在 Swagger 中发送带有 body 的 POST 请求,请求中没有任何内容...我认为问题是因为它没有 header "content-type"
- https://i.stack.imgur.com/896kA.png
在postman中测试相同的请求正常到达(为什么有header)。
当我在 swaggerOptions 中添加授权时,停止发送 header,特别是“openapi”、“schemes”和“ 安全"
swaggerOptions.json
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
version: "1.0.0",
title: "Diniz API",
description: "Rest API Diniz",
servers: ['http://localhost:5000']
},
components: {
securitySchemes: {
bearerAuth: {
type: 'apiKey',
name: 'Authorization',
scheme: 'bearer',
in: 'header',
},
}
},
security: [{
bearerAuth: [],
}],
},
apis: ['routes/*.js']
}
在您的 /signup
注释中,将 parameters
部分替换为以下 requestBody
部分:
* ...
* summary: Create new account
*
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* - email
* - ... # add the rest of the required properties
* properties:
* name:
* type: string
* ... # add the rest of the properties
在 Swagger 中发送带有 body 的 POST 请求,请求中没有任何内容...我认为问题是因为它没有 header "content-type"
- https://i.stack.imgur.com/896kA.png
在postman中测试相同的请求正常到达(为什么有header)。
当我在 swaggerOptions 中添加授权时,停止发送 header,特别是“openapi”、“schemes”和“ 安全"
swaggerOptions.json
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
version: "1.0.0",
title: "Diniz API",
description: "Rest API Diniz",
servers: ['http://localhost:5000']
},
components: {
securitySchemes: {
bearerAuth: {
type: 'apiKey',
name: 'Authorization',
scheme: 'bearer',
in: 'header',
},
}
},
security: [{
bearerAuth: [],
}],
},
apis: ['routes/*.js']
}
在您的 /signup
注释中,将 parameters
部分替换为以下 requestBody
部分:
* ...
* summary: Create new account
*
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* - email
* - ... # add the rest of the required properties
* properties:
* name:
* type: string
* ... # add the rest of the properties