亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復從使用 application/x-www-form-urlencoded 內容類型的

如何修復從使用 application/x-www-form-urlencoded 內容類型的

Go
萬千封印 2022-06-21 16:46:57
我已經按照此處提到的開放 api 指南定義了一個使用 application/x-www-form-urlencoded 并寫在下面的 API 的 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"                    }                }            }        }    }}運行下面的命令以使用代碼生成器從上面的開放 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`如何解決上述錯誤?
查看完整描述

1 回答

?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

您混淆了 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


查看完整回答
反對 回復 2022-06-21
  • 1 回答
  • 0 關注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號