コンポーネント

それはAとして機能します cache 再利用できる他の要素の場合 リソース内および 複数のリソースにわたる. 同様のタグの再発を減らし、コンサイザーコードで長押しされたファイルを最適化します。 コンポーネントのすべての子要素には、 お名前 a を持つ属性 ユニークな価値 を除く。 熱 意/ヘルプ/ zest -仕様ファイル/構造/導入/"> その中で 参照名 ユニークな価値を持つことになります。 コンポーネントを再利用する場合は、コンポーネントに一意の値を入力します。 お名前 対応する参照要素の属性です。 別のZspecファイルから要素を再利用するには:

  • 両方のファイルは同じファイルに属している必要があります。 バージョン そして 製品情報. このようなリソースからコンポーネントを参照する場合は、 一意の名前 コンポーネントの リソース名.
copy

<{element-name}-ref name="{resource-name}.{component-name}" />
  • ここで コンポーネント名 は、他のリソースのコンポーネントの子要素の名前を示します。

可能な場所

  • 熱 意/ヘルプ/ zest -仕様ファイル/リソース/">リソース

子要素

  • 熱意 /ヘルプ/ - zest 仕様ファイル/コンテンツ/例/">例 繰り返し - 熱意 /ヘルプ/ -仕 zest 様ファイル/構造/導入/">構造 繰り返し - 熱意 /ヘルプ/ - zest 仕様ファイル/コンテンツ/紹介/">コンテンツ 繰り返し - 熱意 /ヘルプ/ -仕 zest 様ファイル/引数/">引 数 繰り返し - 熱意 /ヘルプ/ -仕 zest 様ファイル/url/操作/リクエスト本文/">リクエスト本文 繰り返し - 熱意 /ヘルプ/ -仕 zest 様ファイル/url/操作/応答/">応答 繰り返し - 熱意 /ヘルプ/ - zest 仕様ファイル/サーバー/導入/">サーバー 繰り返し - 熱意 /ヘルプ/ -仕様ファイル/ zest 情報/連絡先の詳細/">連絡先の詳細 繰り返し - 熱意 /ヘルプ/ -仕 zest 様ファイル/情報/ライセンスの詳細/">ライセンスの詳細 繰り返し - 熱意 /ヘルプ/ -仕 zest 様-ファイル/情報/紹介/#child-要素">利用規約 繰り返し - 熱意 /ヘルプ/ - zest 仕様ファイル/url/操作/タグ/">タグ 繰り返し - 熱意 /ヘルプ/ - zest 指定ファイル/認証スキーマ/トークン/">トークン 繰り返し - 熱意 /ヘルプ/ - zest 仕様ファイル/認証スキーマ/oauth2/">Oauth2 繰り返し - 熱意 /ヘルプ/ - zest 仕様ファイル/url/操作/スロットリング/">スロットリング 繰り返し
注:
  • 上記のすべての子要素は、対応する参照タグを持つことができます。

  • 一意の名前は、英数字、スペース、ハイフン、アンダースコア文字のみをサポートします。 これは、特定のリソースに対してのみユニークでなければなりません。

  • 一意の名前はタイトルのケースに表示されます。

サンプル

同じコンポーネント内

トリップ リソースに同じ操作 (取得、投稿) のエンドポイントが 2 つあると仮定します。 これにより、リソースを繰り返す必要があります。 熱 意/ヘルプ/ zest -仕様ファイル/構造/導入/"> Zspecファイルで複数回、つまり取得の2回 熱 意/ヘルプ/ zest -仕様ファイル/url/操作/応答/"> そして2回で 熱 意/ヘルプ/ zest -指定ファイル/url/操作/要求ボディ/"> . また、投稿の成功構造を2回繰り返す必要があります。

copy

sample JSON with primary-structure:
 {
 "trips": [
 {
 "trip_name":"Spring Break - John Doe",
 "trip_id": "4437464000001832063",
 "destination": "Bali",
 "start_time": "2023-11-13T17:30:00",
 "end_time": "2023-11-17T22:30:00",
 "no_of_days": 4
 },
 {
 "trip_name":"christmas Break - Diana Williams",
 "trip_id": "4437464000001832227",
 "destination": "London",
 "start_time": "2023-12-20T21:30:00",
 "end_time": "2023-12-28T09:30:00",
 "no_of_days": 7
 }
 ]
 }
