标签: openapi

open api 3.0 如何支持具有多个值的单个查询参数键?

对于这种格式的api:GET /resource?param=value1&param=value2&param=value3 在open Api 2.0中,我们可以这样指定:

parameters:
    - in: query
      name: color
      type: array
      collectionFormat: multi
      items:
        type: string 
Run Code Online (Sandbox Code Playgroud)

但在 v3.0 中,属性 collectionFormat 不可用。因此,在尝试使用 collectionFormat 时,我收到错误消息 should not have additional property: collectionFormat

我搜索了文档但找不到任何答案。有谁知道从 2.0 版本迁移到 3.0 版本的新实现应该是什么?

swagger openapi

4
推荐指数
1
解决办法
5053
查看次数

Swagger UI 中的掩码输入(示例 - 密码)?

我有一个 API 的三个路径变量。我想用 ***** 屏蔽 Swagger UI 上的一个输入。

使用 Springdoc OpenAPI 时如何做到这一点?

swagger-ui openapi springdoc-openapi-ui

4
推荐指数
1
解决办法
8605
查看次数

如何使用另一个 swagger 文档扩展 FastAPI 文档?

我决定在Python的FastApi框架中制作一个微服务网关。drf-yasg我的授权服务是用 Django 编写的,并且已经由包 swagger 文档生成。我在想是否有一种方法可以将身份验证的模式导入网关。我可以通过 http 格式提供模式json并从网关访问它。问题是如何将 FastApi 的文档与原始 swagger 模式文件集成。

python swagger openapi drf-yasg fastapi

4
推荐指数
1
解决办法
5488
查看次数

如何在 springdoc 中注释 requestBody 的各个元素?

我有一个 spring(启动)服务器,想要使用 springdoc 从注释生成 OpenAPI 规范。

我有一个请求,请求正文中有两个参数。我希望第一个是必需的,第二个是可选的。

@RequestBody(required = {true|false})似乎只将主体中的所有参数设置为(不需要)。@Parameter另一方面,Javadoc说要使用io.swagger.v3.oas.annotations.parameters.RequestBody

这是我的代码,我希望生成一个规范,其中第一个参数是必需的,第二个参数是可选的:

@GetMapping("/fstVector")
public ResponseEntity<Vector> fstV(@RequestBody final Vector v1, @RequestBody(required = false) final Vector v2) {
    return new ResponseEntity<>(v1, HttpStatus.OK);
}

