2016-06-22 3 views
2

나는 문서를 가지고 있으며 해당 API에 새 API 문서를 추가하려고합니다.램 리소스에 대한 일반적인 응답을 포함하는 방법

기본 RAML 문서를 살펴 보았습니다.

나는 raml 파일을 가지고 있습니다.

#Filename: base.raml 
title: Test RAML 
documentation: 
    - title: Test RAML docs first time :) 
    content: This is RAML testing 
baseUri: https://myportal.com/{version}/scriptmanagement 
version: v1.0 
mediaType: application/json 
protocols: [ HTTPS ] 

/test: 
    !include raml/test.raml 

는 실제 raml 콘텐츠 RAML, 400 위에서

#Filename: test.raml 
displayName: Test RAML Inheritance 
description: Testing for RAML inheritance for responses. 

get: 
    description: Get all TEST 
    headers: 
     name: 
      description: name required in each request 
      example: testname 
      required: true 
    responses: 
     200: 
      description: SUCCESS 
      body: 
       application/json: 
        example: | 
         {} 
     400: 
      description: BAD REQUEST 
      body: 
       application/json: 
        example: | 
         {"error": "Bad Request"} 
     500: 
      description: INTERNAL ERROR 
      body: 
       application/json: 
        example: | 
         {"error": "Internal Error"} 

post: 
    description: Get all TEST 
    headers: 
     name: 
      description: name required in each request 
      example: testname 
      required: true 
    responses: 
     200: 
      description: SUCCESS 
      body: 
       application/json: 
        example: | 
         {"message": "Created"} 
     400: 
      description: BAD REQUEST 
      body: 
       application/json: 
        example: | 
         {"error": "Bad Request"} 
     500: 
      description: INTERNAL ERROR 
      body: 
       application/json: 
        example: | 
         {"error": "Internal Error"} 


/{test_id}: 
    description: TEST DETAILS 
    get: 
     description: Retrieve resource own by x-user-name 
     headers: 
      name: 
       description: name required in each request 
       example: testname 
       required: true 
     responses: 
      200: 
       description: SUCCESS 
       body: 
        application/json: 
         example: | 
          {"message": "Details"} 
      400: 
       description: BAD REQUEST 
       body: 
        application/json: 
         example: | 
          {"error": "Bad Request"} 
      500: 
       description: INTERNAL ERROR 
       body: 
        application/json: 
         example: | 
          {"error": "Internal Error"} 

test.raml이고 500 응답이 일반적이고, name 헤더가 일반적이다.

한 번 작성하고 모든 리소스를 추가하려면 어떻게해야합니까? 나는 traits<<: 모두 작동하지 않았다.

+0

특징은 나를 위해 작동합니다! – Sachin

+0

@Sachin은 답안에서'trait' 예제를 줄 수 있습니까? – Nilesh

답변

1

특성이 올바른 해결책입니다.

형질

traits: 
    nameHeader: 
    headers: 
     name: 
     description: name required in each request 
     example: testname 
     required: true 

사용 특성을 정의

명시 적으로 요청 사양 내부를 언급해야이 특성을 사용하려면 : 이것은 당신의 name 헤더 시나리오에 대한 예입니다 :

/{test_id}: 
    description: TEST DETAILS 
    get: 
    description: Retrieve resource own by x-user-name 
    is: [nameHeader] 
    responses: 
     200: 
     description: SUCCESS 
     body: 
      application/json: 
      example: | 
       {"message": "Details"} 

동일한 방법으로 귀하의 응답에 대한 특성을 극대화하십시오.

+0

'traits'는 한번도 시도한 적이 없지만 작동한다면 시도해 볼 것입니다. – Nilesh

+0

감사! 다행이라도 거의 1 년 후 도움이 될 수 있습니다 :) – flogy