如果要驗證 response「要有某個欄位」,在 api 定義(yaml 或 json 檔)裡該欄位要設 required
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| paths: /general/test: get: summary: test responses: 200: description: test content: application/json: schema: type: object properties: id: type: integer username: type: string required: - id - username
|
用 component 的版本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| paths: /general/test: get: summary: test responses: 200: description: test content: application/json: schema: \$ref: '#/components/schemas/User' components: schemas: User: type: object properties: id: type: integer username: type: string required: - id - username
|