Skip to content

devidw/trpc-openapi

 
 

Repository files navigation

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": "..."
    }
  }
}

About

OpenAPI support for tRPC 🧩

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages

  • TypeScript 99.8%
  • JavaScript 0.2%