2016-11-16 1 views
4

저는 매우 신입 사원 입니다. 님,이 질문은 기본적인 질문 일 수 있습니다. 다음과 같이 내가 매개 변수로 정수의 배열을 취하는 API에 대한 .yml 파일을 만들 수 있어요배열 객체를 매개 변수로 정의하는 방법은 무엇입니까?

는 :

Add samples 
--- 
tags: 
- MY API 
parameters: 
- name: my_id 
    in: path 
    type: integer 
    required: true 
    description: Some des 
- name: body 
    in: body 
    schema: 
    id: add_samples 
    required: 
     - sample_ids 
    properties: 
     sample_ids: 
     type: array 
     items: 
      type: integer 
     description: A list of sample ids to be added 
responses: 
    '200': 
    description: Added samples. 
    '400': 
    description: Error adding samples. 

이것은 내가 위의 API에 보내 모든 것이 잘 작동 것입니다 :

{"sample_ids": [475690,475689,475688]} 

자, 정수 배열 대신 매개 변수로 복잡한 객체를 사용하려면 어떻게해야합니까?

예. 이것이 내가 보내려는 것일 경우 :

{"sample_ids": [{ 
    "sample_id": "7", 
    "some_prop": "123" 
}, 
{ 
    "sample_id": "17", 
    "some_prop": "134" 
}]} 

.yml 파일은 어떻게 표시되어야합니까? 나는 이런 식으로 뭔가를 시도하고 작동하지 않는 것 :

Add sample 
--- 
tags: 
- Samples API 
models: 
    Sample: 
    id: Sample 
    properties: 
     sample_id: 
     type: string 
     default: "" 
     description: The id for this sample 
     some_prop: 
     type: integer 
     description: Some prop this sample 
parameters: 
- name: body 
    in: body 
    schema: 
    id: add_sample 
    required: 
     - sample_ids 
    properties: 
     samples: 
     type: array 
     description: A list of samples to be added 
     items: 
      $ref: Sample 
responses: 
    '201': 
    description: Created a new sample with the provided parameters 
    '400': 
    description: SOME ERROR CODE 
+0

'samples'의 값인 매핑에는 'description'이라는 두 개의 키가 있습니다. YAML에서는 허용되지 않습니다. – Anthon

+0

@Anthon : 질문을 게시하는 동안 복사 붙여 넣기 오류가 발생했습니다. 나는 설명을 갱신했다. 감사. – Bhushan

답변

2

이 하나가 주로 작동하는 것 같다 :

Add sample 
--- 
tags: 
- Samples API 
models: 
    Sample: 
    id: Sample 
    properties: 
     sample_id: 
     type: string 
     default: "" 
     description: The id for this sample 
     some_prop: 
     type: integer 
     description: Some prop this sample 
parameters: 
- name: body 
    in: body 
    schema: 
    id: add_sample 
    required: 
     - sample_ids 
    properties: 
     samples: 
     type: array 
     description: A list of samples to be added 
     items: 
      $ref: Sample 
responses: 
    '201': 
    description: Created a new sample with the provided parameters 
    '400': 
    description: SOME ERROR CODE 

이제 문제는의 자신감 UI에, 그것을하지 않습니다 멤버 변수와 기본값을 보여줍니다. 오히려 null로 표시됩니다.

관련 문제