@redocly/client-generator 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -54
- package/eject-assets/AGENTS.md +137 -0
- package/eject-assets/generators/cli/docs.ts +224 -0
- package/eject-assets/generators/cli/engine-source.ts +21 -0
- package/eject-assets/generators/cli/index.ts +90 -0
- package/eject-assets/generators/cli/render.ts +348 -0
- package/eject-assets/generators/go/client.ts +57 -0
- package/eject-assets/generators/go/descriptor.ts +41 -0
- package/eject-assets/generators/go/index.ts +336 -0
- package/eject-assets/generators/go/models.ts +179 -0
- package/eject-assets/generators/go/naming.ts +49 -0
- package/eject-assets/generators/go/operations.ts +296 -0
- package/eject-assets/generators/go/pagination.ts +194 -0
- package/eject-assets/generators/go/types.ts +60 -0
- package/eject-assets/generators/mock/faker.ts +214 -0
- package/eject-assets/generators/mock/index.ts +35 -0
- package/eject-assets/generators/mock/render.ts +282 -0
- package/eject-assets/generators/mock/sample.ts +316 -0
- package/eject-assets/generators/mock/values.ts +63 -0
- package/eject-assets/generators/php/client.ts +63 -0
- package/eject-assets/generators/php/descriptor.ts +58 -0
- package/eject-assets/generators/php/index.ts +237 -0
- package/eject-assets/generators/php/models.ts +275 -0
- package/eject-assets/generators/php/naming.ts +51 -0
- package/eject-assets/generators/php/operations.ts +232 -0
- package/eject-assets/generators/php/pagination.ts +133 -0
- package/eject-assets/generators/php/types.ts +148 -0
- package/eject-assets/generators/python/client.ts +123 -0
- package/eject-assets/generators/python/descriptor.ts +52 -0
- package/eject-assets/generators/python/index.ts +251 -0
- package/eject-assets/generators/python/models.ts +242 -0
- package/eject-assets/generators/python/naming.ts +46 -0
- package/eject-assets/generators/python/operations.ts +147 -0
- package/eject-assets/generators/python/pagination.ts +128 -0
- package/eject-assets/generators/python/types.ts +54 -0
- package/eject-assets/generators/swr/index.ts +37 -0
- package/eject-assets/generators/swr/render.ts +78 -0
- package/eject-assets/generators/tanstack-query/index.ts +48 -0
- package/eject-assets/generators/tanstack-query/render.ts +346 -0
- package/eject-assets/generators/transformers/index.ts +46 -0
- package/eject-assets/generators/transformers/render.ts +506 -0
- package/eject-assets/generators/typescript/banner.ts +35 -0
- package/eject-assets/generators/typescript/client.ts +254 -0
- package/eject-assets/generators/typescript/descriptor.ts +137 -0
- package/eject-assets/generators/typescript/index.ts +101 -0
- package/eject-assets/generators/typescript/inline-runtime.ts +135 -0
- package/eject-assets/generators/typescript/operation-signature.ts +62 -0
- package/eject-assets/generators/typescript/operation-types.ts +17 -0
- package/eject-assets/generators/typescript/operations.ts +524 -0
- package/eject-assets/generators/typescript/response-headers.ts +74 -0
- package/eject-assets/generators/typescript/type-guards.ts +159 -0
- package/eject-assets/generators/typescript/types.ts +172 -0
- package/eject-assets/generators/zod/index.ts +32 -0
- package/eject-assets/generators/zod/schemas.ts +456 -0
- package/eject-assets/skills/cli-generator/SKILL.md +121 -0
- package/eject-assets/skills/client-generators/SKILL.md +142 -0
- package/eject-assets/skills/go-generator/SKILL.md +96 -0
- package/eject-assets/skills/mock-generator/SKILL.md +50 -0
- package/eject-assets/skills/php-generator/SKILL.md +112 -0
- package/eject-assets/skills/python-generator/SKILL.md +110 -0
- package/eject-assets/skills/swr-generator/SKILL.md +50 -0
- package/eject-assets/skills/tanstack-query-generator/SKILL.md +55 -0
- package/eject-assets/skills/transformers-generator/SKILL.md +47 -0
- package/eject-assets/skills/typescript-generator/SKILL.md +95 -0
- package/eject-assets/skills/zod-generator/SKILL.md +54 -0
- package/lib/authoring/index.d.ts +11 -0
- package/lib/authoring/index.d.ts.map +1 -0
- package/lib/authoring/index.js +42 -0
- package/lib/authoring/index.js.map +1 -0
- package/lib/authoring/naming.d.ts +34 -0
- package/lib/authoring/naming.d.ts.map +1 -0
- package/lib/authoring/naming.js +104 -0
- package/lib/authoring/naming.js.map +1 -0
- package/lib/authoring/operation.d.ts +47 -0
- package/lib/authoring/operation.d.ts.map +1 -0
- package/lib/authoring/operation.js +86 -0
- package/lib/authoring/operation.js.map +1 -0
- package/lib/authoring/options.d.ts +9 -0
- package/lib/authoring/options.d.ts.map +1 -0
- package/lib/authoring/options.js +5 -0
- package/lib/authoring/options.js.map +1 -0
- package/lib/authoring/pagination.d.ts +19 -0
- package/lib/authoring/pagination.d.ts.map +1 -0
- package/lib/authoring/pagination.js +45 -0
- package/lib/authoring/pagination.js.map +1 -0
- package/lib/authoring/printer.d.ts +16 -0
- package/lib/authoring/printer.d.ts.map +1 -0
- package/lib/authoring/printer.js +36 -0
- package/lib/authoring/printer.js.map +1 -0
- package/lib/authoring/reference-page.d.ts +31 -0
- package/lib/authoring/reference-page.d.ts.map +1 -0
- package/lib/authoring/reference-page.js +160 -0
- package/lib/authoring/reference-page.js.map +1 -0
- package/lib/authoring/schema.d.ts +51 -0
- package/lib/authoring/schema.d.ts.map +1 -0
- package/lib/authoring/schema.js +190 -0
- package/lib/authoring/schema.js.map +1 -0
- package/lib/cli-contract.d.ts +126 -0
- package/lib/cli-contract.d.ts.map +1 -0
- package/lib/cli-contract.js +25 -0
- package/lib/cli-contract.js.map +1 -0
- package/lib/{emitters/wrapper-support.d.ts → contracts/typescript.d.ts} +13 -24
- package/lib/contracts/typescript.d.ts.map +1 -0
- package/lib/contracts/typescript.js +87 -0
- package/lib/contracts/typescript.js.map +1 -0
- package/lib/generate.d.ts +10 -10
- package/lib/generate.d.ts.map +1 -1
- package/lib/generate.js +25 -106
- package/lib/generate.js.map +1 -1
- package/lib/generators/cli/docs.d.ts +19 -0
- package/lib/generators/cli/docs.d.ts.map +1 -0
- package/lib/generators/cli/docs.js +187 -0
- package/lib/generators/cli/docs.js.map +1 -0
- package/lib/generators/cli/engine-source.d.ts +5 -0
- package/lib/generators/cli/engine-source.d.ts.map +1 -0
- package/lib/generators/cli/engine-source.js +12 -0
- package/lib/generators/cli/engine-source.js.map +1 -0
- package/lib/generators/cli/index.d.ts +18 -0
- package/lib/generators/cli/index.d.ts.map +1 -0
- package/lib/generators/cli/index.js +67 -0
- package/lib/generators/cli/index.js.map +1 -0
- package/lib/generators/cli/render.d.ts +39 -0
- package/lib/generators/cli/render.d.ts.map +1 -0
- package/lib/generators/cli/render.js +281 -0
- package/lib/generators/cli/render.js.map +1 -0
- package/lib/generators/cli/runtime/cli.d.ts +42 -0
- package/lib/generators/cli/runtime/cli.d.ts.map +1 -0
- package/lib/generators/cli/runtime/cli.js +582 -0
- package/lib/generators/cli/runtime/cli.js.map +1 -0
- package/lib/generators/compatibility.d.ts +10 -0
- package/lib/generators/compatibility.d.ts.map +1 -0
- package/lib/generators/compatibility.js +45 -0
- package/lib/generators/compatibility.js.map +1 -0
- package/lib/generators/go/client.d.ts +5 -0
- package/lib/generators/go/client.d.ts.map +1 -0
- package/lib/generators/go/client.js +34 -0
- package/lib/generators/go/client.js.map +1 -0
- package/lib/generators/go/descriptor.d.ts +6 -0
- package/lib/generators/go/descriptor.d.ts.map +1 -0
- package/lib/generators/go/descriptor.js +26 -0
- package/lib/generators/go/descriptor.js.map +1 -0
- package/lib/generators/go/index.d.ts +14 -0
- package/lib/generators/go/index.d.ts.map +1 -0
- package/lib/generators/go/index.js +240 -0
- package/lib/generators/go/index.js.map +1 -0
- package/lib/generators/go/models.d.ts +4 -0
- package/lib/generators/go/models.d.ts.map +1 -0
- package/lib/generators/go/models.js +125 -0
- package/lib/generators/go/models.js.map +1 -0
- package/lib/generators/go/naming.d.ts +15 -0
- package/lib/generators/go/naming.d.ts.map +1 -0
- package/lib/generators/go/naming.js +36 -0
- package/lib/generators/go/naming.js.map +1 -0
- package/lib/generators/go/operations.d.ts +16 -0
- package/lib/generators/go/operations.d.ts.map +1 -0
- package/lib/generators/go/operations.js +200 -0
- package/lib/generators/go/operations.js.map +1 -0
- package/lib/generators/go/pagination.d.ts +5 -0
- package/lib/generators/go/pagination.d.ts.map +1 -0
- package/lib/generators/go/pagination.js +93 -0
- package/lib/generators/go/pagination.js.map +1 -0
- package/lib/generators/go/types.d.ts +4 -0
- package/lib/generators/go/types.d.ts.map +1 -0
- package/lib/generators/go/types.js +48 -0
- package/lib/generators/go/types.js.map +1 -0
- package/lib/generators/index.d.ts +2 -3
- package/lib/generators/index.d.ts.map +1 -1
- package/lib/generators/index.js +31 -53
- package/lib/generators/index.js.map +1 -1
- package/lib/generators/meta.d.ts +13 -0
- package/lib/generators/meta.d.ts.map +1 -0
- package/lib/generators/meta.js +157 -0
- package/lib/generators/meta.js.map +1 -0
- package/lib/{emitters → generators/mock}/faker.d.ts +4 -5
- package/lib/generators/mock/faker.d.ts.map +1 -0
- package/lib/generators/mock/faker.js +180 -0
- package/lib/generators/mock/faker.js.map +1 -0
- package/lib/generators/{mock.d.ts → mock/index.d.ts} +2 -2
- package/lib/generators/mock/index.d.ts.map +1 -0
- package/lib/generators/{mock.js → mock/index.js} +8 -8
- package/lib/generators/mock/index.js.map +1 -0
- package/lib/{emitters/mock.d.ts → generators/mock/render.d.ts} +2 -3
- package/lib/generators/mock/render.d.ts.map +1 -0
- package/lib/generators/mock/render.js +228 -0
- package/lib/generators/mock/render.js.map +1 -0
- package/lib/{emitters → generators/mock}/sample.d.ts +1 -2
- package/lib/generators/mock/sample.d.ts.map +1 -0
- package/lib/generators/mock/sample.js.map +1 -0
- package/lib/generators/mock/values.d.ts +33 -0
- package/lib/generators/mock/values.d.ts.map +1 -0
- package/lib/generators/mock/values.js +46 -0
- package/lib/generators/mock/values.js.map +1 -0
- package/lib/generators/options.d.ts +7 -0
- package/lib/generators/options.d.ts.map +1 -0
- package/lib/generators/options.js +74 -0
- package/lib/generators/options.js.map +1 -0
- package/lib/generators/php/client.d.ts +5 -0
- package/lib/generators/php/client.d.ts.map +1 -0
- package/lib/generators/php/client.js +38 -0
- package/lib/generators/php/client.js.map +1 -0
- package/lib/generators/php/descriptor.d.ts +7 -0
- package/lib/generators/php/descriptor.d.ts.map +1 -0
- package/lib/generators/php/descriptor.js +42 -0
- package/lib/generators/php/descriptor.js.map +1 -0
- package/lib/generators/php/index.d.ts +14 -0
- package/lib/generators/php/index.d.ts.map +1 -0
- package/lib/generators/php/index.js +166 -0
- package/lib/generators/php/index.js.map +1 -0
- package/lib/generators/php/models.d.ts +8 -0
- package/lib/generators/php/models.d.ts.map +1 -0
- package/lib/generators/php/models.js +200 -0
- package/lib/generators/php/models.js.map +1 -0
- package/lib/generators/php/naming.d.ts +16 -0
- package/lib/generators/php/naming.d.ts.map +1 -0
- package/lib/generators/php/naming.js +31 -0
- package/lib/generators/php/naming.js.map +1 -0
- package/lib/generators/php/operations.d.ts +21 -0
- package/lib/generators/php/operations.d.ts.map +1 -0
- package/lib/generators/php/operations.js +156 -0
- package/lib/generators/php/operations.js.map +1 -0
- package/lib/generators/php/pagination.d.ts +5 -0
- package/lib/generators/php/pagination.d.ts.map +1 -0
- package/lib/generators/php/pagination.js +68 -0
- package/lib/generators/php/pagination.js.map +1 -0
- package/lib/generators/php/types.d.ts +27 -0
- package/lib/generators/php/types.d.ts.map +1 -0
- package/lib/generators/php/types.js +128 -0
- package/lib/generators/php/types.js.map +1 -0
- package/lib/generators/python/client.d.ts +6 -0
- package/lib/generators/python/client.d.ts.map +1 -0
- package/lib/generators/python/client.js +80 -0
- package/lib/generators/python/client.js.map +1 -0
- package/lib/generators/python/descriptor.d.ts +9 -0
- package/lib/generators/python/descriptor.d.ts.map +1 -0
- package/lib/generators/python/descriptor.js +38 -0
- package/lib/generators/python/descriptor.js.map +1 -0
- package/lib/generators/python/index.d.ts +15 -0
- package/lib/generators/python/index.d.ts.map +1 -0
- package/lib/generators/python/index.js +197 -0
- package/lib/generators/python/index.js.map +1 -0
- package/lib/generators/python/models.d.ts +31 -0
- package/lib/generators/python/models.d.ts.map +1 -0
- package/lib/generators/python/models.js +203 -0
- package/lib/generators/python/models.js.map +1 -0
- package/lib/generators/python/naming.d.ts +22 -0
- package/lib/generators/python/naming.d.ts.map +1 -0
- package/lib/generators/python/naming.js +28 -0
- package/lib/generators/python/naming.js.map +1 -0
- package/lib/generators/python/operations.d.ts +4 -0
- package/lib/generators/python/operations.d.ts.map +1 -0
- package/lib/generators/python/operations.js +108 -0
- package/lib/generators/python/operations.js.map +1 -0
- package/lib/generators/python/pagination.d.ts +5 -0
- package/lib/generators/python/pagination.d.ts.map +1 -0
- package/lib/generators/python/pagination.js +95 -0
- package/lib/generators/python/pagination.js.map +1 -0
- package/lib/generators/python/types.d.ts +4 -0
- package/lib/generators/python/types.d.ts.map +1 -0
- package/lib/generators/python/types.js +45 -0
- package/lib/generators/python/types.js.map +1 -0
- package/lib/generators/resolve.d.ts.map +1 -1
- package/lib/generators/resolve.js +92 -13
- package/lib/generators/resolve.js.map +1 -1
- package/lib/generators/{swr.d.ts → swr/index.d.ts} +3 -3
- package/lib/generators/swr/index.d.ts.map +1 -0
- package/lib/generators/{swr.js → swr/index.js} +7 -10
- package/lib/generators/swr/index.js.map +1 -0
- package/lib/{emitters/swr.d.ts → generators/swr/render.d.ts} +2 -4
- package/lib/generators/swr/render.d.ts.map +1 -0
- package/lib/generators/swr/render.js +57 -0
- package/lib/generators/swr/render.js.map +1 -0
- package/lib/generators/{tanstack-query.d.ts → tanstack-query/index.d.ts} +3 -3
- package/lib/generators/tanstack-query/index.d.ts.map +1 -0
- package/lib/generators/{tanstack-query.js → tanstack-query/index.js} +11 -10
- package/lib/generators/tanstack-query/index.js.map +1 -0
- package/lib/{emitters/tanstack-query.d.ts → generators/tanstack-query/render.d.ts} +6 -5
- package/lib/generators/tanstack-query/render.d.ts.map +1 -0
- package/lib/{emitters/tanstack-query.js → generators/tanstack-query/render.js} +33 -21
- package/lib/generators/tanstack-query/render.js.map +1 -0
- package/lib/generators/{transformers.d.ts → transformers/index.d.ts} +2 -2
- package/lib/generators/transformers/index.d.ts.map +1 -0
- package/lib/generators/{transformers.js → transformers/index.js} +11 -8
- package/lib/generators/transformers/index.js.map +1 -0
- package/lib/{emitters/transformers.d.ts → generators/transformers/render.d.ts} +2 -2
- package/lib/generators/transformers/render.d.ts.map +1 -0
- package/lib/{emitters/transformers.js → generators/transformers/render.js} +125 -165
- package/lib/generators/transformers/render.js.map +1 -0
- package/lib/generators/types.d.ts +190 -12
- package/lib/generators/types.d.ts.map +1 -1
- package/lib/generators/typescript/banner.d.ts +12 -0
- package/lib/generators/typescript/banner.d.ts.map +1 -0
- package/lib/{emitters/emit-options.js → generators/typescript/banner.js} +2 -3
- package/lib/generators/typescript/banner.js.map +1 -0
- package/lib/generators/typescript/client.d.ts +25 -0
- package/lib/generators/typescript/client.d.ts.map +1 -0
- package/lib/generators/typescript/client.js +207 -0
- package/lib/generators/typescript/client.js.map +1 -0
- package/lib/generators/typescript/descriptor.d.ts +11 -0
- package/lib/generators/typescript/descriptor.d.ts.map +1 -0
- package/lib/generators/typescript/descriptor.js +97 -0
- package/lib/generators/typescript/descriptor.js.map +1 -0
- package/lib/generators/typescript/index.d.ts +20 -0
- package/lib/generators/typescript/index.d.ts.map +1 -0
- package/lib/generators/typescript/index.js +80 -0
- package/lib/generators/typescript/index.js.map +1 -0
- package/lib/generators/typescript/inline-runtime.d.ts +21 -0
- package/lib/generators/typescript/inline-runtime.d.ts.map +1 -0
- package/lib/generators/typescript/inline-runtime.js +114 -0
- package/lib/generators/typescript/inline-runtime.js.map +1 -0
- package/lib/generators/typescript/operation-signature.d.ts +23 -0
- package/lib/generators/typescript/operation-signature.d.ts.map +1 -0
- package/lib/generators/typescript/operation-signature.js +41 -0
- package/lib/generators/typescript/operation-signature.js.map +1 -0
- package/lib/generators/typescript/operation-types.d.ts +9 -0
- package/lib/generators/typescript/operation-types.d.ts.map +1 -0
- package/lib/generators/typescript/operation-types.js +11 -0
- package/lib/generators/typescript/operation-types.js.map +1 -0
- package/lib/generators/typescript/operations.d.ts +60 -0
- package/lib/generators/typescript/operations.d.ts.map +1 -0
- package/lib/generators/typescript/operations.js +386 -0
- package/lib/generators/typescript/operations.js.map +1 -0
- package/lib/generators/typescript/response-headers.d.ts +12 -0
- package/lib/generators/typescript/response-headers.d.ts.map +1 -0
- package/lib/generators/typescript/response-headers.js +40 -0
- package/lib/generators/typescript/response-headers.js.map +1 -0
- package/lib/generators/typescript/runtime/auth.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/auth.js.map +1 -0
- package/lib/{runtime → generators/typescript/runtime}/create-client.d.ts +7 -2
- package/lib/generators/typescript/runtime/create-client.d.ts.map +1 -0
- package/lib/{runtime → generators/typescript/runtime}/create-client.js +84 -30
- package/lib/generators/typescript/runtime/create-client.js.map +1 -0
- package/lib/generators/typescript/runtime/errors.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/errors.js.map +1 -0
- package/lib/generators/typescript/runtime/index.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/index.js.map +1 -0
- package/lib/generators/typescript/runtime/multipart.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/multipart.js.map +1 -0
- package/lib/{runtime → generators/typescript/runtime}/paginate.d.ts +2 -2
- package/lib/generators/typescript/runtime/paginate.d.ts.map +1 -0
- package/lib/{runtime → generators/typescript/runtime}/paginate.js +12 -12
- package/lib/generators/typescript/runtime/paginate.js.map +1 -0
- package/lib/generators/typescript/runtime/parse.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/parse.js.map +1 -0
- package/lib/generators/typescript/runtime/retry.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/retry.js.map +1 -0
- package/lib/generators/typescript/runtime/send.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/send.js.map +1 -0
- package/lib/generators/typescript/runtime/setup.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/setup.js.map +1 -0
- package/lib/generators/typescript/runtime/sse.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/sse.js.map +1 -0
- package/lib/{runtime → generators/typescript/runtime}/types.d.ts +17 -95
- package/lib/generators/typescript/runtime/types.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/types.js.map +1 -0
- package/lib/generators/typescript/runtime/url.d.ts.map +1 -0
- package/lib/generators/typescript/runtime/url.js.map +1 -0
- package/lib/generators/typescript/type-guards.d.ts +4 -0
- package/lib/generators/typescript/type-guards.d.ts.map +1 -0
- package/lib/{emitters → generators/typescript}/type-guards.js +18 -52
- package/lib/generators/typescript/type-guards.js.map +1 -0
- package/lib/generators/typescript/types.d.ts +8 -0
- package/lib/generators/typescript/types.d.ts.map +1 -0
- package/lib/generators/typescript/types.js +132 -0
- package/lib/generators/typescript/types.js.map +1 -0
- package/lib/generators/{zod.d.ts → zod/index.d.ts} +2 -2
- package/lib/generators/zod/index.d.ts.map +1 -0
- package/lib/generators/{zod.js → zod/index.js} +5 -7
- package/lib/generators/zod/index.js.map +1 -0
- package/lib/{emitters/zod.d.ts → generators/zod/schemas.d.ts} +4 -5
- package/lib/generators/zod/schemas.d.ts.map +1 -0
- package/lib/{emitters/zod.js → generators/zod/schemas.js} +118 -154
- package/lib/generators/zod/schemas.js.map +1 -0
- package/lib/index.d.ts +8 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +18 -11
- package/lib/index.js.map +1 -1
- package/lib/intermediate-representation/build.d.ts +8 -1
- package/lib/intermediate-representation/build.d.ts.map +1 -1
- package/lib/intermediate-representation/build.js +59 -4
- package/lib/intermediate-representation/build.js.map +1 -1
- package/lib/intermediate-representation/model.d.ts +26 -1
- package/lib/intermediate-representation/model.d.ts.map +1 -1
- package/lib/intermediate-representation/model.js.map +1 -1
- package/lib/intermediate-representation/sanitize-identifiers.d.ts +1 -10
- package/lib/intermediate-representation/sanitize-identifiers.d.ts.map +1 -1
- package/lib/intermediate-representation/sanitize-identifiers.js +37 -38
- package/lib/intermediate-representation/sanitize-identifiers.js.map +1 -1
- package/lib/{emitters/pagination.d.ts → pagination.d.ts} +39 -15
- package/lib/pagination.d.ts.map +1 -0
- package/lib/{emitters/pagination.js → pagination.js} +13 -52
- package/lib/pagination.js.map +1 -0
- package/lib/pipeline.d.ts +17 -0
- package/lib/pipeline.d.ts.map +1 -0
- package/lib/pipeline.js +244 -0
- package/lib/pipeline.js.map +1 -0
- package/lib/plugin.d.ts +4 -4
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +12 -9
- package/lib/plugin.js.map +1 -1
- package/lib/printers/go.d.ts +33 -0
- package/lib/printers/go.d.ts.map +1 -0
- package/lib/printers/go.js +209 -0
- package/lib/printers/go.js.map +1 -0
- package/lib/printers/index.d.ts +5 -0
- package/lib/printers/index.d.ts.map +1 -0
- package/lib/printers/index.js +9 -0
- package/lib/printers/index.js.map +1 -0
- package/lib/printers/php.d.ts +21 -0
- package/lib/printers/php.d.ts.map +1 -0
- package/lib/printers/php.js +68 -0
- package/lib/printers/php.js.map +1 -0
- package/lib/printers/python.d.ts +31 -0
- package/lib/printers/python.d.ts.map +1 -0
- package/lib/printers/python.js +101 -0
- package/lib/printers/python.js.map +1 -0
- package/lib/printers/typescript.d.ts +82 -0
- package/lib/printers/typescript.d.ts.map +1 -0
- package/lib/printers/typescript.js +268 -0
- package/lib/printers/typescript.js.map +1 -0
- package/lib/reserved-names.d.ts +8 -0
- package/lib/reserved-names.d.ts.map +1 -0
- package/lib/{emitters/reserved-names.js → reserved-names.js} +16 -27
- package/lib/reserved-names.js.map +1 -0
- package/lib/runtime-contract.d.ts +62 -2
- package/lib/runtime-contract.d.ts.map +1 -1
- package/lib/runtime-contract.js +3 -3
- package/lib/runtime-contract.js.map +1 -1
- package/lib/runtime-sources/go.d.ts +2 -0
- package/lib/runtime-sources/go.d.ts.map +1 -0
- package/lib/runtime-sources/go.js +3 -0
- package/lib/runtime-sources/go.js.map +1 -0
- package/lib/runtime-sources/php.d.ts +2 -0
- package/lib/runtime-sources/php.d.ts.map +1 -0
- package/lib/runtime-sources/php.js +3 -0
- package/lib/runtime-sources/php.js.map +1 -0
- package/lib/runtime-sources/python.d.ts +12 -0
- package/lib/runtime-sources/python.d.ts.map +1 -0
- package/lib/runtime-sources/python.js +12 -0
- package/lib/runtime-sources/python.js.map +1 -0
- package/lib/runtime-sources/typescript.d.ts +36 -0
- package/lib/runtime-sources/typescript.d.ts.map +1 -0
- package/lib/runtime-sources/typescript.js +152 -0
- package/lib/runtime-sources/typescript.js.map +1 -0
- package/lib/runtime-sources.d.ts +5 -0
- package/lib/runtime-sources.d.ts.map +1 -0
- package/lib/runtime-sources.js +10 -0
- package/lib/runtime-sources.js.map +1 -0
- package/lib/setup-bake.d.ts.map +1 -0
- package/lib/{emitters/setup-bake.js → setup-bake.js} +11 -2
- package/lib/setup-bake.js.map +1 -0
- package/lib/types.d.ts +38 -8
- package/lib/types.d.ts.map +1 -1
- package/package.json +40 -4
- package/lib/emitters/auth.d.ts +0 -14
- package/lib/emitters/auth.d.ts.map +0 -1
- package/lib/emitters/auth.js +0 -30
- package/lib/emitters/auth.js.map +0 -1
- package/lib/emitters/client-assembly.d.ts +0 -15
- package/lib/emitters/client-assembly.d.ts.map +0 -1
- package/lib/emitters/client-assembly.js +0 -358
- package/lib/emitters/client-assembly.js.map +0 -1
- package/lib/emitters/descriptor.d.ts +0 -22
- package/lib/emitters/descriptor.d.ts.map +0 -1
- package/lib/emitters/descriptor.js +0 -199
- package/lib/emitters/descriptor.js.map +0 -1
- package/lib/emitters/emit-options.d.ts +0 -67
- package/lib/emitters/emit-options.d.ts.map +0 -1
- package/lib/emitters/emit-options.js.map +0 -1
- package/lib/emitters/faker.d.ts.map +0 -1
- package/lib/emitters/faker.js +0 -221
- package/lib/emitters/faker.js.map +0 -1
- package/lib/emitters/identifier.d.ts +0 -34
- package/lib/emitters/identifier.d.ts.map +0 -1
- package/lib/emitters/identifier.js +0 -104
- package/lib/emitters/identifier.js.map +0 -1
- package/lib/emitters/inline-runtime.d.ts +0 -11
- package/lib/emitters/inline-runtime.d.ts.map +0 -1
- package/lib/emitters/inline-runtime.js +0 -99
- package/lib/emitters/inline-runtime.js.map +0 -1
- package/lib/emitters/jsdoc.d.ts +0 -9
- package/lib/emitters/jsdoc.d.ts.map +0 -1
- package/lib/emitters/jsdoc.js +0 -83
- package/lib/emitters/jsdoc.js.map +0 -1
- package/lib/emitters/mock.d.ts.map +0 -1
- package/lib/emitters/mock.js +0 -265
- package/lib/emitters/mock.js.map +0 -1
- package/lib/emitters/operation-aliases.d.ts +0 -27
- package/lib/emitters/operation-aliases.d.ts.map +0 -1
- package/lib/emitters/operation-aliases.js +0 -150
- package/lib/emitters/operation-aliases.js.map +0 -1
- package/lib/emitters/operation-signature.d.ts +0 -24
- package/lib/emitters/operation-signature.d.ts.map +0 -1
- package/lib/emitters/operation-signature.js +0 -42
- package/lib/emitters/operation-signature.js.map +0 -1
- package/lib/emitters/operation-types.d.ts +0 -32
- package/lib/emitters/operation-types.d.ts.map +0 -1
- package/lib/emitters/operation-types.js +0 -117
- package/lib/emitters/operation-types.js.map +0 -1
- package/lib/emitters/operations.d.ts +0 -41
- package/lib/emitters/operations.d.ts.map +0 -1
- package/lib/emitters/operations.js +0 -35
- package/lib/emitters/operations.js.map +0 -1
- package/lib/emitters/pagination.d.ts.map +0 -1
- package/lib/emitters/pagination.js.map +0 -1
- package/lib/emitters/reserved-names.d.ts +0 -5
- package/lib/emitters/reserved-names.d.ts.map +0 -1
- package/lib/emitters/reserved-names.js.map +0 -1
- package/lib/emitters/response-headers.d.ts +0 -14
- package/lib/emitters/response-headers.d.ts.map +0 -1
- package/lib/emitters/response-headers.js +0 -91
- package/lib/emitters/response-headers.js.map +0 -1
- package/lib/emitters/runtime-sources.d.ts +0 -16
- package/lib/emitters/runtime-sources.d.ts.map +0 -1
- package/lib/emitters/runtime-sources.js +0 -16
- package/lib/emitters/runtime-sources.js.map +0 -1
- package/lib/emitters/sample.d.ts.map +0 -1
- package/lib/emitters/sample.js.map +0 -1
- package/lib/emitters/setup-bake.d.ts.map +0 -1
- package/lib/emitters/setup-bake.js.map +0 -1
- package/lib/emitters/sse.d.ts +0 -10
- package/lib/emitters/sse.d.ts.map +0 -1
- package/lib/emitters/sse.js +0 -46
- package/lib/emitters/sse.js.map +0 -1
- package/lib/emitters/support.d.ts +0 -18
- package/lib/emitters/support.d.ts.map +0 -1
- package/lib/emitters/support.js +0 -37
- package/lib/emitters/support.js.map +0 -1
- package/lib/emitters/swr.d.ts.map +0 -1
- package/lib/emitters/swr.js +0 -88
- package/lib/emitters/swr.js.map +0 -1
- package/lib/emitters/tanstack-query.d.ts.map +0 -1
- package/lib/emitters/tanstack-query.js.map +0 -1
- package/lib/emitters/transformers.d.ts.map +0 -1
- package/lib/emitters/transformers.js.map +0 -1
- package/lib/emitters/ts.d.ts +0 -42
- package/lib/emitters/ts.d.ts.map +0 -1
- package/lib/emitters/ts.js +0 -116
- package/lib/emitters/ts.js.map +0 -1
- package/lib/emitters/type-guards.d.ts +0 -21
- package/lib/emitters/type-guards.d.ts.map +0 -1
- package/lib/emitters/type-guards.js.map +0 -1
- package/lib/emitters/types.d.ts +0 -15
- package/lib/emitters/types.d.ts.map +0 -1
- package/lib/emitters/types.js +0 -125
- package/lib/emitters/types.js.map +0 -1
- package/lib/emitters/wrapper-support.d.ts.map +0 -1
- package/lib/emitters/wrapper-support.js +0 -127
- package/lib/emitters/wrapper-support.js.map +0 -1
- package/lib/emitters/zod.d.ts.map +0 -1
- package/lib/emitters/zod.js.map +0 -1
- package/lib/generators/anchor.d.ts +0 -9
- package/lib/generators/anchor.d.ts.map +0 -1
- package/lib/generators/anchor.js +0 -10
- package/lib/generators/anchor.js.map +0 -1
- package/lib/generators/mock.d.ts.map +0 -1
- package/lib/generators/mock.js.map +0 -1
- package/lib/generators/sdk.d.ts +0 -12
- package/lib/generators/sdk.d.ts.map +0 -1
- package/lib/generators/sdk.js +0 -26
- package/lib/generators/sdk.js.map +0 -1
- package/lib/generators/swr.d.ts.map +0 -1
- package/lib/generators/swr.js.map +0 -1
- package/lib/generators/tanstack-query.d.ts.map +0 -1
- package/lib/generators/tanstack-query.js.map +0 -1
- package/lib/generators/transformers.d.ts.map +0 -1
- package/lib/generators/transformers.js.map +0 -1
- package/lib/generators/zod.d.ts.map +0 -1
- package/lib/generators/zod.js.map +0 -1
- package/lib/runtime/auth.d.ts.map +0 -1
- package/lib/runtime/auth.js.map +0 -1
- package/lib/runtime/create-client.d.ts.map +0 -1
- package/lib/runtime/create-client.js.map +0 -1
- package/lib/runtime/errors.d.ts.map +0 -1
- package/lib/runtime/errors.js.map +0 -1
- package/lib/runtime/index.d.ts.map +0 -1
- package/lib/runtime/index.js.map +0 -1
- package/lib/runtime/multipart.d.ts.map +0 -1
- package/lib/runtime/multipart.js.map +0 -1
- package/lib/runtime/paginate.d.ts.map +0 -1
- package/lib/runtime/paginate.js.map +0 -1
- package/lib/runtime/parse.d.ts.map +0 -1
- package/lib/runtime/parse.js.map +0 -1
- package/lib/runtime/retry.d.ts.map +0 -1
- package/lib/runtime/retry.js.map +0 -1
- package/lib/runtime/send.d.ts.map +0 -1
- package/lib/runtime/send.js.map +0 -1
- package/lib/runtime/setup.d.ts.map +0 -1
- package/lib/runtime/setup.js.map +0 -1
- package/lib/runtime/sse.d.ts.map +0 -1
- package/lib/runtime/sse.js.map +0 -1
- package/lib/runtime/types.d.ts.map +0 -1
- package/lib/runtime/types.js.map +0 -1
- package/lib/runtime/url.d.ts.map +0 -1
- package/lib/runtime/url.js.map +0 -1
- /package/lib/{emitters → generators/mock}/sample.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/auth.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/auth.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/errors.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/errors.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/index.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/index.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/multipart.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/multipart.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/parse.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/parse.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/retry.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/retry.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/send.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/send.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/setup.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/setup.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/sse.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/sse.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/types.js +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/url.d.ts +0 -0
- /package/lib/{runtime → generators/typescript/runtime}/url.js +0 -0
- /package/lib/{emitters/setup-bake.d.ts → setup-bake.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -10,8 +10,8 @@ See https://github.com/Redocly/redocly-cli for the full project.
|
|
|
10
10
|
|
|
11
11
|
The generated client uses only web-standard APIs (`fetch`, `AbortController`, `URLSearchParams`), so by default it is a single self-contained file with zero runtime dependencies that runs in browsers, Node ≥ 18, Bun, Deno, and edge runtimes.
|
|
12
12
|
(Running the generator itself requires the Node version in this package's `engines` field.)
|
|
13
|
-
Code is
|
|
14
|
-
Apps that only consume a
|
|
13
|
+
Code is printed through per-language text printers; `typescript` is the only peer dependency — optional, needed only when generation bakes a `--setup` module, and it must be 6.x there (TypeScript 7's native compiler has no compiler API).
|
|
14
|
+
Apps that only consume a generated client don't need it at all, and can compile the generated code with any TypeScript, including 7.
|
|
15
15
|
|
|
16
16
|
This package is the engine behind the [`generate-client` command](https://redocly.com/docs/cli/commands/generate-client) — install [`@redocly/cli`](https://www.npmjs.com/package/@redocly/cli) to run it from the command line or `redocly.yaml`.
|
|
17
17
|
How to use the generated client — auth, middleware, retries, pagination, Server-Sent Events, and the add-on generators (`zod`, `tanstack-query`, `swr`, `mock`, `transformers`) — is documented in [Use the generated client](https://redocly.com/docs/cli/guides/use-generated-client).
|
|
@@ -27,7 +27,7 @@ import { generateClient } from '@redocly/client-generator';
|
|
|
27
27
|
const result = await generateClient({
|
|
28
28
|
api: './openapi.yaml', // file path or URL; OpenAPI 3.0/3.1/3.2 or Swagger 2.0
|
|
29
29
|
output: './src/api/client.ts',
|
|
30
|
-
generators: ['
|
|
30
|
+
generators: ['typescript', 'zod'],
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
console.log(`Wrote ${result.files.length} file(s), ${result.bytes} bytes.`);
|
|
@@ -41,8 +41,7 @@ For type-safe authoring of a standalone options object, annotate it with `satisf
|
|
|
41
41
|
The generated module exports its operation descriptors, so an app can build additional instances with independent configuration and credentials over the same generated code:
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
|
-
import { createClient } from '
|
|
45
|
-
import { OPERATIONS, type Ops } from './client.ts';
|
|
44
|
+
import { createClient, OPERATIONS, type Ops } from './client.ts';
|
|
46
45
|
|
|
47
46
|
const internal = createClient<Ops>(OPERATIONS, {
|
|
48
47
|
serverUrl: 'https://api.example.com',
|
|
@@ -50,48 +49,35 @@ const internal = createClient<Ops>(OPERATIONS, {
|
|
|
50
49
|
});
|
|
51
50
|
```
|
|
52
51
|
|
|
53
|
-
With `runtime: 'package'` the generated client also imports its whole engine from this package (instead of embedding it), so engine fixes arrive via `npm update` — install this package as a regular dependency of the consuming app.
|
|
54
|
-
|
|
55
52
|
### Write a custom generator
|
|
56
53
|
|
|
57
54
|
A custom generator reads the same API model the built-ins consume, runs in the same pass, and returns files.
|
|
58
|
-
|
|
55
|
+
Generators print text: `Printer` handles indentation, and `tsType` is the same schema→type renderer the built-in sdk uses, so the mapping (refs, arrays, unions, formats, parenthesization) matches the generated client exactly:
|
|
59
56
|
|
|
60
57
|
```ts
|
|
61
58
|
// response-map-generator.ts
|
|
62
|
-
import { defineGenerator } from '@redocly/client-generator';
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
const { factory } = ts;
|
|
59
|
+
import { defineGenerator, Printer } from '@redocly/client-generator';
|
|
60
|
+
import { tsType } from '@redocly/client-generator/generate';
|
|
66
61
|
|
|
67
62
|
export default defineGenerator({
|
|
68
63
|
name: 'response-map',
|
|
69
|
-
requires: ['
|
|
70
|
-
run({ model,
|
|
64
|
+
requires: ['typescript'],
|
|
65
|
+
run({ model, output }) {
|
|
66
|
+
const printer = new Printer();
|
|
71
67
|
// One `ResponseShapes` entry per operation with a JSON success body.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
),
|
|
84
|
-
];
|
|
85
|
-
});
|
|
86
|
-
const alias = factory.createTypeAliasDeclaration(
|
|
87
|
-
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
88
|
-
'ResponseShapes',
|
|
89
|
-
undefined,
|
|
90
|
-
factory.createTypeLiteralNode(members)
|
|
68
|
+
printer.block(
|
|
69
|
+
'export type ResponseShapes = {',
|
|
70
|
+
() => {
|
|
71
|
+
for (const service of model.services) {
|
|
72
|
+
for (const op of service.operations) {
|
|
73
|
+
const success = op.successResponses.find((r) => r.contentType.includes('json'));
|
|
74
|
+
if (success) printer.line(`${op.name}: ${tsType(success.schema)};`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
'};'
|
|
91
79
|
);
|
|
92
|
-
return [
|
|
93
|
-
{ path: outputPath.replace(/\.ts$/, '.responses.ts'), content: printStatements([alias]) },
|
|
94
|
-
];
|
|
80
|
+
return [{ path: output.path.replace(/\.ts$/, '.responses.ts'), content: printer.toString() }];
|
|
95
81
|
},
|
|
96
82
|
});
|
|
97
83
|
```
|
|
@@ -122,12 +108,12 @@ type GenerateClientResult = {
|
|
|
122
108
|
};
|
|
123
109
|
```
|
|
124
110
|
|
|
125
|
-
`GenerateClientOptions` is the options type ([`src/types.ts`](https://github.com/Redocly/redocly-cli/blob/main/packages/client-generator/src/types.ts)) (`api` and `output` required; `outputMode`, `runtime`, `importExt`, `argsStyle`, `errorMode`, `dateType`, `serverUrl`, `mockData`, `mockSeed`, `generators`, `customGenerators`, `setup`, `pagination` optional) plus an optional resolved Redocly `config` used to load the description.
|
|
111
|
+
`GenerateClientOptions` is the options type ([`src/types.ts`](https://github.com/Redocly/redocly-cli/blob/main/packages/client-generator/src/types.ts)) (`api` and `output` required; `outputMode`, `runtime`, `importExt`, `argsStyle`, `errorMode`, `dateType`, `serverUrl`, `mockData`, `mockSeed`, `generators`, `customGenerators`, `options`, `setup`, `pagination`, `queryKeyPrefix`, `goPackage`, `cliOutput`, `codeSamples`, `docs`, `docsFrontmatter` optional) plus an optional resolved Redocly `config` used to load the description.
|
|
126
112
|
|
|
127
113
|
### `collectGeneratedFiles`
|
|
128
114
|
|
|
129
115
|
Runs the configured generators against a built model and returns the files in memory, without writing to disk.
|
|
130
|
-
Imported from `@redocly/client-generator/generate` — the generation-time entry; the package root stays
|
|
116
|
+
Imported from `@redocly/client-generator/generate` — the generation-time entry; the package root stays a small authoring surface:
|
|
131
117
|
|
|
132
118
|
```ts
|
|
133
119
|
function collectGeneratedFiles(
|
|
@@ -144,13 +130,16 @@ function collectGeneratedFiles(
|
|
|
144
130
|
|
|
145
131
|
### `defineGenerator`
|
|
146
132
|
|
|
147
|
-
Authors a custom generator (`{ name, run }` plus optional `requires`/`errorModes`/`dateTypes
|
|
133
|
+
Authors a custom generator (`{ name, run }` plus optional `requires`/`errorModes`/`dateTypes` compatibility metadata, validated up front):
|
|
148
134
|
|
|
149
135
|
```ts
|
|
150
136
|
function defineGenerator(generator: CustomGenerator): CustomGenerator;
|
|
151
137
|
```
|
|
152
138
|
|
|
153
|
-
The `@redocly/client-generator/generate` entry also exports the
|
|
139
|
+
The `@redocly/client-generator/generate` entry also exports the TypeScript renderers the built-ins use (`tsType`, `tsJsdoc`, `codeLiteral`, `operationSignature`, `pascalCase`, `safeIdent`).
|
|
140
|
+
The package root exports the IR types plus the language-neutral toolkit.
|
|
141
|
+
A custom generator emits TypeScript exactly as the first-party ones do.
|
|
142
|
+
See the [`typescript-types-generator` example](https://github.com/Redocly/redocly-cli/tree/main/tests/e2e/generate-client/examples/typescript-types-generator).
|
|
154
143
|
|
|
155
144
|
### `defineClientSetup`
|
|
156
145
|
|
|
@@ -165,20 +154,9 @@ function defineClientSetup(setup: {
|
|
|
165
154
|
|
|
166
155
|
A setup module may import only from `@redocly/client-generator`, so it never adds a dependency to the client (the import is stripped at generation time).
|
|
167
156
|
|
|
168
|
-
### `createClient`
|
|
169
|
-
|
|
170
|
-
The runtime factory that `runtime: 'package'` clients import, also usable directly to build extra instances over generated descriptors (see [Basic usage](#build-extra-client-instances)):
|
|
171
|
-
|
|
172
|
-
```ts
|
|
173
|
-
function createClient<Ops>(
|
|
174
|
-
operations: Record<string, OperationDescriptor>,
|
|
175
|
-
config?: ClientConfig
|
|
176
|
-
): Client<Ops>;
|
|
177
|
-
```
|
|
178
|
-
|
|
179
157
|
## Examples
|
|
180
158
|
|
|
181
|
-
Runnable examples — from a zero-install quickstart to middleware, publisher setup, SSE streaming, pagination, custom generators
|
|
159
|
+
Runnable examples — from a zero-install quickstart to middleware, publisher setup, SSE streaming, pagination, and custom generators — live in [`tests/e2e/generate-client/examples`](https://github.com/Redocly/redocly-cli/tree/main/tests/e2e/generate-client/examples).
|
|
182
160
|
Each is a standalone Vite app with a checked-in, drift-checked generated client.
|
|
183
161
|
|
|
184
162
|
## Documentation
|
|
@@ -195,8 +173,8 @@ Run all commands from the repo root:
|
|
|
195
173
|
|
|
196
174
|
```sh
|
|
197
175
|
npm run compile # build this package
|
|
198
|
-
npm run unit # unit tests
|
|
176
|
+
npm run unit # unit tests
|
|
199
177
|
VITEST_SUITE=e2e npx vitest run tests/e2e/generate-client/ # behavioral e2e
|
|
200
178
|
```
|
|
201
179
|
|
|
202
|
-
|
|
180
|
+
Each generator that embeds a runtime keeps its sources in its own folder (`src/generators/<name>/runtime/` — real, unit-testable modules that generation embeds), the IR lives in `src/intermediate-representation/`, and the generators in `src/generators/`.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Writing custom client generators
|
|
2
|
+
|
|
3
|
+
A generator is a plain module: `(input) => GeneratedFile[]`. It receives the
|
|
4
|
+
language-agnostic API model and returns files — in ANY output language. It runs
|
|
5
|
+
in the same pass as the built-ins; select it by path in `redocly.yaml`:
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
client:
|
|
9
|
+
generators: [typescript, ./generators/my-generator.mjs]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## The contract
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
/** @type {import('@redocly/client-generator').CustomGenerator} */
|
|
16
|
+
export default {
|
|
17
|
+
name: 'my-generator',
|
|
18
|
+
run({ model, output, outputMode, emit }) {
|
|
19
|
+
return [{ path: output.path.replace(/\.ts$/, '.mine.txt'), content: '…' }];
|
|
20
|
+
},
|
|
21
|
+
// Optional: one idiomatic call snippet per operation for docs (x-codeSamples),
|
|
22
|
+
// collected into an overlay file when `client.codeSamples: true` is set.
|
|
23
|
+
sample(operation, { model, emit }) {
|
|
24
|
+
return { lang: 'python', source: '…' };
|
|
25
|
+
},
|
|
26
|
+
// Optional: the reference page for what `run` emits, written when `client.docs` (or
|
|
27
|
+
// --docs) is on. Same `{ path, content }` shape as `run`; `renderReferencePage` gives
|
|
28
|
+
// the standard layout and takes `sample` for its snippets. A generator documents itself.
|
|
29
|
+
docs({ model, output, emit }) {
|
|
30
|
+
return [{ path: output.path.replace(/\.ts$/, '.mine.md'), content: '…' }];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Declaring options
|
|
36
|
+
|
|
37
|
+
A generator that needs configuration declares it as a schema; `run` then receives
|
|
38
|
+
`options` already validated, with defaults applied:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
export default {
|
|
42
|
+
name: 'permissions-matrix',
|
|
43
|
+
options: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: { groupBy: { enum: ['tag', 'path'], default: 'tag' } },
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
run({ model, output, options }) {
|
|
49
|
+
return [
|
|
50
|
+
{ path: output.path.replace(/\.ts$/, '.permissions.md'), content: render(options.groupBy) },
|
|
51
|
+
];
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Users set them per generator name:
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
client:
|
|
60
|
+
generators: [typescript, ./generators/permissions-matrix.mjs]
|
|
61
|
+
options:
|
|
62
|
+
permissions-matrix:
|
|
63
|
+
groupBy: path
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The supported subset is a top-level `type: 'object'` with `properties`, `required`, and
|
|
67
|
+
`additionalProperties`; each property is a scalar (`string`/`number`/`boolean`), an
|
|
68
|
+
`enum`, or an array of scalars, and may carry a `default` and a `description`. Don't
|
|
69
|
+
validate options inside `run` — an unknown key, a wrong type, a value outside an `enum`,
|
|
70
|
+
or a missing `required` key already fails generation before `run` is called.
|
|
71
|
+
|
|
72
|
+
Rules: output is deterministic (same description → same bytes); never add
|
|
73
|
+
dependencies to the generated client; **never hand-edit generated output** —
|
|
74
|
+
edit this generator and regenerate. Emitted file paths must stay inside the
|
|
75
|
+
`--output` directory (subdirectories are fine) — escapes are rejected.
|
|
76
|
+
Optionally declare `requiresGenerator` — the `@redocly/client-generator` version
|
|
77
|
+
range you wrote this against (`'^1.2.0'`, `'~1.2.0'`, `'>=1.2.0'`, or an exact
|
|
78
|
+
version). A CLI outside the range then fails with the fix path instead of feeding
|
|
79
|
+
your generator an unexpected model shape. Ejected generators carry it
|
|
80
|
+
automatically; hand-written ones without it are taken as current.
|
|
81
|
+
|
|
82
|
+
## The model (IR)
|
|
83
|
+
|
|
84
|
+
`model.services[].operations[]` — each operation carries `name`, `specName`,
|
|
85
|
+
`method`, `path`, `tags`, `pathParams`/`queryParams`/`headerParams`/`cookieParams`,
|
|
86
|
+
`requestBody`, `successResponses`/`errorResponses` (each with a `schema`), and
|
|
87
|
+
`security`. `model.schemas` holds the named schemas. Every schema is a
|
|
88
|
+
discriminated union on `kind`: `scalar`, `array`, `object`, `record`, `ref`,
|
|
89
|
+
`literal`, `enum`, `union` (optionally with a discriminator), `intersection`
|
|
90
|
+
(allOf), `null`, `unknown`, `omit`.
|
|
91
|
+
|
|
92
|
+
## Helpers (import from '@redocly/client-generator')
|
|
93
|
+
|
|
94
|
+
| Helper | Use |
|
|
95
|
+
| ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
96
|
+
| `flattenAllOf(schema, model)` | The merged property view of allOf compositions — languages without intersection types render this. |
|
|
97
|
+
| `deref(schema, model)` | Follow a `ref` chain to the schema it names (cycle-guarded). |
|
|
98
|
+
| `jsonSuccessSchema(op)` / `sseResponse(op)` | The primary JSON success schema; the `text/event-stream` response when the operation streams. |
|
|
99
|
+
| `isMultipartBody(op)` | Whether the request body is multipart. |
|
|
100
|
+
| `serverUrlParts(server)` | A server-URL template as literal/variable parts, ready for any concatenation syntax. |
|
|
101
|
+
| `securityRequirements(op, model)` | The operation's security as OR-alternatives of AND-sets, denormalized against the declared schemes. |
|
|
102
|
+
| `paginationItemSchema(pageSchema, itemsPointer, model)` | The raw element schema behind a pagination rule's `items` pointer — a `ref` element keeps its name. |
|
|
103
|
+
| `discriminatorCases(schema, model)` | `{ property, cases }` dispatch table for discriminated unions. |
|
|
104
|
+
| `isNullable(schema)` / `unwrapNullable(schema)` | Detect and strip `null` union members (`Optional[T]`, pointers, `Option<T>`). |
|
|
105
|
+
| `enumValues(schema)` | Values plus SCREAMING_SNAKE member-name suggestions. |
|
|
106
|
+
| `headerCoerceType(schema, model)` | Response-header coerce hint (`integer`/`number`/`boolean`/`string`) through refs, nullables, and allOf wrappers. |
|
|
107
|
+
| `casing` / `identifierFor(name, { style, reserved })` | camel/pascal/snake/screaming; keyword-safe identifiers (`RESERVED_WORDS.python/go/typescript` shipped). |
|
|
108
|
+
| `uniqueIdentifiers(names, { style, reserved, taken })` | The same, made unique among themselves and among names you already took — for a signature that takes one argument per parameter. |
|
|
109
|
+
| `Printer` | Indentation-aware text builder — no manual whitespace bookkeeping. |
|
|
110
|
+
| `docText(description)` | Description as trimmed lines for any comment syntax. |
|
|
111
|
+
| `schemaAtPointer(schema, pointer, model)` | Resolve an RFC 6901 JSON pointer over a schema (through refs and allOf) — e.g. a pagination `items` pointer to its element type. |
|
|
112
|
+
| `paginationRuleFor(op, config)` | The pagination rule that applies to an operation (per-op config > extension > fitting convention), normalized. |
|
|
113
|
+
| `renderReferencePage(model, options)` | The Markdown reference page a generator's `docs` hook returns — your `sample` hook supplies its call snippets. |
|
|
114
|
+
| `NotSupportedError` | Throw it to reject an option the generator can't honor — the CLI prints the message as a user error, not a crash. |
|
|
115
|
+
| `AUTHORING_HELPER_NAMES` | The list of the above (introspection). |
|
|
116
|
+
|
|
117
|
+
Worked example: the built-in `python` generator
|
|
118
|
+
(`packages/client-generator/src/generators/python/index.ts` in the Redocly CLI repo) is
|
|
119
|
+
authored with exactly this toolkit and nothing else — models via `flattenAllOf`/
|
|
120
|
+
`enumValues`/`discriminatorCases`, all code through `Printer`, every name through
|
|
121
|
+
`identifierFor(..., RESERVED_WORDS.python)`.
|
|
122
|
+
|
|
123
|
+
A generator that emits TypeScript may additionally use the source-text renderers from
|
|
124
|
+
`@redocly/client-generator/generate` — `tsType` (schema → type), `tsJsdoc`, `codeLiteral`,
|
|
125
|
+
`operationSignature`, `pascalCase`, `safeIdent`. There is no AST toolkit and no
|
|
126
|
+
`typescript` dependency: every generator prints text through `Printer`.
|
|
127
|
+
|
|
128
|
+
## The loop
|
|
129
|
+
|
|
130
|
+
1. Edit the generator.
|
|
131
|
+
2. Run `redocly generate-client`.
|
|
132
|
+
3. Inspect `git diff` of the generated output.
|
|
133
|
+
4. Repeat. Generated files are never hand-edited.
|
|
134
|
+
|
|
135
|
+
If you had to work around a **missing helper** or a wrong default, tell the user
|
|
136
|
+
and suggest filing an issue at https://github.com/Redocly/redocly-cli/issues —
|
|
137
|
+
include the generator snippet and the helper you expected to exist.
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Ejected from @redocly/client-generator@0.4.0 — the built-in "cli" generator.
|
|
2
|
+
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
|
+
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
|
+
// `redocly eject-generator cli --update`.
|
|
5
|
+
// The cli-docs emitter: renders the Markdown reference for the generated CLI from the
|
|
6
|
+
// SAME command table `runCli` dispatches on, and the same `groupSlug`/`constantCase` the
|
|
7
|
+
// runtime addresses groups and reads credentials with. A second model would drift from
|
|
8
|
+
// the tool the first time either side changed.
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
type CliCommand,
|
|
12
|
+
type CliFlag,
|
|
13
|
+
constantCase,
|
|
14
|
+
groupSlug,
|
|
15
|
+
Printer,
|
|
16
|
+
} from '@redocly/client-generator';
|
|
17
|
+
|
|
18
|
+
export type CliDocsOptions = {
|
|
19
|
+
/** Page heading. */
|
|
20
|
+
title: string;
|
|
21
|
+
/** Emit YAML front matter carrying the title, for docs sites that expect it. */
|
|
22
|
+
frontmatter: boolean;
|
|
23
|
+
/** The generated file's stem: what the page calls the command, and what its credential
|
|
24
|
+
* variables derive from. A reader who installs it under another bin name renames only
|
|
25
|
+
* the command — the variables are fixed at generation. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Auth schemes the description declares, in the order the CLI resolves them. */
|
|
28
|
+
schemes: Array<{ key: string; kind: 'bearer' | 'basic' | 'apiKey' }>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Table-cell-safe text: one line, and pipes/backslashes escaped so they don't alter columns/escaping. */
|
|
32
|
+
function cell(text: string | undefined): string {
|
|
33
|
+
return (text ?? '').replace(/\s+/g, ' ').trim().replace(/\\/g, '\\\\').replace(/\|/g, '\\|');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** How a command is typed at the prompt: `<group-slug> <name>`, or just `<name>`. */
|
|
37
|
+
function address(command: CliCommand): string {
|
|
38
|
+
return [command.group === undefined ? undefined : groupSlug(command.group), command.name]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(' ');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function usageLine(name: string, command: CliCommand): string {
|
|
44
|
+
const words = [
|
|
45
|
+
name,
|
|
46
|
+
address(command),
|
|
47
|
+
...command.positionals.map((positional) => `<${positional.name}>`),
|
|
48
|
+
...command.flags.filter((flag) => flag.required).map((flag) => `--${flag.name} <${flag.type}>`),
|
|
49
|
+
...(command.body ? [command.body.required ? "--json '<json>'" : "[--json '<json>']"] : []),
|
|
50
|
+
];
|
|
51
|
+
return words.filter((word) => word !== '').join(' ');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function writeFlagTable(printer: Printer, flags: CliFlag[]): void {
|
|
55
|
+
printer.line('| Flag | Type | Required | Description |');
|
|
56
|
+
printer.line('| ---- | ---- | -------- | ----------- |');
|
|
57
|
+
for (const flag of flags) {
|
|
58
|
+
const description = [
|
|
59
|
+
cell(flag.description),
|
|
60
|
+
flag.enum === undefined
|
|
61
|
+
? ''
|
|
62
|
+
: `One of ${flag.enum.map((value) => `\`${value}\``).join(', ')}.`,
|
|
63
|
+
flag.type === 'array' ? 'Repeat the flag for multiple values.' : '',
|
|
64
|
+
]
|
|
65
|
+
.filter((part) => part !== '')
|
|
66
|
+
.join(' ');
|
|
67
|
+
printer.line(
|
|
68
|
+
`| \`--${flag.name}\` | ${flag.type} | ${flag.required ? 'yes' : 'no'} | ${description} |`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
printer.blank();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function writeCommand(printer: Printer, command: CliCommand, options: CliDocsOptions): void {
|
|
75
|
+
printer.line(`### \`${address(command)}\``);
|
|
76
|
+
printer.blank();
|
|
77
|
+
if (command.summary !== undefined) {
|
|
78
|
+
printer.line(cell(command.summary));
|
|
79
|
+
printer.blank();
|
|
80
|
+
}
|
|
81
|
+
printer.line(`\`${command.method} ${command.path}\``);
|
|
82
|
+
printer.blank();
|
|
83
|
+
printer.line('```sh');
|
|
84
|
+
printer.line(usageLine(options.name, command));
|
|
85
|
+
printer.line('```');
|
|
86
|
+
printer.blank();
|
|
87
|
+
if (command.positionals.length > 0) {
|
|
88
|
+
printer.line('| Argument | Description |');
|
|
89
|
+
printer.line('| -------- | ----------- |');
|
|
90
|
+
for (const positional of command.positionals) {
|
|
91
|
+
printer.line(`| \`<${positional.name}>\` | ${cell(positional.description)} |`);
|
|
92
|
+
}
|
|
93
|
+
printer.blank();
|
|
94
|
+
}
|
|
95
|
+
if (command.flags.length > 0) writeFlagTable(printer, command.flags);
|
|
96
|
+
const notes = [
|
|
97
|
+
command.body === undefined
|
|
98
|
+
? ''
|
|
99
|
+
: `Takes a JSON body${command.body.required ? ' (required)' : ''}: \`--json '<json>'\`, \`--json @file.json\`, or \`--json @-\` for stdin.`,
|
|
100
|
+
command.unsupportedBody === undefined
|
|
101
|
+
? ''
|
|
102
|
+
: `Takes a \`${command.unsupportedBody}\` body, which the CLI cannot build — call this operation through the generated client instead.`,
|
|
103
|
+
command.paginated === true
|
|
104
|
+
? 'Paginated: `--page-all` follows every page, printing one JSON page per line.'
|
|
105
|
+
: '',
|
|
106
|
+
command.sse === true ? 'Streams server-sent events as one JSON object per line.' : '',
|
|
107
|
+
command.blob === true ? 'Returns binary content, so `--output <path>` is required.' : '',
|
|
108
|
+
].filter((note) => note !== '');
|
|
109
|
+
for (const note of notes) printer.line(note);
|
|
110
|
+
if (notes.length > 0) printer.blank();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The whole page: heading, global flags, credentials, exit codes, then every command. */
|
|
114
|
+
export function renderCliDocs(commands: CliCommand[], options: CliDocsOptions): string {
|
|
115
|
+
const printer = new Printer();
|
|
116
|
+
if (options.frontmatter) {
|
|
117
|
+
printer.line('---');
|
|
118
|
+
printer.line(`title: ${options.title}`);
|
|
119
|
+
printer.line('---');
|
|
120
|
+
printer.blank();
|
|
121
|
+
}
|
|
122
|
+
printer.line(`# ${options.title}`);
|
|
123
|
+
printer.blank();
|
|
124
|
+
printer.line(
|
|
125
|
+
`Generated command-line reference for \`${options.name}\`, produced from the API description by \`redocly generate-client\`.`
|
|
126
|
+
);
|
|
127
|
+
printer.line('Re-run generation to update it — this file is not hand-edited.');
|
|
128
|
+
printer.blank();
|
|
129
|
+
|
|
130
|
+
printer.line('## Usage');
|
|
131
|
+
printer.blank();
|
|
132
|
+
printer.line('```sh');
|
|
133
|
+
printer.line(`${options.name} <command> [flags]`);
|
|
134
|
+
printer.line(`${options.name} --help`);
|
|
135
|
+
printer.line(`${options.name} schema <command> # request/response schemas`);
|
|
136
|
+
printer.line('```');
|
|
137
|
+
printer.blank();
|
|
138
|
+
printer.line(
|
|
139
|
+
'Install the file under any `bin` name: the command takes that name, and the credential variables below do not change.'
|
|
140
|
+
);
|
|
141
|
+
printer.blank();
|
|
142
|
+
|
|
143
|
+
printer.line('## Global flags');
|
|
144
|
+
printer.blank();
|
|
145
|
+
printer.line('| Flag | Description |');
|
|
146
|
+
printer.line('| ---- | ----------- |');
|
|
147
|
+
// `--token` mirrors the CLI itself: without a bearer scheme the tool rejects the flag,
|
|
148
|
+
// so the reference must not list it.
|
|
149
|
+
const hasBearer = options.schemes.some((scheme) => scheme.kind === 'bearer');
|
|
150
|
+
for (const [flag, description] of [
|
|
151
|
+
['--server-url <url>', 'Override the server URL included in the client.'],
|
|
152
|
+
['--format <json\\|ndjson>', 'Output format.'],
|
|
153
|
+
['--dry-run', 'Print the prepared request, credentials redacted, without sending it.'],
|
|
154
|
+
['--page-all', 'Follow pagination, printing one JSON page per line.'],
|
|
155
|
+
['--output <path>', 'Write the response body to a file. Required for binary responses.'],
|
|
156
|
+
...(hasBearer ? [['--token <token>', 'Bearer token, overriding the environment.']] : []),
|
|
157
|
+
['--json <json\\|@file\\|@->', 'Request body, inline or from a file or stdin.'],
|
|
158
|
+
] as const) {
|
|
159
|
+
printer.line(`| \`${flag}\` | ${description} |`);
|
|
160
|
+
}
|
|
161
|
+
printer.blank();
|
|
162
|
+
|
|
163
|
+
const prefix = constantCase(options.name);
|
|
164
|
+
printer.line('## Credentials');
|
|
165
|
+
printer.blank();
|
|
166
|
+
if (options.schemes.length === 0) {
|
|
167
|
+
printer.line('The description declares no security schemes, so no credentials are read.');
|
|
168
|
+
} else {
|
|
169
|
+
printer.line('Credentials come from the environment:');
|
|
170
|
+
printer.blank();
|
|
171
|
+
printer.line('| Scheme | Variable |');
|
|
172
|
+
printer.line('| ------ | -------- |');
|
|
173
|
+
for (const scheme of options.schemes) {
|
|
174
|
+
const variable =
|
|
175
|
+
scheme.kind === 'bearer'
|
|
176
|
+
? `\`${prefix}_TOKEN\` (or \`--token\`)`
|
|
177
|
+
: scheme.kind === 'basic'
|
|
178
|
+
? `\`${prefix}_USERNAME\` and \`${prefix}_PASSWORD\``
|
|
179
|
+
: `\`${prefix}_API_KEY_${constantCase(scheme.key)}\``;
|
|
180
|
+
printer.line(`| ${scheme.kind} (\`${scheme.key}\`) | ${variable} |`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
printer.blank();
|
|
184
|
+
|
|
185
|
+
printer.line('## Exit codes');
|
|
186
|
+
printer.blank();
|
|
187
|
+
printer.line('| Code | Meaning |');
|
|
188
|
+
printer.line('| ---- | ------- |');
|
|
189
|
+
for (const [code, meaning] of [
|
|
190
|
+
[0, 'success'],
|
|
191
|
+
[1, 'API error (status other than 401 or 403)'],
|
|
192
|
+
[2, 'auth error (401 or 403)'],
|
|
193
|
+
[3, 'validation error'],
|
|
194
|
+
[4, 'usage error (unknown command or flag, bad `--json`)'],
|
|
195
|
+
] as const) {
|
|
196
|
+
printer.line(`| ${code} | ${meaning} |`);
|
|
197
|
+
}
|
|
198
|
+
printer.blank();
|
|
199
|
+
printer.line('Errors print one JSON object to stderr, so stdout stays clean for piping.');
|
|
200
|
+
printer.blank();
|
|
201
|
+
|
|
202
|
+
// One section per tag, in the order the description declares them, then the untagged
|
|
203
|
+
// commands — the same order `--help` lists them in.
|
|
204
|
+
const groups = [...new Set(commands.map((command) => command.group))];
|
|
205
|
+
for (const group of groups) {
|
|
206
|
+
const inGroup = commands.filter((command) => command.group === group);
|
|
207
|
+
if (group === undefined) {
|
|
208
|
+
printer.line('## Commands');
|
|
209
|
+
printer.blank();
|
|
210
|
+
} else {
|
|
211
|
+
printer.line(`## ${group}`);
|
|
212
|
+
printer.blank();
|
|
213
|
+
printer.line(`Addressed as \`${options.name} ${groupSlug(group)} <command>\`.`);
|
|
214
|
+
printer.blank();
|
|
215
|
+
}
|
|
216
|
+
for (const command of inGroup) writeCommand(printer, command, options);
|
|
217
|
+
}
|
|
218
|
+
return (
|
|
219
|
+
printer
|
|
220
|
+
.toString()
|
|
221
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
222
|
+
.trimEnd() + '\n'
|
|
223
|
+
);
|
|
224
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Ejected from @redocly/client-generator@0.4.0 — the built-in "cli" generator.
|
|
2
|
+
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
|
+
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
|
+
// `redocly eject-generator cli --update`.
|
|
5
|
+
// The cli engine's embeddable source, snapshotted at prepare time (see
|
|
6
|
+
// scripts/generate-runtime-sources.mjs).
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
RUNTIME_SOURCES,
|
|
10
|
+
RUNTIME_SOURCES_STRIPPED,
|
|
11
|
+
} from '@redocly/client-generator/runtime-sources';
|
|
12
|
+
|
|
13
|
+
/** The cli engine (`runCli` + types) stripped for embedding into `<stem>.cli.ts`. */
|
|
14
|
+
export function embedCliRuntime(): string {
|
|
15
|
+
return RUNTIME_SOURCES_STRIPPED['cli.ts'];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The cli engine RAW, for `runtime: 'module'` (written as `runtime/cli.ts`). */
|
|
19
|
+
export function cliRuntimeSource(): string {
|
|
20
|
+
return RUNTIME_SOURCES['cli.ts'];
|
|
21
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Ejected from @redocly/client-generator@0.4.0 — the built-in "cli" generator.
|
|
2
|
+
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
|
+
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
|
+
// `redocly eject-generator cli --update`.
|
|
5
|
+
import {
|
|
6
|
+
type CodeSample,
|
|
7
|
+
type Generator,
|
|
8
|
+
groupSlug,
|
|
9
|
+
type OperationModel,
|
|
10
|
+
type SampleContext,
|
|
11
|
+
} from '@redocly/client-generator';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
import { renderCliDocs } from './docs.ts';
|
|
15
|
+
import { cliRuntimeSource } from './engine-source.ts';
|
|
16
|
+
import { cliAuthSchemes, commandData, renderCliModule } from './render.ts';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The cli generator: a bin-ready `<stem>.cli.ts` — a zero-dependency, typed
|
|
20
|
+
* command-line interface over the sibling client (typed flags, `--json`
|
|
21
|
+
* bodies, env auth, `--page-all`, SSE/blob output, a documented exit-code
|
|
22
|
+
* contract). Requires `typescript` (throw mode); wires zod validation when co-selected.
|
|
23
|
+
*/
|
|
24
|
+
export const cliGenerator: Generator = ({ model, output, banner, emit, selected, pagination }) => {
|
|
25
|
+
const content = renderCliModule(model, {
|
|
26
|
+
stem: output.stem,
|
|
27
|
+
importExt: emit.importExt ?? 'js',
|
|
28
|
+
zodSelected: selected?.includes('zod') ?? false,
|
|
29
|
+
pagination,
|
|
30
|
+
argsStyle: emit.argsStyle ?? 'grouped',
|
|
31
|
+
runtime: emit.runtime ?? 'inline',
|
|
32
|
+
});
|
|
33
|
+
const entry = { path: join(output.dir, `${output.stem}.cli.ts`), content };
|
|
34
|
+
if (emit.runtime !== 'module') return [entry];
|
|
35
|
+
const header = banner.map((line) => `// ${line}`).join('\n');
|
|
36
|
+
return [
|
|
37
|
+
entry,
|
|
38
|
+
{
|
|
39
|
+
path: join(output.dir, 'runtime', 'cli.ts'),
|
|
40
|
+
content: `${header}\n\n${cliRuntimeSource().trim()}\n`,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The CLI's own reference page, written when `client.docs` is on: the usage line, the
|
|
47
|
+
* global flags, the credential variables, the exit codes, and one section per command.
|
|
48
|
+
* It renders from `commandData` — the same table `runCli` dispatches on — so the page
|
|
49
|
+
* cannot describe a tool other than the one beside it.
|
|
50
|
+
*/
|
|
51
|
+
export const cliDocs: Generator = ({ model, output, emit, pagination }) => {
|
|
52
|
+
const content = renderCliDocs(commandData(model, { pagination }), {
|
|
53
|
+
title: `${model.title} command-line reference`,
|
|
54
|
+
frontmatter: emit.docsFrontmatter === true,
|
|
55
|
+
name: output.stem,
|
|
56
|
+
schemes: cliAuthSchemes(model),
|
|
57
|
+
});
|
|
58
|
+
return [{ path: join(output.dir, `${output.stem}.cli.md`), content }];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** One shell invocation per operation — feeds `x-codeSamples` for docs. */
|
|
62
|
+
export function cliSample(op: OperationModel, ctx: SampleContext): CodeSample | undefined {
|
|
63
|
+
const command = commandData(ctx.model, { pagination: ctx.pagination }).find(
|
|
64
|
+
(candidate) => candidate.name === op.name
|
|
65
|
+
);
|
|
66
|
+
if (command === undefined) return undefined;
|
|
67
|
+
const words = [
|
|
68
|
+
'client',
|
|
69
|
+
...(command.group ? [groupSlug(command.group)] : []),
|
|
70
|
+
command.name,
|
|
71
|
+
...command.positionals.map((positional) => `<${positional.name}>`),
|
|
72
|
+
...command.flags.filter((flag) => flag.required).map((flag) => `--${flag.name} <${flag.type}>`),
|
|
73
|
+
...(command.body ? ["--json '<json>'"] : []),
|
|
74
|
+
];
|
|
75
|
+
return {
|
|
76
|
+
lang: 'shell',
|
|
77
|
+
label: 'CLI',
|
|
78
|
+
source: `npx tsx client.cli.ts ${words.slice(1).join(' ')}\n`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default {
|
|
83
|
+
name: 'cli',
|
|
84
|
+
run: cliGenerator,
|
|
85
|
+
sample: cliSample,
|
|
86
|
+
docs: cliDocs,
|
|
87
|
+
requires: ["typescript","zod"],
|
|
88
|
+
errorModes: ["throw"],
|
|
89
|
+
requiresGenerator: '^0.4.0',
|
|
90
|
+
};
|