我正在编写 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。提前致谢。
我现有的项目在 Spring Framework 上,而不是 Spring Boot。
我想将 Open API 3 与它集成。
我想使用 springdoc-openapi 而不使用 Jersey 进行集成。
如何在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",显然要匹配枚举值。
如何使模式不区分大小写并理解所有类型的传递参数?
该@nestjs/swagger文档在这里描述了定义额外模型应该这样完成:
@ApiExtraModels(ExtraModel)
export class CreateCatDto {}
Run Code Online (Sandbox Code Playgroud)
但ExtraModel这里是什么?该文档对此不是很清楚。
我想使用 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
我正在使用 Springdoc 来记录在 Spring Boot 中制作的 REST API。\n我需要从Swagger UI 的Schemas部分隐藏一些模型/架构,这些模型/架构仅在 API 内部使用,因此无需在Schemas部分中显示它们。
\n这是我试图隐藏的模型之一:
\n@Getter\n@Setter\n@EqualsAndHashCode(callSuper = true)\n@AllArgsConstructor\n@NoArgsConstructor\n@Entity\n@Table\npublic class EventRole extends AbstractEntity implements Serializable {\n @Column(nullable = false, length = 25)\n private String descriptor;\n}\nRun Code Online (Sandbox Code Playgroud)\n上面显示的模型的超类:
\n@Data\n@RequiredArgsConstructor\n@SuperBuilder\n@MappedSuperclass\npublic abstract class AbstractEntity {\n @Id\n @GeneratedValue(strategy = GenerationType.IDENTITY)\n private Long id;\n\n @CreationTimestamp\n @Column(nullable = false, updatable = false)\n private LocalDateTime creationDate;\n\n @UpdateTimestamp\n @Column(nullable = false)\n private LocalDateTime modificationDate;\n}\nRun Code Online (Sandbox Code Playgroud)\n这些示例中的大多数注释都来自 JPA 或 Lombok。\n需要明确的是:在模式AbstractEntity部分 \xe2\x80\x93中不可见,我将其包含在此处以防万一。
我正在使用 OpenAPI 3.0 设计和实现一个简单的 API,以允许对数据库实体进行基本的 CRUD 操作。
让我们假设一个实体Pet具有一些客户端给定的属性 ( name& age) 和一些生成的属性 ( id& created):
components:
schemas:
Pet:
type: object
properties:
id:
type: string
created:
type: string
format: date-time
name:
type: string
age:
type: integer
Run Code Online (Sandbox Code Playgroud)
我想指定 REST 端点来 POST、GET、PUT(如果可能的话 PATCH)宠物:
paths:
/pets:
post:
operationId: createPet
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
responses:
"200":
content:
application/json:
schema:
type: boolean
/pets/{id}:
parameters:
- name: id
schema:
type: string
in: path
required: true
get:
operationId: getPet
responses: …Run Code Online (Sandbox Code Playgroud) openapi ×10
swagger ×5
swagger-ui ×4
springdoc ×3
java ×2
rest ×2
spring ×2
aws-lambda ×1
dto ×1
enums ×1
javascript ×1
nestjs ×1
nullable ×1
spring-boot ×1
swagger-2.0 ×1
typescript ×1