我正在使用 swagger 指定我的 API 我使用的是 2.0 现在有新版本 3.0.0 根据我使用离线 swagger 编辑器指定 3.0.0 规范的文档。准备好后,我下载了 json 文件,我将使用该文件生成 spring 服务器代码。我下载了swagger-codegen
使用构建它mvn clean package然后我执行了以下命令:
java -jar <PARENT_DIR>/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i <PARENT_DIR>/ServerCode/swagger.json -l spring -o <PARENT_DIR>/ServerCode
Run Code Online (Sandbox Code Playgroud)
上面的命令给了我以下错误:
[main] INFO io.swagger.parser.Swagger20Parser - reading from swagger.json
[main] INFO io.swagger.parser.Swagger20Parser - reading from swagger.json
[main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:723)
at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Run Code Online (Sandbox Code Playgroud)
更新 :
我的 swagger.json 文件如下(这是我的试验项目,因此我在这里粘贴了我的 api 结构):
{ …Run Code Online (Sandbox Code Playgroud) Swagger/OpenAPI 2.0 中的 Schema 对象是否必须具有该type属性?
一方面,根据 JSON Schema Draft 4 规范,不指定type属性是可以的,这意味着实例可以是任何类型(对象、数组或基元)。
另一方面,我已经看到很多 Swagger 模式,其中包含没有type属性的Schema 对象,但是有properties属性,这清楚地表明模式作者希望实例是一个适当的对象(并且不想接受数组或原始值作为有效值)。
所有这些模式都不正确吗?或者是type: object隐含的存在properties?Swagger 或 JSON Schema 规范中都没有说明情况就是如此。事实上,我看到一些评论明确表示情况并非如此。
我正在尝试记录包含各种身份验证是可选的端点的现有 API。也就是说,如果用户获得授权,则返回的数据比未授权时返回的数据多。
无法在 OAspec v3 中明确找到。是否有编码技巧来定义这种情况?
我目前的解决方法是编写授权代码,但在端点的描述中写入授权是可选的。这有效并且似乎足够了。然而,我内心的纯粹主义者想知道是否还有另一种方式。
我正在尝试使用 OpenAPI 规范 (v3) 定义文件下载端点。我面临两个问题。1) 文件没有被下载 2) 在 swagger-ui 中,响应正文显示一条不是由服务器生成的消息(即无法解析 JSON。原始结果:”
任何人都知道我做错了什么?
下面这个错误是什么意思?(在 Swagger 编辑器中运行)
架构错误不应具有附加属性 additionalProperty: /buildinfo, /clearcache, /countries/{countryId}/cinemas/{theatreid}/screens/{screenid}/layout, /countries/{countryId}/cinemas/{theatreid}/screens跳到第 0 行
下面是我的 yaml 文件。
openapi: "3.0.1"
info:
title: Mobile backend
version: 1.0.0
license:
name: Apache 2.0
paths:
/buildinfo:
get:
description: Returns the build information (Version and Time stamp).
operationId: getBuildInfo
parameters:
- name: LBPATH
in: header
/clearcache:
get:
description: Clears the mobile backends cache (You need to be Admin to do this call)
operationId: clearCache
parameters:
- name: LBPATH
in: header
/countries/{countryId}/cinemas/{theatreid}/screens/{screenid}/layout:
get:
description: Returns a list of Auditoriums that …Run Code Online (Sandbox Code Playgroud) 我想在 JSON 文件中制作一个表格
是否有任何解决方法可以在 openapi.json 中包含表?
我在 OpenAPI 3.0 中使用 Swagger 编辑器。我需要记录一条包含上传图像的路线。尝试“试用”时,我没有让文件浏览器选择要在请求正文中上传的图像,我得到的只是一个带有参数名称和类型的 JSON 字符串。

这是路由的 YAML 描述:
openapi: 3.0.0
...
paths:
/media/upload/thumbnail:
post:
tags:
- media
- publications
security:
- bearerAuth: []
summary: upload a kid's publication
operationId: uploadPublication
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
upload:
type: string
format: binary
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
id:
type: string
description: ObjectId of the uploaded file in db (original size)
example: 5a6048b3fad06019afe44f24
filename:
type: string
example: myPainting.png
thumbnail:
type: string
description: …Run Code Online (Sandbox Code Playgroud) OpenAPI 规范(fka Swagger 规范)是第 3 版 - 请参阅https://swagger.io/specification
但是,npm swagger 包使用规范的第 2 版。
我如何将 Swagger 框架与 Node.js 结合使用,但使用 OpenAPI 规范的第 3 版?是否有用于 OpenAPI 3.0 的官方 npm 包?还是我的想法完全错误?也许 Swagger 现在是一个独立的桌面应用程序或其他东西,不再与 npm 一起安装?(类似于 Postman 是一个独立的桌面应用程序。)
我正在尝试为此multipart/form-data请求创建 OpenAPI 定义:
curl -X POST \
http://localhost:1234/api/v1/Submit \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-H 'sessionkey: kjYgfORsZ0GeiCls0FcR7w==' \
-F item1=abc \
-F item2=def
-F item3=ghi
...
Run Code Online (Sandbox Code Playgroud)
我的API定义是这样的:
curl -X POST \
http://localhost:1234/api/v1/Submit \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-H 'sessionkey: kjYgfORsZ0GeiCls0FcR7w==' \
-F item1=abc \
-F item2=def
-F item3=ghi
...
Run Code Online (Sandbox Code Playgroud)
它适用于 formData 中的固定字段。
但是,我的表单数据将是动态的,我需要能够发送任意键和值。
我尝试更改表单参数以使用数组 and additionalProperties,但它没有产生所需的结果:
post:
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- in: formData
name: …Run Code Online (Sandbox Code Playgroud) 我们在使用 OpenAPI 2.0 鉴别器时遇到了麻烦,让 Swagger 工具和 Jackson 序列化器都满意。
问题:在序列化期间,Jackson 当前为鉴别器生成两个 JSON 属性,其中之一具有null值。
OpenAPI 2.0 定义
swagger: '2.0'
info:
version: v1
title: Error API
paths:
/errors:
get:
description: Stack Overflow test
responses:
'200':
description: OK
schema:
$ref: '#/definitions/SpecificError'
definitions:
GeneralError:
description: Error Base Structure
type: object
discriminator: errorType
properties:
errorType:
type: string
message:
type: string
required:
- errorType
SpecificError:
description: Test
allOf:
- $ref: "#/definitions/GeneralError"
Run Code Online (Sandbox Code Playgroud)
AFAIU 鉴别器被正确定义。规范要求它同时列在properties和required列表中。
使用的属性名称必须在此模式中定义,并且必须在所需的属性列表中。使用时,该值必须是该模式或继承它的任何模式的名称。
Swagger 代码生成器
Swagger Java 代码生成器生成的是: …
openapi ×10
swagger ×6
swagger-ui ×3
jackson ×1
json ×1
jsonschema ×1
markdown ×1
node.js ×1
swagger-2.0 ×1
validation ×1
yaml ×1