12024.6.28 • Published 12 months ago

@devidw/trpc-openapi v12024.6.28

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

trpc-openapi with model schema support

in your script where you generate your specs you can now pass a object of the schemas you want to be defined as components/schemas in the output doc

import { generateOpenApiDocument } from "trpc-openapi";
import { z } from "zod";

const SomeSchema = z.object({
  a: z.literal(69),
});

generateOpenApiDocument(appRouter, {
  // ...
  defs: {
    SomeSchema,
  },
});

which will be included in the response object definition like

{
  "$ref": "#/components/schemas/SomeSchema"
}

and in the actual schemas list like

{
  "components": {
    "schemas": {
      "SomeSchema": "..."
    }
  }
}