---
schema_version: "1"
id: 50a8eb31318c9107a4215be1d93a58007aa0be3dd3408a1abf8f18b00e186add
title: API 仕様の作成およびインポート
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/anypoint-code-builder/des-create-api-specs.md
canonical_url: https://docs.mulesoft.com/jp/anypoint-code-builder/des-create-api-specs
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 55ebc6a3eb2f05f76e4c70b8b3639d1a61209f988f1fdfcee752757bb07f6b8b
description: MuleSoft Documentation Site
latest: true
---
# API 仕様の作成およびインポート

**進行中のベータリリース**​: **クラウド IDE は進行中のベータリリースです**​。ベータ状態での Anypoint Code Builder の使用には、IDE で入手できる、該当するベータサービス契約条件が適用されます。

Anypoint Exchange にパブリッシュする前に Anypoint Code Builder を使用して API 仕様の作成、インポート、テストを行います。

1. IDE から Anypoint Code Builder で API 仕様プロジェクトを作成するか、MuleSoft VCS から仕様をインポートして API 仕様プロジェクトを作成します。
    
    - [IDE から API 仕様プロジェクトを作成する](#design-new-api-spec)
    - [MuleSoft VCS から API 仕様をインポートする](#import-spec)
2. [出力パネルで進行状況を追跡します](#open-output-panel)​。
3. [API Console で仕様を確認します](#review-spec-console)​。
4. [モッキングサービスを使用して仕様をテストします](#test-spec)​。

Anypoint Code Builder の機能を調べるには、​[`oas-example`](#example-oas-api-spec)​ API 仕様を使用してください。

## [](#始める前に)始める前に

- [Web またはデスクトップ IDE をセットアップしてアクセスします](https://docs.mulesoft.com/jp/anypoint-code-builder/start-acb)​。
- API 仕様の設計の基礎を理解します。
    
    詳細は、[チュートリアル](https://docs.mulesoft.com/jp/anypoint-code-builder/tutorials)を参照してください。
- [ビジネスグループ](https://docs.mulesoft.com/jp/access-management/business-groups)​に精通します。
    
    API 仕様を Anypoint Code Builder から Exchange にパブリッシュすると、IDE でビジネスグループの名前が要求されます。[ビジネスグループ](https://docs.mulesoft.com/jp/access-management/business-groups)を参照してください。

## [](#design-new-api-spec)新しい API 仕様プロジェクトを作成する

Anypoint Code Builder で API 仕様プロジェクトを作成する手順は、次のとおりです。

1. IDE のアクティビティバーで、​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-ms-logo.png)​ (​**Anypoint Code Builder**​) アイコンをクリックします。
    
    ![アクティビティバー内で強調表示されている \[Anypoint Code Builder\] アイコン](_images/anypoint-code-builder-view.png)
2. **\[Quick Actions (クイックアクション)\]**​ から ​**\[Design an API (API を設計)\]**​ をクリックします。
    
    ![\*「Quick Actions (クイックアクション)」\* セクション内の強調表示された \*「Design an API (API を設計)」\* リンク](/mulesoft/current/ja-jp/anypoint-code-builder/_images/design-api-1.png)
3. **\[API Specification (API 仕様)\]**​ フォームに入力します。
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目名</th>
<th class="tableblock halign-left valign-top">Field Value (項目値)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Project Name (プロジェクト名)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>プロジェクトの一意の名前。</p>
</div>
<div class="paragraph">
<p>この名前は Exchange での API 仕様のタイトル、仕様ファイルの名前、プロジェクトのルートディレクトリの名前として使用されます。
たとえば、プロジェクト名が​<em>「OAS Example」</em>​ (OAS 例) の場合、仕様ファイル名は ​<code>oas-example</code>​ になります。</p>
</div>
<div class="paragraph">
<p>既存のプロジェクト名を再利用するには、その名前をすでに使用しているプロジェクトを最初に削除する必要があります。<a href="https://docs.mulesoft.com/jp/anypoint-code-builder/des-delete-api-projects" class="xref page">API 仕様とフラグメントの削除</a>を参照してください。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Project Location (プロジェクトの場所)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>ホームディレクトリまたは作成する別のディレクトリ。</p>
</div>
<div class="paragraph">
<p><a href="https://docs.mulesoft.com/jp/anypoint-code-builder/start-add-folders" class="xref page">ホームディレクトリへのフォルダーの追加</a>を参照してください。</p>
</div>
<div class="paragraph">
<p>別のプロジェクトディレクトリ内にプロジェクトを作成しないでください。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>API Type (API 種別)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>作成する API 仕様のエンティティの種別。</p>
</div>
<div class="paragraph">
<p>使用可能なオプションは、​<strong>[REST API]</strong>​ と ​<strong>[AsyncAPI]</strong>​ です。</p>
</div>
<div class="paragraph">
<p>この手順で​<a href="#example-oas-api-spec">サンプル</a>​を使用するには、​<strong>[REST API]</strong>​ を選択します。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>API Specification Language (API 仕様言語)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a href="https://docs.mulesoft.com/jp/anypoint-code-builder/des-designing-api-specs#supported-spec-languages" class="xref page">サポートされる OAS および RAML バージョン</a>​を参照してください。</p>
</div>
<div class="paragraph">
<p>この手順で​<a href="#example-oas-api-spec">サンプル</a>​を使用するには、​<strong>[OAS 3.0 (YAML)]</strong>​ を選択します。</p>
</div></div></td>
</tr>
</tbody>
</table>
4. **\[Create Project (プロジェクトを作成)\]**​ をクリックします。
    
    確認を促されたら、フォルダー内のファイルの作成者を信頼します。
    
    プロジェクトの編集準備が整ったら、API プロジェクトのエディタービューで次の OAS 3.0 (YAML) 仕様のような仕様が開きます。
    
    ![新しい OAS 3.0 (YAML) API プロジェクト](/mulesoft/current/ja-jp/anypoint-code-builder/_images/des-oas-create.png)
5. 引き続き API 仕様を設計します。
    
    要素を入力するときに、​[オートコンプリート](https://docs.mulesoft.com/jp/anypoint-code-builder/start-discover-ui#auto-complete)​ (または Ctrl+Space) を使用すると、コンテキスト内で使用可能なオプションが表示されます。

## [](#import-spec)MuleSoft VCS から API 仕様をインポートする

MuleSoft VCS から API 仕様をインポートし、デスクトップまたはクラウド IDE で Git または VS Code と互換性のある別のソース管理システムを使用して、プロジェクトの同期を維持します。詳細は、​[API 設計プロジェクトのソース制御](https://docs.mulesoft.com/jp/anypoint-code-builder/des-designing-api-specs#mulesoft-vcs)​を参照してください。

1. コマンドパレットを開きます。
    
    手順を表示
    
    - キーボードショートカットを使用する。
        
        - Mac: Cmd+Shift+p
        - Windows: Ctrl+Shift+p
    - デスクトップ IDE で、​**\[View (表示)\]**​ > ​**\[Command Palette (コマンドパレット)\]**​ を選択する。
    - クラウド IDE で、​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-menu.png)​ (メニュー) アイコンをクリックし、​**\[View (表示)\]**​ > ​**\[Command Palette (コマンドパレット)\]**​ を選択する。
2. 次のコマンドを入力します。
    
    ```command
    MuleSoft: Import API Specification from MuleSoft VCS
    ```
3. Anypoint Platform にログインするように促されたら、IDE からログインします。
4. インポートプロセスを完了します。
    
    1. **\[Select a Business Group (ビジネスグループを選択)\]**​ ポップアップからビジネスグループを選択します。
    2. **\[APIs from MuleSoft VCS (MuleSoft VCS から API)\]**​ 項目で API 仕様を検索します。
    3. 仕様のフォルダーに移動するか、そのフォルダーを作成して、​**\[Select target folder (対象フォルダーを選択)\]**​ をクリックします。
        
        インポートが失敗したといったエラー (​**「Importing project _a\_project\_name_ has failed (プロジェクト _a\_project\_name_ のインポートに失敗しました)」**​) を受け取ったら、同じ名前のプロジェクトの対象フォルダーを確認します。インポートする前に重複する名前の問題に対処するには、設計プロジェクトを別の対象フォルダーにインポートするか、プロジェクトを IDE から削除することができます ([API 仕様とフラグメントの削除](https://docs.mulesoft.com/jp/anypoint-code-builder/des-delete-api-projects)を参照)。
5. 必要に応じて、仕様を編集するか、引き続き仕様を設計します。
    
    要素を入力するときに、​[オートコンプリート](https://docs.mulesoft.com/jp/anypoint-code-builder/start-discover-ui#auto-complete)​ (または Ctrl+Space) を使用すると、コンテキスト内で使用可能なオプションが表示されます。
6. 変更を MuleSoft VCS と同期できます。
    
    この機能は、MuleSoft VCS からインポートした API プロジェクトでのみ使用できます。作業内容を別の SCM に保存することもできます。SCM オプションについては、[ソースファイルの制御](https://docs.mulesoft.com/jp/anypoint-code-builder/start-scm)を参照してください。

## [](#open-output-panel)出力パネルで進行状況を追跡する

API を設計しているときに内部処理の進行状況を追跡する手順は、次のとおりです。

1. 出力パネルを開きます。
    
    手順を表示
    
    - キーボードショートカットを使用する。
        
        - Mac: Cmd+Shift+u
        - Windows: Ctrl+Shift+u
    - デスクトップ IDE で、​**\[View (表示)\]**​ > ​**\[Output (出力)\]**​ を選択する。
    - クラウド IDE で、​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-menu.png)​ (メニュー) アイコンをクリックし、​**\[View (表示)\]**​ > ​**\[Output (出力)\]**​ を選択する。
2. ドロップダウンリストから ​**\[Mule DX Server (Mule DX サーバー)\]**​ を選択します。
    
    ![出力ペイン内の \[Mule DX Server (Mule DX サーバー)\]](_images/des-output-panel.png)

スキャフォールディングエラーのみを表示するには、リストから ​**\[Mule DX Server: Scaffolding (Mule DX サーバー: スキャフォールディング)\]**​ を選択します。

## [](#review-spec-console)API Console で仕様を確認する

コンソールに仕様を表示する手順は、次のとおりです。

1. エディターで仕様ファイルをクリックします。
2. ![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-api-console.png)​ (​**API Console**​) アイコンをクリックします。
    
    または、​[コマンドパレット](https://docs.mulesoft.com/jp/anypoint-code-builder/start-use-command-palette)​でコマンド ​`MuleSoft: API Console`​ を入力することができます。
3. API Console にエンドポイントが表示されるまで待機します。
    
    API Console に仕様のエンドポイントが表示されます。次に例を示します。
    
    ![API Console 内の API 仕様](/mulesoft/current/ja-jp/anypoint-code-builder/_images/des-api-console.png)
    
    <table><tbody><tr><td><i class="conum" data-value="1"></i><b>1</b></td><td>メソッドをクリックして詳細を表示します。</td></tr><tr><td><i class="conum" data-value="2"></i><b>2</b></td><td>コンソールメニューを表示します。</td></tr></tbody></table>
4. コンソールでメソッドをクリックするか、メニューから項目を選択して、仕様のさまざまな部分を表示します。 たとえば、​**\[GET\]**​ をクリックすると、次のように表示されます。
    
    ![Get の詳細を含む API Console](/mulesoft/current/ja-jp/anypoint-code-builder/_images/des-api-console-detail.png)

## [](#test-spec)モッキングサービスを使用して API 仕様をテストする

API Console でモッキングサービスを使用して、API 仕様で設定した要求と応答を確認します。

1. Anypoint Code Builder で API プロジェクトの仕様 (​[`oas-example`](#example-oas-api-spec)​ など) を開きます。
2. ![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-api-console.png)​ (​**API Console**​) アイコンをクリックして、コンソールに仕様を表示します。
3. API Console で GET や POST などのメソッドをクリックします。
4. **\[Try It (試す)\]**​ をクリックします。
    
    ![API Console の \[Try It (試す)\] ボタン](_images/des-api-console-try-it.png)
5. 定義したパラメーターが正しいことを確認して、​**\[Send (送信)\]**​ をクリックします。
6. 定義した応答が API Console に返されることを検証します。次に例を示します。
    
    ![API Console での応答例](/mulesoft/current/ja-jp/anypoint-code-builder/_images/des-api-console-response.png)
7. 必要に応じて、モックされた API エンドポイントを照会するときに、設定済みの応答例を確認します。

## [](#example-oas-api-spec)OAS 3.0 (YAML) API 仕様の例

OAS 3.0 (YAML) プロジェクトを作成したら、初期仕様を次のコード例で置き換えることができます。

OAS 3.0 (YAML) API 仕様の例

```YAML
  openapi: "3.0.0"
  info:
    version: 1.0.0
    title: oas-example
  paths:
    /contacts:
      get:
        summary: Retrieve a list of contacts
        description: Returns a list of contacts.
        responses:
          '200':
            description: Successful response
            content:
              application/json:
                example:
                  - id: 1
                    firstName: John
                    lastName: Doe
                    company: Example Corp
                  - id: 2
                    firstName: Jane
                    lastName: Smith
                    company: Another Company

      post:
        summary: Create a new contact
        description: Creates a new contact.
        requestBody:
          description: Contact object to be created
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contact'
        responses:
          '201':
            description: Contact created successfully
            content:
              application/json:
                example:
                  id: 3
                  firstName: John
                  lastName: Doe
                  company: Example Corp
          '400':
            description: Invalid request
          '500':
            description: Internal server error

    '/contacts/{contactId}':
      put:
        summary: Update a contact
        description: Updates an existing contact based on the contact ID.
        parameters:
          - name: contactId
            in: path
            description: ID of the contact to update
            required: true
            schema:
              type: integer
              format: int64
        requestBody:
          description: Updated contact object
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contact'
        responses:
          '200':
            description: Contact updated successfully
            content:
              application/json:
                example:
                  id: 3
                  firstName: John
                  lastName: Doe
                  company: Updated Corp
          '400':
            description: Invalid request
          '404':
            description: Contact not found
          '500':
            description: Internal server error

  components:
    schemas:
      Contact:
        type: object
        properties:
          id:
            type: integer
            format: int64
          firstName:
            type: string
          lastName:
            type: string
          company:
            type: string
        required:
          - firstName
          - lastName
```

## [](#関連情報)関連情報

- [Anypoint Code Builder 入門](https://docs.mulesoft.com/jp/anypoint-code-builder/start-acb)
- [チュートリアル](https://docs.mulesoft.com/jp/anypoint-code-builder/tutorials)
- [ビジネスグループ](https://docs.mulesoft.com/jp/access-management/business-groups)
- [エディターのオートコンプリートを使用する](https://docs.mulesoft.com/jp/anypoint-code-builder/start-discover-ui#use-autocomplete)
- [American Flights API 仕様の設計](https://docs.mulesoft.com/jp/anypoint-code-builder/tut-af-design-am-flights-api)チュートリアル
- [API 仕様とフラグメントの削除](https://docs.mulesoft.com/jp/anypoint-code-builder/des-delete-api-projects)