首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不允许在路径中使用Swagger查询字符串

不允许在路径中使用Swagger查询字符串
EN

Stack Overflow用户
提问于 2019-05-23 08:48:58
回答 1查看 7.3K关注 0票数 2

有人能解释我为什么有错误吗?

不允许路径中的查询字符串。

我使用OpenApi 3.0.1,并按照这个文档描述了这部分代码。所以这个错误不应该出现,但它是,为什么?

代码语言:javascript
复制
/posts/{postid}?offset=0&limit=5:
get:
  tags:
  - posts
  summary: example
  description: 'example text'
  operationId: getComments
  parameters:
  - name: postId
    in: path
    description: Post id
    required: true
    schema:
      type: string
  - name: offset
    in: query
    schema:
      type: integer
    description: The number of items to skip before starting to collect the result set
    required: false
  - in: query
    name: limit
    schema:
      type: integer
    description: The numbers of items to return
    required: false
  responses:
    200:
      description: example desc
      content:
        application/json:
          schema:
            items:
              $ref: '#/components/schemas/ResponseData'
    422:
      description: Unprocessable entity
      content: {}

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-01-08 10:41:42

你应该写:

/posts/{postid}

而不是

/posts/{postid}?offset=0&limit=5:

参数部分中偏移量和限制的定义足以知道这些是查询参数,因为它们已经包含属性in: query

如果您查看https://swagger.io/docs/specification/describing-parameters/,并不是说您应该按照swagger规范的paths部分添加查询字符串。(可能令人困惑的是,会显示一些包含查询字符串的GET请求,这可能会使您感到困惑,认为您应该像swagger规范中那样编写查询字符串。)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56271407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档