fork of hey-api/openapi-ts because I need some additional things

docs: add documentation for Fastify plugin

Lubos 4182e152 04f9318f

+169 -15
+4
docs/.vitepress/config/en.ts
··· 48 48 { 49 49 items: [ 50 50 { 51 + link: '/openapi-ts/fastify', 52 + text: 'Fastify', 53 + }, 54 + { 51 55 link: '/openapi-ts/tanstack-query', 52 56 text: 'TanStack Query', 53 57 },
+7
docs/embed.ts
··· 25 25 'openapi-ts.config.ts,src/client/schemas.gen.ts,src/client/services.gen.ts,src/client/types.gen.ts,src/App.tsx', 26 26 view: 'editor', 27 27 }); 28 + case 'hey-api-client-fetch-plugin-fastify-example': 29 + return await sdk.embedProjectId(container, projectId, { 30 + height: 700, 31 + openFile: 32 + 'openapi-ts.config.ts,src/client/fastify.gen.ts,src/client/types.gen.ts,src/server.ts', 33 + view: 'editor', 34 + }); 28 35 case 'hey-api-client-fetch-plugin-tanstack-react-query-example': 29 36 return await sdk.embedProjectId(container, projectId, { 30 37 height: 700,
+1 -1
docs/openapi-ts/configuration.md
··· 236 236 237 237 The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](#filters) and more will be added in the future. 238 238 239 - The legacy parser will remain enabled for the [legacy clients](/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates. 239 + The legacy parser will be used with the [legacy clients](/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates. 240 240 241 241 ## Config API 242 242
+75
docs/openapi-ts/fastify.md
··· 1 + --- 2 + title: Fastify 3 + description: Fastify plugin for Hey API. Compatible with all our features. 4 + --- 5 + 6 + # Fastify 7 + 8 + ::: warning 9 + Fastify plugin is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues). 10 + ::: 11 + 12 + [Fastify](https://fastify.dev/) is a fast and low overhead web framework for Node.js. 13 + 14 + <button class="buttonLink" @click="(event) => embedProject('hey-api-client-fetch-plugin-fastify-example')(event)"> 15 + Live demo 16 + </button> 17 + 18 + ## Features 19 + 20 + - seamless integration with `@hey-api/openapi-ts` ecosystem 21 + - type-safe route handlers 22 + - minimal learning curve thanks to extending the underlying technology 23 + 24 + ## Installation 25 + 26 + ::: warning 27 + Fastify plugin works only with the [experimental parser](/openapi-ts/configuration#parser) which is currently an opt-in feature. 28 + ::: 29 + 30 + Ensure you have already [configured](/openapi-ts/get-started) `@hey-api/openapi-ts`. Update your configuration to use the Fastify plugin. 31 + 32 + ```js 33 + export default { 34 + client: '@hey-api/client-fetch', 35 + experimentalParser: true, // [!code ++] 36 + input: 'path/to/openapi.json', 37 + output: 'src/client', 38 + plugins: [ 39 + // ...other plugins 40 + 'fastify', // [!code ++] 41 + ], 42 + }; 43 + ``` 44 + 45 + You can now generate Fastify artifacts. 🎉 46 + 47 + ## Output 48 + 49 + The Fastify plugin will generate the following artifacts, depending on the input specification. 50 + 51 + ## Route Handlers 52 + 53 + Route handlers are generated from all endpoints. The generated interface follows the naming convention of services. 54 + 55 + ```ts 56 + const fastify = Fastify(); 57 + const serviceHandlers: RouteHandlers = { 58 + createPets(request, reply) { 59 + reply.code(201).send(); 60 + }, 61 + listPets(request, reply) { 62 + reply.code(200).send([]); 63 + }, 64 + showPetById(request, reply) { 65 + reply.code(200).send({ 66 + id: Number(request.params.petId), 67 + name: 'Kitty', 68 + }); 69 + }, 70 + }; 71 + fastify.register(glue, { serviceHandlers }); 72 + ``` 73 + 74 + <!--@include: ../examples.md--> 75 + <!--@include: ../sponsorship.md-->
+6
docs/openapi-ts/migrating.md
··· 50 50 51 51 This config option is deprecated and will be removed. 52 52 53 + ## v0.56.0 54 + 55 + ### Deprecated `tree` in `@hey-api/types` 56 + 57 + This config option is deprecated and will be removed when the experimental parser becomes the default. 58 + 53 59 ## v0.55.0 54 60 55 61 This release adds the ability to filter your OpenAPI specification before it's processed. This feature will be useful if you are working with a large specification and are interested in generating output only from a small subset.
+1 -1
docs/openapi-ts/output.md
··· 28 28 └── package.json 29 29 ``` 30 30 31 - Each file is an artifact generated by a plugin. This is the default output, we will cover customizing it on this page. 31 + Each file is an artifact generated by a Hey API plugin. This is the default output, we will cover customizing it on this page. These files also form the base for third-party plugins. 32 32 33 33 Let's go through each file in the `src/client` folder and explain what it looks like, what it does, and how to use it. 34 34
+2 -2
docs/openapi-ts/tanstack-query.md
··· 94 94 95 95 ::: 96 96 97 - You can now run `openapi-ts` to generate TanStack Query artifacts. 🎉 97 + You can now generate TanStack Query artifacts. 🎉 98 98 99 99 ## Output 100 100 101 - The TanStack Query plugin will optionally generate the following output layers, depending on the input specification. 101 + The TanStack Query plugin will optionally generate the following artifacts, depending on the input specification. 102 102 103 103 ## Queries 104 104
+1 -1
examples/openapi-ts-fastify/openapi-ts.config.ts
··· 10 10 lint: 'eslint', 11 11 path: './src/client', 12 12 }, 13 - plugins: ['fastify'], 13 + plugins: ['fastify', '@hey-api/services'], 14 14 });
+1
examples/openapi-ts-fastify/src/client/index.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './services.gen'; 2 3 export * from './types.gen';
+60
examples/openapi-ts-fastify/src/client/services.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { 4 + createClient, 5 + createConfig, 6 + type Options, 7 + } from '@hey-api/client-fetch'; 8 + 9 + import type { 10 + CreatePetsError, 11 + ListPetsData, 12 + ListPetsError, 13 + ListPetsResponse, 14 + ShowPetByIdData, 15 + ShowPetByIdError, 16 + ShowPetByIdResponse, 17 + } from './types.gen'; 18 + 19 + export const client = createClient(createConfig()); 20 + 21 + /** 22 + * List all pets 23 + */ 24 + export const listPets = <ThrowOnError extends boolean = false>( 25 + options?: Options<ListPetsData, ThrowOnError>, 26 + ) => 27 + (options?.client ?? client).get< 28 + ListPetsResponse, 29 + ListPetsError, 30 + ThrowOnError 31 + >({ 32 + ...options, 33 + url: '/pets', 34 + }); 35 + 36 + /** 37 + * Create a pet 38 + */ 39 + export const createPets = <ThrowOnError extends boolean = false>( 40 + options?: Options<unknown, ThrowOnError>, 41 + ) => 42 + (options?.client ?? client).post<unknown, CreatePetsError, ThrowOnError>({ 43 + ...options, 44 + url: '/pets', 45 + }); 46 + 47 + /** 48 + * Info for a specific pet 49 + */ 50 + export const showPetById = <ThrowOnError extends boolean = false>( 51 + options: Options<ShowPetByIdData, ThrowOnError>, 52 + ) => 53 + (options?.client ?? client).get< 54 + ShowPetByIdResponse, 55 + ShowPetByIdError, 56 + ThrowOnError 57 + >({ 58 + ...options, 59 + url: '/pets/{petId}', 60 + });
+11 -10
examples/openapi-ts-fastify/src/handlers.ts
··· 1 1 import type { RouteHandlers } from './client/fastify.gen'; 2 - import type { Pet } from './client/types.gen'; 3 2 4 - export const serviceHandlers: Pick<RouteHandlers, 'showPetById'> = { 3 + export const serviceHandlers: RouteHandlers = { 4 + createPets(request, reply) { 5 + reply.code(201).send(); 6 + }, 7 + listPets(request, reply) { 8 + reply.code(200).send([]); 9 + }, 5 10 showPetById(request, reply) { 6 - const { 7 - params: { petId }, 8 - } = request; 9 - const pet: Pet = { 10 - id: Number(petId), 11 - name: 'petname', 12 - }; 13 - reply.code(200).send(pet); 11 + reply.code(200).send({ 12 + id: Number(request.params.petId), 13 + name: 'Kitty', 14 + }); 14 15 }, 15 16 };