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

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

Open
smackgg opened this issue Apr 2, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@smackgg
Copy link

smackgg commented Apr 2, 2022

{
  "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:https://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
    });
  };
@gogoyqj gogoyqj added the enhancement New feature or request label Apr 6, 2022
@smackgg
Copy link
Author

smackgg commented Apr 7, 2022

有预期解决时间不~ @gogoyqj

@gogoyqj
Copy link
Owner

gogoyqj commented Apr 15, 2022

有预期解决时间不~ @gogoyqj

可能要等到 5 月了,最近比较忙

@gogoyqj
Copy link
Owner

gogoyqj commented Apr 21, 2022

@smackgg 定位到是依赖的 swagger-codegen java 侧的算是一个 bug,有点复杂?建议可以先通过自动删除 additionalProperties 属性,解决这个问题

@smackgg
Copy link
Author

smackgg commented Apr 21, 2022

@gogoyqj 好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants