2016-08-08 6 views
1

I持って、次のファイルRAMLの例では、JSONを再利用する方法

user.json

"user": { 
    "id": 1, 
    "name": "nameuser", 
    "online": true, 
    "profile": { 
    "photo": "", 
    "validated": true, 
    "popular": true, 
    "suspect": false, 
    "moderator": false, 
    "age": "22 ani", 
    "gender_id": "M" 
    } 
} 

profile.raml

displayName: Profile 
get: 
    description: Get profile data 
    queryParameters: 
    userId: 
     description: The user id for which we are requesting the profile data 
     type: integer 
     required: true 
    responses: 
    200: 
     body: 
     application/json: 
      example: | 
      { 
       "user": !include user.json, 
       "details": { 
       "friend": true 
       } 
      } 

ユーザーJSONはより多くの例に存在していると私はしたいですそれを再使用する。 私はraml2htmlを使用していますので、私はこれをどのように行うのか、それは enter image description here

にそれをコンパイル?

答えて

1

過去にパラメータを正常に使用しました。 RAMLは、含まれているすべてのファイルを文字列として表示するため、インクルードされたファイルの中にパラメータを置くことはできません。しかし、あなたはあなたのprofile.ramlにこのような何かを行うことができます。

example: | 
     { 
      "user": <<userItem>>, 
      "details": { 
      "friend": true 
      } 
     } 

RAML 200 Tutorialは、パラメータを宣言し、それらは、それらを渡す方法について(以下スニペットを参照してください)良い説明とコード例を持って、私は非常に読書をお勧めします。全体のチュートリアル。

resourceTypes: 
    - collection: 
     description: Collection of available <<resourcePathName>> in Jukebox. 
     get: 
     description: Get a list of <<resourcePathName>>. 
     responses: 
      200: 
      body: 
       application/json: 
       example: | 
        <<exampleCollection>> 

/songs: 
    type: 
    collection: 
     exampleCollection: !include jukebox-include-songs.sample 
関連する問題