嵌套对象的swagger api文档问题

时间:2020-06-27 13:47:09

标签: swagger

我想用招摇来记录我们内部的詹金斯乔布斯和参数。这样,每个人都可以知道通过API适当触发Jenkins工作的身体是什么样的。

我正在使用swagger.yml文件编写API文档。我要竭尽全力的是记录嵌套对象。

Jenkins需要JSON中的参数。卷曲请求看起来像这样

curl --request POST \
  --url https://myjenkins.com/job/demojob/build \
  --form 'json={
    "parameter": [
        {
         "name": "FilePath", 
         "value": "E:\\Jenkins"
        },
        {
     "name": "FileName", 
         "value": "JenkinsAPI.txt"
        },
        {
     "name": "FileContent", 
         "value": "I am a file created by jenkins through API"
        },
        {
     "name": "Computer", 
         "value": "myhost"
        }
    ]
}'

我能够创建一个yml文件,其中包含类似这样的内容,而这与我所需要的完全不一样。

有人能指出我正确的方向,还是给我一个例子?

paths:
  /job/demojob/build:
    post:
      summary: triggers the job           
      parameters:
        - name: parameters
          in: body
          required: true
        - name: filePath
          in: body
          schema:
            type: string
            default: "C:\\fancyfolder"

1 个答案:

答案 0 :(得分:1)

请检查下面提到的带有svagger属性映射的yml文件,您可以根据需要更改ApiResponse。 :

openapi: 3.0.1
info:
  title: Swagger Jenkins
  description: 'This is a sample server Jenkins server.  You can find out more about     Swagger'
  version: 1.0.0
servers:
- url: https://jenkins.com
tags:
- name: build
  description: Everything about your build

paths:
  /job/demojob/build:
    post:
      tags:
      - build
      summary: build the given branch
      operationId: build
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestParameters'
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse'

components:
  schemas:
    RequestParameters:
      type: array
      items:
        $ref: '#/components/schemas/Parameters'
    Parameters:
      type: object
      properties:
        name:
          type: string
        value:
          type: string
          description: Order Status
    ApiResponse:
      type: object
      properties:
        code:
          type: integer
          format: int32
        type:
          type: string
        message:
          type: string    
相关问题