This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
API Builder (v2.0.0) is a template for generating REST API domain objects and OpenAPI contracts. It transforms JSON Schema entity definitions into OpenAPI 3.0 specifications, serving them via Swagger UI and ReDoc for visualization (not mocking).
Version 2.0 changes: Paths are now organized in ./paths/ directory with separate *Paths.yml files instead of a single openApiPaths.yml. Added yarn docs command to generate schema reference documentation.
yarn startStarts nodemon server on localhost:3000 (Swagger UI) and localhost:3000/doc (ReDoc). Generates OpenAPI spec in-memory only. "Try it out" won't work - this is for visualization only.
yarn docsGenerates API_REFERENCE.md showing all available schema names and their component references. Run this first when creating new entities to see how to reference them in path definitions.
yarn schemasGenerates openApiSchemas.yml containing all entity definitions with updated $ref pointers. Useful for debugging schema transformations.
yarn generateMerges all *Paths.yml files from ./paths/ directory with entity schemas to create complete openApi.yml specification file.
yarn show ./entities/YOUROBJECT.yml
# or
yarn show ./entities/writes/YOUROBJECT.ymlDisplays fully merged entity with all references resolved.
The codebase uses a two-tier entity system:
- Write entities (
./entities/writes/*.yml): Define input properties for creating/updating objects - Full entities (
./entities/*.yml): Extend write entities with system-generated properties usingallOf
Example flow:
entities/writes/user.ymldefines user-provided fieldsentities/user.ymlcombinescommon.yml#/definitions/general,writes/user.yml, andaccess.ymlviaallOf
Paths are now split into multiple files in the ./paths/ directory:
*Paths.ymlfiles: Contain path definitions only (e.g.,userPaths.yml,permissionPaths.yml,systemPaths.yml)_metadata.yml: Top-level OpenAPI metadata (info, tags, servers, security, openapi version)- All
*Paths.ymlfiles are automatically merged duringyarn generate - Files not ending in
Paths.ymlare ignored (except_metadata.ymlwhich is handled specially)
Key difference from old architecture: No more single openApiPaths.yml file. Everything is split into logical path groupings.
common.yml: Single file containing shared schema definitions (general, address, phone, name, social, error, jsonPatch)[name]Common.yml: Multiple grouping files allowed (e.g.,userCommon.yml,accessCommon.yml)- All definitions merge into OpenAPI
components.schemassection - CRITICAL: Avoid duplicate names across all grouping files
The lib.js module transforms filesystem-based $ref pointers to OpenAPI component references:
File references → Component references:
common.yml#/definitions/address→#/components/schemas/address[name]Common.yml#/definitions/foo→#/components/schemas/foowrites/user.yml→#/components/schemas/writeUseruser.yml→#/components/schemas/userObject
Processing order in parseEntities():
- Common groupings (
*Common.ymlfiles) - Write entities (prefixed with
write+ capitalized name) - Full entities (suffixed with
Object)
Path merging in buildSwag() (lib.js:106-141):
- Reads all
*Paths.ymlfiles from./paths/directory - Merges them into single
pathsobject usingObject.assign() - Loads
_metadata.ymlseparately and merges into root OpenAPI object - Combines with entity schemas to create complete spec
lib.js: Core factory containing entity parsing, $ref transformation, path merging, and spec generation logicindex.js: HTTP server serving Swagger UI, ReDoc, and in-memory OpenAPI JSONgenerate.js: CLI wrapper forlib.genSpec()to writeopenApi.ymlschemas.js: CLI wrapper forlib.genSchema()to writeopenApiSchemas.ymldocs.js: Generates API_REFERENCE.md with all schema names and component referencesshowObject.js: CLI tool to dereference and merge entity for debugging./paths/directory: Contains all path definitions split by logical groupings
- Define input schema in
./entities/writes/newEntity.yml - Create full entity in
./entities/newEntity.ymlusingallOfto combine:common.yml#/definitions/general(system fields)writes/newEntity.yml(user fields)- Any other relevant schemas
- Run
yarn docsto generate API_REFERENCE.md showing available schema names - Create or update path file in
./paths/newEntityPaths.ymlwith paths referencing:#/components/schemas/writeNewEntity(request bodies)#/components/schemas/newEntityObject(responses)
Path files in ./paths/ should:
- Follow naming convention
*Paths.yml(e.g.,userPaths.yml,permissionPaths.yml) - Contain ONLY path definitions (no metadata, info, tags, or openapi version)
- Use component schema references:
$ref: '#/components/schemas/schemaName'
Example path file structure (./paths/userPaths.yml):
/user:
post:
tags:
- Users
summary: Create a user
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/writeUser'
responses:
'201':
content:
application/json:
schema:
$ref: '#/components/schemas/userObject'Edit ./paths/_metadata.yml to change:
- API info (version, title, description, logo)
- Global tags
- Security schemes (default: bearer)
- Server URLs
- OpenAPI version
When writing ./paths/*Paths.yml files:
- Write entity refs:
#/components/schemas/write[Name](capitalized, no .yml) - Full entity refs:
#/components/schemas/[name]Object - Common refs:
#/components/schemas/[definitionName]
In entity .yml files, use filesystem refs:
- Common:
common.yml#/definitions/[name]or../common.yml#/definitions/[name] - Write entities:
writes/user.ymlor../writes/user.yml - Other entities:
user.yml(same directory)
Default security schemes auto-added to specs (in lib.js:buildSwag()):
- bearer (HTTP bearer tokens)
- basicAuth (HTTP basic authentication)
- openId (OpenID Connect)
- OAuth2 (authorization code flow)
Customize by modifying ./paths/_metadata.yml security section or updating the buildSwag() function in lib.js.