styledsea
IntegrationsOpenAPI

Configurations

Customise Adalt OpenAPI

File Generator

Pass options to the generateFiles function.

Input

An array of input files. Allowed:

  • File Paths
  • External URLs
  • Wildcard
import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  input: ['./unkey.json'],
});

On Next.js server, the schema is dynamically fetched when the APIPage component renders.

For Vercel

If the schema is passed as a file path, ensure the page will not be re-rendered after build.

Output

Path to the output directory.

import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  output: '/content/docs',
});

Per

Customise how the page is generated, default to operation.

modeGenerate a page for
tageach tag
fileeach schema
operationeach operation (method of endpoint)
import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  per: 'tag',
});

Group By

In operation mode, you can group output files with folders.

Group byDescription
tag{tag}/{page}.mdx (Each operation can only contain 1 tag)
route{api-endpoint}/{page}.mdx
none{page}.mdx (default)
import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  per: 'operation',
  groupBy: 'tag',
});

Name

A function that controls the output path of files.

import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  name: (type, file) => {
    return; // filename
  },
});

Imports

Add additional imports on the top of MDX files.

import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  imports: [
    {
      names: ['Component1', 'Component2'],
      from: '@/components/ui/api',
    },
  ],
});

Frontmatter

Customise the frontmatter of MDX files.

By default, it includes:

propertydescription
titlePage title
descriptionPage description
fullAlways true, added for Adalt UI
methodAvailable method of operation (operation mode)
routeRoute of operation (operation mode)
import { generateFiles } from 'styledsea-docs-openapi';
 
void generateFiles({
  input: ['./petstore.yaml'],
  output: './content/docs',
  frontmatter: (title, description) => ({
    myProperty: 'hello',
  }),
});

OpenAPI Server

The server to render pages.

Generate Code Samples

Generate custom code samples for each API endpoint.

import { createOpenAPI } from 'styledsea-docs-openapi/server';
 
export const openapi = createOpenAPI({
  generateCodeSamples(endpoint) {
    return [
      {
        lang: 'js',
        label: 'JavaScript SDK',
        source: "console.log('hello')",
      },
    ];
  },
});

In addition, you can also specify code samples via OpenAPI schema.

paths:
  /plants:
    get:
      x-codeSamples:
        - lang: js
          label: JavaScript SDK
          source: |
            const planter = require('planter');
            planter.list({ unwatered: true });

Renderer

Customise components in the page.

import { createOpenAPI } from 'styledsea-docs-openapi/server';
 
export const openapi = createOpenAPI({
  renderer: {
    Root(props) {
      // your own (server) component
    },
  },
});

Last updated on

On this page

Edit on GitHub