根据自吹自擂文件,我应该能够拥有所有操作共享的公共参数。问题是,在本地运行codegen时,生成的代码没有任何公共路径参数。下面的yaml为任何语言生成代码(我尝试过两种语言)。
非常令人困惑的是,如果我在https://editor.swagger.io/中使用这个精确的https://editor.swagger.io/,生成的代码 in 具有路径参数。我运行了这两种不同的语言,类型记录:

和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有问题,但我不知道是什么。
发布于 2020-08-04 04:10:07
问题是主修课。我注意到使用io.swagger.codegen.v3.Codegen类会产生不正确的结果:
java -classpath bin/swagger-codegen-cli.jar io.swagger.codegen.v3.Codegen <more>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^但这样做是可行的:
java -jar bin/swagger-codegen-cli.jar <more>这导致我在jar中打开了MANIFEST.MF,并注意到主类实际上如下:
Main-Class: io.swagger.codegen.v3.cli.SwaggerCodegen然后,我像这样运行命令,一切都如愿以偿。
java -classpath bin/swagger-codegen-cli.jar io.swagger.codegen.v3.cli.SwaggerCodegen <more>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^https://stackoverflow.com/questions/63222296
复制相似问题