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 Promise any #159

Closed
smackgg opened this issue Mar 31, 2022 · 5 comments
Closed

Response Promise any #159

smackgg opened this issue Mar 31, 2022 · 5 comments

Comments

@smackgg
Copy link

smackgg commented Mar 31, 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": "code",
            "type": "string",
            "in": "query"
          }
        ],
        "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": "测试"
                },
                "iv": {
                  "type": "string"
                }
              },
              "required": [
                "encryptedData",
                "iv"
              ],
              "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"
      }
    }
  },
  "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": []
    }
  ]
}

为啥还有 Promise 这个问题。。看之前的 issue 已经解决了。

// customer definition
// empty

export class EggService {
  /**
   * egg-like controller method1
   */
  static method1(
    params: {
      /**  */
      code?: string;
    } = {} as any,
    options: IRequestOptions = {}
  ): Promise<any> {
    return new Promise((resolve, reject) => {
      let url = basePath + '/api/method1';

      const configs: IRequestConfig = getConfigs('get', 'application/json', url, options);
      configs.params = { code: params['code'] };

      /** 适配ios13,get请求不允许带body */

      axios(configs, resolve, reject);
    });
  }
}
@Manweill
Copy link
Owner

你对比下你的swagger json 与 exmaple的例子

@smackgg
Copy link
Author

smackgg commented Apr 2, 2022

@Manweill 除了 response 那里用的 $ref 其它的没看出来区别,为什么一定要 ref 才能推出类型?

@Manweill
Copy link
Owner

Manweill commented Apr 6, 2022

你这手打的,生成的基本不会是你的结构,主要是content里面的内容,ref不是必定的。还一个是,openapi 2.0和3.0是有区别的

 "/api/abp/api-definition": {
      "get": {
        "tags": [
          "AbpApiDefinition"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/ApplicationApiDescriptionModel"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApplicationApiDescriptionModel"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApplicationApiDescriptionModel"
                }
              }
            }
          }
        }
      }

@smackgg
Copy link
Author

smackgg commented Apr 6, 2022

@Manweill 就是生成的,并不是手打的。你发的这个是 swagger3,swagger2 content 就是我发的那样的

下面是 example 中 swagger2 的实例
https://github.com/Manweill/swagger-axios-codegen/blob/master/example/swagger.json

@Manweill
Copy link
Owner

Manweill commented Apr 7, 2022

@smackgg 不好意思,确实是我这边没有处理这种形式。你可以参考 #53 的解决方案看看。当然,也欢迎你提交PR

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

No branches or pull requests

2 participants