현재 Swagger.io를 사용하여 내 API를 문서화합니다. 커스텀 json 객체 전송을 문서화하는 방법을 이해하려고합니다.
콜렉션을 / some_endpoint에 PUT
MIME : application / json
맞춤 데이터 :
[
{"keyA": "a value", "keyB": "b value"},
{"keyA": "a value", "keyB": "b value"}
]
Swagger에서 이것을 문서화 할 수 있습니까?
/some_endpoint:
put:
description: |
desc goes here
parameters:
- name: guid
in: query
description:
required: true
type: string
format: string
# Expected responses for this operation
responses:
# Response code
200:
description: Successful response
JSON 데이터는 요청 본문으로 전송되므로 본문 매개 변수 로 정의해야합니다 . 본문 구조는 schema
키워드 (아님 type
)를 사용하여 설명됩니다 . 귀하의 예에서 데이터는 각 객체에 속성 keyA
및 keyB
.
paths:
/some_endpoint:
put:
summary: Puts something
description: |
desc goes here
consumes:
- application/json
parameters:
- in: body
name: body
required: true
schema:
type: array
items:
$ref: '#/definitions/MyObject'
# If you need to define array size constraints:
minItems: 1
minItems: 10
definitions:
MyObject:
type: object
properties:
keyA:
type: string
keyB:
type: string
# If keyA and keyB are required:
required:
- keyA
- keyB
요청 데이터가 JSON임을 지정하려면 consumes
작업 수준에서 키를 사용합니다 . 모든 API 작업이 JSON consumes
을 사용하는 경우 대신 사양의 루트 수준에서 추가 할 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다