Skip to content

response schema 中如果存在 additionalProperties 参数,生成的 ts 文件返回类型全是 AjaxPromise<{ [key: string]: any }> #52

@smackgg

Description

@smackgg
{
  "info": {
    "title": "Test swagger",
    "description": "Testing the Fastify swagger API",
    "version": "0.1.0"
  },
  "paths": {
    "/api/method1": {
      "get": {
        "summary": "egg-like controller method1",
        "description": "egg-like controller method1",
        "parameters": [
          {
            "name": "encryptedData",
            "type": "string",
            "description": "测试",
            "default": "2",
            "require": true,
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string"
                },
                "result": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "number",
                      "enum": [
                        "SUCCESS",
                        "ERR_PARAM",
                        "NOT_WECHAT_AUTH",
                        "NOT_LOGIN",
                        "ERROR",
                        "FAIL_UPLOAD"
                      ]
                    },
                    "msg": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {},
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "code",
                    "msg",
                    "data"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "status"
              ],
              "additionalProperties": false
            }
          },
          "400": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string"
                },
                "result": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "number",
                      "enum": [
                        "SUCCESS",
                        "ERR_PARAM",
                        "NOT_WECHAT_AUTH",
                        "NOT_LOGIN",
                        "ERROR",
                        "FAIL_UPLOAD"
                      ]
                    },
                    "msg": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {},
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "code",
                    "msg",
                    "data"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "status"
              ],
              "additionalProperties": false
            }
          }
        },
        "tags": [
          "Egg"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    },
    "/api/method2": {
      "post": {
        "summary": "egg-like controller method1",
        "description": "egg-like controller method1",
        "parameters": [
          {
            "name": "data",
            "description": "request body",
            "schema": {
              "type": "object",
              "properties": {
                "encryptedData": {
                  "type": "string",
                  "description": "测试",
                  "default": "2",
                  "require": true
                }
              }
            },
            "in": "body"
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "schema": {
              "type": "object",
              "properties": {
                "status_code": {
                  "type": "number",
                  "description": "fdsfsdfdsfds"
                },
                "data": {
                  "type": "object"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "schema": {
              "type": "object",
              "properties": {
                "encryptedData": {
                  "type": "string",
                  "description": "测试",
                  "default": "2"
                }
              },
              "required": [
                "encryptedData"
              ],
              "additionalProperties": false
            }
          }
        },
        "tags": [
          "Egg"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    }
  },
  "responses": {},
  "definitions": {},
  "tags": [
    {
      "name": "user",
      "description": "User related end-points"
    }
  ],
  "swagger": "2.0",
  "securityDefinitions": {
    "api_key": {
      "type": "apiKey",
      "name": "Authorization",
      "in": "header"
    },
    "swagger_auth": {
      "type": "oauth2",
      "authorizationUrl": "http://swagger.io/api/oauth/dialog",
      "flow": "implicit",
      "scopes": {
        "write:homes": "modify home info",
        "read:homes": "read home info"
      }
    }
  },
  "allowUnknown": true,
  "externalDocs": {
    "url": "https://swagger.io",
    "description": "Find more info here"
  },
  "host": "127.0.0.1:7001",
  "schemes": [
    "http",
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "security": [
    {
      "api_key": []
    }
  ]
}

response schema 中如果存在 additionalProperties 参数,生成的 ts 文件返回类型全是 AjaxPromise<{ [key: string]: any }>
删除所有 additionalProperties 就没问题

public apiMethod1Get = (
    params: ParamsapiMethod1Get,
    opt?: ExtraFetchParams
  ): AjaxPromise<{ [key: string]: any }> => {
    const url = this.$basePath + `/api/method1`;
    const p: any = {};
    p.query = {};
    if ('encryptedData' in params) p.query.encryptedData = params.encryptedData;
    return ajax.ajax({
      ...opt,
      method: 'GET',
      url,
      ...p
    });
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions