@kattebak/openapi-generator-ts 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/cli/commands/generate.d.ts +23 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +116 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/list.d.ts +2 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +26 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +80 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/convert-template.d.ts +31 -0
- package/dist/cli/convert-template.d.ts.map +1 -0
- package/dist/cli/convert-template.js +204 -0
- package/dist/cli/convert-template.js.map +1 -0
- package/dist/cli/convert-template.test.d.ts +2 -0
- package/dist/cli/convert-template.test.d.ts.map +1 -0
- package/dist/cli/convert-template.test.js +74 -0
- package/dist/cli/convert-template.test.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 +246 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config.d.ts +252 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +31 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/generator.d.ts +99 -0
- package/dist/core/generator.d.ts.map +1 -0
- package/dist/core/generator.js +492 -0
- package/dist/core/generator.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +47 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generators/generators.test.d.ts +6 -0
- package/dist/generators/generators.test.d.ts.map +1 -0
- package/dist/generators/generators.test.js +247 -0
- package/dist/generators/generators.test.js.map +1 -0
- package/dist/generators/go.d.ts +10 -0
- package/dist/generators/go.d.ts.map +1 -0
- package/dist/generators/go.js +327 -0
- package/dist/generators/go.js.map +1 -0
- package/dist/generators/index.d.ts +29 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +58 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/php.d.ts +14 -0
- package/dist/generators/php.d.ts.map +1 -0
- package/dist/generators/php.js +241 -0
- package/dist/generators/php.js.map +1 -0
- package/dist/generators/python.d.ts +10 -0
- package/dist/generators/python.d.ts.map +1 -0
- package/dist/generators/python.js +273 -0
- package/dist/generators/python.js.map +1 -0
- package/dist/generators/typescript-fetch.d.ts +14 -0
- package/dist/generators/typescript-fetch.d.ts.map +1 -0
- package/dist/generators/typescript-fetch.js +217 -0
- package/dist/generators/typescript-fetch.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/models/codegen-model.d.ts +123 -0
- package/dist/models/codegen-model.d.ts.map +1 -0
- package/dist/models/codegen-model.js +64 -0
- package/dist/models/codegen-model.js.map +1 -0
- package/dist/models/codegen-model.test.d.ts +6 -0
- package/dist/models/codegen-model.test.d.ts.map +1 -0
- package/dist/models/codegen-model.test.js +143 -0
- package/dist/models/codegen-model.test.js.map +1 -0
- package/dist/models/codegen-operation.d.ts +95 -0
- package/dist/models/codegen-operation.d.ts.map +1 -0
- package/dist/models/codegen-operation.js +54 -0
- package/dist/models/codegen-operation.js.map +1 -0
- package/dist/models/codegen-parameter.d.ts +86 -0
- package/dist/models/codegen-parameter.d.ts.map +1 -0
- package/dist/models/codegen-parameter.js +47 -0
- package/dist/models/codegen-parameter.js.map +1 -0
- package/dist/models/codegen-property.d.ts +95 -0
- package/dist/models/codegen-property.d.ts.map +1 -0
- package/dist/models/codegen-property.js +47 -0
- package/dist/models/codegen-property.js.map +1 -0
- package/dist/models/codegen-response.d.ts +64 -0
- package/dist/models/codegen-response.d.ts.map +1 -0
- package/dist/models/codegen-response.js +42 -0
- package/dist/models/codegen-response.js.map +1 -0
- package/dist/models/codegen-security.d.ts +34 -0
- package/dist/models/codegen-security.d.ts.map +1 -0
- package/dist/models/codegen-security.js +18 -0
- package/dist/models/codegen-security.js.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +7 -0
- package/dist/models/index.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/openapi-parser.d.ts +71 -0
- package/dist/parser/openapi-parser.d.ts.map +1 -0
- package/dist/parser/openapi-parser.js +195 -0
- package/dist/parser/openapi-parser.js.map +1 -0
- package/dist/parser/openapi-parser.test.d.ts +6 -0
- package/dist/parser/openapi-parser.test.d.ts.map +1 -0
- package/dist/parser/openapi-parser.test.js +238 -0
- package/dist/parser/openapi-parser.test.js.map +1 -0
- package/dist/parser/operation-transformer.d.ts +95 -0
- package/dist/parser/operation-transformer.d.ts.map +1 -0
- package/dist/parser/operation-transformer.js +634 -0
- package/dist/parser/operation-transformer.js.map +1 -0
- package/dist/parser/schema-transformer.d.ts +134 -0
- package/dist/parser/schema-transformer.d.ts.map +1 -0
- package/dist/parser/schema-transformer.js +557 -0
- package/dist/parser/schema-transformer.js.map +1 -0
- package/dist/template/engine-adapter.d.ts +55 -0
- package/dist/template/engine-adapter.d.ts.map +1 -0
- package/dist/template/engine-adapter.js +178 -0
- package/dist/template/engine-adapter.js.map +1 -0
- package/dist/template/engine-adapter.test.d.ts +6 -0
- package/dist/template/engine-adapter.test.d.ts.map +1 -0
- package/dist/template/engine-adapter.test.js +186 -0
- package/dist/template/engine-adapter.test.js.map +1 -0
- package/dist/template/index.d.ts +5 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +5 -0
- package/dist/template/index.js.map +1 -0
- package/dist/template/lambdas/indent-lambdas.d.ts +40 -0
- package/dist/template/lambdas/indent-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/indent-lambdas.js +98 -0
- package/dist/template/lambdas/indent-lambdas.js.map +1 -0
- package/dist/template/lambdas/index.d.ts +44 -0
- package/dist/template/lambdas/index.d.ts.map +1 -0
- package/dist/template/lambdas/index.js +79 -0
- package/dist/template/lambdas/index.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.d.ts +78 -0
- package/dist/template/lambdas/string-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.js +148 -0
- package/dist/template/lambdas/string-lambdas.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts +6 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.js +158 -0
- package/dist/template/lambdas/string-lambdas.test.js.map +1 -0
- package/dist/template/template-locator.d.ts +72 -0
- package/dist/template/template-locator.d.ts.map +1 -0
- package/dist/template/template-locator.js +173 -0
- package/dist/template/template-locator.js.map +1 -0
- package/dist/template/template-manager.d.ts +65 -0
- package/dist/template/template-manager.d.ts.map +1 -0
- package/dist/template/template-manager.js +185 -0
- package/dist/template/template-manager.js.map +1 -0
- package/package.json +67 -0
- package/templates/go/.travis.yml +8 -0
- package/templates/go/README.mustache +236 -0
- package/templates/go/api.mustache +452 -0
- package/templates/go/api_doc.mustache +92 -0
- package/templates/go/api_test.mustache +59 -0
- package/templates/go/client.mustache +761 -0
- package/templates/go/configuration.mustache +332 -0
- package/templates/go/git_push.sh.mustache +57 -0
- package/templates/go/gitignore.mustache +24 -0
- package/templates/go/go.mod.mustache +16 -0
- package/templates/go/go.sum.mustache +19 -0
- package/templates/go/model.mustache +21 -0
- package/templates/go/model_anyof.mustache +93 -0
- package/templates/go/model_doc.mustache +97 -0
- package/templates/go/model_enum.mustache +101 -0
- package/templates/go/model_oneof.mustache +160 -0
- package/templates/go/model_simple.mustache +572 -0
- package/templates/go/nullable_model.mustache +35 -0
- package/templates/go/openapi.mustache +1 -0
- package/templates/go/partial_header.mustache +18 -0
- package/templates/go/response.mustache +38 -0
- package/templates/go/signing.mustache +453 -0
- package/templates/go/utils.mustache +352 -0
- package/templates/php/.php-cs-fixer.dist.php +29 -0
- package/templates/php/.travis.yml +8 -0
- package/templates/php/ApiException.mustache +111 -0
- package/templates/php/Configuration.mustache +606 -0
- package/templates/php/FormDataProcessor.mustache +238 -0
- package/templates/php/HeaderSelector.mustache +265 -0
- package/templates/php/ModelInterface.mustache +103 -0
- package/templates/php/ObjectSerializer.mustache +591 -0
- package/templates/php/README.mustache +151 -0
- package/templates/php/api.mustache +891 -0
- package/templates/php/api_doc.mustache +105 -0
- package/templates/php/api_test.mustache +80 -0
- package/templates/php/composer.mustache +44 -0
- package/templates/php/git_push.sh.mustache +57 -0
- package/templates/php/gitignore +15 -0
- package/templates/php/libraries/psr-18/ApiException.mustache +114 -0
- package/templates/php/libraries/psr-18/DebugPlugin.mustache +93 -0
- package/templates/php/libraries/psr-18/README.mustache +161 -0
- package/templates/php/libraries/psr-18/api.mustache +833 -0
- package/templates/php/libraries/psr-18/api_doc.mustache +79 -0
- package/templates/php/libraries/psr-18/composer.mustache +56 -0
- package/templates/php/model.mustache +47 -0
- package/templates/php/model_doc.mustache +10 -0
- package/templates/php/model_enum.mustache +33 -0
- package/templates/php/model_generic.mustache +565 -0
- package/templates/php/model_test.mustache +88 -0
- package/templates/php/partial_header.mustache +18 -0
- package/templates/php/php_doc_auth_partial.mustache +23 -0
- package/templates/php/phpunit.xml.mustache +18 -0
- package/templates/python/README.mustache +60 -0
- package/templates/python/README_onlypackage.mustache +50 -0
- package/templates/python/__init__.mustache +1 -0
- package/templates/python/__init__api.mustache +19 -0
- package/templates/python/__init__model.mustache +22 -0
- package/templates/python/__init__package.mustache +49 -0
- package/templates/python/api.mustache +244 -0
- package/templates/python/api_client.mustache +822 -0
- package/templates/python/api_doc.mustache +81 -0
- package/templates/python/api_doc_example.mustache +38 -0
- package/templates/python/api_response.mustache +21 -0
- package/templates/python/api_test.mustache +48 -0
- package/templates/python/asyncio/rest.mustache +209 -0
- package/templates/python/common_README.mustache +85 -0
- package/templates/python/configuration.mustache +806 -0
- package/templates/python/exceptions.mustache +210 -0
- package/templates/python/exports_api.mustache +3 -0
- package/templates/python/exports_model.mustache +3 -0
- package/templates/python/exports_package.mustache +20 -0
- package/templates/python/git_push.sh.mustache +57 -0
- package/templates/python/github-workflow.mustache +35 -0
- package/templates/python/gitignore.mustache +66 -0
- package/templates/python/gitlab-ci.mustache +31 -0
- package/templates/python/httpx/rest.mustache +190 -0
- package/templates/python/model.mustache +16 -0
- package/templates/python/model_anyof.mustache +182 -0
- package/templates/python/model_doc.mustache +40 -0
- package/templates/python/model_enum.mustache +36 -0
- package/templates/python/model_generic.mustache +403 -0
- package/templates/python/model_oneof.mustache +209 -0
- package/templates/python/model_test.mustache +60 -0
- package/templates/python/partial_api.mustache +52 -0
- package/templates/python/partial_api_args.mustache +18 -0
- package/templates/python/partial_header.mustache +19 -0
- package/templates/python/py.typed.mustache +1 -0
- package/templates/python/pyproject.mustache +172 -0
- package/templates/python/python_doc_auth_partial.mustache +108 -0
- package/templates/python/requirements.mustache +23 -0
- package/templates/python/rest.mustache +254 -0
- package/templates/python/setup.mustache +60 -0
- package/templates/python/setup_cfg.mustache +2 -0
- package/templates/python/signing.mustache +422 -0
- package/templates/python/test-requirements.mustache +6 -0
- package/templates/python/tornado/rest.mustache +148 -0
- package/templates/python/tox.mustache +9 -0
- package/templates/python/travis.mustache +17 -0
- package/templates/typescript-fetch/ApiEntitiesRecord.mustache +26 -0
- package/templates/typescript-fetch/ApiEntitiesReducer.mustache +21 -0
- package/templates/typescript-fetch/ApiEntitiesSelectors.mustache +5 -0
- package/templates/typescript-fetch/README.mustache +127 -0
- package/templates/typescript-fetch/allSagas.mustache +19 -0
- package/templates/typescript-fetch/api_doc.mustache +63 -0
- package/templates/typescript-fetch/api_example.mustache +44 -0
- package/templates/typescript-fetch/apis.index.mustache +16 -0
- package/templates/typescript-fetch/apis.mustache +483 -0
- package/templates/typescript-fetch/apisAssignQueryParam.mustache +12 -0
- package/templates/typescript-fetch/gitignore +4 -0
- package/templates/typescript-fetch/index.mustache +17 -0
- package/templates/typescript-fetch/licenseInfo.mustache +11 -0
- package/templates/typescript-fetch/modelEnum.mustache +28 -0
- package/templates/typescript-fetch/modelEnumInterfaces.mustache +37 -0
- package/templates/typescript-fetch/modelGeneric.mustache +261 -0
- package/templates/typescript-fetch/modelGenericInterfaces.mustache +50 -0
- package/templates/typescript-fetch/modelOneOf.mustache +255 -0
- package/templates/typescript-fetch/modelOneOfInterfaces.mustache +6 -0
- package/templates/typescript-fetch/model_doc.mustache +41 -0
- package/templates/typescript-fetch/models.index.mustache +32 -0
- package/templates/typescript-fetch/models.mustache +24 -0
- package/templates/typescript-fetch/npmignore.mustache +1 -0
- package/templates/typescript-fetch/package.mustache +43 -0
- package/templates/typescript-fetch/recordGeneric.mustache +295 -0
- package/templates/typescript-fetch/records.mustache +17 -0
- package/templates/typescript-fetch/runtime.mustache +424 -0
- package/templates/typescript-fetch/runtimeSagasAndRecords.mustache +120 -0
- package/templates/typescript-fetch/sagaApiManager.mustache +28 -0
- package/templates/typescript-fetch/sagas.mustache +245 -0
- package/templates/typescript-fetch/sourceLibraryIndex.mustache +1 -0
- package/templates/typescript-fetch/tsconfig.esm.mustache +7 -0
- package/templates/typescript-fetch/tsconfig.mustache +25 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema transformer
|
|
3
|
+
* Converts OpenAPI schemas to CodegenModel and CodegenProperty objects
|
|
4
|
+
*/
|
|
5
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
6
|
+
import { type CodegenModel, type CodegenProperty } from "../models/index.js";
|
|
7
|
+
export interface SchemaTransformerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Type mappings from OpenAPI types to target language types
|
|
10
|
+
*/
|
|
11
|
+
typeMappings?: Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Import mappings for model types
|
|
14
|
+
*/
|
|
15
|
+
importMappings?: Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Naming convention for property names
|
|
18
|
+
*/
|
|
19
|
+
propertyNaming?: "camelCase" | "snake_case" | "original";
|
|
20
|
+
/**
|
|
21
|
+
* Naming convention for model names
|
|
22
|
+
*/
|
|
23
|
+
modelNaming?: "PascalCase" | "camelCase" | "original";
|
|
24
|
+
/**
|
|
25
|
+
* Reserved words that require model renaming (adds "Model" prefix)
|
|
26
|
+
*/
|
|
27
|
+
reservedWords?: Set<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Custom function to convert property names for the target language.
|
|
30
|
+
* For Go, this returns PascalCase for exported fields.
|
|
31
|
+
* If not provided, uses camelCase by default.
|
|
32
|
+
*/
|
|
33
|
+
toVarName?: (name: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Post-process a property for generator-specific transformations.
|
|
36
|
+
* For Go, this adds x-go-base-type and x-go-datatag vendor extensions.
|
|
37
|
+
*/
|
|
38
|
+
postProcessProperty?: (property: CodegenProperty) => void;
|
|
39
|
+
}
|
|
40
|
+
export declare class SchemaTransformer {
|
|
41
|
+
private options;
|
|
42
|
+
private typeMappings;
|
|
43
|
+
private modelCache;
|
|
44
|
+
constructor(options?: SchemaTransformerOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Transform all schemas in a components object to CodegenModels
|
|
47
|
+
*/
|
|
48
|
+
transformSchemas(schemas: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>): Map<string, CodegenModel>;
|
|
49
|
+
/**
|
|
50
|
+
* Check if a schema is an array alias (type: array with $ref items, no properties)
|
|
51
|
+
*/
|
|
52
|
+
private isArrayAlias;
|
|
53
|
+
/**
|
|
54
|
+
* Transform a single schema to a CodegenModel
|
|
55
|
+
*/
|
|
56
|
+
transformSchema(name: string, schema: OpenAPIV3.SchemaObject): CodegenModel;
|
|
57
|
+
/**
|
|
58
|
+
* Transform an enum schema
|
|
59
|
+
*/
|
|
60
|
+
private transformEnumSchema;
|
|
61
|
+
/**
|
|
62
|
+
* Transform an array schema
|
|
63
|
+
*/
|
|
64
|
+
private transformArraySchema;
|
|
65
|
+
/**
|
|
66
|
+
* Transform an object schema with properties
|
|
67
|
+
*/
|
|
68
|
+
private transformObjectSchema;
|
|
69
|
+
/**
|
|
70
|
+
* Transform an allOf composition schema
|
|
71
|
+
*/
|
|
72
|
+
private transformAllOfSchema;
|
|
73
|
+
/**
|
|
74
|
+
* Transform a oneOf composition schema
|
|
75
|
+
*/
|
|
76
|
+
private transformOneOfSchema;
|
|
77
|
+
/**
|
|
78
|
+
* Transform an anyOf composition schema
|
|
79
|
+
*/
|
|
80
|
+
private transformAnyOfSchema;
|
|
81
|
+
/**
|
|
82
|
+
* Transform a map schema (additionalProperties only)
|
|
83
|
+
*/
|
|
84
|
+
private transformMapSchema;
|
|
85
|
+
/**
|
|
86
|
+
* Transform a primitive type alias schema
|
|
87
|
+
*/
|
|
88
|
+
private transformPrimitiveSchema;
|
|
89
|
+
/**
|
|
90
|
+
* Transform a property schema to CodegenProperty
|
|
91
|
+
*/
|
|
92
|
+
transformPropertySchema(name: string, schema: OpenAPIV3.SchemaObject, required: boolean): CodegenProperty;
|
|
93
|
+
/**
|
|
94
|
+
* Get type information from a schema
|
|
95
|
+
*/
|
|
96
|
+
private getTypeInfo;
|
|
97
|
+
/**
|
|
98
|
+
* Create allowable values object for enums
|
|
99
|
+
*/
|
|
100
|
+
private createAllowableValues;
|
|
101
|
+
/**
|
|
102
|
+
* Resolve inheritance relationships between models
|
|
103
|
+
*/
|
|
104
|
+
private resolveInheritance;
|
|
105
|
+
/**
|
|
106
|
+
* Convert a name to model naming convention
|
|
107
|
+
*/
|
|
108
|
+
private toModelName;
|
|
109
|
+
/**
|
|
110
|
+
* Convert a name to property naming convention
|
|
111
|
+
*/
|
|
112
|
+
private toPropertyName;
|
|
113
|
+
/**
|
|
114
|
+
* Convert a value to enum variable name
|
|
115
|
+
*/
|
|
116
|
+
private toEnumVarName;
|
|
117
|
+
/**
|
|
118
|
+
* Extract ref name from $ref string
|
|
119
|
+
*/
|
|
120
|
+
private getRefName;
|
|
121
|
+
/**
|
|
122
|
+
* Type guard for reference objects
|
|
123
|
+
*/
|
|
124
|
+
private isReferenceObject;
|
|
125
|
+
/**
|
|
126
|
+
* Extract vendor extensions (x-*) from schema
|
|
127
|
+
*/
|
|
128
|
+
private extractVendorExtensions;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create a schema transformer with default options
|
|
132
|
+
*/
|
|
133
|
+
export declare function createSchemaTransformer(options?: SchemaTransformerOptions): SchemaTransformer;
|
|
134
|
+
//# sourceMappingURL=schema-transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-transformer.d.ts","sourceRoot":"","sources":["../../src/parser/schema-transformer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,eAAe,EAGpB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,wBAAwB;IACxC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEtC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExC;;OAEG;IACH,cAAc,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,UAAU,CAAC;IAEzD;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,GAAG,WAAW,GAAG,UAAU,CAAC;IAEtD;;OAEG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAErC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CAC1D;AAuBD,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,UAAU,CAAwC;gBAE9C,OAAO,GAAE,wBAA6B;IAKlD;;OAEG;IACH,gBAAgB,CACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,eAAe,CAAC,GACzE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;IAyB5B;;OAEG;IACH,OAAO,CAAC,YAAY;IAapB;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,YAAY,GAAG,YAAY;IA2D3E;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA6B5B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAyE7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAgD5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA6B5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAiB5B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAuB1B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;OAEG;IACH,uBAAuB,CACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,CAAC,YAAY,EAC9B,QAAQ,EAAE,OAAO,GACf,eAAe;IA8FlB;;OAEG;IACH,OAAO,CAAC,WAAW;IA+CnB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAgB7B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;OAEG;IACH,OAAO,CAAC,WAAW;IAqBnB;;OAEG;IACH,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAa/B;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,OAAO,CAAC,EAAE,wBAAwB,GAChC,iBAAiB,CAEnB"}
|
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema transformer
|
|
3
|
+
* Converts OpenAPI schemas to CodegenModel and CodegenProperty objects
|
|
4
|
+
*/
|
|
5
|
+
import { camelCase, pascalCase, snakeCase } from "es-toolkit/string";
|
|
6
|
+
import { createCodegenModel, createCodegenProperty, } from "../models/index.js";
|
|
7
|
+
const DEFAULT_TYPE_MAPPINGS = {
|
|
8
|
+
integer: "number",
|
|
9
|
+
long: "number",
|
|
10
|
+
float: "number",
|
|
11
|
+
double: "number",
|
|
12
|
+
number: "number",
|
|
13
|
+
string: "string",
|
|
14
|
+
boolean: "boolean",
|
|
15
|
+
date: "string",
|
|
16
|
+
"date-time": "string",
|
|
17
|
+
binary: "Blob",
|
|
18
|
+
byte: "string",
|
|
19
|
+
uuid: "string",
|
|
20
|
+
uri: "string",
|
|
21
|
+
email: "string",
|
|
22
|
+
password: "string",
|
|
23
|
+
file: "File",
|
|
24
|
+
object: "object",
|
|
25
|
+
array: "Array",
|
|
26
|
+
};
|
|
27
|
+
export class SchemaTransformer {
|
|
28
|
+
options;
|
|
29
|
+
typeMappings;
|
|
30
|
+
modelCache = new Map();
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.options = options;
|
|
33
|
+
this.typeMappings = { ...DEFAULT_TYPE_MAPPINGS, ...options.typeMappings };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Transform all schemas in a components object to CodegenModels
|
|
37
|
+
*/
|
|
38
|
+
transformSchemas(schemas) {
|
|
39
|
+
const models = new Map();
|
|
40
|
+
for (const [name, schema] of Object.entries(schemas)) {
|
|
41
|
+
if (this.isReferenceObject(schema)) {
|
|
42
|
+
continue; // Skip references at this level
|
|
43
|
+
}
|
|
44
|
+
// Skip array aliases (e.g., Pets = Array<Pet>)
|
|
45
|
+
// These are not generated as separate models
|
|
46
|
+
if (this.isArrayAlias(schema)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const model = this.transformSchema(name, schema);
|
|
50
|
+
models.set(name, model);
|
|
51
|
+
this.modelCache.set(name, model);
|
|
52
|
+
}
|
|
53
|
+
// Second pass: resolve parent references
|
|
54
|
+
this.resolveInheritance(models);
|
|
55
|
+
return models;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if a schema is an array alias (type: array with $ref items, no properties)
|
|
59
|
+
*/
|
|
60
|
+
isArrayAlias(schema) {
|
|
61
|
+
if (schema.type !== "array") {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const arraySchema = schema;
|
|
65
|
+
// It's an alias if items is a $ref and there are no other properties
|
|
66
|
+
return (arraySchema.items !== undefined &&
|
|
67
|
+
this.isReferenceObject(arraySchema.items) &&
|
|
68
|
+
!schema.properties);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Transform a single schema to a CodegenModel
|
|
72
|
+
*/
|
|
73
|
+
transformSchema(name, schema) {
|
|
74
|
+
const classname = this.toModelName(name);
|
|
75
|
+
const model = createCodegenModel(name, classname);
|
|
76
|
+
// Set classFilename for templates (same as classname for TypeScript)
|
|
77
|
+
model.classFilename = classname;
|
|
78
|
+
// Basic info
|
|
79
|
+
model.title = schema.title;
|
|
80
|
+
model.description = schema.description;
|
|
81
|
+
model.unescapedDescription = schema.description;
|
|
82
|
+
model.isDeprecated = schema.deprecated ?? false;
|
|
83
|
+
model.isNullable = schema.nullable ?? false;
|
|
84
|
+
// External docs
|
|
85
|
+
if (schema.externalDocs) {
|
|
86
|
+
model.externalDocs = {
|
|
87
|
+
url: schema.externalDocs.url,
|
|
88
|
+
description: schema.externalDocs.description,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Vendor extensions
|
|
92
|
+
model.vendorExtensions = this.extractVendorExtensions(schema);
|
|
93
|
+
// Handle different schema types
|
|
94
|
+
if (schema.enum) {
|
|
95
|
+
this.transformEnumSchema(model, schema);
|
|
96
|
+
}
|
|
97
|
+
else if (schema.type === "array") {
|
|
98
|
+
this.transformArraySchema(model, schema);
|
|
99
|
+
}
|
|
100
|
+
else if (schema.type === "object" || schema.properties) {
|
|
101
|
+
this.transformObjectSchema(model, schema);
|
|
102
|
+
}
|
|
103
|
+
else if (schema.allOf) {
|
|
104
|
+
this.transformAllOfSchema(model, schema);
|
|
105
|
+
}
|
|
106
|
+
else if (schema.oneOf) {
|
|
107
|
+
this.transformOneOfSchema(model, schema);
|
|
108
|
+
}
|
|
109
|
+
else if (schema.anyOf) {
|
|
110
|
+
this.transformAnyOfSchema(model, schema);
|
|
111
|
+
}
|
|
112
|
+
else if (schema.additionalProperties) {
|
|
113
|
+
this.transformMapSchema(model, schema);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// Primitive type alias
|
|
117
|
+
this.transformPrimitiveSchema(model, schema);
|
|
118
|
+
}
|
|
119
|
+
// Set helper flags
|
|
120
|
+
model.hasVars = model.vars.length > 0;
|
|
121
|
+
model.hasEnums = model.vars.some((v) => v.isEnum);
|
|
122
|
+
model.hasRequired = model.requiredVars.length > 0;
|
|
123
|
+
model.hasOptional = model.optionalVars.length > 0;
|
|
124
|
+
model.hasReadOnly = model.readOnlyVars.length > 0;
|
|
125
|
+
model.hasOnlyReadOnly =
|
|
126
|
+
model.vars.length > 0 && model.vars.every((v) => v.isReadOnly);
|
|
127
|
+
return model;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Transform an enum schema
|
|
131
|
+
*/
|
|
132
|
+
transformEnumSchema(model, schema) {
|
|
133
|
+
model.isEnum = true;
|
|
134
|
+
model.isString = schema.type === "string";
|
|
135
|
+
model.isInteger = schema.type === "integer";
|
|
136
|
+
model.isNumber = schema.type === "number";
|
|
137
|
+
const enumValues = schema.enum ?? [];
|
|
138
|
+
model.allowableValues = this.createAllowableValues(enumValues, schema.type);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Transform an array schema
|
|
142
|
+
*/
|
|
143
|
+
transformArraySchema(model, schema) {
|
|
144
|
+
model.isArray = true;
|
|
145
|
+
model.isContainer = true;
|
|
146
|
+
const arraySchema = schema;
|
|
147
|
+
if (arraySchema.items) {
|
|
148
|
+
if (this.isReferenceObject(arraySchema.items)) {
|
|
149
|
+
// Handle reference to another model
|
|
150
|
+
const refName = this.getRefName(arraySchema.items.$ref);
|
|
151
|
+
model.arrayModelType = refName;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
model.items = this.transformPropertySchema("items", arraySchema.items, false);
|
|
155
|
+
model.arrayModelType = model.items.dataType;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Constraints
|
|
159
|
+
model.maxItems = schema.maxItems;
|
|
160
|
+
model.minItems = schema.minItems;
|
|
161
|
+
model.uniqueItems = schema.uniqueItems;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Transform an object schema with properties
|
|
165
|
+
*/
|
|
166
|
+
transformObjectSchema(model, schema) {
|
|
167
|
+
model.isModel = true;
|
|
168
|
+
const requiredSet = new Set(schema.required ?? []);
|
|
169
|
+
// Transform properties
|
|
170
|
+
if (schema.properties) {
|
|
171
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
172
|
+
if (this.isReferenceObject(propSchema)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const isRequired = requiredSet.has(propName);
|
|
176
|
+
const property = this.transformPropertySchema(propName, propSchema, isRequired);
|
|
177
|
+
// Add parent model classname to property for template access
|
|
178
|
+
// This is needed because Handlebars doesn't auto-traverse parent scope
|
|
179
|
+
property.classname =
|
|
180
|
+
model.classname;
|
|
181
|
+
model.vars.push(property);
|
|
182
|
+
model.allVars.push(property);
|
|
183
|
+
if (isRequired) {
|
|
184
|
+
model.requiredVars.push(property);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
model.optionalVars.push(property);
|
|
188
|
+
}
|
|
189
|
+
if (property.isReadOnly) {
|
|
190
|
+
model.readOnlyVars.push(property);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
model.readWriteVars.push(property);
|
|
194
|
+
}
|
|
195
|
+
if (!property.isNullable) {
|
|
196
|
+
model.nonNullableVars.push(property);
|
|
197
|
+
}
|
|
198
|
+
// Add import if needed
|
|
199
|
+
if (property.complexType) {
|
|
200
|
+
model.imports.add(property.complexType);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Handle additionalProperties
|
|
205
|
+
if (schema.additionalProperties === true) {
|
|
206
|
+
model.isAdditionalPropertiesTrue = true;
|
|
207
|
+
model.isFreeFormObject = true;
|
|
208
|
+
}
|
|
209
|
+
else if (schema.additionalProperties &&
|
|
210
|
+
!this.isReferenceObject(schema.additionalProperties)) {
|
|
211
|
+
model.additionalProperties = this.transformPropertySchema("additionalProperties", schema.additionalProperties, false);
|
|
212
|
+
model.additionalPropertiesType = model.additionalProperties.dataType;
|
|
213
|
+
}
|
|
214
|
+
// Constraints
|
|
215
|
+
model.maxProperties = schema.maxProperties;
|
|
216
|
+
model.minProperties = schema.minProperties;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Transform an allOf composition schema
|
|
220
|
+
*/
|
|
221
|
+
transformAllOfSchema(model, schema) {
|
|
222
|
+
model.isModel = true;
|
|
223
|
+
if (!schema.allOf)
|
|
224
|
+
return;
|
|
225
|
+
for (const subSchema of schema.allOf) {
|
|
226
|
+
if (this.isReferenceObject(subSchema)) {
|
|
227
|
+
const refName = this.getRefName(subSchema.$ref);
|
|
228
|
+
model.allOf.push(refName);
|
|
229
|
+
model.allParents.push(refName);
|
|
230
|
+
// First parent becomes the main parent
|
|
231
|
+
if (!model.parent) {
|
|
232
|
+
model.parent = refName;
|
|
233
|
+
model.parentSchema = refName;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
model.interfaces.push(refName);
|
|
237
|
+
}
|
|
238
|
+
model.imports.add(refName);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// Inline schema - merge properties
|
|
242
|
+
if (subSchema.properties) {
|
|
243
|
+
const tempModel = this.transformSchema("", subSchema);
|
|
244
|
+
model.vars.push(...tempModel.vars);
|
|
245
|
+
model.allVars.push(...tempModel.allVars);
|
|
246
|
+
model.requiredVars.push(...tempModel.requiredVars);
|
|
247
|
+
model.optionalVars.push(...tempModel.optionalVars);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Handle discriminator
|
|
252
|
+
if (schema.discriminator) {
|
|
253
|
+
model.discriminator = {
|
|
254
|
+
propertyName: schema.discriminator.propertyName,
|
|
255
|
+
propertyBaseName: schema.discriminator.propertyName,
|
|
256
|
+
mapping: schema.discriminator.mapping,
|
|
257
|
+
};
|
|
258
|
+
model.hasDiscriminatorWithNonEmptyMapping =
|
|
259
|
+
!!schema.discriminator.mapping &&
|
|
260
|
+
Object.keys(schema.discriminator.mapping).length > 0;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Transform a oneOf composition schema
|
|
265
|
+
*/
|
|
266
|
+
transformOneOfSchema(model, schema) {
|
|
267
|
+
model.isModel = true;
|
|
268
|
+
if (!schema.oneOf)
|
|
269
|
+
return;
|
|
270
|
+
for (const subSchema of schema.oneOf) {
|
|
271
|
+
if (this.isReferenceObject(subSchema)) {
|
|
272
|
+
const refName = this.getRefName(subSchema.$ref);
|
|
273
|
+
model.oneOf.push(refName);
|
|
274
|
+
model.imports.add(refName);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// Handle discriminator
|
|
278
|
+
if (schema.discriminator) {
|
|
279
|
+
model.discriminator = {
|
|
280
|
+
propertyName: schema.discriminator.propertyName,
|
|
281
|
+
propertyBaseName: schema.discriminator.propertyName,
|
|
282
|
+
mapping: schema.discriminator.mapping,
|
|
283
|
+
};
|
|
284
|
+
model.hasDiscriminatorWithNonEmptyMapping =
|
|
285
|
+
!!schema.discriminator.mapping &&
|
|
286
|
+
Object.keys(schema.discriminator.mapping).length > 0;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Transform an anyOf composition schema
|
|
291
|
+
*/
|
|
292
|
+
transformAnyOfSchema(model, schema) {
|
|
293
|
+
model.isModel = true;
|
|
294
|
+
if (!schema.anyOf)
|
|
295
|
+
return;
|
|
296
|
+
for (const subSchema of schema.anyOf) {
|
|
297
|
+
if (this.isReferenceObject(subSchema)) {
|
|
298
|
+
const refName = this.getRefName(subSchema.$ref);
|
|
299
|
+
model.anyOf.push(refName);
|
|
300
|
+
model.imports.add(refName);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Transform a map schema (additionalProperties only)
|
|
306
|
+
*/
|
|
307
|
+
transformMapSchema(model, schema) {
|
|
308
|
+
model.isMap = true;
|
|
309
|
+
model.isContainer = true;
|
|
310
|
+
if (schema.additionalProperties === true) {
|
|
311
|
+
model.isAdditionalPropertiesTrue = true;
|
|
312
|
+
model.additionalPropertiesType = "any";
|
|
313
|
+
}
|
|
314
|
+
else if (schema.additionalProperties &&
|
|
315
|
+
!this.isReferenceObject(schema.additionalProperties)) {
|
|
316
|
+
model.additionalProperties = this.transformPropertySchema("value", schema.additionalProperties, false);
|
|
317
|
+
model.additionalPropertiesType = model.additionalProperties.dataType;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Transform a primitive type alias schema
|
|
322
|
+
*/
|
|
323
|
+
transformPrimitiveSchema(model, schema) {
|
|
324
|
+
model.isAlias = true;
|
|
325
|
+
model.isPrimitiveType = true;
|
|
326
|
+
const typeInfo = this.getTypeInfo(schema);
|
|
327
|
+
Object.assign(model, typeInfo);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Transform a property schema to CodegenProperty
|
|
331
|
+
*/
|
|
332
|
+
transformPropertySchema(name, schema, required) {
|
|
333
|
+
const propName = this.toPropertyName(name);
|
|
334
|
+
const typeInfo = this.getTypeInfo(schema);
|
|
335
|
+
const property = createCodegenProperty(name, typeInfo.dataType ?? "any");
|
|
336
|
+
property.name = propName;
|
|
337
|
+
property.baseName = name;
|
|
338
|
+
property.required = required;
|
|
339
|
+
property.description = schema.description;
|
|
340
|
+
property.unescapedDescription = schema.description;
|
|
341
|
+
property.title = schema.title;
|
|
342
|
+
property.example = schema.example;
|
|
343
|
+
property.defaultValue = schema.default;
|
|
344
|
+
// Type flags
|
|
345
|
+
Object.assign(property, typeInfo);
|
|
346
|
+
// Constraints
|
|
347
|
+
property.maxLength = schema.maxLength;
|
|
348
|
+
property.minLength = schema.minLength;
|
|
349
|
+
property.minimum = schema.minimum?.toString();
|
|
350
|
+
property.maximum = schema.maximum?.toString();
|
|
351
|
+
property.pattern = schema.pattern;
|
|
352
|
+
property.multipleOf = schema.multipleOf;
|
|
353
|
+
property.exclusiveMinimum = schema.exclusiveMinimum;
|
|
354
|
+
property.exclusiveMaximum = schema.exclusiveMaximum;
|
|
355
|
+
property.maxItems = schema.maxItems;
|
|
356
|
+
property.minItems = schema.minItems;
|
|
357
|
+
property.uniqueItems = schema.uniqueItems;
|
|
358
|
+
// Status flags
|
|
359
|
+
property.isReadOnly = schema.readOnly ?? false;
|
|
360
|
+
property.isWriteOnly = schema.writeOnly ?? false;
|
|
361
|
+
property.isNullable = schema.nullable ?? false;
|
|
362
|
+
property.deprecated = schema.deprecated ?? false;
|
|
363
|
+
// Validation flag
|
|
364
|
+
property.hasValidation = !!(property.maxLength ||
|
|
365
|
+
property.minLength ||
|
|
366
|
+
property.minimum ||
|
|
367
|
+
property.maximum ||
|
|
368
|
+
property.pattern ||
|
|
369
|
+
property.maxItems ||
|
|
370
|
+
property.minItems);
|
|
371
|
+
// Handle enums
|
|
372
|
+
if (schema.enum) {
|
|
373
|
+
property.isEnum = true;
|
|
374
|
+
property.allowableValues = this.createAllowableValues(schema.enum, schema.type);
|
|
375
|
+
}
|
|
376
|
+
// Handle arrays
|
|
377
|
+
if (schema.type === "array") {
|
|
378
|
+
property.isArray = true;
|
|
379
|
+
property.isContainer = true;
|
|
380
|
+
const arraySchema = schema;
|
|
381
|
+
if (arraySchema.items && !this.isReferenceObject(arraySchema.items)) {
|
|
382
|
+
property.items = this.transformPropertySchema("items", arraySchema.items, false);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// Named getter/setter
|
|
386
|
+
property.getter = `get${pascalCase(propName)}`;
|
|
387
|
+
property.setter = `set${pascalCase(propName)}`;
|
|
388
|
+
// Name variants
|
|
389
|
+
property.nameInCamelCase = camelCase(propName);
|
|
390
|
+
property.nameInPascalCase = pascalCase(propName);
|
|
391
|
+
property.nameInSnakeCase = snakeCase(propName);
|
|
392
|
+
// Vendor extensions from schema
|
|
393
|
+
property.vendorExtensions = this.extractVendorExtensions(schema);
|
|
394
|
+
// Generator-specific post-processing (e.g., Go vendor extensions)
|
|
395
|
+
if (this.options.postProcessProperty) {
|
|
396
|
+
this.options.postProcessProperty(property);
|
|
397
|
+
}
|
|
398
|
+
return property;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get type information from a schema
|
|
402
|
+
*/
|
|
403
|
+
getTypeInfo(schema) {
|
|
404
|
+
const result = {};
|
|
405
|
+
const type = schema.type;
|
|
406
|
+
const format = schema.format;
|
|
407
|
+
// Map to language type
|
|
408
|
+
const mappedType = format
|
|
409
|
+
? (this.typeMappings[format] ?? this.typeMappings[type] ?? type)
|
|
410
|
+
: (this.typeMappings[type] ?? type);
|
|
411
|
+
result.dataType = mappedType;
|
|
412
|
+
result.openApiType = type;
|
|
413
|
+
// Set type flags
|
|
414
|
+
result.isString = type === "string" && !format;
|
|
415
|
+
result.isNumeric = type === "number" || type === "integer";
|
|
416
|
+
result.isInteger = type === "integer";
|
|
417
|
+
result.isLong = type === "integer" && format === "int64";
|
|
418
|
+
result.isNumber = type === "number";
|
|
419
|
+
result.isFloat = type === "number" && format === "float";
|
|
420
|
+
result.isDouble = type === "number" && format === "double";
|
|
421
|
+
result.isBoolean = type === "boolean";
|
|
422
|
+
result.isDate = type === "string" && format === "date";
|
|
423
|
+
result.isDateTime = type === "string" && format === "date-time";
|
|
424
|
+
result.isByteArray = type === "string" && format === "byte";
|
|
425
|
+
result.isBinary = type === "string" && format === "binary";
|
|
426
|
+
result.isFile = type === "file";
|
|
427
|
+
result.isUuid = type === "string" && format === "uuid";
|
|
428
|
+
result.isUri = type === "string" && format === "uri";
|
|
429
|
+
result.isEmail = type === "string" && format === "email";
|
|
430
|
+
result.isArray = type === "array";
|
|
431
|
+
result.isMap = type === "object" && !!schema.additionalProperties;
|
|
432
|
+
result.isAnyType = !type;
|
|
433
|
+
result.isPrimitiveType =
|
|
434
|
+
result.isString ||
|
|
435
|
+
result.isNumeric ||
|
|
436
|
+
result.isBoolean ||
|
|
437
|
+
result.isDate ||
|
|
438
|
+
result.isDateTime;
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create allowable values object for enums
|
|
443
|
+
*/
|
|
444
|
+
createAllowableValues(enumValues, type) {
|
|
445
|
+
const isString = type === "string";
|
|
446
|
+
return {
|
|
447
|
+
values: enumValues,
|
|
448
|
+
enumVars: enumValues.map((value) => ({
|
|
449
|
+
name: this.toEnumVarName(String(value)),
|
|
450
|
+
value: isString ? `"${value}"` : String(value),
|
|
451
|
+
isString,
|
|
452
|
+
})),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Resolve inheritance relationships between models
|
|
457
|
+
*/
|
|
458
|
+
resolveInheritance(models) {
|
|
459
|
+
for (const model of models.values()) {
|
|
460
|
+
if (model.parent) {
|
|
461
|
+
const parentModel = models.get(model.parent);
|
|
462
|
+
if (parentModel) {
|
|
463
|
+
model.parentModel = parentModel;
|
|
464
|
+
parentModel.hasChildren = true;
|
|
465
|
+
parentModel.children = parentModel.children ?? [];
|
|
466
|
+
parentModel.children.push(model);
|
|
467
|
+
// Copy parent vars
|
|
468
|
+
model.parentVars = [...parentModel.vars];
|
|
469
|
+
// allVars should include parent vars
|
|
470
|
+
model.allVars = [...parentModel.allVars, ...model.vars];
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Convert a name to model naming convention
|
|
477
|
+
*/
|
|
478
|
+
toModelName(name) {
|
|
479
|
+
let result;
|
|
480
|
+
switch (this.options.modelNaming) {
|
|
481
|
+
case "camelCase":
|
|
482
|
+
result = camelCase(name);
|
|
483
|
+
break;
|
|
484
|
+
case "original":
|
|
485
|
+
result = name;
|
|
486
|
+
break;
|
|
487
|
+
default:
|
|
488
|
+
result = pascalCase(name);
|
|
489
|
+
}
|
|
490
|
+
// Check if name conflicts with reserved words (like Error, Array, etc.)
|
|
491
|
+
if (this.options.reservedWords?.has(result)) {
|
|
492
|
+
result = `Model${result}`;
|
|
493
|
+
}
|
|
494
|
+
return result;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Convert a name to property naming convention
|
|
498
|
+
*/
|
|
499
|
+
toPropertyName(name) {
|
|
500
|
+
// Use custom toVarName function if provided (e.g., for Go PascalCase)
|
|
501
|
+
if (this.options.toVarName) {
|
|
502
|
+
return this.options.toVarName(name);
|
|
503
|
+
}
|
|
504
|
+
switch (this.options.propertyNaming) {
|
|
505
|
+
case "snake_case":
|
|
506
|
+
return snakeCase(name);
|
|
507
|
+
case "original":
|
|
508
|
+
return name;
|
|
509
|
+
default:
|
|
510
|
+
return camelCase(name);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Convert a value to enum variable name
|
|
515
|
+
*/
|
|
516
|
+
toEnumVarName(value) {
|
|
517
|
+
// Replace special characters with underscores
|
|
518
|
+
let name = value.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
519
|
+
// Ensure it doesn't start with a number
|
|
520
|
+
if (/^[0-9]/.test(name)) {
|
|
521
|
+
name = `_${name}`;
|
|
522
|
+
}
|
|
523
|
+
return name.toUpperCase();
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Extract ref name from $ref string
|
|
527
|
+
*/
|
|
528
|
+
getRefName(ref) {
|
|
529
|
+
const parts = ref.split("/");
|
|
530
|
+
return parts[parts.length - 1];
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Type guard for reference objects
|
|
534
|
+
*/
|
|
535
|
+
isReferenceObject(obj) {
|
|
536
|
+
return !!obj && typeof obj === "object" && "$ref" in obj;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Extract vendor extensions (x-*) from schema
|
|
540
|
+
*/
|
|
541
|
+
extractVendorExtensions(schema) {
|
|
542
|
+
const extensions = {};
|
|
543
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
544
|
+
if (key.startsWith("x-")) {
|
|
545
|
+
extensions[key] = value;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return extensions;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Create a schema transformer with default options
|
|
553
|
+
*/
|
|
554
|
+
export function createSchemaTransformer(options) {
|
|
555
|
+
return new SchemaTransformer(options);
|
|
556
|
+
}
|
|
557
|
+
//# sourceMappingURL=schema-transformer.js.map
|