Skip to content

Commit

Permalink
Merge pull request #18 from HiDeoo/hd-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Feb 18, 2024
2 parents b37afd6 + 74dc93f commit 98cb2eb
Show file tree
Hide file tree
Showing 36 changed files with 2,311 additions and 2,337 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.json

This file was deleted.

13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"eslint.experimental.useFlatConfig": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"vue",
"markdown",
"astro"
]
}
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<h1>starlight-openapi 🧭</h1>
<p>Astro integration for Starlight to generate documentation from OpenAPI/Swagger specifications.</p>
<p>Starlight plugin to generate documentation from OpenAPI/Swagger specifications.</p>
</div>

<div align="center">
Expand Down
97 changes: 50 additions & 47 deletions docs/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import { generateAPI } from 'starlight-openapi'
import starlightOpenAPI, { openAPISidebarGroups } from 'starlight-openapi'

const { openAPISidebarGroups, starlightOpenAPI } = await generateAPI([
{
base: 'api/petstore',
collapsed: false,
label: 'Petstore',
schema: '../schemas/v3.0/petstore-expanded.yaml',
},
{
base: 'api/1password',
label: '1Password Connect',
schema:
'https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages/v2/specs/1password.local/connect/1.5.7/openapi.yaml',
},
{
base: 'api/giphy',
label: 'Giphy',
schema:
'https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages/v2/specs/giphy.com/1.0/openapi.yaml',
},
{
base: 'api/v3/petstore-simple',
label: 'Petstore v3.0 (simple)',
schema: '../schemas/v3.0/petstore.json',
},
{
base: 'api/v2/petstore-simple',
label: 'Petstore v2.0 (simple)',
schema: '../schemas/v2.0/petstore-simple.yaml',
},
{
base: 'api/v3/animals',
label: 'Animals v3.0',
schema: '../schemas/v3.0/animals.yaml',
},
{
base: 'api/v2/animals',
label: 'Animals v2.0',
schema: '../schemas/v2.0/animals.yaml',
},
])
import { starlightOpenAPIDocsDemoPlugin } from './src/libs/sidebar'

