Skip to content

nevr openapi

Generate an OpenAPI 3.0 specification from your entity definitions.

Usage

bash
npx nevr openapi [options]

Description

This command generates a complete OpenAPI specification from your entities and plugins, including:

  1. CRUD endpoints for each public entity (list, get, create, update, delete)
  2. Plugin endpoints from auth, payment, organization, and other plugins
  3. Custom actions defined with .actions()
  4. Request/response schemas derived from entity fields
  5. Query parameters for filtering, sorting, pagination

Note: Plugin entities marked as internal (e.g., user, session, account from the auth plugin) do not generate CRUD routes. They are managed through the plugin's custom endpoints instead.

Options

OptionAliasDefaultDescription
--config <path>-c./nevr.config.tsPath to your config file
--output <path>-o./openapi.jsonOutput file path
--format <fmt>jsonOutput format: json or yaml
--title <title>Nevr APIAPI title in spec
--version <ver>1.0.0API version in spec
--base-path <path>/apiBase path for all routes

Examples

Generate JSON spec:

bash
npx nevr openapi

Generate YAML spec:

bash
npx nevr openapi --format yaml

Custom output path:

bash
npx nevr openapi -o ./docs/api-spec.json

With custom title and version:

bash
npx nevr openapi --title "My App API" --version "2.0.0"

Full example:

bash
npx nevr openapi \
  --format yaml \
  -o ./docs/openapi.yaml \
  --title "E-Commerce API" \
  --version "1.2.0" \
  --base-path "/v1"

Output

The generated spec includes:

Entity Endpoints

For each entity (e.g., post):

MethodPathOperation
GET/api/postsList all posts
POST/api/postsCreate a post
GET/api/posts/{id}Get a post
PUT/api/posts/{id}Update a post
DELETE/api/posts/{id}Delete a post

Plugin Endpoints

Plugins that define custom endpoints (auth, organization, payment, etc.) are automatically included:

MethodPathPluginOperation
POST/auth/sign-up/emailAuthenticationSign up with email
POST/auth/sign-in/emailAuthenticationSign in with email
GET/auth/get-sessionAuthenticationGet current session
POST/organization/createOrganizationCreate organization
POST/payment/stripe/webhookPaymentStripe webhook

Each plugin's basePath is used as the route prefix, and endpoint metadata (summary, tags, description) is extracted from the endpoint definitions.

Schemas

Each entity generates a schema in #/components/schemas/:

yaml
components:
  schemas:
    Post:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        body:
          type: string
        published:
          type: boolean
      required:
        - title
        - body

Custom Actions

Actions defined with .actions() are included:

typescript
const order = entity("order", { ... })
  .actions({
    checkout: action("checkout")
      .post()
      .input({ paymentMethod: string })
      .meta({ summary: "Process checkout" }),
  })

Generates:

yaml
/api/orders/{id}/checkout:
  post:
    summary: Process checkout
    requestBody:
      content:
        application/json:
          schema:
            type: object
            properties:
              paymentMethod:
                type: string

Use Cases

Import into API Tools

bash
# Generate and open in Swagger UI
npx nevr openapi -o ./public/openapi.json
# Then serve via your app or use online Swagger Editor

Generate Client SDKs

bash
# Generate spec
npx nevr openapi -o openapi.json

# Use OpenAPI Generator to create SDKs
npx @openapitools/openapi-generator-cli generate \
  -i openapi.json \
  -g typescript-fetch \
  -o ./sdk

CI/CD Integration

yaml
# .github/workflows/docs.yml
- name: Generate OpenAPI
  run: npx nevr openapi -o ./docs/openapi.json

- name: Upload spec
  uses: actions/upload-artifact@v3
  with:
    name: openapi-spec
    path: ./docs/openapi.json

See Also

Released under the MIT License.