标签: openapi

在Swagger中描述json参数

问题

根据这个这个扬鞭支持复杂的参数,但是当我试图描述一个JSON参数扬鞭编辑器显示了以下问题:

无法呈现ParameterRow,请参见控制台。

预期行为

Json对象作为参数。

YAML

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Trackmeeasy API
paths:
  /getLabelUrl.action:
    post:
      parameters:
        - in: query
          name: filter
          content:
            application/json:
              schema:
                type: object
                properties:
                  type:
                    type: string
                  color:
                    type: string
      responses:
        '200':
          description: OK
Run Code Online (Sandbox Code Playgroud)

复制...

  1. 复制yaml
  2. 前往http://editor.swagger.io
  3. 糊状Yaml
  4. 看到错误

屏幕截图

屏幕截图

swagger openapi

0
推荐指数
1
解决办法
1851
查看次数

jsonschema:使用特定键验证字典列表

我正在尝试为字典列表(也称为对象数组)编写一个 jsonschema,在其中验证字典中的键。此示例中的标签是我感兴趣的。我想允许任意数量的标签,并希望验证namevalue字段始终存在于标签字典中。以下是表示为 yaml 的示例输入。

some_field1: "value_a"
some_field2: "value_b"
labels:
- name: "bar"
  value: "foo"
- name: "baz"
  value: "blah"
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止拼凑的内容,但它并没有验证字典中的键。我不确定 extraProperites 在这种情况下是如何工作的,但我在网上找到了一个例子。

properties:
  some_field1:
    type: string
    default: 'value_a'
  some_field2:
    type: string
    default: 'value_b'
  labels:
    type: array
    items:
      type: object
      additionalProperties:
        type: string
Run Code Online (Sandbox Code Playgroud)

我的用例是,我尝试为 Kubernetes 创建自定义资源定义 (CRD),在其中验证输入,我的理解是 CRD 使用 openapi3/jsonschema 验证来定义其字段。

我无法找到有关如何使用特定键验证字典列表的信息。如果您提供任何帮助,我将不胜感激。

validation json jsonschema kubernetes openapi

0
推荐指数
1
解决办法
2507
查看次数

如何将 openapi.yaml 规范公开到其余的 Spring Boot 中

我已经在外部安装了 swagger-ui,我只想将 swagger-ui (开源)实例从 openapi.yaml 连接到 localhost:8000/doc/api (.yaml) 。有什么想法吗?PS:我尝试使用

 @Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components().addSecuritySchemes("basicScheme",
                    new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
            .info(new Info().title("SpringShop API").version("0.1")
                    .license(new License().name("Apache 2.0").url("http://springdoc.org")))
            .externalDocs(new ExternalDocumentation()
                    .url("restapi/doc/openapi.yaml"));
}

    @Bean
    public SpringDocConfiguration springDocConfiguration(){
        return new SpringDocConfiguration();
    }
    @Bean
    public SpringDocConfigProperties springDocConfigProperties() {
        return new SpringDocConfigProperties();
    }
Run Code Online (Sandbox Code Playgroud)

但我没有发现任何有用的东西。谢谢。

    application.properties:
    springdoc.api-docs.enabled=false
springdoc.swagger-ui.url=openapi.yaml
springdoc.swagger-ui.path=/doc/api/ui.html

dependecies:
<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.4</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

spring swagger openapi springdoc

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

OpenApi - 需要一个类型为“org.springdoc.webmvc.ui.SwaggerIndexTransformer”的 bean,但无法找到

我正在使用功能控制器将 Swagger 添加到我的 Spring Webflux 服务中。首先我收到这个错误:

描述:无法注册在类路径资源 [org/springdoc/webflux/ui/SwaggerConfig.class] 中定义的 bean“swaggerWelcome”。具有该名称的 bean 已在类路径资源 [org/springdoc/webmvc/ui/SwaggerConfig.class] 中定义,并且覆盖被禁用。

行动:

考虑重命名其中一个 bean 或通过设置 spring.main.allow-bean-definition-overriding=true 来启用覆盖

所以我将 spring.main.allow-bean-definition-overriding=true 添加到我的 application.properties 文件中。

现在我收到这个错误:

描述:

org.springdoc.webmvc.ui.SwaggerConfig 中方法 swaggerWebMvcConfigurer 的参数 1 需要一个类型为“org.springdoc.webmvc.ui.SwaggerIndexTransformer”的 bean,但无法找到。

行动:

考虑在配置中定义“org.springdoc.webmvc.ui.SwaggerIndexTransformer”类型的 bean。

Pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company/groupId>
    <artifactId>service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!-- For all mvc and web functions -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency> …
Run Code Online (Sandbox Code Playgroud)

api-doc openapi spring-webflux springdoc-openapi-ui

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

Swagger 中鉴别器内的映射有什么作用?

文档中的解释对我来说不清楚。我的 api 文档渲染后没有看到任何差异。
视觉上有什么区别?从逻辑上讲,映射是做什么的?例如

MySchema:
  oneOf:
    - $ref: '#/componets/schemas/SubSchema1'
    - $ref: '#/componets/schemas/SubSchema2'
  discriminator:
    propertyName: some_property:
    mapping:
      TypeA: '#/componets/schemas/SubSchema1'
      TypeB: '#/componets/schemas/SubSchema2'
Run Code Online (Sandbox Code Playgroud)

documentation rest swagger openapi

0
推荐指数
1
解决办法
2437
查看次数

在 DRF 中使用 @extend_schema 而非 @actoin 时出现问题

您好,我的代码中有一个drf_spectaulous库的@extend_schema我需要在@action上使用它来自定义OpenAPI中的详细信息,但我收到这样的错误

Internal Server Error: /api/schema/
Traceback (most recent call last):
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/asgiref/sync.py", line 482, in thread_handler
    raise exc_info[1]
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/django/core/handlers/exception.py", line 38, in inner
    response = await get_response(request)
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/django/core/handlers/base.py", line 233, in _get_response_async
    response = await wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/asgiref/sync.py", line 444, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/usr/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
    return await fut
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/asgiref/sync.py", line …
Run Code Online (Sandbox Code Playgroud)

python django swagger openapi drf-spectacular

0
推荐指数
1
解决办法
1128
查看次数