copy

post success:
 {
 "code": "SUCCESS",
 "message": "Record created",
 "status": "success"
 }

まず、 熱 意/ヘルプ/ zest -仕様ファイル/コンテンツ/紹介/"> コンポーネントにおいて。 次に、それを参照してください。 熱 意/ヘルプ/ zest -仕様ファイル/url/操作/応答/"> そして 熱 意/ヘルプ/ zest -指定ファイル/url/操作/要求ボディ/"> また、コンポーネント自体についてです。コンテンツを再利用するには、 一意の名前 の要素の お名前 コンテンツ参照の属性。

copy

<components>
 <structure ref-name="trips" name="trips_data"> <!-- primary structure of the trips resource -->
 <property name="trip_name" type="string"/>
 <property name="trip_id" type="long_string"/>
 <property name="destination" type="string"/>
 <property name="start_time" type="datetime"/>
 <property name="end_time" type="datetime"/>
 <property name="no_of_days" type="string"/>
 </structure>
 <structure ref-name="data" name="wrapper"> <!-- wrapper of the primary structure -->
 <property name="trips" type="collections">
 <structure-ref name="trips" />
 </property>
 </structure>
 <content name="sample_content">
 <encode type="application/json" />
 <structure>
 <property name="trips" type ="collections">
 <structure-ref name="data" />
 </property>
 </structure>
 </content>
 <response name="get_success" status="200">
 <content-ref name="sample_content" />
 </response>
 <request-body name="req_payload">
 <content-ref name="sample_content" />
 </request-body>
 <response name="post_success" status="201">
 <content>
 <encode type="application/json" />
 <structure>
 <property name="code" type="string" values="SUCCESS"/>
 <property name="message" type="string" values="Record Added"/>
 <property name="status" type="string" values="success"/>
 </structure>
 </content>
 </response>
 </components>

これらのコンポーネントはすべて、同じ製品とバージョンで再利用できます。 —

同じZspecファイル内

今、あなたは再利用する必要があります 熱 意/ヘルプ/ zest -仕様ファイル/url/操作/応答/"> そして 熱 意/ヘルプ/ zest -指定ファイル/url/操作/要求ボディ/"> 2 つの異なる Url の上記のコンポーネントから。を指定します。 一意の名前 これらの要素の お名前 対応する参照要素の属性です。

copy

<url path="/travel_bureau/v4/trips"> <!-- First URL -->
 <operation method="get" name="GET trips" category="read">
 <response-ref name="get_success" />
 </operation>
 <operation method="post" name="POST trips" category="create">
 <request-body-ref name="req_payload" />
 <response-ref name="post_success" />
 </operation>
 </url>
 <url path="/travel_bureau/v4/trips__s"> <!-- Second URL -->
 <operation method="get" name="GET trip" category="read">
 <response-ref name="get_success" />
 </operation>
 <operation method="post" name="POST trip" category="create">
 <request-body-ref name="req_payload" />
 <response-ref name="post_success" />
 </operation>
 </url>

別のZspecファイルからの再利用

ポスト操作の成功を再利用したいとしましょう 熱 意/ヘルプ/ zest -仕様ファイル/url/操作/応答/"> 旅行者リソースの旅行リソースから。 この要件では、レスポンスの一意の名前にリソース名のプレフィックスが必要です。以下は、あなたがそれをどのように使うべきかです、

copy

<url path="/travel_bureau/v4/travelers">
 <operation method="post" name="POST travelers" category="create">
 <request-body name="req_payload">
 <content>
 <encode type="application/json" />
 <structure>
 <property name="travelers" type ="collections">
 <structure>
 <property name="traveler_name" type="string" />
 <property name="traveler_id" type="long_string"/>
 </structure>
 </property>
 </structure>
 </content>
 </request-body>
 <response-ref name="trips.post_success" /> <!-- reusing the success response from the trips resource -->
 </operation>
 </url> 

Last Updated 2026-02-06 15:55:45 +0530 IST