klasik 1.0.41 → 2.0.1
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 +568 -1063
- package/demo-output/models/index.ts +2 -0
- package/demo-output/models/owner.ts +74 -0
- package/demo-output/models/pet.ts +107 -0
- package/demo-output/package.json +14 -0
- package/demo-output/tsconfig.json +26 -0
- package/dist/__tests__/test-helpers/cleanup-utils.d.ts +64 -0
- package/dist/__tests__/test-helpers/cleanup-utils.d.ts.map +1 -0
- package/dist/__tests__/test-helpers/cleanup-utils.js +236 -0
- package/dist/__tests__/test-helpers/cleanup-utils.js.map +1 -0
- package/dist/builders/class-builder.d.ts +99 -0
- package/dist/builders/class-builder.d.ts.map +1 -0
- package/dist/builders/class-builder.js +238 -0
- package/dist/builders/class-builder.js.map +1 -0
- package/dist/builders/import-manager.d.ts +62 -0
- package/dist/builders/import-manager.d.ts.map +1 -0
- package/dist/builders/import-manager.js +124 -0
- package/dist/builders/import-manager.js.map +1 -0
- package/dist/cli/commands/download.d.ts +16 -0
- package/dist/cli/commands/download.d.ts.map +1 -0
- package/dist/cli/commands/download.js +104 -0
- package/dist/cli/commands/download.js.map +1 -0
- package/dist/cli/commands/generate-crd.d.ts +23 -0
- package/dist/cli/commands/generate-crd.d.ts.map +1 -0
- package/dist/cli/commands/generate-crd.js +153 -0
- package/dist/cli/commands/generate-crd.js.map +1 -0
- package/dist/cli/commands/generate-jsonschema.d.ts +21 -0
- package/dist/cli/commands/generate-jsonschema.d.ts.map +1 -0
- package/dist/cli/commands/generate-jsonschema.js +185 -0
- package/dist/cli/commands/generate-jsonschema.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +24 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +98 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +25 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/logger.d.ts +47 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +79 -0
- package/dist/cli/utils/logger.js.map +1 -0
- package/dist/cli/utils/options.d.ts +74 -0
- package/dist/cli/utils/options.d.ts.map +1 -0
- package/dist/cli/utils/options.js +170 -0
- package/dist/cli/utils/options.js.map +1 -0
- package/dist/config/configuration.d.ts +38 -0
- package/dist/config/configuration.d.ts.map +1 -0
- package/dist/config/configuration.js +48 -0
- package/dist/config/configuration.js.map +1 -0
- package/dist/generator/export-style-manager.d.ts +73 -0
- package/dist/generator/export-style-manager.d.ts.map +1 -0
- package/dist/generator/export-style-manager.js +190 -0
- package/dist/generator/export-style-manager.js.map +1 -0
- package/dist/generator/generator.d.ts +70 -0
- package/dist/generator/generator.d.ts.map +1 -0
- package/dist/generator/generator.js +358 -0
- package/dist/generator/generator.js.map +1 -0
- package/dist/generators/api-client-generator.d.ts +88 -0
- package/dist/generators/api-client-generator.d.ts.map +1 -0
- package/dist/generators/api-client-generator.js +920 -0
- package/dist/generators/api-client-generator.js.map +1 -0
- package/dist/generators/tsdoc-generator.d.ts +46 -0
- package/dist/generators/tsdoc-generator.d.ts.map +1 -0
- package/dist/generators/tsdoc-generator.js +233 -0
- package/dist/generators/tsdoc-generator.js.map +1 -0
- package/dist/index.d.ts +24 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -22
- package/dist/index.js.map +1 -0
- package/dist/ir/types.d.ts +250 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/ir/types.js +101 -0
- package/dist/ir/types.js.map +1 -0
- package/dist/loaders/ref-inliner.d.ts +71 -0
- package/dist/loaders/ref-inliner.d.ts.map +1 -0
- package/dist/loaders/ref-inliner.js +152 -0
- package/dist/loaders/ref-inliner.js.map +1 -0
- package/dist/loaders/ref-resolver.d.ts +86 -0
- package/dist/loaders/ref-resolver.d.ts.map +1 -0
- package/dist/loaders/ref-resolver.js +237 -0
- package/dist/loaders/ref-resolver.js.map +1 -0
- package/dist/loaders/spec-loader.d.ts +105 -0
- package/dist/loaders/spec-loader.d.ts.map +1 -0
- package/dist/loaders/spec-loader.js +335 -0
- package/dist/loaders/spec-loader.js.map +1 -0
- package/dist/parsers/crd-parser.d.ts +144 -0
- package/dist/parsers/crd-parser.d.ts.map +1 -0
- package/dist/parsers/crd-parser.js +298 -0
- package/dist/parsers/crd-parser.js.map +1 -0
- package/dist/parsers/crd-to-ir.d.ts +97 -0
- package/dist/parsers/crd-to-ir.d.ts.map +1 -0
- package/dist/parsers/crd-to-ir.js +354 -0
- package/dist/parsers/crd-to-ir.js.map +1 -0
- package/dist/parsers/json-schema-parser.d.ts +162 -0
- package/dist/parsers/json-schema-parser.d.ts.map +1 -0
- package/dist/parsers/json-schema-parser.js +424 -0
- package/dist/parsers/json-schema-parser.js.map +1 -0
- package/dist/parsers/openapi-parser.d.ts +188 -0
- package/dist/parsers/openapi-parser.d.ts.map +1 -0
- package/dist/parsers/openapi-parser.js +385 -0
- package/dist/parsers/openapi-parser.js.map +1 -0
- package/dist/plugins/class-transformer-plugin.d.ts +34 -0
- package/dist/plugins/class-transformer-plugin.d.ts.map +1 -0
- package/dist/plugins/class-transformer-plugin.js +96 -0
- package/dist/plugins/class-transformer-plugin.js.map +1 -0
- package/dist/plugins/class-validator-plugin.d.ts +43 -0
- package/dist/plugins/class-validator-plugin.d.ts.map +1 -0
- package/dist/plugins/class-validator-plugin.js +214 -0
- package/dist/plugins/class-validator-plugin.js.map +1 -0
- package/dist/plugins/nestjs-swagger-plugin.d.ts +47 -0
- package/dist/plugins/nestjs-swagger-plugin.d.ts.map +1 -0
- package/dist/plugins/nestjs-swagger-plugin.js +197 -0
- package/dist/plugins/nestjs-swagger-plugin.js.map +1 -0
- package/dist/plugins/plugin-interface.d.ts +116 -0
- package/dist/plugins/plugin-interface.d.ts.map +1 -0
- package/dist/plugins/plugin-interface.js +137 -0
- package/dist/plugins/plugin-interface.js.map +1 -0
- package/dist/runtime/response-transformer.d.ts +178 -0
- package/dist/runtime/response-transformer.d.ts.map +1 -0
- package/dist/runtime/response-transformer.js +316 -0
- package/dist/runtime/response-transformer.js.map +1 -0
- package/dist/templates/template-engine.d.ts +64 -0
- package/dist/templates/template-engine.d.ts.map +1 -0
- package/dist/templates/template-engine.js +292 -0
- package/dist/templates/template-engine.js.map +1 -0
- package/dist/utils/ir-merger.d.ts +76 -0
- package/dist/utils/ir-merger.d.ts.map +1 -0
- package/dist/utils/ir-merger.js +210 -0
- package/dist/utils/ir-merger.js.map +1 -0
- package/dist/utils/name-utils.d.ts +36 -0
- package/dist/utils/name-utils.d.ts.map +1 -0
- package/dist/utils/name-utils.js +77 -0
- package/dist/utils/name-utils.js.map +1 -0
- package/docs/ARCHITECTURE.md +845 -0
- package/docs/JSDOC_ESCAPING.md +280 -0
- package/docs/json-schema-support.md +353 -0
- package/docs/validation.md +350 -0
- package/package.json +26 -15
- package/templates/api-class.mustache +86 -0
- package/templates/configuration.mustache +225 -139
- package/templates/index.mustache +3 -0
- package/templates/model.mustache +33 -0
- package/.claude/settings.local.json +0 -34
- package/TEST_CHECKLIST.md +0 -536
- package/USAGE_EXAMPLES.md +0 -221
- package/dist/attribute-typemap-fixer.d.ts +0 -57
- package/dist/attribute-typemap-fixer.js +0 -164
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -268
- package/dist/crd/crd-generator.d.ts +0 -149
- package/dist/crd/crd-generator.js +0 -481
- package/dist/crd/crd-parser.d.ts +0 -62
- package/dist/crd/crd-parser.js +0 -296
- package/dist/crd/crd-to-openapi.d.ts +0 -99
- package/dist/crd/crd-to-openapi.js +0 -341
- package/dist/crd/types.d.ts +0 -232
- package/dist/crd/types.js +0 -5
- package/dist/enum-order-fixer.d.ts +0 -28
- package/dist/enum-order-fixer.js +0 -141
- package/dist/esm-fixer.d.ts +0 -29
- package/dist/esm-fixer.js +0 -139
- package/dist/jsonschema/jsonschema-generator.d.ts +0 -108
- package/dist/jsonschema/jsonschema-generator.js +0 -318
- package/dist/jsonschema/jsonschema-parser.d.ts +0 -44
- package/dist/jsonschema/jsonschema-parser.js +0 -239
- package/dist/jsonschema/jsonschema-to-openapi.d.ts +0 -67
- package/dist/jsonschema/jsonschema-to-openapi.js +0 -284
- package/dist/jsonschema/types.d.ts +0 -118
- package/dist/jsonschema/types.js +0 -5
- package/dist/nestjs-type-fixer.d.ts +0 -77
- package/dist/nestjs-type-fixer.js +0 -265
- package/dist/openapi-client-generator.d.ts +0 -97
- package/dist/openapi-client-generator.js +0 -243
- package/dist/spec-downloader.d.ts +0 -84
- package/dist/spec-downloader.js +0 -403
- package/dist/utils/export-style.d.ts +0 -47
- package/dist/utils/export-style.js +0 -155
- package/example.md +0 -139
- package/openapitools.json +0 -0
- package/templates/apiInner.mustache +0 -526
- package/templates/modelGeneric.mustache +0 -137
- package/test-crd-fix/index.ts +0 -2
- package/test-crd-fix/v1alpha1/index.ts +0 -2
- package/test-crd-fix/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -83
- package/test-crd-fix/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -83
- package/test-crd-fix/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -83
- package/test-crd-fix/v1alpha1/models/app-project-spec-destinations-item.ts +0 -83
- package/test-crd-fix/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -65
- package/test-crd-fix/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -65
- package/test-crd-fix/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -83
- package/test-crd-fix/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -70
- package/test-crd-fix/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -85
- package/test-crd-fix/v1alpha1/models/app-project-spec-roles-item.ts +0 -124
- package/test-crd-fix/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -47
- package/test-crd-fix/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -209
- package/test-crd-fix/v1alpha1/models/app-project-spec.ts +0 -331
- package/test-crd-fix/v1alpha1/models/app-project.ts +0 -119
- package/test-crd-fix/v1alpha1/models/index.ts +0 -16
- package/test-crd-fix/v1alpha1/models/object-meta.ts +0 -212
- package/test-export-both/index.ts +0 -20
- package/test-export-both/v1alpha1/index.ts +0 -20
- package/test-export-both/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
- package/test-export-both/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
- package/test-export-both/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
- package/test-export-both/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
- package/test-export-both/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
- package/test-export-both/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
- package/test-export-both/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
- package/test-export-both/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
- package/test-export-both/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
- package/test-export-both/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
- package/test-export-both/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
- package/test-export-both/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
- package/test-export-both/v1alpha1/models/app-project-spec.ts +0 -259
- package/test-export-both/v1alpha1/models/app-project.ts +0 -96
- package/test-export-both/v1alpha1/models/index.ts +0 -16
- package/test-export-both/v1alpha1/models/object-meta.ts +0 -157
- package/test-export-direct/index.ts +0 -16
- package/test-export-direct/v1alpha1/index.ts +0 -16
- package/test-export-direct/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
- package/test-export-direct/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
- package/test-export-direct/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
- package/test-export-direct/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
- package/test-export-direct/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
- package/test-export-direct/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
- package/test-export-direct/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
- package/test-export-direct/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
- package/test-export-direct/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
- package/test-export-direct/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
- package/test-export-direct/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
- package/test-export-direct/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
- package/test-export-direct/v1alpha1/models/app-project-spec.ts +0 -259
- package/test-export-direct/v1alpha1/models/app-project.ts +0 -96
- package/test-export-direct/v1alpha1/models/index.ts +0 -16
- package/test-export-direct/v1alpha1/models/object-meta.ts +0 -157
- package/test-export-namespace/index.ts +0 -2
- package/test-export-namespace/v1alpha1/index.ts +0 -2
- package/test-export-namespace/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
- package/test-export-namespace/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
- package/test-export-namespace/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
- package/test-export-namespace/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
- package/test-export-namespace/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
- package/test-export-namespace/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
- package/test-export-namespace/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
- package/test-export-namespace/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
- package/test-export-namespace/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
- package/test-export-namespace/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
- package/test-export-namespace/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
- package/test-export-namespace/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
- package/test-export-namespace/v1alpha1/models/app-project-spec.ts +0 -259
- package/test-export-namespace/v1alpha1/models/app-project.ts +0 -96
- package/test-export-namespace/v1alpha1/models/index.ts +0 -16
- package/test-export-namespace/v1alpha1/models/object-meta.ts +0 -157
- package/test-export-none/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
- package/test-export-none/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
- package/test-export-none/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
- package/test-export-none/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
- package/test-export-none/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
- package/test-export-none/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
- package/test-export-none/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
- package/test-export-none/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
- package/test-export-none/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
- package/test-export-none/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
- package/test-export-none/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
- package/test-export-none/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
- package/test-export-none/v1alpha1/models/app-project-spec.ts +0 -259
- package/test-export-none/v1alpha1/models/app-project.ts +0 -96
- package/test-export-none/v1alpha1/models/index.ts +0 -16
- package/test-export-none/v1alpha1/models/object-meta.ts +0 -157
- package/test-fix-verification/index.ts +0 -27
- package/test-fix-verification/models/config-map-args.ts +0 -211
- package/test-fix-verification/models/field-selector.ts +0 -47
- package/test-fix-verification/models/field-spec.ts +0 -116
- package/test-fix-verification/models/generator-options.ts +0 -101
- package/test-fix-verification/models/helm-chart.ts +0 -241
- package/test-fix-verification/models/image.ts +0 -116
- package/test-fix-verification/models/inventory.ts +0 -70
- package/test-fix-verification/models/kustomization-helm-globals.ts +0 -65
- package/test-fix-verification/models/kustomization-legacy-sort-options.ts +0 -62
- package/test-fix-verification/models/kustomization-sort-options-one-of.ts +0 -75
- package/test-fix-verification/models/kustomization-sort-options-one-of1.ts +0 -52
- package/test-fix-verification/models/kustomization-sort-options.ts +0 -33
- package/test-fix-verification/models/kustomization.ts +0 -693
- package/test-fix-verification/models/kvsource.ts +0 -80
- package/test-fix-verification/models/labels.ts +0 -103
- package/test-fix-verification/models/metadata.ts +0 -98
- package/test-fix-verification/models/name-args.ts +0 -62
- package/test-fix-verification/models/patch-json6902-one-of.ts +0 -67
- package/test-fix-verification/models/patch-json6902-one-of1.ts +0 -67
- package/test-fix-verification/models/patch-json6902-one-of2-value.ts +0 -23
- package/test-fix-verification/models/patch-json6902-one-of2.ts +0 -116
- package/test-fix-verification/models/patch-json6902.ts +0 -38
- package/test-fix-verification/models/patch-target.ts +0 -116
- package/test-fix-verification/models/patches-inline-patch.ts +0 -90
- package/test-fix-verification/models/patches-options.ts +0 -62
- package/test-fix-verification/models/patches-patch-path.ts +0 -90
- package/test-fix-verification/models/replacements-inline-one-of.ts +0 -72
- package/test-fix-verification/models/replacements-inline-one-of1.ts +0 -67
- package/test-fix-verification/models/replacements-inline.ts +0 -35
- package/test-fix-verification/models/replacements-path.ts +0 -44
- package/test-fix-verification/models/replacements-source-options.ts +0 -80
- package/test-fix-verification/models/replacements-source.ts +0 -160
- package/test-fix-verification/models/replacements-target-options.ts +0 -80
- package/test-fix-verification/models/replacements-target.ts +0 -110
- package/test-fix-verification/models/replicas.ts +0 -62
- package/test-fix-verification/models/secret-args.ts +0 -229
- package/test-fix-verification/models/selector.ts +0 -155
- package/test-fix-verification/models/target.ts +0 -134
- package/test-fix-verification/models/var.ts +0 -93
- package/test-jsonschema-decorators/index.ts +0 -27
- package/test-jsonschema-decorators/models/config-map-args.ts +0 -211
- package/test-jsonschema-decorators/models/field-selector.ts +0 -47
- package/test-jsonschema-decorators/models/field-spec.ts +0 -116
- package/test-jsonschema-decorators/models/generator-options.ts +0 -101
- package/test-jsonschema-decorators/models/helm-chart.ts +0 -241
- package/test-jsonschema-decorators/models/image.ts +0 -116
- package/test-jsonschema-decorators/models/inventory.ts +0 -70
- package/test-jsonschema-decorators/models/kustomization-helm-globals.ts +0 -65
- package/test-jsonschema-decorators/models/kustomization-legacy-sort-options.ts +0 -62
- package/test-jsonschema-decorators/models/kustomization-sort-options-one-of.ts +0 -75
- package/test-jsonschema-decorators/models/kustomization-sort-options-one-of1.ts +0 -52
- package/test-jsonschema-decorators/models/kustomization-sort-options.ts +0 -33
- package/test-jsonschema-decorators/models/kustomization.ts +0 -693
- package/test-jsonschema-decorators/models/kvsource.ts +0 -80
- package/test-jsonschema-decorators/models/labels.ts +0 -103
- package/test-jsonschema-decorators/models/metadata.ts +0 -98
- package/test-jsonschema-decorators/models/name-args.ts +0 -62
- package/test-jsonschema-decorators/models/patch-json6902-one-of.ts +0 -67
- package/test-jsonschema-decorators/models/patch-json6902-one-of1.ts +0 -67
- package/test-jsonschema-decorators/models/patch-json6902-one-of2-value.ts +0 -23
- package/test-jsonschema-decorators/models/patch-json6902-one-of2.ts +0 -116
- package/test-jsonschema-decorators/models/patch-json6902.ts +0 -38
- package/test-jsonschema-decorators/models/patch-target.ts +0 -116
- package/test-jsonschema-decorators/models/patches-inline-patch.ts +0 -90
- package/test-jsonschema-decorators/models/patches-options.ts +0 -62
- package/test-jsonschema-decorators/models/patches-patch-path.ts +0 -90
- package/test-jsonschema-decorators/models/replacements-inline-one-of.ts +0 -72
- package/test-jsonschema-decorators/models/replacements-inline-one-of1.ts +0 -67
- package/test-jsonschema-decorators/models/replacements-inline.ts +0 -35
- package/test-jsonschema-decorators/models/replacements-path.ts +0 -44
- package/test-jsonschema-decorators/models/replacements-source-options.ts +0 -80
- package/test-jsonschema-decorators/models/replacements-source.ts +0 -160
- package/test-jsonschema-decorators/models/replacements-target-options.ts +0 -80
- package/test-jsonschema-decorators/models/replacements-target.ts +0 -110
- package/test-jsonschema-decorators/models/replicas.ts +0 -62
- package/test-jsonschema-decorators/models/secret-args.ts +0 -229
- package/test-jsonschema-decorators/models/selector.ts +0 -155
- package/test-jsonschema-decorators/models/target.ts +0 -134
- package/test-jsonschema-decorators/models/var.ts +0 -93
- package/test-jsonschema-output/index.ts +0 -27
- package/test-jsonschema-output/models/config-map-args.ts +0 -163
- package/test-jsonschema-output/models/field-selector.ts +0 -40
- package/test-jsonschema-output/models/field-spec.ts +0 -89
- package/test-jsonschema-output/models/generator-options.ts +0 -79
- package/test-jsonschema-output/models/helm-chart.ts +0 -163
- package/test-jsonschema-output/models/image.ts +0 -89
- package/test-jsonschema-output/models/inventory.ts +0 -58
- package/test-jsonschema-output/models/kustomization-helm-globals.ts +0 -53
- package/test-jsonschema-output/models/kustomization-legacy-sort-options.ts +0 -50
- package/test-jsonschema-output/models/kustomization-sort-options-one-of.ts +0 -62
- package/test-jsonschema-output/models/kustomization-sort-options-one-of1.ts +0 -44
- package/test-jsonschema-output/models/kustomization-sort-options.ts +0 -33
- package/test-jsonschema-output/models/kustomization.ts +0 -526
- package/test-jsonschema-output/models/kvsource.ts +0 -63
- package/test-jsonschema-output/models/labels.ts +0 -81
- package/test-jsonschema-output/models/metadata.ts +0 -76
- package/test-jsonschema-output/models/name-args.ts +0 -50
- package/test-jsonschema-output/models/patch-json6902-one-of.ts +0 -55
- package/test-jsonschema-output/models/patch-json6902-one-of1.ts +0 -55
- package/test-jsonschema-output/models/patch-json6902-one-of2-value.ts +0 -23
- package/test-jsonschema-output/models/patch-json6902-one-of2.ts +0 -93
- package/test-jsonschema-output/models/patch-json6902.ts +0 -38
- package/test-jsonschema-output/models/patch-target.ts +0 -89
- package/test-jsonschema-output/models/patches-inline-patch.ts +0 -73
- package/test-jsonschema-output/models/patches-options.ts +0 -50
- package/test-jsonschema-output/models/patches-patch-path.ts +0 -73
- package/test-jsonschema-output/models/replacements-inline-one-of.ts +0 -60
- package/test-jsonschema-output/models/replacements-inline-one-of1.ts +0 -55
- package/test-jsonschema-output/models/replacements-inline.ts +0 -35
- package/test-jsonschema-output/models/replacements-path.ts +0 -37
- package/test-jsonschema-output/models/replacements-source-options.ts +0 -63
- package/test-jsonschema-output/models/replacements-source.ts +0 -123
- package/test-jsonschema-output/models/replacements-target-options.ts +0 -63
- package/test-jsonschema-output/models/replacements-target.ts +0 -88
- package/test-jsonschema-output/models/replicas.ts +0 -50
- package/test-jsonschema-output/models/secret-args.ts +0 -176
- package/test-jsonschema-output/models/selector.ts +0 -118
- package/test-jsonschema-output/models/target.ts +0 -102
- package/test-jsonschema-output/models/var.ts +0 -76
- package/test-kebab-case/app-project/index.ts +0 -2
- package/test-kebab-case/app-project/v1alpha1/index.ts +0 -2
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
- package/test-kebab-case/app-project/v1alpha1/models/app-project-spec.ts +0 -259
- package/test-kebab-case/app-project/v1alpha1/models/app-project.ts +0 -96
- package/test-kebab-case/app-project/v1alpha1/models/index.ts +0 -16
- package/test-kebab-case/app-project/v1alpha1/models/object-meta.ts +0 -157
- package/test-kebab-case/application/index.ts +0 -2
- package/test-kebab-case/application/v1alpha1/index.ts +0 -2
- package/test-kebab-case/application/v1alpha1/models/application-spec-destination.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-ignore-differences-item.ts +0 -118
- package/test-kebab-case/application/v1alpha1/models/application-spec-info-item.ts +0 -50
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory-jsonnet-ext-vars-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory-jsonnet-tlas-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory-jsonnet.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory.ts +0 -84
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-helm-file-parameters-item.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-helm-parameters-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-helm.ts +0 -118
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory-jsonnet-ext-vars-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory-jsonnet-tlas-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory-jsonnet.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory.ts +0 -84
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-helm-file-parameters-item.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-helm-parameters-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-helm.ts +0 -118
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize-patches-item-target.ts +0 -115
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize-patches-item.ts +0 -81
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize-replicas-item.ts +0 -56
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize.ts +0 -132
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-plugin-env-item.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-plugin-parameters-item.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-plugin.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source.ts +0 -138
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-hydrate-to.ts +0 -40
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-sync-source.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator.ts +0 -81
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize-patches-item-target.ts +0 -115
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize-patches-item.ts +0 -81
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize-replicas-item.ts +0 -51
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize.ts +0 -132
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-plugin-env-item.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-plugin-parameters-item.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-source-plugin.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-source.ts +0 -177
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory-jsonnet-ext-vars-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory-jsonnet-tlas-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory-jsonnet.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory.ts +0 -84
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-helm-file-parameters-item.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-helm-parameters-item.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-helm.ts +0 -118
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize-patches-item-target.ts +0 -115
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize-patches-item.ts +0 -81
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize-replicas-item.ts +0 -56
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize.ts +0 -132
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-plugin-env-item.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-plugin-parameters-item.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-plugin.ts +0 -76
- package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item.ts +0 -177
- package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-automated.ts +0 -79
- package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-managed-namespace-metadata.ts +0 -53
- package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-retry-backoff.ts +0 -66
- package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-retry.ts +0 -71
- package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy.ts +0 -94
- package/test-kebab-case/application/v1alpha1/models/application-spec.ts +0 -179
- package/test-kebab-case/application/v1alpha1/models/application.ts +0 -96
- package/test-kebab-case/application/v1alpha1/models/index.ts +0 -60
- package/test-kebab-case/application/v1alpha1/models/object-meta.ts +0 -157
- package/test-kebab-case/index.ts +0 -3
- package/test-multi-schemas/index.ts +0 -27
- package/test-multi-schemas/models/config-map-args.ts +0 -163
- package/test-multi-schemas/models/field-selector.ts +0 -40
- package/test-multi-schemas/models/field-spec.ts +0 -89
- package/test-multi-schemas/models/generator-options.ts +0 -79
- package/test-multi-schemas/models/helm-chart.ts +0 -163
- package/test-multi-schemas/models/image.ts +0 -89
- package/test-multi-schemas/models/inventory.ts +0 -58
- package/test-multi-schemas/models/kustomization-helm-globals.ts +0 -53
- package/test-multi-schemas/models/kustomization-legacy-sort-options.ts +0 -50
- package/test-multi-schemas/models/kustomization-sort-options-one-of.ts +0 -62
- package/test-multi-schemas/models/kustomization-sort-options-one-of1.ts +0 -44
- package/test-multi-schemas/models/kustomization-sort-options.ts +0 -33
- package/test-multi-schemas/models/kustomization.ts +0 -526
- package/test-multi-schemas/models/kvsource.ts +0 -63
- package/test-multi-schemas/models/labels.ts +0 -81
- package/test-multi-schemas/models/metadata.ts +0 -76
- package/test-multi-schemas/models/name-args.ts +0 -50
- package/test-multi-schemas/models/patch-json6902-one-of.ts +0 -55
- package/test-multi-schemas/models/patch-json6902-one-of1.ts +0 -55
- package/test-multi-schemas/models/patch-json6902-one-of2-value.ts +0 -23
- package/test-multi-schemas/models/patch-json6902-one-of2.ts +0 -93
- package/test-multi-schemas/models/patch-json6902.ts +0 -38
- package/test-multi-schemas/models/patch-target.ts +0 -89
- package/test-multi-schemas/models/patches-inline-patch.ts +0 -73
- package/test-multi-schemas/models/patches-options.ts +0 -50
- package/test-multi-schemas/models/patches-patch-path.ts +0 -73
- package/test-multi-schemas/models/replacements-inline-one-of.ts +0 -60
- package/test-multi-schemas/models/replacements-inline-one-of1.ts +0 -55
- package/test-multi-schemas/models/replacements-inline.ts +0 -35
- package/test-multi-schemas/models/replacements-path.ts +0 -37
- package/test-multi-schemas/models/replacements-source-options.ts +0 -63
- package/test-multi-schemas/models/replacements-source.ts +0 -123
- package/test-multi-schemas/models/replacements-target-options.ts +0 -63
- package/test-multi-schemas/models/replacements-target.ts +0 -88
- package/test-multi-schemas/models/replicas.ts +0 -50
- package/test-multi-schemas/models/secret-args.ts +0 -176
- package/test-multi-schemas/models/selector.ts +0 -118
- package/test-multi-schemas/models/target.ts +0 -102
- package/test-multi-schemas/models/var.ts +0 -76
package/README.md
CHANGED
|
@@ -1,1328 +1,824 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Klasik
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate TypeScript clients from OpenAPI specifications, Kubernetes CRDs, and JSON Schema with full type safety and class-transformer support.
|
|
4
|
+
|
|
5
|
+
Perfect for:
|
|
6
|
+
- 🚀 Kubernetes operators and controllers
|
|
7
|
+
- 🔧 REST API clients with type safety
|
|
8
|
+
- 📦 NestJS backend services
|
|
9
|
+
- 🎯 Type-safe microservice communication
|
|
4
10
|
|
|
5
11
|
## Features
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
✨ **Easy to Use** - Single CLI command to generate types
|
|
14
|
+
🎯 **Type-Safe** - Full TypeScript support with strict typing
|
|
15
|
+
🔄 **class-transformer** - Automatic serialization/deserialization
|
|
16
|
+
✅ **class-validator** - Built-in validation decorators
|
|
17
|
+
🎨 **NestJS Ready** - @ApiProperty decorators out of the box
|
|
18
|
+
📦 **Multiple Formats** - OpenAPI, Kubernetes CRDs, JSON Schema
|
|
19
|
+
🌐 **ESM Support** - Modern JavaScript modules with .js extensions
|
|
20
|
+
🔗 **External $refs** - Automatic resolution of external schemas
|
|
21
|
+
🎭 **Custom Templates** - Mustache-based customization
|
|
22
|
+
⚙️ **Flexible Output** - Multiple export styles (namespace, direct, both)
|
|
23
|
+
🧪 **Well Tested** - Comprehensive test coverage (748 passing tests)
|
|
24
|
+
🚀 **Production Ready** - Used in real-world projects
|
|
25
|
+
📝 **Full CLI** - Rich command-line interface with 4 commands
|
|
26
|
+
🔐 **Authentication** - Custom headers including Bearer tokens
|
|
20
27
|
|
|
21
28
|
## Installation
|
|
22
29
|
|
|
23
30
|
```bash
|
|
24
|
-
npm install klasik
|
|
31
|
+
npm install -g klasik
|
|
32
|
+
|
|
33
|
+
# or use directly with npx
|
|
34
|
+
npx klasik <command>
|
|
25
35
|
```
|
|
26
36
|
|
|
27
37
|
## Quick Start
|
|
28
38
|
|
|
29
39
|
### CLI Usage
|
|
30
40
|
|
|
31
|
-
Generate
|
|
41
|
+
Generate from OpenAPI spec:
|
|
32
42
|
|
|
33
43
|
```bash
|
|
34
|
-
|
|
35
|
-
npx klasik generate \
|
|
36
|
-
--url https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json \
|
|
37
|
-
--output ./k8s-client
|
|
38
|
-
|
|
39
|
-
# YAML spec
|
|
40
|
-
npx klasik generate \
|
|
41
|
-
--url https://api.example.com/openapi.yaml \
|
|
42
|
-
--output ./client
|
|
44
|
+
klasik generate --url https://api.example.com/openapi.json --output ./src/generated
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
Generate from
|
|
47
|
+
Generate from Kubernetes CRDs:
|
|
46
48
|
|
|
47
49
|
```bash
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
--
|
|
51
|
-
--
|
|
52
|
-
|
|
53
|
-
# Relative path
|
|
54
|
-
npx klasik generate \
|
|
55
|
-
--url ./specs/openapi.json \
|
|
56
|
-
--output ./client
|
|
57
|
-
|
|
58
|
-
# file:// URL
|
|
59
|
-
npx klasik generate \
|
|
60
|
-
--url file:///path/to/openapi.yaml \
|
|
61
|
-
--output ./client
|
|
50
|
+
klasik generate-crd \
|
|
51
|
+
--url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
|
|
52
|
+
--output ./src/generated \
|
|
53
|
+
--class-validator \
|
|
54
|
+
--nestjs-swagger
|
|
62
55
|
```
|
|
63
56
|
|
|
64
|
-
|
|
57
|
+
Generate from JSON Schema:
|
|
65
58
|
|
|
66
59
|
```bash
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
--
|
|
70
|
-
--output ./specs/api-spec.json
|
|
71
|
-
|
|
72
|
-
# Download YAML spec
|
|
73
|
-
npx klasik download \
|
|
74
|
-
--url https://api.example.com/openapi.yaml \
|
|
75
|
-
--output ./specs/api-spec.yaml
|
|
60
|
+
klasik generate-jsonschema \
|
|
61
|
+
--url ./schemas/user.json \
|
|
62
|
+
--output ./src/generated
|
|
76
63
|
```
|
|
77
64
|
|
|
78
65
|
### Programmatic Usage
|
|
79
66
|
|
|
80
67
|
```typescript
|
|
81
|
-
import {
|
|
68
|
+
import { Generator, OpenAPIParser, SpecLoader } from 'klasik';
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await
|
|
86
|
-
specUrl: 'https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json',
|
|
87
|
-
outputDir: './k8s-client',
|
|
88
|
-
});
|
|
89
|
-
```
|
|
70
|
+
// Load and parse OpenAPI spec
|
|
71
|
+
const loader = new SpecLoader();
|
|
72
|
+
const spec = await loader.load({ url: 'https://api.example.com/openapi.json' });
|
|
90
73
|
|
|
91
|
-
|
|
74
|
+
const parser = new OpenAPIParser();
|
|
75
|
+
const ir = parser.parse(spec, { includeOperations: true });
|
|
92
76
|
|
|
93
|
-
|
|
77
|
+
// Generate TypeScript code
|
|
78
|
+
const generator = new Generator({
|
|
79
|
+
outputDir: './generated',
|
|
80
|
+
mode: 'full', // or 'models-only'
|
|
81
|
+
nestJsSwagger: true,
|
|
82
|
+
classValidator: true,
|
|
83
|
+
});
|
|
94
84
|
|
|
95
|
-
|
|
85
|
+
await generator.generate(ir);
|
|
86
|
+
```
|
|
96
87
|
|
|
97
|
-
|
|
88
|
+
## Request and Response Validation
|
|
98
89
|
|
|
99
|
-
|
|
100
|
-
# From a URL (e.g., ArgoCD AppProject CRD)
|
|
101
|
-
npx klasik generate-crd \
|
|
102
|
-
--url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
|
|
103
|
-
--output ./generated
|
|
90
|
+
Klasik supports automatic validation of both API requests and responses using class-validator. When enabled, requests and responses are validated against the decorators generated by the `--class-validator` plugin.
|
|
104
91
|
|
|
105
|
-
|
|
106
|
-
npx klasik generate-crd \
|
|
107
|
-
-u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
|
|
108
|
-
-u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
|
|
109
|
-
--output ./generated
|
|
92
|
+
### Configuration
|
|
110
93
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
```typescript
|
|
95
|
+
import { Configuration } from './generated/configuration';
|
|
96
|
+
import { TasksApi, NewTask } from './generated';
|
|
97
|
+
import axios from 'axios';
|
|
115
98
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
99
|
+
const config = new Configuration({
|
|
100
|
+
basePath: 'https://api.example.com',
|
|
101
|
+
enableResponseTransformation: true, // Required for response validation
|
|
102
|
+
enableResponseValidation: true, // Enable response validation (default: false)
|
|
103
|
+
enableRequestValidation: true, // Enable request validation (default: false)
|
|
104
|
+
});
|
|
121
105
|
|
|
122
|
-
|
|
123
|
-
npx klasik generate-crd \
|
|
124
|
-
--url ./my-crd.yaml \
|
|
125
|
-
--output ./src/generated \
|
|
126
|
-
--nestjs-swagger \
|
|
127
|
-
--class-validator
|
|
106
|
+
const api = new TasksApi(config, axios.create());
|
|
128
107
|
```
|
|
129
108
|
|
|
130
|
-
###
|
|
109
|
+
### Request Validation
|
|
131
110
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- ✅ **Multi-document YAML support** - Process multiple CRDs from a single file
|
|
136
|
-
- ✅ **Nested type extraction** - Complex nested objects become separate TypeScript interfaces
|
|
137
|
-
- ✅ **Full decorator support** - Works with `--nestjs-swagger`, `--class-validator`, `--esm`
|
|
138
|
-
- ✅ **Spec and Status schemas** - Optional status model generation with `--include-status`
|
|
139
|
-
- ✅ **Kubernetes metadata** - Standard ObjectMeta types included
|
|
111
|
+
Request validation ensures request bodies are:
|
|
112
|
+
1. Instances of the expected class
|
|
113
|
+
2. Valid according to class-validator decorators
|
|
140
114
|
|
|
141
|
-
|
|
115
|
+
```typescript
|
|
116
|
+
import { NewTask } from './generated/models';
|
|
142
117
|
|
|
143
|
-
|
|
118
|
+
// Create instance
|
|
119
|
+
const newTask = new NewTask();
|
|
120
|
+
newTask.title = 'My Task';
|
|
121
|
+
newTask.description = 'Task description';
|
|
144
122
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
├── v1alpha1/
|
|
148
|
-
│ ├── models/
|
|
149
|
-
│ │ ├── app-project.ts # Main resource
|
|
150
|
-
│ │ ├── app-project-spec.ts # Spec definition
|
|
151
|
-
│ │ ├── app-project-status.ts # Status (if --include-status)
|
|
152
|
-
│ │ ├── object-meta.ts # Kubernetes metadata
|
|
153
|
-
│ │ └── [nested-types].ts # Extracted nested types
|
|
154
|
-
│ └── index.ts # Version exports
|
|
155
|
-
├── v1beta1/
|
|
156
|
-
│ └── ... (same structure)
|
|
157
|
-
└── index.ts # All versions
|
|
123
|
+
// This will validate before sending
|
|
124
|
+
const response = await api.createTask(newTask);
|
|
158
125
|
```
|
|
159
126
|
|
|
160
|
-
|
|
127
|
+
Request validation will throw if:
|
|
128
|
+
- Request body is not an instance: `RequestNotInstanceError`
|
|
129
|
+
- Request body fails validation: `ValidationError`
|
|
161
130
|
|
|
162
|
-
|
|
163
|
-
import { AppProject, AppProjectSpec } from './generated/v1alpha1';
|
|
164
|
-
|
|
165
|
-
// Create a typed Kubernetes resource
|
|
166
|
-
const project: AppProject = {
|
|
167
|
-
apiVersion: 'argoproj.io/v1alpha1',
|
|
168
|
-
kind: 'AppProject',
|
|
169
|
-
metadata: {
|
|
170
|
-
name: 'my-project',
|
|
171
|
-
namespace: 'argocd'
|
|
172
|
-
},
|
|
173
|
-
spec: {
|
|
174
|
-
description: 'My ArgoCD project',
|
|
175
|
-
destinations: [
|
|
176
|
-
{ server: 'https://kubernetes.default.svc', namespace: '*' }
|
|
177
|
-
],
|
|
178
|
-
sourceRepos: ['*']
|
|
179
|
-
}
|
|
180
|
-
};
|
|
131
|
+
### Response Validation
|
|
181
132
|
|
|
182
|
-
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### CRD Programmatic API
|
|
133
|
+
Response validation ensures responses match the expected schema:
|
|
186
134
|
|
|
187
135
|
```typescript
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
includeStatus: true,
|
|
197
|
-
nestJsSwagger: true,
|
|
198
|
-
classValidator: true
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Multiple URLs (merged into single output)
|
|
202
|
-
await generator.generate({
|
|
203
|
-
urls: [
|
|
204
|
-
'https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml',
|
|
205
|
-
'https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml',
|
|
206
|
-
'./local/my-crd.yaml'
|
|
207
|
-
],
|
|
208
|
-
outputDir: './generated',
|
|
209
|
-
includeStatus: true,
|
|
210
|
-
nestJsSwagger: true
|
|
211
|
-
});
|
|
136
|
+
try {
|
|
137
|
+
const response = await api.getTasks();
|
|
138
|
+
// Response is validated
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error instanceof ValidationError) {
|
|
141
|
+
console.error('Validation failed:', error.validationErrors);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
212
144
|
```
|
|
213
145
|
|
|
214
|
-
###
|
|
215
|
-
|
|
216
|
-
Klasik automatically handles multi-document YAML files (CRDs separated by `---`):
|
|
217
|
-
|
|
218
|
-
```yaml
|
|
219
|
-
---
|
|
220
|
-
apiVersion: apiextensions.k8s.io/v1
|
|
221
|
-
kind: CustomResourceDefinition
|
|
222
|
-
metadata:
|
|
223
|
-
name: appprojects.argoproj.io
|
|
224
|
-
spec:
|
|
225
|
-
# ... AppProject CRD
|
|
226
|
-
---
|
|
227
|
-
apiVersion: apiextensions.k8s.io/v1
|
|
228
|
-
kind: CustomResourceDefinition
|
|
229
|
-
metadata:
|
|
230
|
-
name: applications.argoproj.io
|
|
231
|
-
spec:
|
|
232
|
-
# ... Application CRD
|
|
233
|
-
```
|
|
146
|
+
### Custom Error Handling
|
|
234
147
|
|
|
235
|
-
|
|
148
|
+
Use callbacks for custom error handling:
|
|
236
149
|
|
|
150
|
+
```typescript
|
|
151
|
+
const config = new Configuration({
|
|
152
|
+
basePath: 'https://api.example.com',
|
|
153
|
+
enableRequestValidation: true,
|
|
154
|
+
onRequestValidationError: (errors, modelClass, instance) => {
|
|
155
|
+
console.error(`Request validation failed for ${modelClass.name}:`);
|
|
156
|
+
errors.forEach(err => {
|
|
157
|
+
console.error(` - ${err.property}: ${Object.values(err.constraints || {}).join(', ')}`);
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
enableResponseValidation: true,
|
|
161
|
+
onResponseValidationError: (errors, modelClass, instance) => {
|
|
162
|
+
console.error(`Response validation failed for ${modelClass.name}:`);
|
|
163
|
+
// Log to monitoring service
|
|
164
|
+
Sentry.captureException(new Error('API validation failed'));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
237
167
|
```
|
|
238
|
-
output/
|
|
239
|
-
├── AppProject/
|
|
240
|
-
│ ├── v1alpha1/
|
|
241
|
-
│ └── index.ts
|
|
242
|
-
├── Application/
|
|
243
|
-
│ ├── v1alpha1/
|
|
244
|
-
│ └── index.ts
|
|
245
|
-
└── index.ts
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## JSON Schema Support
|
|
249
168
|
|
|
250
|
-
|
|
169
|
+
### Requirements
|
|
251
170
|
|
|
252
|
-
|
|
171
|
+
- Models must be generated with `--class-validator` flag
|
|
172
|
+
- For response validation: `enableResponseTransformation` must be `true` (default)
|
|
173
|
+
- `class-validator` package must be installed
|
|
253
174
|
|
|
254
|
-
|
|
175
|
+
### Example with CLI
|
|
255
176
|
|
|
256
177
|
```bash
|
|
257
|
-
#
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
# From multiple schemas (merged into single output)
|
|
263
|
-
npx klasik generate-jsonschema \
|
|
264
|
-
-u https://json.schemastore.org/kustomization.json \
|
|
265
|
-
-u https://json.schemastore.org/package.json \
|
|
266
|
-
-o ./generated/models
|
|
267
|
-
|
|
268
|
-
# From a local file
|
|
269
|
-
npx klasik generate-jsonschema \
|
|
270
|
-
-u ./my-schema.json \
|
|
271
|
-
-o ./generated
|
|
272
|
-
|
|
273
|
-
# With NestJS and validation decorators
|
|
274
|
-
npx klasik generate-jsonschema \
|
|
275
|
-
-u ./schema.json \
|
|
276
|
-
-o ./src/generated \
|
|
277
|
-
--nestjs-swagger \
|
|
178
|
+
# Generate models with validation decorators
|
|
179
|
+
klasik generate \
|
|
180
|
+
--url https://api.example.com/openapi.json \
|
|
181
|
+
--output ./src/generated \
|
|
278
182
|
--class-validator
|
|
279
|
-
```
|
|
280
183
|
|
|
281
|
-
|
|
184
|
+
# Use in your code
|
|
185
|
+
import { Configuration, TasksApi, NewTask } from './generated';
|
|
282
186
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
- ✅ **patternProperties handling** - Automatically converts to OpenAPI-compatible schemas
|
|
187
|
+
const config = new Configuration({
|
|
188
|
+
basePath: 'https://api.example.com',
|
|
189
|
+
enableRequestValidation: true,
|
|
190
|
+
enableResponseValidation: true
|
|
191
|
+
});
|
|
289
192
|
|
|
290
|
-
|
|
193
|
+
const api = new TasksApi(config);
|
|
291
194
|
|
|
292
|
-
|
|
195
|
+
// Request will be validated
|
|
196
|
+
const newTask = new NewTask();
|
|
197
|
+
newTask.title = 'My Task';
|
|
198
|
+
const created = await api.createTask(newTask);
|
|
293
199
|
|
|
200
|
+
// Response will be validated
|
|
201
|
+
const tasks = await api.listTasks();
|
|
294
202
|
```
|
|
295
|
-
output/
|
|
296
|
-
├── models/
|
|
297
|
-
│ ├── kustomization.ts
|
|
298
|
-
│ ├── config-map-args.ts
|
|
299
|
-
│ ├── helm-chart.ts
|
|
300
|
-
│ └── ... (all definitions)
|
|
301
|
-
└── index.ts
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
**Naming convention:**
|
|
305
|
-
- `ConfigMapArgs` → `config-map-args.ts`
|
|
306
|
-
- `HelmChart` → `helm-chart.ts`
|
|
307
|
-
- `Kustomization` → `kustomization.ts`
|
|
308
203
|
|
|
309
|
-
|
|
204
|
+
For more details, see the [Validation Guide](./docs/validation.md).
|
|
310
205
|
|
|
311
|
-
|
|
312
|
-
import { Kustomization, ConfigMapArgs } from './generated/kustomization';
|
|
313
|
-
|
|
314
|
-
// Create a typed kustomization file
|
|
315
|
-
const kustomization: Kustomization = {
|
|
316
|
-
apiVersion: 'kustomize.config.k8s.io/v1beta1',
|
|
317
|
-
kind: 'Kustomization',
|
|
318
|
-
resources: [
|
|
319
|
-
'./deployment.yaml',
|
|
320
|
-
'./service.yaml'
|
|
321
|
-
],
|
|
322
|
-
configMapGenerator: [
|
|
323
|
-
{
|
|
324
|
-
name: 'my-config',
|
|
325
|
-
literals: ['key=value']
|
|
326
|
-
}
|
|
327
|
-
]
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// Full TypeScript intellisense and type checking!
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### JSON Schema Programmatic API
|
|
206
|
+
## CLI Commands
|
|
334
207
|
|
|
335
|
-
|
|
336
|
-
import { JSONSchemaGenerator } from 'klasik';
|
|
208
|
+
### `klasik generate`
|
|
337
209
|
|
|
338
|
-
|
|
210
|
+
Generate TypeScript client from OpenAPI specification.
|
|
339
211
|
|
|
340
|
-
|
|
341
|
-
await generator.generate({
|
|
342
|
-
urls: './schemas/my-schema.json',
|
|
343
|
-
outputDir: './generated',
|
|
344
|
-
nestJsSwagger: true,
|
|
345
|
-
classValidator: true
|
|
346
|
-
});
|
|
212
|
+
**Usage:**
|
|
347
213
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
urls: [
|
|
351
|
-
'https://json.schemastore.org/kustomization.json',
|
|
352
|
-
'./local-schema.json'
|
|
353
|
-
],
|
|
354
|
-
outputDir: './generated',
|
|
355
|
-
keepSpec: true // Keep intermediate OpenAPI specs
|
|
356
|
-
});
|
|
214
|
+
```bash
|
|
215
|
+
klasik generate [options]
|
|
357
216
|
```
|
|
358
217
|
|
|
359
|
-
**JSONSchemaGeneratorOptions:**
|
|
360
|
-
- `urls: string | string[]` - URL(s) or file path(s) to JSON Schema files (required)
|
|
361
|
-
- `outputDir: string` - Output directory (required)
|
|
362
|
-
- `headers?: Record<string, string>` - Custom HTTP headers
|
|
363
|
-
- `timeout?: number` - Request timeout in milliseconds (default: 30000)
|
|
364
|
-
- `fixEsmImports?: boolean` - Add .js extensions for ESM (default: false)
|
|
365
|
-
- `nestJsSwagger?: boolean` - Include NestJS decorators (default: false)
|
|
366
|
-
- `classValidator?: boolean` - Include validation decorators (default: false)
|
|
367
|
-
- `skipJsExtensions?: boolean` - Skip .js extensions (default: false)
|
|
368
|
-
- `templateDir?: string` - Custom template directory
|
|
369
|
-
- `keepSpec?: boolean` - Keep intermediate OpenAPI specs (default: false)
|
|
370
|
-
|
|
371
|
-
## CLI Commands
|
|
372
|
-
|
|
373
|
-
### `generate`
|
|
374
|
-
|
|
375
|
-
Generate a TypeScript client from an OpenAPI spec (remote URL or local file).
|
|
376
|
-
|
|
377
218
|
**Options:**
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
- Automatically adds `class-validator` and `class-transformer` to generated package.json
|
|
395
|
-
- Enables runtime validation with decorators like `@IsString`, `@IsEmail`, `@Min`, `@Max`
|
|
396
|
-
- Forward-compatible flag - full decorator generation coming in future version
|
|
397
|
-
- `-t, --template <dir>` - Custom template directory (klasik includes enhanced TSDoc templates by default)
|
|
398
|
-
- `-k, --keep-spec` - Keep the downloaded spec file after generation
|
|
399
|
-
- `--timeout <ms>` - Request timeout in milliseconds for HTTP requests (default: 30000)
|
|
219
|
+
|
|
220
|
+
| Option | Description | Default |
|
|
221
|
+
|--------|-------------|---------|
|
|
222
|
+
| `-u, --url <url>` | OpenAPI spec URL or file path (required) | - |
|
|
223
|
+
| `-o, --output <dir>` | Output directory (required) | - |
|
|
224
|
+
| `-m, --mode <mode>` | Generation mode: `full` or `models-only` | `full` |
|
|
225
|
+
| `--resolve-refs` | Resolve external $ref files | `false` |
|
|
226
|
+
| `--esm` | Add .js extensions for ESM compatibility | `false` |
|
|
227
|
+
| `--skip-js-extensions` | Skip .js extensions (for bundlers) | `false` |
|
|
228
|
+
| `--nestjs-swagger` | Add @ApiProperty decorators | `false` |
|
|
229
|
+
| `--class-validator` | Add class-validator decorators | `false` |
|
|
230
|
+
| `--header <header>` | Custom header (repeatable) | - |
|
|
231
|
+
| `--timeout <ms>` | Request timeout | `30000` |
|
|
232
|
+
| `--template <dir>` | Custom template directory | - |
|
|
233
|
+
| `--keep-spec` | Keep downloaded spec file(s) | `false` |
|
|
234
|
+
| `--export-style <style>` | Export style: `namespace`, `direct`, `both`, `none` | `namespace` |
|
|
400
235
|
|
|
401
236
|
**Examples:**
|
|
402
237
|
|
|
403
238
|
```bash
|
|
404
|
-
#
|
|
405
|
-
klasik generate
|
|
406
|
-
--url https://api.example.com/openapi.json \
|
|
407
|
-
--output ./client \
|
|
408
|
-
--header "Authorization: Bearer token123" \
|
|
409
|
-
--timeout 60000
|
|
410
|
-
|
|
411
|
-
# With external reference resolution
|
|
412
|
-
klasik generate \
|
|
413
|
-
--url https://api.example.com/openapi.json \
|
|
414
|
-
--output ./client \
|
|
415
|
-
--header "Authorization: Bearer token123" \
|
|
416
|
-
--resolve-refs
|
|
239
|
+
# Basic generation
|
|
240
|
+
klasik generate --url ./openapi.yaml --output ./generated
|
|
417
241
|
|
|
418
|
-
#
|
|
242
|
+
# Full client with API methods (default mode)
|
|
419
243
|
klasik generate \
|
|
420
|
-
--url https://
|
|
421
|
-
--output ./src/
|
|
422
|
-
--mode models-only \
|
|
423
|
-
--nestjs-swagger
|
|
244
|
+
--url https://petstore.swagger.io/v2/swagger.json \
|
|
245
|
+
--output ./src/api
|
|
424
246
|
|
|
425
|
-
#
|
|
247
|
+
# Models only (no API client)
|
|
426
248
|
klasik generate \
|
|
427
249
|
--url https://api.example.com/openapi.json \
|
|
428
|
-
--output ./src/
|
|
429
|
-
--mode models-only
|
|
430
|
-
--class-validator
|
|
250
|
+
--output ./src/models \
|
|
251
|
+
--mode models-only
|
|
431
252
|
|
|
432
|
-
#
|
|
253
|
+
# With NestJS and validation support
|
|
433
254
|
klasik generate \
|
|
434
|
-
--url https://api.example.com/
|
|
435
|
-
--output ./src/
|
|
436
|
-
--mode models-only \
|
|
255
|
+
--url https://api.example.com/spec.json \
|
|
256
|
+
--output ./src/api \
|
|
437
257
|
--nestjs-swagger \
|
|
438
258
|
--class-validator
|
|
439
259
|
|
|
440
|
-
#
|
|
260
|
+
# With external refs and authentication
|
|
441
261
|
klasik generate \
|
|
442
|
-
--url https://api.example.com/
|
|
443
|
-
--output ./
|
|
444
|
-
--
|
|
445
|
-
--header "
|
|
262
|
+
--url https://api.example.com/spec.json \
|
|
263
|
+
--output ./generated \
|
|
264
|
+
--resolve-refs \
|
|
265
|
+
--header "Authorization: Bearer ${TOKEN}"
|
|
446
266
|
|
|
447
|
-
#
|
|
267
|
+
# ESM compatibility
|
|
448
268
|
klasik generate \
|
|
449
|
-
--url ./
|
|
450
|
-
--output ./
|
|
269
|
+
--url ./openapi.yaml \
|
|
270
|
+
--output ./generated \
|
|
271
|
+
--esm
|
|
451
272
|
|
|
452
|
-
#
|
|
273
|
+
# Custom templates
|
|
453
274
|
klasik generate \
|
|
454
|
-
--url
|
|
455
|
-
--output ./
|
|
275
|
+
--url ./openapi.yaml \
|
|
276
|
+
--output ./generated \
|
|
277
|
+
--template ./my-templates
|
|
456
278
|
```
|
|
457
279
|
|
|
458
|
-
### `download`
|
|
280
|
+
### `klasik download`
|
|
281
|
+
|
|
282
|
+
Download OpenAPI spec without generating code.
|
|
459
283
|
|
|
460
|
-
|
|
284
|
+
**Usage:**
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
klasik download [options]
|
|
288
|
+
```
|
|
461
289
|
|
|
462
290
|
**Options:**
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
291
|
+
|
|
292
|
+
| Option | Description | Default |
|
|
293
|
+
|--------|-------------|---------|
|
|
294
|
+
| `-u, --url <url>` | Remote spec URL (required) | - |
|
|
295
|
+
| `-o, --output <file>` | Output file path (required) | - |
|
|
296
|
+
| `--header <header>` | Custom header (repeatable) | - |
|
|
297
|
+
| `--resolve-refs` | Resolve external $ref files | `false` |
|
|
298
|
+
| `--timeout <ms>` | Request timeout | `30000` |
|
|
468
299
|
|
|
469
300
|
**Examples:**
|
|
470
301
|
|
|
471
302
|
```bash
|
|
472
|
-
# Download spec
|
|
303
|
+
# Download spec
|
|
304
|
+
klasik download \
|
|
305
|
+
--url https://api.example.com/openapi.json \
|
|
306
|
+
--output ./specs/api-spec.json
|
|
307
|
+
|
|
308
|
+
# With authentication
|
|
473
309
|
klasik download \
|
|
474
310
|
--url https://api.example.com/openapi.json \
|
|
475
311
|
--output ./specs/api-spec.json \
|
|
476
|
-
--header "Authorization: Bearer
|
|
312
|
+
--header "Authorization: Bearer ${TOKEN}"
|
|
477
313
|
|
|
478
|
-
# Download
|
|
314
|
+
# Download with all external references
|
|
479
315
|
klasik download \
|
|
480
316
|
--url https://api.example.com/openapi.json \
|
|
481
317
|
--output ./specs/api-spec.json \
|
|
482
|
-
--header "Authorization: Bearer token123" \
|
|
483
318
|
--resolve-refs
|
|
484
319
|
```
|
|
485
320
|
|
|
486
|
-
### `generate-crd`
|
|
487
|
-
|
|
488
|
-
Generate TypeScript models from Kubernetes CustomResourceDefinition (CRD) YAML files.
|
|
321
|
+
### `klasik generate-crd`
|
|
489
322
|
|
|
490
|
-
|
|
491
|
-
- `-u, --url <url...>` - URL(s) or file path(s) to CRD YAML files (required)
|
|
492
|
-
- Can be specified multiple times: `-u url1 -u url2 -u url3`
|
|
493
|
-
- All CRDs from all URLs are merged into a single output directory
|
|
494
|
-
- Supports: `https://...`, `http://...`, `file://...`, `/absolute/path`, `./relative/path`
|
|
495
|
-
- `-o, --output <dir>` - Output directory for generated models (required)
|
|
496
|
-
- `--include-status` - Generate status schemas in addition to spec schemas (default: false)
|
|
497
|
-
- By default, only spec models are generated
|
|
498
|
-
- Enable this to also generate status models for reading resource status
|
|
499
|
-
- `--nestjs-swagger` - Include NestJS Swagger `@ApiProperty` decorators
|
|
500
|
-
- `--class-validator` - Include class-validator decorators
|
|
501
|
-
- `--esm` - Add `.js` extensions to imports for ESM compatibility
|
|
502
|
-
- `-H, --header <header...>` - Custom headers for HTTP requests (format: "Key: Value")
|
|
503
|
-
- `-t, --template <dir>` - Custom template directory
|
|
504
|
-
- `-k, --keep-spec` - Keep the generated OpenAPI spec files (for debugging)
|
|
505
|
-
- `--crd-kind-case <format>` - Format for CRD kind names in folder names (default: pascal)
|
|
506
|
-
- `pascal`: `AppProject` (default)
|
|
507
|
-
- `snake`: `app_project`
|
|
508
|
-
- `kebab`: `app-project`
|
|
509
|
-
- `--timeout <ms>` - Request timeout in milliseconds (default: 30000)
|
|
323
|
+
Generate TypeScript models from Kubernetes CustomResourceDefinitions.
|
|
510
324
|
|
|
511
|
-
**
|
|
325
|
+
**Usage:**
|
|
512
326
|
|
|
513
327
|
```bash
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
--url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
|
|
517
|
-
--output ./generated/crds
|
|
328
|
+
klasik generate-crd [options]
|
|
329
|
+
```
|
|
518
330
|
|
|
519
|
-
|
|
520
|
-
klasik generate-crd \
|
|
521
|
-
-u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
|
|
522
|
-
-u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
|
|
523
|
-
--output ./generated/argocd
|
|
331
|
+
**Options:**
|
|
524
332
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
333
|
+
| Option | Description | Default |
|
|
334
|
+
|--------|-------------|---------|
|
|
335
|
+
| `-u, --url <url>` | CRD URL or file path (repeatable) | - |
|
|
336
|
+
| `-o, --output <dir>` | Output directory (required) | - |
|
|
337
|
+
| `--include-status` | Generate status schemas | `false` |
|
|
338
|
+
| `--crd-kind-case <format>` | Folder naming: `pascal`, `snake`, `kebab` | `pascal` |
|
|
339
|
+
| `--nestjs-swagger` | Add @ApiProperty decorators | `false` |
|
|
340
|
+
| `--class-validator` | Add class-validator decorators | `false` |
|
|
341
|
+
| `--esm` | Add .js extensions for ESM | `false` |
|
|
342
|
+
| `--header <header>` | Custom header (repeatable) | - |
|
|
343
|
+
| `--resolve-refs` | Resolve external $ref files | `false` |
|
|
344
|
+
| `--template <dir>` | Custom template directory | - |
|
|
345
|
+
| `--keep-spec` | Keep downloaded spec file(s) | `false` |
|
|
346
|
+
| `--timeout <ms>` | Request timeout | `30000` |
|
|
347
|
+
|
|
348
|
+
**Examples:**
|
|
531
349
|
|
|
532
|
-
|
|
350
|
+
```bash
|
|
351
|
+
# Single CRD
|
|
533
352
|
klasik generate-crd \
|
|
534
353
|
--url ./my-crd.yaml \
|
|
535
|
-
--output ./
|
|
536
|
-
--include-status
|
|
354
|
+
--output ./src/types
|
|
537
355
|
|
|
538
|
-
#
|
|
356
|
+
# Multiple CRDs (automatic deduplication)
|
|
539
357
|
klasik generate-crd \
|
|
540
|
-
--url
|
|
541
|
-
--
|
|
358
|
+
--url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
|
|
359
|
+
--url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
|
|
360
|
+
--output ./src/generated \
|
|
361
|
+
--crd-kind-case kebab \
|
|
542
362
|
--nestjs-swagger \
|
|
543
363
|
--class-validator
|
|
544
364
|
|
|
545
|
-
#
|
|
546
|
-
klasik generate-crd \
|
|
547
|
-
--url ./local-crd.yaml \
|
|
548
|
-
--output ./generated \
|
|
549
|
-
--header "Authorization: Bearer token"
|
|
550
|
-
|
|
551
|
-
# Multi-CRD file
|
|
552
|
-
klasik generate-crd \
|
|
553
|
-
--url ./all-crds.yaml \
|
|
554
|
-
--output ./generated \
|
|
555
|
-
--include-status \
|
|
556
|
-
--nestjs-swagger
|
|
557
|
-
|
|
558
|
-
# Generate with snake_case folder names
|
|
365
|
+
# With status schemas
|
|
559
366
|
klasik generate-crd \
|
|
560
|
-
--url
|
|
561
|
-
--output ./
|
|
562
|
-
--
|
|
367
|
+
--url ./operator-crd.yaml \
|
|
368
|
+
--output ./src/types \
|
|
369
|
+
--include-status
|
|
563
370
|
|
|
564
|
-
#
|
|
371
|
+
# With authentication
|
|
565
372
|
klasik generate-crd \
|
|
566
|
-
--url https://
|
|
567
|
-
--output ./
|
|
568
|
-
--
|
|
373
|
+
--url https://private-repo.com/crd.yaml \
|
|
374
|
+
--output ./src/types \
|
|
375
|
+
--header "Authorization: Bearer ${TOKEN}"
|
|
569
376
|
```
|
|
570
377
|
|
|
571
|
-
|
|
378
|
+
### `klasik generate-jsonschema`
|
|
572
379
|
|
|
573
|
-
|
|
574
|
-
```
|
|
575
|
-
output/
|
|
576
|
-
├── v1alpha1/
|
|
577
|
-
│ └── models/
|
|
578
|
-
│ ├── my-resource.ts
|
|
579
|
-
│ ├── my-resource-spec.ts
|
|
580
|
-
│ ├── my-resource-status.ts (if --include-status)
|
|
581
|
-
│ └── ...
|
|
582
|
-
└── index.ts
|
|
583
|
-
```
|
|
380
|
+
Generate TypeScript models from JSON Schema files.
|
|
584
381
|
|
|
585
|
-
|
|
586
|
-
```
|
|
587
|
-
output/
|
|
588
|
-
├── AppProject/
|
|
589
|
-
│ ├── v1alpha1/
|
|
590
|
-
│ └── index.ts
|
|
591
|
-
├── Application/
|
|
592
|
-
│ ├── v1alpha1/
|
|
593
|
-
│ └── index.ts
|
|
594
|
-
└── index.ts
|
|
595
|
-
```
|
|
382
|
+
**Usage:**
|
|
596
383
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
output/
|
|
600
|
-
├── app_project/
|
|
601
|
-
│ ├── v1alpha1/
|
|
602
|
-
│ └── index.ts
|
|
603
|
-
├── application/
|
|
604
|
-
│ ├── v1alpha1/
|
|
605
|
-
│ └── index.ts
|
|
606
|
-
└── index.ts
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
With `--crd-kind-case kebab`:
|
|
610
|
-
```
|
|
611
|
-
output/
|
|
612
|
-
├── app-project/
|
|
613
|
-
│ ├── v1alpha1/
|
|
614
|
-
│ └── index.ts
|
|
615
|
-
├── application/
|
|
616
|
-
│ ├── v1alpha1/
|
|
617
|
-
│ └── index.ts
|
|
618
|
-
└── index.ts
|
|
384
|
+
```bash
|
|
385
|
+
klasik generate-jsonschema [options]
|
|
619
386
|
```
|
|
620
387
|
|
|
621
|
-
### `generate-jsonschema`
|
|
622
|
-
|
|
623
|
-
Generate TypeScript models from JSON Schema files.
|
|
624
|
-
|
|
625
388
|
**Options:**
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
-
|
|
636
|
-
|
|
637
|
-
|
|
389
|
+
|
|
390
|
+
| Option | Description | Default |
|
|
391
|
+
|--------|-------------|---------|
|
|
392
|
+
| `-u, --url <url>` | JSON Schema URL or file path (repeatable) | - |
|
|
393
|
+
| `-o, --output <dir>` | Output directory (required) | - |
|
|
394
|
+
| `--nestjs-swagger` | Add @ApiProperty decorators | `false` |
|
|
395
|
+
| `--class-validator` | Add class-validator decorators | `false` |
|
|
396
|
+
| `--esm` | Add .js extensions for ESM | `false` |
|
|
397
|
+
| `--header <header>` | Custom header (repeatable) | - |
|
|
398
|
+
| `--resolve-refs` | Resolve external $ref files | `false` |
|
|
399
|
+
| `--template <dir>` | Custom template directory | - |
|
|
400
|
+
| `--keep-spec` | Keep intermediate OpenAPI specs | `false` |
|
|
401
|
+
| `--timeout <ms>` | Request timeout | `30000` |
|
|
638
402
|
|
|
639
403
|
**Examples:**
|
|
640
404
|
|
|
641
405
|
```bash
|
|
642
|
-
#
|
|
643
|
-
klasik generate-jsonschema \
|
|
644
|
-
--url https://json.schemastore.org/kustomization.json \
|
|
645
|
-
--output ./generated/kustomization
|
|
646
|
-
|
|
647
|
-
# Generate from multiple JSON Schema files (merged into single output)
|
|
406
|
+
# From SchemaStore
|
|
648
407
|
klasik generate-jsonschema \
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
--output ./generated/schemas
|
|
408
|
+
--url https://json.schemastore.org/package.json \
|
|
409
|
+
--output ./src/types
|
|
652
410
|
|
|
653
|
-
#
|
|
411
|
+
# Multiple schemas
|
|
654
412
|
klasik generate-jsonschema \
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
-u ./schemas/another-schema.json \
|
|
413
|
+
--url https://json.schemastore.org/kustomization.json \
|
|
414
|
+
--url https://json.schemastore.org/package.json \
|
|
658
415
|
--output ./src/generated
|
|
659
416
|
|
|
660
|
-
#
|
|
417
|
+
# From local file
|
|
661
418
|
klasik generate-jsonschema \
|
|
662
|
-
--url ./schemas/ \
|
|
663
|
-
--output ./src/
|
|
419
|
+
--url ./schemas/user.json \
|
|
420
|
+
--output ./src/types \
|
|
664
421
|
--nestjs-swagger \
|
|
665
422
|
--class-validator
|
|
666
|
-
|
|
667
|
-
# From local file with ESM support
|
|
668
|
-
klasik generate-jsonschema \
|
|
669
|
-
--url ./local-schema.json \
|
|
670
|
-
--output ./generated \
|
|
671
|
-
--esm
|
|
672
|
-
|
|
673
|
-
# Keep intermediate OpenAPI specs for debugging
|
|
674
|
-
klasik generate-jsonschema \
|
|
675
|
-
--url https://json.schemastore.org/kustomization.json \
|
|
676
|
-
--output ./generated \
|
|
677
|
-
--keep-spec
|
|
678
|
-
```
|
|
679
|
-
|
|
680
|
-
**Output Structure:**
|
|
681
|
-
|
|
682
|
-
```
|
|
683
|
-
output/
|
|
684
|
-
├── models/
|
|
685
|
-
│ ├── type-a.ts
|
|
686
|
-
│ ├── type-b.ts
|
|
687
|
-
│ └── ... (all definitions from all schemas)
|
|
688
|
-
└── index.ts
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
## Programmatic API
|
|
692
|
-
|
|
693
|
-
### OpenAPIClientGenerator
|
|
694
|
-
|
|
695
|
-
```typescript
|
|
696
|
-
import { OpenAPIClientGenerator } from 'klasik';
|
|
697
|
-
|
|
698
|
-
const generator = new OpenAPIClientGenerator();
|
|
699
|
-
|
|
700
|
-
await generator.generate({
|
|
701
|
-
specUrl: 'https://api.example.com/openapi.json',
|
|
702
|
-
outputDir: './client',
|
|
703
|
-
mode: 'models-only',
|
|
704
|
-
headers: {
|
|
705
|
-
'Authorization': 'Bearer token123',
|
|
706
|
-
'X-Custom-Header': 'value'
|
|
707
|
-
},
|
|
708
|
-
resolveReferences: true, // Download external $ref files
|
|
709
|
-
nestJsSwagger: true, // Include @ApiProperty decorators
|
|
710
|
-
classValidator: true, // Include validation decorators
|
|
711
|
-
templateDir: './custom-templates', // Optional
|
|
712
|
-
keepSpec: true, // Keep downloaded spec file
|
|
713
|
-
timeout: 60000 // Request timeout in ms
|
|
714
|
-
});
|
|
715
423
|
```
|
|
716
424
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
```typescript
|
|
720
|
-
import { SpecDownloader } from 'klasik';
|
|
721
|
-
|
|
722
|
-
const downloader = new SpecDownloader();
|
|
425
|
+
## Kubernetes CRD Support
|
|
723
426
|
|
|
724
|
-
|
|
725
|
-
url: 'https://api.example.com/openapi.json',
|
|
726
|
-
outputPath: './specs/api-spec.json',
|
|
727
|
-
headers: {
|
|
728
|
-
'Authorization': 'Bearer token123'
|
|
729
|
-
},
|
|
730
|
-
resolveReferences: true, // Download external $ref files
|
|
731
|
-
timeout: 30000
|
|
732
|
-
});
|
|
427
|
+
Klasik can generate TypeScript models directly from Kubernetes CustomResourceDefinitions (CRDs). Perfect for working with custom Kubernetes resources like ArgoCD Applications, Cert-Manager Certificates, or your own custom resources.
|
|
733
428
|
|
|
734
|
-
|
|
429
|
+
### Features
|
|
735
430
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
431
|
+
- ✅ **Automatic schema extraction** from `openAPIV3Schema`
|
|
432
|
+
- ✅ **Multiple URL support** - Generate from multiple CRDs in one command
|
|
433
|
+
- ✅ **Automatic deduplication** - Shared types (ObjectMeta, TypeMeta) generated once
|
|
434
|
+
- ✅ **Multi-document YAML** - Process multiple CRDs from a single file
|
|
435
|
+
- ✅ **Nested type extraction** - Complex objects become separate interfaces
|
|
436
|
+
- ✅ **Full decorator support** - NestJS, class-validator, class-transformer
|
|
437
|
+
- ✅ **Status schemas** - Optional with `--include-status`
|
|
438
|
+
- ✅ **Version support** - Handles multiple CRD versions (v1alpha1, v1, etc.)
|
|
739
439
|
|
|
740
|
-
###
|
|
440
|
+
### Automatic Deduplication
|
|
741
441
|
|
|
742
|
-
|
|
442
|
+
When generating from multiple CRDs, Klasik automatically deduplicates shared types by name:
|
|
743
443
|
|
|
744
|
-
```
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
await generator.generate({
|
|
750
|
-
url: 'https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml',
|
|
751
|
-
outputDir: './generated/crds',
|
|
752
|
-
includeStatus: true, // Generate status models
|
|
753
|
-
nestJsSwagger: true, // Include @ApiProperty decorators
|
|
754
|
-
classValidator: true, // Include validation decorators
|
|
755
|
-
fixEsmImports: false, // Add .js extensions
|
|
756
|
-
headers: {
|
|
757
|
-
'Authorization': 'Bearer token123'
|
|
758
|
-
},
|
|
759
|
-
timeout: 60000
|
|
760
|
-
});
|
|
444
|
+
```bash
|
|
445
|
+
klasik generate-crd \
|
|
446
|
+
--url application-crd.yaml \ # Defines ObjectMeta
|
|
447
|
+
--url appproject-crd.yaml \ # Also defines ObjectMeta
|
|
448
|
+
--output ./generated
|
|
761
449
|
```
|
|
762
450
|
|
|
763
|
-
**
|
|
764
|
-
- `url: string` - URL or file path to CRD YAML (required)
|
|
765
|
-
- `outputDir: string` - Output directory (required)
|
|
766
|
-
- `includeStatus?: boolean` - Generate status schemas (default: false)
|
|
767
|
-
- `headers?: Record<string, string>` - Custom HTTP headers
|
|
768
|
-
- `timeout?: number` - Request timeout in milliseconds (default: 30000)
|
|
769
|
-
- `fixEsmImports?: boolean` - Add .js extensions for ESM (default: false)
|
|
770
|
-
- `nestJsSwagger?: boolean` - Include NestJS decorators (default: false)
|
|
771
|
-
- `classValidator?: boolean` - Include validation decorators (default: false)
|
|
772
|
-
- `skipJsExtensions?: boolean` - Skip .js extensions (default: false)
|
|
773
|
-
- `templateDir?: string` - Custom template directory
|
|
774
|
-
- `keepSpec?: boolean` - Keep intermediate OpenAPI specs (default: false)
|
|
775
|
-
|
|
776
|
-
**Multi-CRD YAML:**
|
|
777
|
-
|
|
778
|
-
The CRDGenerator automatically handles multi-document YAML files:
|
|
779
|
-
|
|
780
|
-
```typescript
|
|
781
|
-
// This YAML contains multiple CRDs separated by ---
|
|
782
|
-
await generator.generate({
|
|
783
|
-
url: './all-crds.yaml', // Contains AppProject, Application, etc.
|
|
784
|
-
outputDir: './generated',
|
|
785
|
-
includeStatus: true
|
|
786
|
-
});
|
|
787
|
-
|
|
788
|
-
// Output will be organized by CRD kind
|
|
789
|
-
// ./generated/AppProject/v1alpha1/...
|
|
790
|
-
// ./generated/Application/v1alpha1/...
|
|
791
|
-
```
|
|
451
|
+
**Result:** Only ONE `object-meta.ts` file is generated. The last CRD's definition is used (controllable via URL order).
|
|
792
452
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
The generated TypeScript client includes:
|
|
796
|
-
|
|
797
|
-
- ✅ **Class-transformer decorators** - `@Expose()` and `@Type()` on all models
|
|
798
|
-
- ✅ **Automatic response transformation** - API responses converted to class instances
|
|
799
|
-
- ✅ **Runtime type metadata** - Static `attributeTypeMap` on all models
|
|
800
|
-
- ✅ **Union type support** - `anyOf` schemas become TypeScript unions
|
|
801
|
-
- ✅ **Rich TSDoc comments** - Comprehensive documentation from OpenAPI spec metadata
|
|
802
|
-
- ✅ **Vendor extensions** - Preserved in JSDoc comments and metadata
|
|
803
|
-
- ✅ **Error handling** - Configurable transformation error handlers
|
|
804
|
-
- ✅ **Configuration options** - Enable/disable transformation, custom error handlers
|
|
805
|
-
- ✅ **NestJS Swagger decorators** (optional) - `@ApiProperty` with type, description, example, required, and nullable when `--nestjs-swagger` is enabled
|
|
806
|
-
- ✅ **class-validator decorators** (optional) - Runtime validation decorators when `--class-validator` is enabled (full support in v2.0+)
|
|
807
|
-
|
|
808
|
-
### Enhanced TSDoc Documentation
|
|
809
|
-
|
|
810
|
-
Klasik includes enhanced Mustache templates that generate rich TSDoc comments from your OpenAPI specification. The generated code includes:
|
|
811
|
-
|
|
812
|
-
**For Models:**
|
|
813
|
-
- Class-level documentation with description
|
|
814
|
-
- Property descriptions from OpenAPI schema
|
|
815
|
-
- Type information with `@type` tags
|
|
816
|
-
- Validation constraints (`@minimum`, `@maximum`, `@minLength`, `@maxLength`, `@pattern`)
|
|
817
|
-
- Format specifications (`@format`)
|
|
818
|
-
- Example values (`@example`)
|
|
819
|
-
- Required field markers (`@required`)
|
|
820
|
-
- Deprecation warnings (`@deprecated`)
|
|
821
|
-
|
|
822
|
-
**For API Endpoints:**
|
|
823
|
-
- Method name and HTTP verb (`@method`)
|
|
824
|
-
- Summary and detailed descriptions
|
|
825
|
-
- Parameter documentation with types and requirements
|
|
826
|
-
- Return type information
|
|
827
|
-
- Error scenarios (`@throws`)
|
|
828
|
-
- Deprecation notices
|
|
829
|
-
|
|
830
|
-
Example generated model with rich TSDoc:
|
|
453
|
+
### Generated Structure
|
|
831
454
|
|
|
832
|
-
```typescript
|
|
833
|
-
/**
|
|
834
|
-
* User
|
|
835
|
-
*
|
|
836
|
-
* Represents a user in the system
|
|
837
|
-
*
|
|
838
|
-
* @export
|
|
839
|
-
* @class User
|
|
840
|
-
*/
|
|
841
|
-
export class User {
|
|
842
|
-
/**
|
|
843
|
-
* id - Unique identifier for the user
|
|
844
|
-
*
|
|
845
|
-
* @type {string}
|
|
846
|
-
* @memberof User
|
|
847
|
-
* @required
|
|
848
|
-
* @format uuid
|
|
849
|
-
* @example "550e8400-e29b-41d4-a716-446655440000"
|
|
850
|
-
*/
|
|
851
|
-
@Expose()
|
|
852
|
-
'id': string;
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* email - User's email address
|
|
856
|
-
*
|
|
857
|
-
* @type {string}
|
|
858
|
-
* @memberof User
|
|
859
|
-
* @required
|
|
860
|
-
* @format email
|
|
861
|
-
* @pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
|
|
862
|
-
*/
|
|
863
|
-
@Expose()
|
|
864
|
-
'email': string;
|
|
865
|
-
}
|
|
866
455
|
```
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
* @param {string} userId - The user's unique identifier (required)
|
|
879
|
-
* @param {RawAxiosRequestConfig} [options] Override http request option.
|
|
880
|
-
* @throws {RequiredError} When required parameters are missing
|
|
881
|
-
* @returns {Promise<AxiosResponse<User>>}
|
|
882
|
-
*/
|
|
883
|
-
async getUserById(userId: string, options?: RawAxiosRequestConfig): Promise<AxiosResponse<User>>
|
|
456
|
+
src/generated/
|
|
457
|
+
└── models/
|
|
458
|
+
├── application.ts # Main Application CRD
|
|
459
|
+
├── application-spec.ts # Nested spec type
|
|
460
|
+
├── application-status.ts # Status (with --include-status)
|
|
461
|
+
├── app-project.ts # Main AppProject CRD
|
|
462
|
+
├── object-meta.ts # SHARED (deduplicated)
|
|
463
|
+
├── type-meta.ts # SHARED (deduplicated)
|
|
464
|
+
├── package.json
|
|
465
|
+
├── tsconfig.json
|
|
466
|
+
└── index.ts # Barrel exports
|
|
884
467
|
```
|
|
885
468
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
**Note:** Klasik's templates automatically handle special characters in descriptions by using proper escaping, ensuring your TSDoc comments are always valid even when OpenAPI descriptions contain characters like `*`, `/`, `@`, etc.
|
|
889
|
-
|
|
890
|
-
### Using the Generated Client
|
|
469
|
+
### Using Generated CRD Models
|
|
891
470
|
|
|
892
471
|
```typescript
|
|
893
|
-
import {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
472
|
+
import { Application } from './generated/models';
|
|
473
|
+
|
|
474
|
+
const app = new Application();
|
|
475
|
+
app.apiVersion = 'argoproj.io/v1alpha1';
|
|
476
|
+
app.kind = 'Application';
|
|
477
|
+
app.metadata = {
|
|
478
|
+
name: 'my-app',
|
|
479
|
+
namespace: 'default'
|
|
480
|
+
};
|
|
481
|
+
app.spec = {
|
|
482
|
+
project: 'default',
|
|
483
|
+
source: {
|
|
484
|
+
repoURL: 'https://github.com/example/repo',
|
|
485
|
+
path: '.',
|
|
486
|
+
targetRevision: 'HEAD'
|
|
487
|
+
},
|
|
488
|
+
destination: {
|
|
489
|
+
server: 'https://kubernetes.default.svc',
|
|
490
|
+
namespace: 'default'
|
|
491
|
+
}
|
|
492
|
+
};
|
|
910
493
|
|
|
911
|
-
|
|
494
|
+
// Full TypeScript intellisense and type checking!
|
|
912
495
|
```
|
|
913
496
|
|
|
914
|
-
##
|
|
915
|
-
|
|
916
|
-
Klasik can automatically resolve and download external `$ref` references in your OpenAPI specs. This is useful when your spec splits schemas across multiple files.
|
|
917
|
-
|
|
918
|
-
### How It Works
|
|
919
|
-
|
|
920
|
-
When you enable `--resolve-refs` (CLI) or `resolveReferences: true` (programmatic), klasik will:
|
|
921
|
-
|
|
922
|
-
1. **Parse the main spec** for external `$ref` references
|
|
923
|
-
2. **Download all referenced files** preserving directory structure
|
|
924
|
-
3. **Recursively resolve nested references** in downloaded files
|
|
925
|
-
4. **Use the same authentication** for all downloads
|
|
926
|
-
|
|
927
|
-
### Example OpenAPI Spec with External References
|
|
497
|
+
## JSON Schema Support
|
|
928
498
|
|
|
929
|
-
|
|
930
|
-
{
|
|
931
|
-
"openapi": "3.0.0",
|
|
932
|
-
"paths": {
|
|
933
|
-
"/users": {
|
|
934
|
-
"get": {
|
|
935
|
-
"responses": {
|
|
936
|
-
"200": {
|
|
937
|
-
"content": {
|
|
938
|
-
"application/json": {
|
|
939
|
-
"schema": {
|
|
940
|
-
"$ref": "./schemas/users-orgs.yaml#/components/schemas/Org"
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
```
|
|
499
|
+
Klasik can generate TypeScript models from JSON Schema files (like those from [SchemaStore.org](https://schemastore.org)). Perfect for configuration files, data formats, and schema definitions.
|
|
951
500
|
|
|
952
|
-
|
|
501
|
+
### Features
|
|
953
502
|
|
|
954
|
-
|
|
503
|
+
- ✅ **All definitions generated** - Creates models for every definition
|
|
504
|
+
- ✅ **Multiple URL support** - Merge models from multiple schemas
|
|
505
|
+
- ✅ **Standards compliant** - Supports JSON Schema Draft 4 and Draft 7
|
|
506
|
+
- ✅ **Nested type extraction** - Complex objects become separate interfaces
|
|
507
|
+
- ✅ **Full decorator support** - NestJS, class-validator, class-transformer
|
|
508
|
+
- ✅ **Automatic naming** - Schema title or filename becomes class name
|
|
955
509
|
|
|
956
|
-
|
|
510
|
+
### Generated Structure
|
|
957
511
|
|
|
958
512
|
```
|
|
959
513
|
output/
|
|
960
|
-
├──
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
### Supported Reference Types
|
|
968
|
-
|
|
969
|
-
- **Relative paths**: `./schemas/user.yaml`, `../common/types.yaml`
|
|
970
|
-
- When the main spec is from a remote URL, relative paths are resolved against the spec's URL
|
|
971
|
-
- Example: spec at `https://raw.githubusercontent.com/org/repo/main/api/openapi.yaml` with ref `./schemas/user.yaml` resolves to `https://raw.githubusercontent.com/org/repo/main/api/schemas/user.yaml`
|
|
972
|
-
- **Remote URLs**: `https://api.example.com/schemas/user.yaml`
|
|
973
|
-
- **Mixed**: Main spec from HTTPS, references can be relative or absolute
|
|
974
|
-
|
|
975
|
-
### CLI Example
|
|
976
|
-
|
|
977
|
-
```bash
|
|
978
|
-
# Download spec with all external references
|
|
979
|
-
npx klasik generate \
|
|
980
|
-
--url https://api.example.com/openapi.json \
|
|
981
|
-
--output ./client \
|
|
982
|
-
--header "Authorization: Bearer token" \
|
|
983
|
-
--resolve-refs
|
|
514
|
+
├── models/
|
|
515
|
+
│ ├── package.ts
|
|
516
|
+
│ ├── person.ts
|
|
517
|
+
│ ├── repository.ts
|
|
518
|
+
│ └── index.ts
|
|
519
|
+
├── package.json
|
|
520
|
+
└── tsconfig.json
|
|
984
521
|
```
|
|
985
522
|
|
|
986
|
-
###
|
|
523
|
+
### Using Generated JSON Schema Models
|
|
987
524
|
|
|
988
525
|
```typescript
|
|
989
|
-
import {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
526
|
+
import { Package } from './generated/models';
|
|
527
|
+
|
|
528
|
+
const pkg: Package = {
|
|
529
|
+
name: 'my-package',
|
|
530
|
+
version: '1.0.0',
|
|
531
|
+
description: 'My awesome package',
|
|
532
|
+
author: {
|
|
533
|
+
name: 'John Doe',
|
|
534
|
+
email: 'john@example.com'
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// Full TypeScript intellisense and type checking!
|
|
998
539
|
```
|
|
999
540
|
|
|
1000
541
|
## NestJS Integration
|
|
1001
542
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
Klasik-generated models integrate seamlessly with NestJS applications. Use `--mode models-only` with decorator flags for best results.
|
|
543
|
+
Klasik integrates seamlessly with NestJS, generating models with `@ApiProperty` decorators for automatic Swagger/OpenAPI documentation and `class-validator` decorators for runtime validation.
|
|
1005
544
|
|
|
1006
|
-
|
|
545
|
+
### Setup
|
|
1007
546
|
|
|
1008
|
-
Generate models with
|
|
547
|
+
Generate models with NestJS support:
|
|
1009
548
|
|
|
1010
549
|
```bash
|
|
1011
|
-
|
|
550
|
+
klasik generate \
|
|
1012
551
|
--url https://api.example.com/openapi.json \
|
|
1013
|
-
--output ./src/generated
|
|
552
|
+
--output ./src/generated \
|
|
1014
553
|
--mode models-only \
|
|
1015
|
-
--nestjs-swagger
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
This generates DTOs like:
|
|
1019
|
-
|
|
1020
|
-
```typescript
|
|
1021
|
-
import { Expose } from 'class-transformer';
|
|
1022
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
1023
|
-
|
|
1024
|
-
export class UserDto {
|
|
1025
|
-
@ApiProperty({
|
|
1026
|
-
type: String,
|
|
1027
|
-
description: 'Unique identifier',
|
|
1028
|
-
required: true,
|
|
1029
|
-
example: '123e4567-e89b-41d3-a456-426614174000',
|
|
1030
|
-
})
|
|
1031
|
-
@Expose()
|
|
1032
|
-
id: string;
|
|
1033
|
-
|
|
1034
|
-
@ApiProperty({
|
|
1035
|
-
type: String,
|
|
1036
|
-
description: 'User email address',
|
|
1037
|
-
required: true,
|
|
1038
|
-
format: 'email',
|
|
1039
|
-
})
|
|
1040
|
-
@Expose()
|
|
1041
|
-
email: string;
|
|
1042
|
-
}
|
|
554
|
+
--nestjs-swagger \
|
|
555
|
+
--class-validator
|
|
1043
556
|
```
|
|
1044
557
|
|
|
1045
|
-
|
|
558
|
+
### Using in NestJS Controllers
|
|
1046
559
|
|
|
1047
560
|
```typescript
|
|
1048
|
-
import { Controller,
|
|
1049
|
-
import { ApiTags,
|
|
1050
|
-
import {
|
|
561
|
+
import { Controller, Post, Body } from '@nestjs/common';
|
|
562
|
+
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
563
|
+
import { CreateUserDto } from './generated/models';
|
|
1051
564
|
|
|
1052
565
|
@ApiTags('users')
|
|
1053
566
|
@Controller('users')
|
|
1054
567
|
export class UsersController {
|
|
1055
|
-
@Get()
|
|
1056
|
-
@ApiResponse({ type: [UserDto], status: 200 })
|
|
1057
|
-
async findAll(): Promise<UserDto[]> {
|
|
1058
|
-
// Your implementation
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
568
|
@Post()
|
|
1062
|
-
@
|
|
1063
|
-
async create(@Body() createUserDto:
|
|
1064
|
-
//
|
|
569
|
+
@ApiOperation({ summary: 'Create user' })
|
|
570
|
+
async create(@Body() createUserDto: CreateUserDto) {
|
|
571
|
+
// Automatic validation via class-validator
|
|
572
|
+
// Automatic Swagger docs via @ApiProperty
|
|
573
|
+
return this.usersService.create(createUserDto);
|
|
1065
574
|
}
|
|
1066
575
|
}
|
|
1067
576
|
```
|
|
1068
577
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
#### Runtime Validation Support
|
|
1072
|
-
|
|
1073
|
-
Add the `--class-validator` flag for runtime validation decorators:
|
|
1074
|
-
|
|
1075
|
-
```bash
|
|
1076
|
-
npx klasik generate \
|
|
1077
|
-
--url https://api.example.com/openapi.json \
|
|
1078
|
-
--output ./src/generated/dto \
|
|
1079
|
-
--mode models-only \
|
|
1080
|
-
--nestjs-swagger \
|
|
1081
|
-
--class-validator
|
|
1082
|
-
```
|
|
1083
|
-
|
|
1084
|
-
**Note**: Full decorator generation requires openapi-class-transformer v2.0+. For now, the dependencies are added to package.json, and you can manually add validation decorators:
|
|
578
|
+
### Generated Model Example
|
|
1085
579
|
|
|
1086
580
|
```typescript
|
|
1087
|
-
import { Expose } from 'class-transformer';
|
|
1088
581
|
import { ApiProperty } from '@nestjs/swagger';
|
|
1089
|
-
import { IsString, IsEmail } from 'class-validator';
|
|
1090
|
-
|
|
1091
|
-
export class UserDto {
|
|
1092
|
-
@ApiProperty({ type: String, required: true })
|
|
1093
|
-
@IsString()
|
|
1094
|
-
@Expose()
|
|
1095
|
-
id: string;
|
|
1096
|
-
|
|
1097
|
-
@ApiProperty({ type: String, required: true, format: 'email' })
|
|
1098
|
-
@IsEmail()
|
|
1099
|
-
@Expose()
|
|
1100
|
-
email: string;
|
|
1101
|
-
}
|
|
1102
|
-
```
|
|
582
|
+
import { IsString, IsEmail, MinLength, IsOptional } from 'class-validator';
|
|
583
|
+
import { Expose } from 'class-transformer';
|
|
1103
584
|
|
|
1104
|
-
|
|
585
|
+
export class CreateUserDto {
|
|
586
|
+
@Expose()
|
|
587
|
+
@ApiProperty({
|
|
588
|
+
type: String,
|
|
589
|
+
description: 'User email address',
|
|
590
|
+
required: true,
|
|
591
|
+
format: 'email'
|
|
592
|
+
})
|
|
593
|
+
@IsEmail()
|
|
594
|
+
email: string;
|
|
595
|
+
|
|
596
|
+
@Expose()
|
|
597
|
+
@ApiProperty({
|
|
598
|
+
type: String,
|
|
599
|
+
description: 'User password',
|
|
600
|
+
required: true,
|
|
601
|
+
minLength: 8
|
|
602
|
+
})
|
|
603
|
+
@IsString()
|
|
604
|
+
@MinLength(8)
|
|
605
|
+
password: string;
|
|
1105
606
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
// In controller
|
|
1116
|
-
@Post()
|
|
1117
|
-
async create(@Body() dto: UserDto): Promise<UserDto> {
|
|
1118
|
-
// dto is already validated and transformed to UserDto instance!
|
|
607
|
+
@Expose()
|
|
608
|
+
@ApiProperty({
|
|
609
|
+
type: String,
|
|
610
|
+
description: 'User display name',
|
|
611
|
+
required: false
|
|
612
|
+
})
|
|
613
|
+
@IsString()
|
|
614
|
+
@IsOptional()
|
|
615
|
+
name?: string;
|
|
1119
616
|
}
|
|
1120
617
|
```
|
|
1121
618
|
|
|
1122
|
-
|
|
619
|
+
## Advanced Topics
|
|
620
|
+
|
|
621
|
+
### External Reference Resolution
|
|
1123
622
|
|
|
1124
|
-
When
|
|
623
|
+
When your OpenAPI spec uses external `$ref`, Klasik can automatically download and inline them:
|
|
1125
624
|
|
|
1126
625
|
```bash
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
626
|
+
klasik generate \
|
|
627
|
+
--url ./api-spec.yaml \
|
|
628
|
+
--output ./generated \
|
|
629
|
+
--resolve-refs
|
|
1130
630
|
```
|
|
1131
631
|
|
|
1132
|
-
|
|
632
|
+
**What it does:**
|
|
633
|
+
1. Discovers all external `$ref` recursively
|
|
634
|
+
2. Downloads referenced files (with auth if needed)
|
|
635
|
+
3. Inlines them into the main spec
|
|
636
|
+
4. Generates complete TypeScript types
|
|
1133
637
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
638
|
+
**Supported formats:**
|
|
639
|
+
- ✅ Relative paths: `./schemas/User.yaml`
|
|
640
|
+
- ✅ Absolute paths: `/path/to/schema.yaml`
|
|
641
|
+
- ✅ Remote URLs: `https://api.example.com/schemas/User.yaml`
|
|
642
|
+
- ✅ With fragments: `./User.yaml#/definitions/User`
|
|
643
|
+
- ✅ Nested refs (ref within ref)
|
|
644
|
+
- ✅ Circular reference detection
|
|
645
|
+
|
|
646
|
+
**Example spec with external refs:**
|
|
647
|
+
|
|
648
|
+
```yaml
|
|
649
|
+
# main-spec.yaml
|
|
650
|
+
components:
|
|
651
|
+
schemas:
|
|
652
|
+
User:
|
|
653
|
+
$ref: './schemas/user.yaml' # Local file
|
|
654
|
+
Post:
|
|
655
|
+
$ref: 'https://api.example.com/schemas/post.yaml' # Remote URL
|
|
656
|
+
Comment:
|
|
657
|
+
$ref: './schemas/comment.yaml#/Comment' # With fragment
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
**With authentication:**
|
|
661
|
+
```bash
|
|
662
|
+
klasik generate \
|
|
663
|
+
--url https://private-api.com/spec.yaml \
|
|
664
|
+
--resolve-refs \
|
|
665
|
+
--header "Authorization: Bearer ${TOKEN}"
|
|
1141
666
|
```
|
|
1142
667
|
|
|
1143
|
-
|
|
668
|
+
### Authentication Headers
|
|
1144
669
|
|
|
1145
|
-
|
|
1146
|
-
2. **Separate directories**: Generate into `src/generated/dto` or similar
|
|
1147
|
-
3. **Extend generated classes**: For complex validation, extend generated DTOs
|
|
1148
|
-
4. **Version control**: Commit generated files or regenerate in CI/CD
|
|
670
|
+
Access private API specs with custom headers:
|
|
1149
671
|
|
|
1150
|
-
```
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
672
|
+
```bash
|
|
673
|
+
# Bearer token
|
|
674
|
+
klasik generate \
|
|
675
|
+
--url https://internal-api.company.com/spec.json \
|
|
676
|
+
--header "Authorization: Bearer ${API_TOKEN}" \
|
|
677
|
+
--output ./generated
|
|
1154
678
|
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1159
|
-
|
|
679
|
+
# API key
|
|
680
|
+
klasik generate \
|
|
681
|
+
--url https://api.example.com/spec.json \
|
|
682
|
+
--header "X-API-Key: ${API_KEY}" \
|
|
683
|
+
--output ./generated
|
|
1160
684
|
|
|
1161
|
-
|
|
685
|
+
# Multiple headers
|
|
686
|
+
klasik generate \
|
|
687
|
+
--url https://api.example.com/spec.json \
|
|
688
|
+
--header "Authorization: Bearer ${TOKEN}" \
|
|
689
|
+
--header "X-Custom-Header: value" \
|
|
690
|
+
--output ./generated
|
|
691
|
+
```
|
|
1162
692
|
|
|
1163
|
-
|
|
693
|
+
### ESM Support
|
|
1164
694
|
|
|
1165
|
-
|
|
695
|
+
For Node.js ESM projects, use the `--esm` flag to add `.js` extensions to imports:
|
|
1166
696
|
|
|
1167
697
|
```bash
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
--
|
|
1171
|
-
--
|
|
1172
|
-
--mode models-only \
|
|
1173
|
-
--resolve-refs
|
|
698
|
+
klasik generate \
|
|
699
|
+
--url ./openapi.yaml \
|
|
700
|
+
--output ./generated \
|
|
701
|
+
--esm
|
|
1174
702
|
```
|
|
1175
703
|
|
|
1176
|
-
|
|
704
|
+
**Generated imports:**
|
|
1177
705
|
|
|
1178
|
-
|
|
706
|
+
```typescript
|
|
707
|
+
// With --esm
|
|
708
|
+
import { User } from './user.js';
|
|
709
|
+
import { Post } from './post.js';
|
|
1179
710
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
{
|
|
1183
|
-
"scripts": {
|
|
1184
|
-
"generate-client": "npx klasik generate --url $API_URL --output ./src/generated --mode models-only --resolve-refs && npm run cleanup-generated",
|
|
1185
|
-
"cleanup-generated": "rm -f ./src/generated/package.json ./src/generated/tsconfig*.json ./src/generated/.openapi-generator*"
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
711
|
+
// Without --esm
|
|
712
|
+
import { User } from './user';
|
|
713
|
+
import { Post } from './post';
|
|
1188
714
|
```
|
|
1189
715
|
|
|
1190
|
-
|
|
716
|
+
**For bundlers (webpack, vite, esbuild):**
|
|
1191
717
|
|
|
1192
|
-
|
|
718
|
+
Use `--skip-js-extensions` to omit extensions:
|
|
1193
719
|
|
|
1194
|
-
```
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
720
|
+
```bash
|
|
721
|
+
klasik generate \
|
|
722
|
+
--url ./openapi.yaml \
|
|
723
|
+
--output ./generated \
|
|
724
|
+
--esm \
|
|
725
|
+
--skip-js-extensions
|
|
1202
726
|
```
|
|
1203
727
|
|
|
1204
|
-
###
|
|
728
|
+
### Custom Templates
|
|
1205
729
|
|
|
1206
|
-
|
|
1207
|
-
- Only need data models with class-transformer decorators
|
|
1208
|
-
- Want to use your own API client (axios, fetch, etc.)
|
|
1209
|
-
- Are integrating into an existing project with its own HTTP layer
|
|
1210
|
-
- Want to avoid package.json/tsconfig.json conflicts
|
|
730
|
+
Klasik uses Mustache templates for code generation. You can provide custom templates:
|
|
1211
731
|
|
|
1212
732
|
```bash
|
|
1213
|
-
|
|
1214
|
-
--url
|
|
1215
|
-
--output ./
|
|
1216
|
-
--
|
|
733
|
+
klasik generate \
|
|
734
|
+
--url ./openapi.yaml \
|
|
735
|
+
--output ./generated \
|
|
736
|
+
--template ./my-templates
|
|
1217
737
|
```
|
|
1218
738
|
|
|
1219
|
-
|
|
739
|
+
**Template structure:**
|
|
1220
740
|
|
|
1221
|
-
|
|
1222
|
-
-
|
|
1223
|
-
|
|
1224
|
-
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
npx klasik generate \
|
|
1228
|
-
--url https://api.example.com/openapi.yaml \
|
|
1229
|
-
--output ./api-client \
|
|
1230
|
-
--mode full # Generates complete client with APIs
|
|
741
|
+
```
|
|
742
|
+
my-templates/
|
|
743
|
+
├── model.mustache # Model class template
|
|
744
|
+
├── api-class.mustache # API class template (full mode)
|
|
745
|
+
├── configuration.mustache # Configuration class template
|
|
746
|
+
└── index.mustache # Barrel export template
|
|
1231
747
|
```
|
|
1232
748
|
|
|
1233
|
-
###
|
|
749
|
+
### Best Practices
|
|
1234
750
|
|
|
1235
|
-
|
|
751
|
+
#### 1. Use Version Pinning
|
|
1236
752
|
|
|
1237
|
-
|
|
1238
|
-
# Generate ESM-compatible code
|
|
1239
|
-
npx klasik generate \
|
|
1240
|
-
--url https://api.example.com/openapi.yaml \
|
|
1241
|
-
--output ./src/generated \
|
|
1242
|
-
--mode models-only \
|
|
1243
|
-
--esm # ✅ Adds .js extensions to imports
|
|
1244
|
-
```
|
|
753
|
+
For production projects, pin to specific spec versions:
|
|
1245
754
|
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
-
|
|
1249
|
-
|
|
1250
|
-
|
|
755
|
+
```bash
|
|
756
|
+
# ✅ Good: Specific commit hash
|
|
757
|
+
klasik generate-crd \
|
|
758
|
+
--url https://raw.githubusercontent.com/argoproj/argo-cd/v2.8.0/manifests/crds/application-crd.yaml \
|
|
759
|
+
--output ./src/types
|
|
1251
760
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
export * from './api/orgs-api';
|
|
761
|
+
# ❌ Bad: Using master/main branch
|
|
762
|
+
klasik generate-crd \
|
|
763
|
+
--url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
|
|
764
|
+
--output ./src/types
|
|
1257
765
|
```
|
|
1258
766
|
|
|
1259
|
-
|
|
1260
|
-
```typescript
|
|
1261
|
-
import { User } from './models/user.js';
|
|
1262
|
-
import { Cluster } from '../models/cluster.js';
|
|
1263
|
-
export * from './api/orgs-api.js';
|
|
1264
|
-
```
|
|
767
|
+
#### 2. Keep Generated Code Separate
|
|
1265
768
|
|
|
1266
|
-
|
|
1267
|
-
- Your package.json has `"type": "module"`
|
|
1268
|
-
- You're using Node.js native ESM
|
|
1269
|
-
- You're targeting modern JavaScript environments
|
|
1270
|
-
- You want to eliminate post-processing scripts
|
|
769
|
+
Store generated code in a dedicated directory:
|
|
1271
770
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
771
|
+
```
|
|
772
|
+
src/
|
|
773
|
+
├── api/
|
|
774
|
+
│ └── generated/ # Generated code here
|
|
775
|
+
│ ├── models/
|
|
776
|
+
│ ├── apis/
|
|
777
|
+
│ └── index.ts
|
|
778
|
+
├── services/ # Your business logic
|
|
779
|
+
└── controllers/ # Your controllers
|
|
1280
780
|
```
|
|
1281
781
|
|
|
1282
|
-
|
|
782
|
+
Add to `.gitignore`:
|
|
1283
783
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
```typescript
|
|
1287
|
-
const config = new Configuration({
|
|
1288
|
-
basePath: 'https://api.example.com',
|
|
1289
|
-
onTransformationError: (error, modelClass, data) => {
|
|
1290
|
-
// Log to custom logger
|
|
1291
|
-
logger.error('Failed to transform response', {
|
|
1292
|
-
error: error.message,
|
|
1293
|
-
modelClass: modelClass.name,
|
|
1294
|
-
rawData: data
|
|
1295
|
-
});
|
|
1296
|
-
|
|
1297
|
-
// Send to error tracking
|
|
1298
|
-
Sentry.captureException(error);
|
|
1299
|
-
}
|
|
1300
|
-
});
|
|
784
|
+
```gitignore
|
|
785
|
+
src/api/generated/
|
|
1301
786
|
```
|
|
1302
787
|
|
|
1303
|
-
|
|
788
|
+
Regenerate in CI/CD:
|
|
1304
789
|
|
|
1305
|
-
```
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
790
|
+
```yaml
|
|
791
|
+
# .github/workflows/ci.yml
|
|
792
|
+
- name: Generate API Client
|
|
793
|
+
run: |
|
|
794
|
+
npx klasik generate \
|
|
795
|
+
--url https://api.example.com/openapi.json \
|
|
796
|
+
--output ./src/api/generated \
|
|
797
|
+
--nestjs-swagger \
|
|
798
|
+
--class-validator
|
|
1310
799
|
```
|
|
1311
800
|
|
|
1312
|
-
|
|
801
|
+
#### 3. Validate After Generation
|
|
802
|
+
|
|
803
|
+
Always compile generated code to catch issues early:
|
|
1313
804
|
|
|
1314
|
-
|
|
1315
|
-
|
|
805
|
+
```bash
|
|
806
|
+
klasik generate --url ./spec.yaml --output ./generated
|
|
807
|
+
cd ./generated
|
|
808
|
+
npm install
|
|
809
|
+
npm run build
|
|
810
|
+
```
|
|
1316
811
|
|
|
1317
|
-
|
|
812
|
+
#### 4. Use Consistent Options
|
|
1318
813
|
|
|
1319
|
-
|
|
814
|
+
Create a script or Makefile for consistent generation:
|
|
1320
815
|
|
|
1321
816
|
```json
|
|
817
|
+
// package.json
|
|
1322
818
|
{
|
|
1323
|
-
"
|
|
1324
|
-
"
|
|
1325
|
-
"
|
|
819
|
+
"scripts": {
|
|
820
|
+
"generate": "klasik generate --url https://api.example.com/openapi.json --output ./src/generated --nestjs-swagger --class-validator",
|
|
821
|
+
"generate:crds": "klasik generate-crd --url https://example.com/crd.yaml --output ./src/k8s --include-status"
|
|
1326
822
|
}
|
|
1327
823
|
}
|
|
1328
824
|
```
|
|
@@ -1330,6 +826,10 @@ Your `tsconfig.json` must include:
|
|
|
1330
826
|
## Development
|
|
1331
827
|
|
|
1332
828
|
```bash
|
|
829
|
+
# Clone the repository
|
|
830
|
+
git clone https://github.com/yourusername/klasik-2.git
|
|
831
|
+
cd klasik-2
|
|
832
|
+
|
|
1333
833
|
# Install dependencies
|
|
1334
834
|
npm install
|
|
1335
835
|
|
|
@@ -1339,20 +839,25 @@ npm run build
|
|
|
1339
839
|
# Run tests
|
|
1340
840
|
npm test
|
|
1341
841
|
|
|
1342
|
-
#
|
|
1343
|
-
|
|
842
|
+
# Run CLI locally
|
|
843
|
+
node dist/cli/index.js generate --url ./test-spec.yaml --output ./test-output
|
|
1344
844
|
```
|
|
1345
845
|
|
|
846
|
+
For more details, see [CONTRIBUTING.md](CONTRIBUTING.md) and [ARCHITECTURE.md](ARCHITECTURE.md).
|
|
847
|
+
|
|
1346
848
|
## License
|
|
1347
849
|
|
|
1348
850
|
MIT
|
|
1349
851
|
|
|
1350
|
-
##
|
|
852
|
+
## Credits
|
|
1351
853
|
|
|
1352
|
-
|
|
1353
|
-
- [
|
|
1354
|
-
- [
|
|
854
|
+
Built with:
|
|
855
|
+
- [ts-morph](https://github.com/dsherret/ts-morph) - TypeScript Compiler API wrapper
|
|
856
|
+
- [class-transformer](https://github.com/typestack/class-transformer) - Object transformation
|
|
857
|
+
- [class-validator](https://github.com/typestack/class-validator) - Runtime validation
|
|
858
|
+
- [mustache](https://github.com/janl/mustache.js) - Template engine
|
|
859
|
+
- [commander](https://github.com/tj/commander.js) - CLI framework
|
|
1355
860
|
|
|
1356
|
-
|
|
861
|
+
---
|
|
1357
862
|
|
|
1358
|
-
|
|
863
|
+
**Note:** Klasik is a complete rebuild with AST-based code generation, replacing the string manipulation approach from v1. See [ARCHITECTURE.md](ARCHITECTURE.md) for technical details.
|