|
| 1 | +--- |
| 2 | +description: >- |
| 3 | + Learn how to add and update an OpenAPI specification in GitBook application or |
| 4 | + from CLI. |
| 5 | +--- |
| 6 | + |
1 | 7 | # Add an OpenAPI specification
|
2 | 8 |
|
3 | 9 | {% include "../../.gitbook/includes/openapi-availability-hint.md" %}
|
4 | 10 |
|
5 |
| -If you have an OpenAPI specification, you can add it directly to your organization. You can link your specification via the URL of a hosted OpenAPI document, or by uploading the OpenAPI file directly. |
| 11 | +If you have an OpenAPI spec, you can add it to your organization by uploading the file directly, linking to a hosted URL, or using the [GitBook CLI](https://app.gitbook.com/s/2SyQSbIa1iYS7z6Dx5di/cli). |
6 | 12 |
|
7 | 13 | <figure><img src="../../.gitbook/assets/02_04_25_add_api_spec.svg" alt=""><figcaption></figcaption></figure>
|
8 | 14 |
|
9 |
| -### Add a specification |
10 |
| - |
11 |
| -To add a specification, head to the OpenAPI panel in the sidebar. Here you’ll be able to upload a file, link via URL to your existing OpenAPI specification, or use our [CLI](https://docs.gitbook.com/developers/cli/quickstart) to publish your OpenAPI spec to GitBook. |
| 15 | +### How to add a specification |
12 | 16 |
|
13 |
| -You’ll need to give your specification a name, which will be its identifier if you add more than 1 specification to your organization. |
| 17 | +1. Open the **OpenAPI** section in the sidebar |
| 18 | +2. Click on **Add specification** |
| 19 | +3. Give your specification a name. This helps identify it, especially if you manage multiple specs |
| 20 | +4. Choose one of the following: |
| 21 | + * Upload a file (e.g. _openapi.yaml_) |
| 22 | + * Enter a URL to a hosted spec |
| 23 | + * Use the CLI to publish the spec |
14 | 24 |
|
15 | 25 | <figure><img src="../../.gitbook/assets/03_04_25_api_spec_modal (1).svg" alt=""><figcaption><p>Add an OpenAPI specification modal.</p></figcaption></figure>
|
16 | 26 |
|
17 | 27 | ### Update your specification
|
18 | 28 |
|
19 |
| -From time to time you might need to update or modify your API specification.  |
| 29 | +You can update your OpenAPI specification at any time using the GitBook UI or the CLI, regardless of how it was initially added. |
20 | 30 |
|
21 |
| -#### Updating your specification via URL |
| 31 | +#### In GitBook Application |
22 | 32 |
|
23 |
| -If you added your specification via URL, GitBook will automatically check for updates every 6 hours. If you need to update your specification faster than that, click the “Check for updates” button in the upper right corner of the OpenAPI section. |
| 33 | +In the OpenAPI panel: |
24 | 34 |
|
25 |
| -#### Updating your specification via file |
| 35 | +* If your spec is linked to a URL: |
| 36 | + * GitBook checks for updates automatically **every 6 hours**. |
| 37 | + * To fetch updates immediately, click **Check for updates**. |
| 38 | +* If your spec was uploaded as a file: |
| 39 | + * Click **Update** to upload a new version. |
| 40 | +* You can switch from a File to a URL source by clicking on **Edit** in the breadcrumb actions menu. |
26 | 41 |
|
27 |
| -To update your OpenAPI spec if you’ve added it as a file, click the “Update” button in the upper right corner of the OpenAPI section to update or replace the file. |
| 42 | +#### Using the CLI |
28 | 43 |
|
29 |
| -#### Updating your specification via CLI |
30 |
| - |
31 |
| -If you’ve used the [CLI](https://docs.gitbook.com/developers/cli/quickstart) to add an OpenAPI specification, you can update it by running the same command: |
| 44 | +Use the same command to update your specification: |
32 | 45 |
|
33 | 46 | ```bash
|
34 |
| -gitbook openapi publish --spec api-spec-name --organization organization_id <path-to-openapi-file> |
| 47 | +gitbook openapi publish --spec api-spec-name --organization organization_id <path-or-url> |
35 | 48 | ```
|
36 | 49 |
|
| 50 | +You can also use the CLI to **Check for updates** by running the publish command on the same URL. |
| 51 | + |
| 52 | +Read our [support-for-ci-cd-with-api-blocks.md](../guides/support-for-ci-cd-with-api-blocks.md "mention") guide to learn how to automate the update of your specification. |
0 commit comments