我正在尝试在命令提示符中执行此命令,以生成python的代码:
java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar \
generate \
-i http://localhost/test/swagger-docs/api-docs.json \
-l python -o c:\temp\python_testapi_client
Run Code Online (Sandbox Code Playgroud)
它告诉我这个错误:
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:89)
at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中打开此文件时,它包含:
{
"swaggerVersion": "1.2",
"apis": [{
"path": "\/v1-machinetags",
"description": "Deletes machine tags by they titles."
}, {
"path": "\/v1-photos",
"description": "Uploads photo with tags."
}, {
"path": "\/v1-photos-bymachinetags",
"description": "List of photos with possibility filtering by Machine tags."
}, {
"path": "\/v1-photos-bytags",
"description": "List of photos with possibility filtering …Run Code Online (Sandbox Code Playgroud) 我想将"account"参数应用于所有路径,没有任何例外.有没有办法用Swagger 2做这个(我不想为每个路径应用"account"参数)?
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "Doc"
},
"host": "localhost",
"schemes": [
"http"
],
"produces": [
"application/json"
],
"parameters": {
"account": {
"in": "header",
"name": "X-ACCOUNT",
"description": "Account id",
"type": "string",
"required": true
}
},
"paths": {
"/account": {
"get": {
"summary": "Get account",
"operationId": "getAccount",
"responses": {
"200": {
"description": "test"
}
}
}
},
..... other paths
}
}
Run Code Online (Sandbox Code Playgroud) 貌似官方招摇的OpenAPI的规范V3支持接近释放https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/和招摇,代码生成了3.0.0支持开发并在分支上传递一定程度的测试https://github.com/swagger-api/swagger-codegen3.0.0
我有一个swagger规范(从我现有的2.0规范通过https://github.com/mermade/swagger2openapi生成,输出看起来不错)
是否有一种简单的方法来运行swagger-codegen而无需自己打包jar?
[main] INFO io.swagger.parser.Swagger20Parser - 从/input/myspec.openapi3.json读取[main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - 找不到.swagger-codegen-ignore文件.线程"main"中的异常java.lang.RuntimeException:缺少swagger输入或配置!at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:685)at io.swagger.codegen.cmd.Generate.run(Generate.java:285)at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java) :35)
看起来swagger-codegen repo 在你构建之后运行一个docker容器有一些支持的方式; 我只是希望/猜测有一种支持的方法来做到这一点,而不需要在本地编译,因为我需要在几个地方设置它.
我正在编写 Open API 3.0 规范并尝试获取响应链接以在 Swagger UI v 3.18.3 中呈现。
例子:
openapi: 3.0.0
info:
title: Test
version: '1.0'
tags:
- name: Artifacts
paths:
/artifacts:
post:
tags:
- Artifacts
operationId: createArtifact
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
responses:
201:
description: create
headers:
Location:
schema:
type: string
format: uri
example: /artifacts/100
content:
application/json:
schema:
type: object
properties:
artifactId:
type: integer
format: int64
links:
Read Artifact:
operationId: getArtifact
parameters:
artifact-id: '$response.body#/artifactId'
/artifacts/{artifact-id}:
parameters:
- name: artifact-id
in: path
required: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 OpenAPI Generator 4.0.0-SNAPSHOT(我们的经理出于某种原因要求我们使用该版本)生成 Typescript 客户端,该客户端读取 OpenAPI 3.0 规范。我们当前的所有端点要么接受查询字符串中的数据,要么接受表单正文中的数据,并且它们都工作得很好。我有一个新端点,它将在 POST 正文中读取 JSON 数据(其他端点最终也会被转换)。它将接受如下所示的对象:
{email: "something@domain.com"}
我正在尝试在 YAML 中记录端点,如下所示:
/users/send-password-reminder:
post:
[...]
requestBody:
content:
application/json:
schema:
type: object
properties:
email:
type: string
responses:
[...]
Run Code Online (Sandbox Code Playgroud)
但是,当我生成 Typescript 客户端时,它会生成一个SendPasswordReminderRequest对象,该对象包装一个自动生成的InlineObject1对象,该对象包装我实际的email.
这导致我像这样使用它:
const req: SendPasswordReminderRequest = {
inlineObject1:{
email: "..."
}
};
APIClient.user.sendPasswordReminder(req, ...)
Run Code Online (Sandbox Code Playgroud)
InlineObject1我想要的是完全摆脱它并SendPasswordReminderRequest直接包装email属性,并能够将其用作:
const req: SendPasswordReminderRequest = {
email: "..."
};
APIClient.user.sendPasswordReminder(req, ...)
Run Code Online (Sandbox Code Playgroud)
components/requestBodies我尝试在和 using中定义主体$ref,它仍然包装实际主体,即使它使用我的请求主体类型的名称。
我怎样才能摆脱这个包装?
我的狂妄定义如下:
someDef:
type: object
properties:
enable:
type: boolean
default: false
nodes:
type: array
maxItems: 3
items:
type: object
properties:
ip:
type: string
default: ''
Run Code Online (Sandbox Code Playgroud)
我的节点是数组,它有 maxitems: 3。我希望我的节点项长度为 0 或 3。提前致谢。
我正在尝试使用anyOf和allOf属性创建OpenAPI自动生成的PHP客户端。
目标是能够返回其中具有多态性的数组:不同类型的对象。
这些对象也具有一个公共的基础对象。
在我的示例模式中,Items是一个数组,其中各项可以是类型ItemOne或ItemTwo。
这两种类型的项目有一个自己的财产(itemOneProperty和itemTwoProperty,分别地),和一个共同的属性baseItemProperty(从继承BaseItem与allOf关键字)。
这里有API规范yaml:
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
servers:
- url: https://api.myjson.com/bins
paths:
/roxgd:
get:
operationId: getItems
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Items'
components:
schemas:
Items:
type: array
items:
anyOf:
- $ref: '#/components/schemas/ItemOne'
- $ref: '#/components/schemas/ItemTwo'
BaseItem:
type: object
properties:
baseItemProperty:
type: string
ItemOne:
allOf:
- $ref: '#/components/schemas/BaseItem'
- type: object …Run Code Online (Sandbox Code Playgroud) 如何在springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html) 中启用“授权”按钮以进行基本身份验证。
Spring@Controller和@Configuration类需要添加哪些注解?
我有一个带有如下参数的开放 API 规范:
- name: platform
in: query
description: "Platform of the application"
required: true
schema:
type: string
enum:
- "desktop"
- "online"
Run Code Online (Sandbox Code Playgroud)
当我从 URL 获取“平台”参数时,它可以是这样的:
platform=online or
platform=ONLINE or
platform=Online or
platform=onLine or ... any other format
Run Code Online (Sandbox Code Playgroud)
但是当我要使用它时,它仅在参数全部为小写时才有效,例如"platform=online",显然要匹配枚举值。
如何使模式不区分大小写并理解所有类型的传递参数?
我想使用 AWS CDK 来定义 API 网关和 APIG 将代理到的 lambda。
OpenAPI 规范支持x-amazon-apigateway-integration对 Swagger 规范的自定义扩展(在此处详细说明),为此需要 lambda 的调用 URL。如果 lambda 定义在与 API 相同的堆栈中,我在 OpenAPI 规范中看不到如何提供它。我能想到的最好的方法是使用 lambda 定义一个堆栈,然后从中获取输出并运行sed以在 OpenAPI 规范中执行查找和替换以插入 uri,然后使用此修改创建第二个堆栈OpenAPI 规范。
例子:
/items:
post:
x-amazon-apigateway-integration:
uri: "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:123456789012:function:MyStack-SingletonLambda4677ac3018fa48679f6-B1OYQ50UIVWJ/invocations"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
type: "aws_proxy"
Run Code Online (Sandbox Code Playgroud)
一季度。这似乎是一个鸡与蛋的问题,以上是唯一的方法吗?
我尝试使用SpecRestApi CDK 构造的defaultIntegration属性。该文件指出:
除非指定了集成,否则用作此 API 中创建的所有方法的默认值的集成。
这似乎应该能够使用 CDK 规范中定义的 lambda 定义默认集成,因此所有方法都使用此集成,而无需提前知道 lambda 的 uri。
因此我试过这个:
SingletonFunction myLambda = ...
SpecRestApi openapiRestApi = SpecRestApi.Builder.create(this, "MyApi")
.restApiName("MyApi")
.apiDefinition(ApiDefinition.fromAsset("openapi.yaml"))
.defaultIntegration(LambdaIntegration.Builder.create(myLambda)
.proxy(false)
.build())
.deploy(true) …Run Code Online (Sandbox Code Playgroud) amazon-web-services swagger aws-lambda aws-api-gateway openapi
openapi ×10
swagger ×6
swagger-2.0 ×2
swagger-ui ×2
aws-lambda ×1
enums ×1
java ×1
php ×1
polymorphism ×1
spring ×1
springdoc ×1
typescript ×1