Skip to content

OpenAPI Generation

generateOpenAPI() converts a Resource’s static Zod schema into an OpenAPI 3.0-compatible inner schema object.

import { generateOpenAPI } from "@amrachraf6690/resourcesjs";
const schema = generateOpenAPI(UserResource);

Example output:

{
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
}
},
"required": ["id", "name"],
"additionalProperties": false
}
  • The function returns an inner schema object, not a complete OpenAPI document.
  • The Resource must define a static Zod schema.
  • OpenAPI generation documents the schema input side because Zod transforms cannot always be represented in OpenAPI.

If the Resource has no schema, ResourcesJS throws:

UserResource must define a static Zod schema to generate OpenAPI