如何使用样式 simple + 路径变量作为 Object 来执行 swagger 请求验证

问题描述 投票:0回答:1

我想使用 Open API 3.0.0 执行 swagger 请求验证,样式简单,路径变量作为对象。

根据 swagger 官方文档,我希望在我的 API 中对路径变量进行以下配置。

https://swagger.io/docs/specification/serialization/

风格 对象 id = {"role": "admin", "firstName": "Alex"}
简单 /用户/角色,管理员,名字,Alex

我的后端API应该如下:

http://test-api/users/role,admin,firstName,Alex

任何人都可以建议如何为此配置创建 yml 文件吗?

谢谢

我尝试了一些解决方法,但它不起作用并给我 json 解析错误

swagger openapi swagger-ui openapi-generator
1个回答
0
投票
openapi: 3.0.3
info:
  title: My API
  version: 1.0.0
paths:
  /users/{id}:
    get:
      summary: my api endpoint
      operationId: getUsersById
      parameters:
      - $ref: "#/components/parameters/path_id"
      responses: 
        '200':
          description: OK
          content: 
            application/json: 
              schema: {}
        '400':
            description: Bad Request
            content:
              'application/problem+json':
                schema: 
                  $ref: "#/components/schemas/problem_json"
components: 
  parameters: 
    path_id:
      name: id
      in: path
      style: simple
      explode: false
      schema:
        type: object
        properties:
          role:
            enum:
            - admin
            - user
          firstName:
            type: string
  schemas:
    problem_json:
      title: RFC9457 - Problem JSON
      description: Problem Details for HTTP APIs - RFC9457
      type: object
      properties:
        type:
          type: string
          format: 'uri-reference'
        status:
          type: number
        title:
          type: string
        detail:
          type: string
        instance:
          type: string
          format: 'uri-reference'
    
© www.soinside.com 2019 - 2024. All rights reserved.