export default defineConfig({
integrations: [
Expand All @@ -50,25 +11,67 @@ export default defineConfig({
editLink: {
baseUrl: 'https://github.com/HiDeoo/starlight-openapi/edit/main/docs/',
},
plugins: [
starlightOpenAPI([
{
base: 'api/petstore',
collapsed: false,
label: 'Petstore',
schema: '../schemas/v3.0/petstore-expanded.yaml',
},
{
base: 'api/1password',
label: '1Password Connect',
schema:
'https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages/v2/specs/1password.local/connect/1.5.7/openapi.yaml',
},
{
base: 'api/giphy',
label: 'Giphy',
schema:
'https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages/v2/specs/giphy.com/1.0/openapi.yaml',
},
{
base: 'api/v3/petstore-simple',
label: 'Petstore v3.0 (simple)',
schema: '../schemas/v3.0/petstore.json',
},
{
base: 'api/v2/petstore-simple',
label: 'Petstore v2.0 (simple)',
schema: '../schemas/v2.0/petstore-simple.yaml',
},
{
base: 'api/v3/animals',
label: 'Animals v3.0',
schema: '../schemas/v3.0/animals.yaml',
},
{
base: 'api/v2/animals',
label: 'Animals v2.0',
schema: '../schemas/v2.0/animals.yaml',
},
]),
starlightOpenAPIDocsDemoPlugin(),
],
sidebar: [
{
label: 'Guides',
label: 'Start Here',
items: [
{ label: 'Getting Started', link: '/guides/getting-started/' },
{ label: 'Configuration', link: '/guides/configuration/' },
{ label: 'Getting Started', link: '/getting-started/' },
{ label: 'Configuration', link: '/configuration/' },
],
},
{
label: 'Examples',
items: openAPISidebarGroups.slice(0, 3),
label: 'Demo',
items: openAPISidebarGroups,
},
],
social: {
github: 'https://github.com/HiDeoo/starlight-openapi',
},
title: 'Starlight OpenAPI',
}),
starlightOpenAPI(),
],
image: { service: { entrypoint: 'astro/assets/services/sharp' } },
})
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "starlight-openapi-docs",
"version": "0.4.0",
"license": "MIT",
"description": "Astro integration for Starlight to generate documentation from OpenAPI/Swagger specifications.",
"description": "Starlight plugin to generate documentation from OpenAPI/Swagger specifications.",
"author": "HiDeoo <[email protected]> (https://hideoo.dev)",
"type": "module",
"scripts": {
Expand All @@ -14,12 +14,11 @@
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0"
},
"dependencies": {
"@astrojs/starlight": "0.11.0",
"astro": "3.2.3",
"@astrojs/starlight": "0.19.0",
"astro": "4.4.0",
"sharp": "0.33.2",
"shiki": "0.14.4",
"starlight-openapi": "workspace:*",
"starlight-package-managers": "0.1.0"
"starlight-package-managers": "0.3.0"
},
"engines": {
"node": ">=18.14.1"
Expand All @@ -29,6 +28,7 @@
"sideEffects": false,
"keywords": [
"starlight",
"plugin",
"openapi",
"swagger",
"documentation",
Expand Down
127 changes: 127 additions & 0 deletions docs/src/content/docs/configuration.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
title: Configuration
description: An overview of all the configuration options supported by the Starlight OpenAPI plugin.
---

The Starlight OpenAPI plugin can be configured inside the `astro.config.mjs` configuration file of your project:

```js {11}
// astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightOpenAPI, { openAPISidebarGroups } from 'starlight-openapi'

export default defineConfig({
integrations: [
starlight({
plugins: [
starlightOpenAPI([
// Configuration options go here.
]),
],
title: 'My Docs',
}),
],
})
```

## Plugin configuration

The Starlight OpenAPI plugin accepts an array of objects where each object represents a configuration for a specific OpenAPI/Swagger schema.

A configuration object can have the following properties:

### `base` (required)

**Type:** `string`

The base path containing the generated documentation, e.g. `'api/petstore'`.

### `schema` (required)

**Type:** `string`

The OpenAPI/Swagger schema path or URL.

### `label`

**Type:** `string`

The generated documentation sidebar group label.

### `collapsed`

**Type:** `boolean`

Wheter the generated documentation sidebar group should be collapsed by default or not.

## Multiple schemas

You can generate documentation for multiple OpenAPI/Swagger schemas by passing multiple objects to the plugin configuration.

```js {11-21}
// astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightOpenAPI, { openAPISidebarGroups } from 'starlight-openapi'

export default defineConfig({
integrations: [
starlight({
plugins: [
starlightOpenAPI([
{
base: 'api/petstore',
label: 'My API',
schema: '../schemas/api-schema.yaml',
},
{
base: 'api/1password',
label: '1Password Connect',
schema:
'https://raw.githubusercontent.com/APIs-guru/openapi-directory/gh-pages/v2/specs/1password.local/connect/1.5.7/openapi.yaml',
},
]),
],
title: 'My Docs',
}),
],
})
```

## Sidebar groups

The `openAPISidebarGroups` export can be used in your Starlight [sidebar configuration](https://starlight.astro.build/reference/configuration/#sidebar) to add the generated documentation sidebar group to the sidebar.

```js {24-25} "{ openAPISidebarGroups }"
// astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightOpenAPI, { openAPISidebarGroups } from 'starlight-openapi'

export default defineConfig({
integrations: [
starlight({
plugins: [
// Generate the OpenAPI documentation pages.
starlightOpenAPI([
{
base: 'api',
label: 'My API',
schema: '../schemas/api-schema.yaml',
},
]),
],
sidebar: [
{
label: 'Guides',
items: [{ label: 'Example Guide', link: '/guides/example/' }],
},
// Add the generated sidebar group to the sidebar.
...openAPISidebarGroups,
],
title: 'My Docs',
}),
],
})
```
63 changes: 63 additions & 0 deletions docs/src/content/docs/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Getting Started
description: Learn how to generate documentation from OpenAPI/Swagger specifications using the Starlight OpenAPI plugin.
---

import PackageManagers from '../../components/PackageManagers.astro'

A [Starlight](https://starlight.astro.build) plugin to generate documentation from OpenAPI/Swagger specifications.

- Support for [Swagger 2.0](https://swagger.io/specification/v2/), [OpenAPI 3.0](https://swagger.io/specification/v3/) and [OpenAPI 3.1](https://swagger.io/specification/) specifications.
- Support for local and remote schemas.
- Configurable sidebar label and sidebar group collapsing.

## Prerequisites

You will need to have a Starlight website set up.
If you don't have one yet, you can follow the ["Getting Started"](https://starlight.astro.build/getting-started) guide in the Starlight docs to create one.

## Install the plugin

Starlight OpenAPI is a Starlight [plugin](https://starlight.astro.build/reference/plugins/).
Install it using your favorite package manager:

<PackageManagers pkg="starlight-openapi" />

## Configure the plugin

The Starlight OpenAPI plugin can be configured in your Starlight [configuration](https://starlight.astro.build/reference/configuration/#plugins) in the `astro.config.mjs` file.

```diff lang="js"
// astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
+import starlightOpenAPI, { openAPISidebarGroups } from 'starlight-openapi'

export default defineConfig({
integrations: [
starlight({
+ plugins: [
+ // Generate the OpenAPI documentation pages.
+ starlightOpenAPI([
+ {
+ base: 'api',
+ label: 'My API',
+ schema: '../schemas/api-schema.yaml',
+ },
+ ]),
+ ],
sidebar: [
{
label: 'Guides',
items: [{ label: 'Example Guide', link: '/guides/example/' }],
},
+ // Add the generated sidebar group to the sidebar.
+ ...openAPISidebarGroups,
],
title: 'My Docs',
}),
],
})
```

The Starlight OpenAPI plugin behavior can be tweaked using various [configuration options](/configuration).
Loading

0 comments on commit 98cb2eb

Please sign in to comment.