不是有效的参数定义,Swagger 2.0

时间:2016-09-15 06:58:38

标签: yaml swagger-2.0 swagger-editor

我是swagger的新手,以下是我试图在在线编辑器中编辑的代码。但是它在参数字段中显示错误,表示“不是有效的参数定义”。

# Example YAML to get you started quickly.
# Be aware that YAML has indentation based scoping.
# Code completion support is available so start typing for available options.
swagger: '2.0'

# This is your document metadata
info:
  version: "0.0.0"
  title: <test>

# Describe your paths here
paths:
  # This is a path endpoint. Change it.
  /test:
    # This is a HTTP operation
    post:
      # Describe this verb here. Note: you can use markdown

      description: Pass list of input parameter.
      # This is array of GET operation parameters:
      operationId: test
      produces:
        - application/json
        - application/xml
        - text/xml
        - text/html
      parameters:
        - 
          name: value
          in: body
          description: Input parameter list
          required: true
          schema:
          type: array
          items:
            type: object
            properties:
              Name:
                type: string
              Age:
                type: integer
                format: int32
              Address:
                type: string
              Company:
                type: string
              WorkExperience:
                type: integer
                format: int32

      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Successful response
          # A schema describing your response object.
          # Use JSON Schema format
          schema:
            title: ArrayOfPersons
            type: array
            items:
              title: Person
              type: object
              properties:
                name:
                  type: string
                single:
                  type: boolean

swagger预览器中显示以下错误

Swagger Error
Not a valid parameter definition
Jump to line 28
Details
 Object
code:  "ONE_OF_MISSING"
 params: Array [0]
message:  "Not a valid parameter definition"
 path: Array [5]
schemaId:  "http://swagger.io/v2/schema.json#"
 inner: Array [2]
level: 900
type:  "Swagger Error"
description:  "Not a valid parameter definition"
lineNumber: 28

2 个答案:

答案 0 :(得分:1)

这是代码意图错误。

schema:
    type: array
    items:
        type: object
        properties:

答案 1 :(得分:0)

架构字段中的“type:array”定义没有正确缩进。

      parameters:
        - 
          name: value
          in: body
          description: Input parameter list
          required: true
          schema:
            type: array
            items:
              type: object
              properties:
                Name:
                  type: string
                Age:
                  type: integer
                  format: int32
                Address:
                  type: string
                Company:
                  type: string
                WorkExperience:
                  type: integer
                  format: int32