3

Swagger Editorを使用して、API 用のカスタム JSON/YAML を作成しようとしています。Accept基本的には、次のテンプレートのように、エンドポイントへの POST リクエストとContent-Typeヘッダーと POST データを JSON の形式で記述したいと考えています{"document": "Some text paragraph", "documentType": "text/plain"}

これは私の swagger.yml ファイルです

swagger: '2.0'
info:
  title: Random title
  description: Blah blah
  version: 1.2.3
host: endpoint.com
schemes:
  - https
securityDefinitions:
  basicAuth:
    type: basic
    description: HTTP Basic Authentication.
basePath: /v1
paths:
  '/{pipelineID}':
    parameters:
      - $ref: '#/parameters/pipelineID'
    post:
      summary: Hello world
      description: World hello
      security:
        - basicAuth: []
      consumes:
        - application/json
      produces:
        - application/json
      tags:
        - TextAnnotation
      parameters:
        - name: body
          in: body
          description: JSON
          required: true
          schema:
            - $ref: "#/definitions/json"
        - name: Accept
          in: header
          required: true
        - name: Content-Type
          in: header
          required: true
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Internal Server Error
parameters:
  pipelineID:
    name: pipelineID
    description: Pipeline ID
    in: path
    type: string
    required: true
definitions:
  json:
    - type: ServiceRequest
      properties:
        - "document":
          - type: string
          "documentType":
          - type: string

Swagger エディターのエラー:

Swagger Error
A deterministic version of a JSON Schema object.
Jump to line 59

59 行目から定義が始まります。より具体的には、json

私は何を間違っていますか?

4

1 に答える 1

2

私はこれでバガーを見つけました。これは絶対に有効で機能するJSONです

"definitions": {
    "ServiceRequest": {
        "type": "object",
        "description": "Payload data to be sent with request. Format: JSON",
        "required": [
            "documentType",
            "document"
        ],
        "properties": {
            "documentType": {
                "type": "string",
                "default": "text/plain"
            },
            "document": {
                "type": "string",
                "default": "Your text here"
            }
        }
    }
}

正しいcurlリクエストを生成します。

于 2015-10-09T15:04:46.057 に答える