@PostMapping("/fstVector")
public ResponseEntity<Vector> fstVPost(@RequestBody(required = true) final Vector v1, @RequestBody(required = false) final Vector v2) {
    return new ResponseEntity<>(v1, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)

然而,生成的规范需要两个参数:

  /pond/fstVector:
    get:
      tags:
      - circle-escape-controller
      operationId: fstV
      parameters:
      - name: v1
        in: query
        required: true
        schema:
          $ref: '#/components/schemas/Vector'
      - name: v2
        in: query
        required: …
Run Code Online (Sandbox Code Playgroud)

spring-boot openapi springdoc springdoc-openapi-ui

4
推荐指数
1
解决办法
1万
查看次数

OpenAPI 是否允许 $ref 指向_特定_枚举值?

假设在我的 OpenAPI v3 描述中,我有以下/componenets/schemas条目(使用 YAML)格式:

\n
WidgetTypes:\n  type: string\n  enum:\n    - WIDGET_A\n    - WIDGET_B\n    - WIDGET_C\n
Run Code Online (Sandbox Code Playgroud)\n

因此,模式WidgetTypes是一个命名的(即值$ref)枚举“类”。在 API 规范的其他各个地方,我们现在可以引用这些枚举值,例如,也许有一个 API 路径,其中一个路径元素必须来自该WidgetTypes集合。

\n

现在,我还有一些附加模式(即对象数据模型),并且可能存在特定 WidgetType值是该对象类型的常量的情况。一个例子:

\n
MySpecificWidgetA:\n  type: object\n  properties:\n    someField1:\n      type: string\n    someField2:\n      type: number\n    widgetType:\n      type: string\n      enum:\n        - WIDGET_A\n
Run Code Online (Sandbox Code Playgroud)\n

这感觉就像是完成此操作的 na\xc3\xafve 方法,因为 now 的MySpecificWidgetA字段widgetType是来自可能的集合的字符串WidgetType但没有实际参考强制WidgetType执行此操作。\n本质上,我想要什么要断言的是,这MySpecificWidgetA.widgetType是枚举模式中的特定值WidgetType(在本例中WIDGET_A)。\nUsing 只是$ref: '#/components/schemas/WidgetType' …

jsonschema openapi

4
推荐指数
1
解决办法
3200
查看次数

将枚举作为组件的 Swagger 注解

我有一个枚举:

public enum UserType {
  ADMIN("Admin"),
  GUEST("Guest"),
  SUPERVIOR("Supervisor"),
  NORMAL("Normal");

  private final String type;

  UserType(final String type) {
    this.type = type;
  }

Run Code Online (Sandbox Code Playgroud)

我将它用作带有 Swagger 注释的查询参数:

@GET
@AsyncTimed
@Path("/all")
void all(
    @ApiParam @PathParam(USER_ID) @Parameter(in = ParameterIn.PATH, name = USER_ID, required = true) final UserId userId,
    @QueryParam(TYPES) final Set<UserType> userTypes,
    @Suspended final AsyncResponse asyncResponse
);
Run Code Online (Sandbox Code Playgroud)

然而,生成的 OpenAPI 文件并没有从枚举中创建组件,而是给出:

get:
  parameters:
  - name: UserId
    in: path
    required: true
    schema:
      $ref: '#/components/schemas/UserId'
  - name: Types
    in: query
    schema:
      uniqueItems: true
      type: array
      items:
        type: string …
Run Code Online (Sandbox Code Playgroud)

java enums swagger openapi

4
推荐指数
1
解决办法
4422
查看次数

swagger 2.0 - 如何解决 Spring Boot 应用程序中不同包中相同的响应类名问题

例如,不同包中有两个具有相同名称 Group 的类。但是,当在 swagger ui 中引用模型时,仅显示一个模型,甚至响应映射也不正确,swagger 错误地引用了这些模型。

java swagger spring-boot swagger-2.0 openapi

4
推荐指数
1
解决办法
4528
查看次数

如何使用 FastApi 依赖项向 OpenAPI 架构添加描述

如果我使用依赖系统,有没有办法将字段描述添加到 FastAPI swagger 模式?

我发现没有地方可以在FastAPI 文档的简单示例中添加描述

async def common_parameters(q: str = None, skip: int = 0, limit: int = 100):
    return {"q": q, "skip": skip, "limit": limit} 
Run Code Online (Sandbox Code Playgroud)

python swagger openapi fastapi

4
推荐指数
1
解决办法
9511
查看次数

如何在 swagger codegen 中设置默认的空列表

有一个带有字段的实体

      cises:
        type: array
        description: An array of brands. The length must match the value of the quantity field, or the array must be empty
        items:
          type: string
Run Code Online (Sandbox Code Playgroud)

代码java

  @SerializedName("cises")
  private List<String> cises = null;
Run Code Online (Sandbox Code Playgroud)

如何使用 swagger codegen 默认设置一个空列表,而不是 null

java openapi swagger-codegen

4
推荐指数
1
解决办法
1926
查看次数

仅根据 OpenAPI 定义生成 POJO

我已将 Web 服务定义编写为 OpenAPI 文档。我使用的 openapi-generator-maven-plugin 总是生成带有 poms 和 gradle 构建脚本的整个项目,但我只需要 pojos 以及可能生成的 API 客户端。它应该与 JaxB 或 JaxWS 代码生成器同等工作。

那么有没有办法告诉插件只生成Java代码呢?也许还有另一个插件可以完成这项工作?

这是我的配置:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>5.1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/my-api.yaml</inputSpec>
                <modelPackage>com.my.path.to.api</modelPackage>
                <generatorName>java</generatorName>
                <generateApis>false</generateApis>
                <generateModels>true</generateModels>
                <generateModelDocumentation>false</generateModelDocumentation>
                <generateModelTests>false</generateModelTests>
                <library>vertx</library>
                <configOptions>
                    <sourceFolder>src/main/java</sourceFolder>
                    <dateLibrary>java8</dateLibrary>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

java maven-plugin maven openapi openapi-generator-maven-plugin

4
推荐指数
1
解决办法
2万
查看次数