【发布时间】:2020-08-03 00:35:41
【问题描述】:
根据swagger documentation,我应该能够拥有所有操作共享的公共参数。问题是在本地运行 codegen 时,生成的代码没有任何 common path 参数。下面的yaml 生成任何语言的代码(我尝试了两种)。
非常令人困惑的是,如果我在https://editor.swagger.io/ 中使用这个确切的yaml,生成的代码确实 有路径参数。我为两种不同的语言运行了这个,打字稿:
和 C#:
左边是editor.swagger.io中生成的代码,右边是我在本地运行codegen生成的代码。
在这两种情况下,.swagger-codegen\VERSION 文件都是3.0.20,这是我正在使用的,但https://editor.swagger.io/ 生成的代码确实有参数路径。
这个简单的 yaml 文件重现了这个问题:
openapi: 3.0.2
info:
title: title
version: 1.0.0
paths:
'/instances/{id}':
summary: Manipulate a particular instance
get:
responses:
'200':
description: Ok
content:
text/plain:
schema:
type: string
example: pong
summary: Fetches an instance
parameters:
- in: path
name: id
schema:
type: integer
required: true
components:
securitySchemes:
bearerAuth:
scheme: bearer
bearerFormat: JWT
type: http
用于生成的命令行:
java ^
-classpath bin/swagger-codegen-cli.jar ^
-DdebugOperations ^
io.swagger.codegen.v3.Codegen ^
generate ^
-i enterpos-api.yaml ^
-l typescript-angular ^
-o generated-code/typescript-angular-builtin
这产生了这个输出:https://gist.github.com/alanboy/45ce792255e079dd0de4f70449ebf455。我觉得这可能是错误的用法或我的 yaml 有问题,但我不知道是什么。
【问题讨论】:
-
看起来像一个错误。在github.com/swagger-api/swagger-codegen/issues 上打开一个问题
-
@Helen 我做到了:github.com/swagger-api/swagger-codegen/issues/10397 我最后在这里问了,因为我在 Github 上没有得到任何回复。
标签: swagger swagger-codegen swagger-editor