LogoRobo.js

OpenAPI

Generate OpenAPI 3.1 specs from your typed endpoints.

The plugin generates an OpenAPI 3.1 specification from your typed endpoints during robo build. Any endpoint created with define() and Zod schemas is automatically included in the spec.

How it works

  1. Define endpoints using define() with Zod schemas (see Typed endpoints).
  2. Run robo build.
  3. The plugin scans all API routes, extracts schemas from handlers that use define(), converts Zod schemas to JSON Schema, and generates .robo/openapi.json.

Configuration

Customize the generated spec through your plugin config:

config/plugins/robojs/server.mjs
export default {
  openapi: {
    title: 'My API',
    version: '1.0.0',
    description: 'Production REST API',
    contact: {
      name: 'API Support',
      email: 'support@example.com'
    },
    license: {
      name: 'MIT',
      identifier: 'MIT'
    },
    servers: [
      { url: 'https://api.example.com', description: 'Production' },
      { url: 'http://localhost:3000', description: 'Development' }
    ],
    tags: [
      { name: 'users', description: 'User management' },
      { name: 'posts', description: 'Blog operations' }
    ],
    securitySchemes: {
      bearerAuth: {
        type: 'http',
        scheme: 'bearer',
        bearerFormat: 'JWT'
      },
      apiKey: {
        type: 'apiKey',
        in: 'header',
        name: 'X-API-Key'
      }
    },
    security: [{ bearerAuth: [] }]
  }
}
config/plugins/robojs/server.mjs
export default {
  openapi: {
    title: 'My API',
    version: '1.0.0',
    description: 'Production REST API',
    contact: {
      name: 'API Support',
      email: 'support@example.com'
    },
    license: {
      name: 'MIT',
      identifier: 'MIT'
    },
    servers: [
      { url: 'https://api.example.com', description: 'Production' },
      { url: 'http://localhost:3000', description: 'Development' }
    ],
    tags: [
      { name: 'users', description: 'User management' },
      { name: 'posts', description: 'Blog operations' }
    ],
    securitySchemes: {
      bearerAuth: {
        type: 'http',
        scheme: 'bearer',
        bearerFormat: 'JWT'
      },
      apiKey: {
        type: 'apiKey',
        in: 'header',
        name: 'X-API-Key'
      }
    },
    security: [{ bearerAuth: [] }]
  }
}

Configuration options

OptionTypeDescription
titlestringAPI title. Default: 'API'.
versionstringAPI version. Default: '1.0.0'.
summarystringBrief API summary.
descriptionstringDetailed API description.
termsOfServicestringURL to terms of service.
contact{ name?, url?, email? }Contact information.
license{ name, identifier?, url? }License information.
serversArray<{ url, description? }>Server URLs.
tagsArray<{ name, description? }>API tags for grouping.
securitySchemesRecord<string, SecurityScheme>Security scheme definitions.
securitySecurityRequirement[]Global security requirements.
externalDocs{ url, description? }Link to external documentation.

Disabling generation

config/plugins/robojs/server.mjs
export default {
  openapi: false
}
config/plugins/robojs/server.mjs
export default {
  openapi: false
}

Route path conversion

The generator converts Robo.js route patterns to OpenAPI path syntax:

  • users/[id]/users/{id}
  • files/[...path]/files/{path}
  • docs/[[...slug]]/docs/{slug}

Schema conversion

Zod schemas are converted to JSON Schema using Zod v4's built-in z.toJSONSchema() with target: 'openapi-3.0'. This ensures compatibility with standard OpenAPI tooling like Swagger UI, Redoc, and code generators.

Output

The generated spec is written to .robo/openapi.json during robo build. You can serve it as a static file, use it with Swagger UI, or feed it to API code generators.

Next steps

On this page