Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI 下,POST 请求,同时存在路径参数与请求体参数时,路径参数丢失 #332

Closed
cainiao0131 opened this issue Aug 11, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@cainiao0131
Copy link

cainiao0131 commented Aug 11, 2022

OpenAPI 下,POST 请求,同时存在路径参数与请求体参数时,路径参数丢失

需求:为了符合 REST 风格的资源路径,需要同时用到路径参数与 request body,故没有将所有参数放到 request body 中

swagger 接口数据结构:
post: {
tags: ['RegisteredClient'],
summary: '给登录用户在指定客户端下实行授权',
operationId: 'grant',
parameters: [
{ name: 'userName', in: 'path', description: '用户名称', required: true, schema: { type: 'string' } },
{ name: 'clientId', in: 'path', description: '客户端编号', required: true, schema: { type: 'string' } },
],
requestBody: {
content: {
'application/json': {
schema: { type: 'array', description: "授予权限,格式['menu.button']", items: { type: 'string' } },
},
},
required: true,
},
responses: {
'400': {
description: 'Bad Request',
content: { '/': { schema: { $ref: '#/components/schemas/GlobalError' } } },
},
'403': {
description: 'Forbidden',
content: { '/': { schema: { $ref: '#/components/schemas/GlobalError' } } },
},
'500': {
description: 'Internal Server Error',
content: { '/': { schema: { $ref: '#/components/schemas/GlobalError' } } },
},
'200': { description: 'OK' },
},
},
},

api-lock.json 数据:
{
"description": "给登录用户在指定客户端下实行授权",
"name": "grant",
"method": "post",
"path": "/users/{userName}/clients/{clientId}/seletedpermissions",
"response": {
"typeArgs": [],
"typeName": "",
"isDefsType": false,
"templateIndex": -1,
"compileTemplateKeyword": "#/definitions/",
"enum": [],
"typeProperties": []
},
"parameters": [
{
"required": true,
"in": "body",
"name": "requestBody",
"dataType": {
"typeArgs": [
{
"typeArgs": [],
"typeName": "string",
"isDefsType": false,
"templateIndex": -1,
"compileTemplateKeyword": "#/definitions/",
"enum": [],
"typeProperties": []
}
],
"typeName": "Array",
"isDefsType": false,
"templateIndex": -1,
"compileTemplateKeyword": "#/definitions/",
"enum": [],
"typeProperties": []
}
}
]
}

看了一下源码,parseSwaggerV3Mods() 方法中
有 requestBody 时,进入 if (inter.requestBody)
里边直接覆盖了 inter.parameters = []
这里是否应该用 inter.parameters.push() 的方式

Context(上下文)

  • pont Version:v1.3.3
  • Node Version:v14.20.0
  • Platform(操作系统平台):Windows 10
  • swagger.version:2.2.0
@ifzm
Copy link

ifzm commented Jan 29, 2023

+1

@z979054461 z979054461 added the bug Something isn't working label Feb 6, 2024
z979054461 added a commit that referenced this issue Feb 6, 2024
fix: #332 OpenAPI 下,POST 请求,同时存在路径参数与请求体参数时,路径参数丢失
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants