Uses Valibot schemas to generate Open API documentation
Install from JSR,
npx jsr add @camflan/valibot-openapi-generator
This is being used in production but needs a lot of help to become as powerful as it can be. Please PR any help, especially around some of the ignored type errors
I used hono-openapi as the starting point, many thanks to that repository and those contributors.
const openApiSpec = getOpenAPISpecs(
[
describeRoute("/accounts", {
summary: "List accounts",
description: "Lists all accounts you have access to",
method: "GET",
responses: {
200: {
content: {
"application/json": {
schema: v.object({
accounts: v.array(
v.object({
id: v.string(),
email: v.string(),
name: v.string(),
}),
),
}),
},
},
description: "OK",
},
500: {
description: "Server error",
},
},
}),
describeRoute("/accounts/{accountId}", {
summary: "Account detail",
description: "Shows detailed information for a specific account",
method: "GET",
parameters: [
{
in: "path",
name: "accountId",
required: true,
},
],
responses: {
200: {
content: {
"application/json": {
schema: v.object({
account: v.object({
id: v.string(),
email: v.string(),
name: v.string(),
}),
}),
},
},
description: "OK",
},
401: {
description: "Not authorized",
},
500: {
description: "Server error",
},
},
}),
],
{
documentation: {
info: {
title: "My first schema",
version: "1",
},
},
},
);