Swagger UI-从组件调用参数

时间:2018-10-24 12:22:42

标签: swagger swagger-ui openapi

我将swagger ui与swaggerapi / swagger-ui docker镜像一起使用。我尝试使用在我的路径之一中的组件中定义的参数,但这不起作用。问题出在哪里?

在我的index.yaml文件中

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <span>1</span>
  <span>2</span>
  <span>3</span>
  <!— last visible child —>
  <span style='display:none'>4</span>
  <span style='display:none'>5</span>
  <!— last child —>
</div>

在我的路径文件中

components:
  ...
  parameters:
    Pagination:
    - in: query
      name: page
      schema:
        type: integer
        required: false
      description: The page to go to
    - in: query
      name: per_page
      schema:
        type: integer
        required: false
      description: The number of items per page
  ...

谢谢您的帮助

1 个答案:

答案 0 :(得分:1)

OpenAPI允许您class User { public function __construct($user) { $this -> user = $user; } } 使用单个参数,但不能使用一组参数。因此,如果您有几个常用参数,则需要在$ref部分中为它们创建单独的定义。另外,components/parameters是参数属性,而不是模式属性:

required

然后在路径文件中使用:

components:
  parameters:
    pageParam:          # <-----
      in: query
      name: page
      schema:
        type: integer
      required: false   # <-----
      description: The page to go to
    perPageParam:       # <-----
      in: query
      name: per_page
      schema:
        type: integer
      required: false   # <-----
      description: The number of items per page