Basedoc Docs

Search...
K
API documentation

Schema files

Learn how to add schema files to your API documentation pages.

If you have schemas for API pages that are repeated across multiple endpoints, you can use schema files to avoid duplication.

Schema files are Markdown files that define the schema for either a request body or a response body.

Creating a schema file

Inside the folder you have your API endpoints, add a /schemas folder. This is where you will store your schema files.

Schema file names can be anything as they're not used by the system, but it's recommended to use a descriptive name that matches the schema.

In the frontmatter, add an api.schema key with the name of the schema the file describes, in this case CreateUser. This is the name you reference in the endpoint page frontmatter.

In the file body, you define the schema for the request body or response body using a simple key-value format.

Markdown pages with only an api.schema key in frontmatter will not be included in your built documentation.

Here's an example of a simple schema file:

Markdownapi/schemas/user.mdx
---
api:
  schema: User
---

email: string
name: string
role?: string

You can also reference other schemas inside schemas.

Schema files are the only way to define arrays or nested objects in your endpoints.

Markdownapi/schemas/member.mdx
---
api:
  schema: Member
---

id: string
user: User

The schema here is the same as you would define in page frontmatter.

So you can add descriptions for each field:

Markdownapi/schemas/member.mdx
---
api:
  schema: Member
---

id: string
  User ID (UUID)
user: User

or

Markdownapi/schemas/member.mdx
---
api:
  schema: Member
---

id:
  type: string
  description: User ID (UUID)
user: User
Schema in frontmatter

Learn how to define schemas.

Using a schema file

In your API endpoint frontmatter, you can reference schema files using a schema key.

Instead of defining the schema in the frontmatter, you reference the schema with the name you added in api.schema in the schema file.

In responses, use schemas like this:

Markdownapi/get-users.mdx
---
api:
  endpoint:
    get /v1/user/{userId}:
      params:
        query:
          userId: string
      responses:
        200:
          schema: User
---

To reference an array of objects in a response using schemas, you can do this:

Markdownapi/list-users.mdx
---
api:
  endpoint:
    get /v1/users:
      responses:
        200:
          schema:
            users: User[]
---

© Basedoc Docs

Powered by Basedoc