gpt4 book ai didi

go - 如何解决从openapi go代码生成器获取使用应用程序/x-www-form-urlencoded内容类型的API的验证错误?

转载 作者:行者123 更新时间:2023-12-01 21:09:33 25 4
gpt4 key购买 nike

我已遵循开放api指南中提到的here定义了一个API,该API消耗了application/x-www-form-urlencoded并编写为以下API:

{
"openapi": "3.0.0",
"info": {
"version": "1.0.draft",
"title": "user management api",
"description": "This document defines interface to user management"
},
"servers": [{
"url": "{apiRoot}/test",
"variables": {
"apiRoot": {
"default": "https://example.com"
}
}
}],
"paths": {
"/users/resetpassword": {
"post": {
"summary": "reset password of a user",
"operationId": "resetUserPassword",
"parameters": [{
"name": "username",
"in": "formData",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "password",
"in": "formData",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"204": {
"description": "User password has been changed"
}
}
}
}
}
}
运行以下命令以使用 code generator从上面的开放API文档生成go代码:
docker run --rm -v ${PWD}:<file_path> openapitools/openapi-generator-cli generate -i <file_path> --skip-validate-spec -g go-server -o <file_out_path>
出现以下错误:
-attribute paths.'/users/resetpassword'(post).parameters.[username].in is not of type `string`
-attribute paths.'/users/resetpassword'(post).parameters.[password].in is not of type `string`
如何解决以上错误?

最佳答案

您混淆了OpenAPI 2.0和OpenAPI 3.0语法。
在OpenAPI 3.0中,通过使用 requestBody 关键字定义了请求主体(包括表单数据)。将parameters部分替换为:

"requestBody": {
"required": true,
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"required": [
"username",
"password"
],
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
}
}
}
}
}
YAML版本:
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
required:
- username
- password
properties:
username:
type: string
password:
type: string

关于go - 如何解决从openapi go代码生成器获取使用应用程序/x-www-form-urlencoded内容类型的API的验证错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63352375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com