标签: openapi

如何在 OpenAPI (Swagger) 中为同一路径定义不同的主体参数?

我有一个服务,可以根据Content-Type标头有两种不同类型的主体参数。

例如对于路径/Pet

  • 如果Content-Type: application/somecustom.resource+json使用,则POST可以作为Petbody参数。

  • 如果Content-Type: application/somecustom.function+json使用,则 POST 应该采用一些不同的主体参数来调用函数并返回不同的响应。

关于如何在 OpenAPI (Swagger) 中体现这一点有什么建议吗?

swagger openapi

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

如何从另一个 OpenAPI 文件导入组件?

您可以导入在其他 OpenAPI 文件中定义的组件吗?
假设我有两个 openAPI 文件: openAPI.yamlotherOpenAPI.yaml. 我openAPI.yml想使用myItem中定义的组件otherOpenAPI.yaml

我可以做一些类似的事情吗: $ref: './otherOpenAPI.yaml/components/myItem

swagger openapi

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

Swashbuckle OperationFilter 添加类型对象的参数

我有一个 C# 对象

public class MyObject
{
 public int property1 { get; set; }
 public string property2 { get; set; }
 public string property3 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想创建一个具有MyObject.

public class MyFilter : IOperationFilter
{
 public void Apply(OpenApiOperation operation, OperationFilterContext context)
 {
   operation.Parameters.Add(new OpenApiParameter
   {
    Name = "MyParameter",
    Description = "MyDescription"
    In = ParameterLocation.Header
    Required = true,
    Schema = new OpenApiSchema()
    {
     Type = "object",
     Properties = new Dictionary<string, OpenApiSchema>()
     {
       // MyObject
     }
    }
   }
  } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net swashbuckle openapi

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

如何使用环回 4 隐藏一条路由的 open-api 规范

Loopback 4 中是否有一种方法可以使用@get()装饰器(或任何其他装饰器),传递路径但不生成该路由的开放 api 规范?
通过传递特殊参数/使用@operation或其他什么?
谢谢。

loopback node.js typescript openapi loopback4

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

如何在 Open API 3.0 中为 GET API 定义 Map 对象

我有 GET API,它将 Map 作为请求参数。如何在 Open API 3.0 中以 yaml 格式定义它

@GetMapping
public void getDevicesInfo(@RequestParam(required = false) Map parameters)
{

}
Run Code Online (Sandbox Code Playgroud)

开放API不支持Map类型。

java yaml swagger openapi openapi-generator

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

如何在 OpenAPI 3.0 中定义 required 和 anyof 属性

我正在为一个 api 创建一个 OpenAPI 3 规范,该规范具有需要某些属性的对象,而对于某些对象来说,它们是任意的。当我创建如下规范时,它会抛出一个错误,我无法修复该错误。

EnrollementRequest:
      type: object
      properties:
        consent:
          $ref: "#/components/schemas/ConsentEnum"
        cid:
          $ref: '#/components/schemas/CID'
        card:
          $ref: '#/components/schemas/Card'
        enrollmentDateTime :
          description: The date and time of enrollment with respective timezone
          format: date-time
          example: 2018-11-13T20:20:39+00:00
        campaign_code: 
          description: the campaign-code for which customer wants to enroll
          type: string
        offer_code:
          description: the offer-code for which customer wants to enroll
          type: string
        channelInfo:
          $ref: '#/components/schemas/Channel'
      required:
        - consent
        - cid
        - enrollmentDateTime
        - channelInfo
      anyOf:
        - campaign_code
        - offer_code       
Run Code Online (Sandbox Code Playgroud)

Swagger 编辑器给出如下错误 -

Errors …
Run Code Online (Sandbox Code Playgroud)

schema json swagger openapi

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

openapi-generator 如何在我的解决方案的 MS 测试项目中生成 c-sharp .NET core 3.1 兼容测试?

我有一个 .net-core 3.1 解决方案,其简单端点仅接受帖子。我想使用 openAPI-generator 生成 SDK(因为Visual Studio for mac中不提供 New REST Client SDK 选项)。

我第一次这样做时,我使用以下命令:

openapi-generator generate -i ../swagger.v0.0.21.json -g csharp -o ./generator
Run Code Online (Sandbox Code Playgroud)

这生成了一个 .net 框架解决方案,因此我必须对其进行一些修改并安装一些 nuget 测试库才能使其运行。毕竟我的连接被拒绝了——我希望这只是因为它是为错误的框架构建的。

我注意到还有另一个生成目标csharp-netcore。但我不确定如何使用它。我的命令应该是什么样的?我刚在想:

openapi-generator generate -i ../swagger.v0.0.21.json -g csharp-netcore -targetFramework netcoreapp3.1 -o ./generator
Run Code Online (Sandbox Code Playgroud)

但这会产生:

[error] Found unexpected parameters: [netcoreapp3.1]
Run Code Online (Sandbox Code Playgroud)

(明确地说,我有一个解决方案结构:

  • 作业_1/
    • 作业_1_测试/

我正是想进行测试。但我的来源直接来自Assignment_1 目录。

c# swagger .net-core openapi openapi-generator

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

WebFlux Swagger(开放 API)集成 - 发布请求示例

我已使用 RouterOperation 将 Swagger (OpenAPI) 与 Spring Webflux 集成,如下所述: https: //springdoc.org/#spring-weblfuxwebmvcfn-with-function-endpoints。集成工作正常,可通过 /swagger-ui.html 访问

但是,对于 POST API,当我单击“试用”按钮时,我没有看到“请求”示例。我的 Post API 接受 Json 作为请求正文。

我该如何配置这个?可以通过注释和 RouterOperation 或其他方式来完成吗?

编辑:下面是我的 Router 类代码:

@Configuration
public class  MyRouter {

    @RouterOperations({
            @RouterOperation(path = "/data", beanClass = MyHandler.class, beanMethod = "getData"),
            @RouterOperation(path = "/allData", beanClass = MyHandler.class, beanMethod = "getAllData") })

    @Bean
    public RouterFunction<ServerResponse> route(MyHandler MyHandler) {

        return RouterFunctions
                .route(RequestPredicates.POST("/data").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), MyHandler::getData)
                .andRoute(RequestPredicates.GET("/allData").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), MyHandler::getAllData);
    }
}
Run Code Online (Sandbox Code Playgroud)

添加 RouterOperations 注释后,我可以看到 swagger-ui 正确显示 GET 和 POST API,但没有显示请求架构示例。

我还遇到了 yaml / json …

java swagger-ui openapi spring-webflux springdoc-openapi-ui

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

如何根据yml文件生成resttemplate?

我使用开放的 openapi-generator-gradle-plugin。这是我的 build.gradle:

buildscript {
    repositories {
        mavenLocal()

        jcenter {
            url "http://nexus.ca.sbrf.ru:8081/nexus/content/repositories/jcenter"
        }
        maven {
            url "http://nexus.ca.sbrf.ru:8081/nexus/content/repositories/central"
        }
        maven { url 'http://nexus.ca.sbrf.ru:8081/nexus/content/repositories/Atlassian_proxy' }
        maven { url 'http://nexus.ca.sbrf.ru:8081/nexus/content/groups/public' }

        dependencies {
            classpath 'org.openapitools:openapi-generator-gradle-plugin:4.3.0'
            classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE"
            classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
        }
    }
}


apply plugin: 'java'
apply plugin: 'org.openapi.generator'
apply plugin: "maven-publish"
apply plugin: "io.spring.dependency-management"
apply plugin: "org.springframework.boot"

dependencies {
    compile 'org.springframework:spring-context:5.3.0'
    compile 'org.springframework:spring-web:4.1.6.RELEASE'
    compile 'javax.servlet:javax.servlet-api:4.0.1'
    compile 'org.openapitools:jackson-databind-nullable:0.2.1'
    compile 'io.swagger:swagger-core:1.5.21'
    compile 'javax.annotation:javax.annotation-api:1.3.1'
}

openApiGenerate {
    generatorName = "spring"
    library = "resttemplate"
    inputSpec = "$rootDir/openapi-contracts/src/main/resources/openapi/api.yml".toString() …
Run Code Online (Sandbox Code Playgroud)

java spring gradle swagger openapi

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

带有路径参数和命令对象的 Springdoc-OpenAPI

我在 Springdoc 生成的 OpenAPI 规范中遇到验证错误,并且无法在网上找到与我的 Java 代码的形成方式相匹配的示例。

我正在尝试使用 Springdoc 为 Spring Boot 控制器生成 OpenAPI 规范。我有一个具有多个路径变量的路径的映射,并且方法签名接受命令对象(命令对象是从这些路径变量自动构造的)。Swagger-UI.html 似乎或多或少可以工作,但生成的 JSON/YAML 规范似乎无效。

我指的代码片段:

@GetMapping("/myPath/{foo}/{bar}/{baz}")
public Mono<MyServiceResponse> doSomethingInteresting(@Valid DoSomethingInterestingCommand command) {
    return interestingService.doSomethingInteresting(command);
}
Run Code Online (Sandbox Code Playgroud)

生成的 OpenApi 片段是:

paths:
  '/myPath/{foo}/{bar}/{baz}':
    get:
      tags:
        - my-controller
      operationId: doSomethingInteresting
      parameters:
        - name: command
          in: query
          required: true
          schema:
            $ref: '#/components/schemas/DoSomethingInterestingCommand'
Run Code Online (Sandbox Code Playgroud)

这会产生如下错误:

Semantic error at paths./myPath/{foo}/{bar}/{baz}
Declared path parameter "foo" needs to be defined as a path parameter at either the path or operation level
Run Code Online (Sandbox Code Playgroud)

为了使生成的规范格式良好,我应该采取哪些不同的做法?我也很好奇为什么 swagger-ui.html 页面似乎工作正常,但这并不那么重要。

java openapi springdoc springdoc-openapi-ui

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