zod-codegen 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +61 -9
- package/dist/scripts/update-manifest.d.ts +14 -0
- package/dist/scripts/update-manifest.d.ts.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +31 -2
- package/dist/src/generator.d.ts +23 -0
- package/dist/src/generator.d.ts.map +1 -0
- package/dist/src/generator.js +3 -2
- package/dist/src/http/fetch-client.d.ts +15 -0
- package/dist/src/http/fetch-client.d.ts.map +1 -0
- package/dist/src/interfaces/code-generator.d.ts +20 -0
- package/dist/src/interfaces/code-generator.d.ts.map +1 -0
- package/dist/src/interfaces/file-reader.d.ts +13 -0
- package/dist/src/interfaces/file-reader.d.ts.map +1 -0
- package/dist/src/polyfills/fetch.d.ts +5 -0
- package/dist/src/polyfills/fetch.d.ts.map +1 -0
- package/dist/src/services/code-generator.service.d.ts +57 -0
- package/dist/src/services/code-generator.service.d.ts.map +1 -0
- package/dist/src/services/code-generator.service.js +38 -1
- package/dist/src/services/file-reader.service.d.ts +9 -0
- package/dist/src/services/file-reader.service.d.ts.map +1 -0
- package/dist/src/services/file-writer.service.d.ts +10 -0
- package/dist/src/services/file-writer.service.d.ts.map +1 -0
- package/dist/src/services/import-builder.service.d.ts +14 -0
- package/dist/src/services/import-builder.service.d.ts.map +1 -0
- package/dist/src/services/type-builder.service.d.ts +12 -0
- package/dist/src/services/type-builder.service.d.ts.map +1 -0
- package/dist/src/types/generator-options.d.ts +59 -0
- package/dist/src/types/generator-options.d.ts.map +1 -0
- package/dist/src/types/generator-options.js +1 -0
- package/dist/src/types/http.d.ts +25 -0
- package/dist/src/types/http.d.ts.map +1 -0
- package/dist/src/types/openapi.d.ts +1120 -0
- package/dist/src/types/openapi.d.ts.map +1 -0
- package/dist/src/utils/error-handler.d.ts +3 -0
- package/dist/src/utils/error-handler.d.ts.map +1 -0
- package/dist/src/utils/error-handler.js +2 -2
- package/dist/src/utils/execution-time.d.ts +2 -0
- package/dist/src/utils/execution-time.d.ts.map +1 -0
- package/dist/src/utils/manifest.d.ts +8 -0
- package/dist/src/utils/manifest.d.ts.map +1 -0
- package/dist/src/utils/naming-convention.d.ts +80 -0
- package/dist/src/utils/naming-convention.d.ts.map +1 -0
- package/dist/src/utils/naming-convention.js +135 -0
- package/dist/src/utils/reporter.d.ts +7 -0
- package/dist/src/utils/reporter.d.ts.map +1 -0
- package/dist/src/utils/signal-handler.d.ts +3 -0
- package/dist/src/utils/signal-handler.d.ts.map +1 -0
- package/dist/src/utils/signal-handler.js +2 -2
- package/dist/src/utils/tty.d.ts +2 -0
- package/dist/src/utils/tty.d.ts.map +1 -0
- package/dist/tests/integration/cli.test.d.ts +2 -0
- package/dist/tests/integration/cli.test.d.ts.map +1 -0
- package/dist/tests/integration/cli.test.js +2 -2
- package/dist/tests/unit/code-generator.test.d.ts +2 -0
- package/dist/tests/unit/code-generator.test.d.ts.map +1 -0
- package/dist/tests/unit/code-generator.test.js +170 -1
- package/dist/tests/unit/file-reader.test.d.ts +2 -0
- package/dist/tests/unit/file-reader.test.d.ts.map +1 -0
- package/dist/tests/unit/generator.test.d.ts +2 -0
- package/dist/tests/unit/generator.test.d.ts.map +1 -0
- package/dist/tests/unit/naming-convention.test.d.ts +2 -0
- package/dist/tests/unit/naming-convention.test.d.ts.map +1 -0
- package/dist/tests/unit/naming-convention.test.js +231 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/package.json +10 -5
- package/src/cli.ts +34 -3
- package/src/generator.ts +8 -1
- package/src/services/code-generator.service.ts +47 -1
- package/src/types/generator-options.ts +60 -0
- package/src/utils/error-handler.ts +2 -2
- package/src/utils/naming-convention.ts +214 -0
- package/src/utils/signal-handler.ts +2 -2
- package/tests/integration/cli.test.ts +2 -2
- package/tests/unit/code-generator.test.ts +189 -1
- package/tests/unit/naming-convention.test.ts +263 -0
- package/tsconfig.json +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 1.4.0 (2025-12-01)
|
|
2
|
+
|
|
3
|
+
- Merge pull request #40 from julienandreu/feat/naming-conventions-and-improvements ([d7c8146](https://github.com/julienandreu/zod-codegen/commit/d7c8146)), closes [#40](https://github.com/julienandreu/zod-codegen/issues/40)
|
|
4
|
+
- feat: add naming convention support and code quality improvements ([3ec8824](https://github.com/julienandreu/zod-codegen/commit/3ec8824))
|
|
5
|
+
- feat: add naming convention support for operation IDs ([0a52f14](https://github.com/julienandreu/zod-codegen/commit/0a52f14))
|
|
6
|
+
|
|
1
7
|
## 1.3.0 (2025-11-24)
|
|
2
8
|
|
|
3
9
|
- Merge pull request #36 from julienandreu/dependabot/npm_and_yarn/dev-dependencies-16beb30ed0 ([3d85de4](https://github.com/julienandreu/zod-codegen/commit/3d85de4)), closes [#36](https://github.com/julienandreu/zod-codegen/issues/36)
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# zod-codegen
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/zod-codegen)
|
|
4
|
-
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
[](https://github.com/julienandreu/zod-codegen/actions)
|
|
7
7
|
[](https://codecov.io/gh/julienandreu/zod-codegen)
|
|
@@ -54,17 +54,42 @@ zod-codegen -i ./swagger.yaml -o ./src/generated
|
|
|
54
54
|
|
|
55
55
|
#### CLI Options
|
|
56
56
|
|
|
57
|
-
| Option
|
|
58
|
-
|
|
|
59
|
-
| `--input`
|
|
60
|
-
| `--output`
|
|
61
|
-
| `--
|
|
62
|
-
| `--
|
|
57
|
+
| Option | Alias | Description | Default |
|
|
58
|
+
| --------------------- | ----- | ----------------------------------- | ----------- |
|
|
59
|
+
| `--input` | `-i` | Path or URL to OpenAPI file | Required |
|
|
60
|
+
| `--output` | `-o` | Directory to output generated files | `generated` |
|
|
61
|
+
| `--naming-convention` | `-n` | Naming convention for operation IDs | (none) |
|
|
62
|
+
| `--help` | `-h` | Show help | |
|
|
63
|
+
| `--version` | `-v` | Show version | |
|
|
64
|
+
|
|
65
|
+
#### Naming Conventions
|
|
66
|
+
|
|
67
|
+
The `--naming-convention` option allows you to transform operation IDs according to common naming conventions. Supported conventions:
|
|
68
|
+
|
|
69
|
+
- `camelCase` - e.g., `getUserById`
|
|
70
|
+
- `PascalCase` - e.g., `GetUserById`
|
|
71
|
+
- `snake_case` - e.g., `get_user_by_id`
|
|
72
|
+
- `kebab-case` - e.g., `get-user-by-id`
|
|
73
|
+
- `SCREAMING_SNAKE_CASE` - e.g., `GET_USER_BY_ID`
|
|
74
|
+
- `SCREAMING-KEBAB-CASE` - e.g., `GET-USER-BY-ID`
|
|
75
|
+
|
|
76
|
+
**Example:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Transform operation IDs to camelCase
|
|
80
|
+
zod-codegen --input ./openapi.json --output ./generated --naming-convention camelCase
|
|
81
|
+
|
|
82
|
+
# Transform operation IDs to snake_case
|
|
83
|
+
zod-codegen -i ./openapi.json -o ./generated -n snake_case
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This is particularly useful when OpenAPI specs have inconsistent or poorly named operation IDs.
|
|
63
87
|
|
|
64
88
|
### Programmatic Usage
|
|
65
89
|
|
|
66
90
|
```typescript
|
|
67
91
|
import {Generator} from 'zod-codegen';
|
|
92
|
+
import type {GeneratorOptions} from 'zod-codegen';
|
|
68
93
|
|
|
69
94
|
// Create a simple reporter object
|
|
70
95
|
const reporter = {
|
|
@@ -72,19 +97,46 @@ const reporter = {
|
|
|
72
97
|
error: (...args: unknown[]) => console.error(...args),
|
|
73
98
|
};
|
|
74
99
|
|
|
75
|
-
// Create generator instance
|
|
100
|
+
// Create generator instance with naming convention
|
|
76
101
|
const generator = new Generator(
|
|
77
102
|
'my-app',
|
|
78
103
|
'1.0.0',
|
|
79
104
|
reporter,
|
|
80
105
|
'./openapi.json', // Input path or URL
|
|
81
106
|
'./generated', // Output directory
|
|
107
|
+
{
|
|
108
|
+
namingConvention: 'camelCase', // Transform operation IDs to camelCase
|
|
109
|
+
},
|
|
82
110
|
);
|
|
83
111
|
|
|
84
112
|
// Run the generator
|
|
85
113
|
const exitCode = await generator.run();
|
|
86
114
|
```
|
|
87
115
|
|
|
116
|
+
#### Custom Operation Name Transformer
|
|
117
|
+
|
|
118
|
+
For more advanced use cases, you can provide a custom transformer function that receives full operation details:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import {Generator} from 'zod-codegen';
|
|
122
|
+
import type {GeneratorOptions, OperationDetails} from 'zod-codegen';
|
|
123
|
+
|
|
124
|
+
const customTransformer: GeneratorOptions['operationNameTransformer'] = (details: OperationDetails) => {
|
|
125
|
+
// details includes: operationId, method, path, tags, summary, description
|
|
126
|
+
const {operationId, method, tags} = details;
|
|
127
|
+
|
|
128
|
+
// Example: Prefix with HTTP method and tag
|
|
129
|
+
const tag = tags?.[0] || 'default';
|
|
130
|
+
return `${method.toUpperCase()}_${tag}_${operationId}`;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const generator = new Generator('my-app', '1.0.0', reporter, './openapi.json', './generated', {
|
|
134
|
+
operationNameTransformer: customTransformer,
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Note:** Custom transformers take precedence over naming conventions if both are provided.
|
|
139
|
+
|
|
88
140
|
## 📁 Generated Output
|
|
89
141
|
|
|
90
142
|
The generator creates a single TypeScript file (`type.ts`) containing:
|
|
@@ -458,7 +510,7 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
458
510
|
|
|
459
511
|
## 📝 License
|
|
460
512
|
|
|
461
|
-
This project is licensed under the
|
|
513
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENCE) file for details.
|
|
462
514
|
|
|
463
515
|
## 🙏 Acknowledgments
|
|
464
516
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface PackageJson {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
description: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Type guard for the package.json object
|
|
8
|
+
*
|
|
9
|
+
* @param input Unknown input
|
|
10
|
+
* @returns true if the input is an event object
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPackageJson(input: unknown): input is PackageJson;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=update-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-manifest.d.ts","sourceRoot":"","sources":["../../scripts/update-manifest.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAclE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/src/cli.js
CHANGED
|
@@ -58,14 +58,43 @@ const argv = yargs(hideBin(process.argv))
|
|
|
58
58
|
type: 'string',
|
|
59
59
|
description: 'Directory to output the generated files',
|
|
60
60
|
default: 'generated',
|
|
61
|
+
})
|
|
62
|
+
.option('naming-convention', {
|
|
63
|
+
alias: 'n',
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'Naming convention to apply to operation IDs',
|
|
66
|
+
choices: ['camelCase', 'PascalCase', 'snake_case', 'kebab-case', 'SCREAMING_SNAKE_CASE', 'SCREAMING-KEBAB-CASE'],
|
|
67
|
+
default: undefined,
|
|
61
68
|
})
|
|
62
69
|
.strict()
|
|
63
70
|
.help()
|
|
64
71
|
.parseSync();
|
|
65
|
-
const { input, output } = argv;
|
|
72
|
+
const { input, output, namingConvention } = argv;
|
|
73
|
+
/**
|
|
74
|
+
* Type guard to validate that a string is a valid naming convention.
|
|
75
|
+
* This ensures type safety when parsing CLI arguments.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The value to check
|
|
78
|
+
* @returns True if the value is a valid NamingConvention
|
|
79
|
+
*/
|
|
80
|
+
function isValidNamingConvention(value) {
|
|
81
|
+
if (value === undefined) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const validConventions = [
|
|
85
|
+
'camelCase',
|
|
86
|
+
'PascalCase',
|
|
87
|
+
'snake_case',
|
|
88
|
+
'kebab-case',
|
|
89
|
+
'SCREAMING_SNAKE_CASE',
|
|
90
|
+
'SCREAMING-KEBAB-CASE',
|
|
91
|
+
];
|
|
92
|
+
return validConventions.includes(value);
|
|
93
|
+
}
|
|
66
94
|
void (async () => {
|
|
67
95
|
try {
|
|
68
|
-
const
|
|
96
|
+
const options = isValidNamingConvention(namingConvention) ? { namingConvention } : {};
|
|
97
|
+
const generator = new Generator(name, version, reporter, input, output, options);
|
|
69
98
|
const exitCode = await generator.run();
|
|
70
99
|
process.exit(exitCode);
|
|
71
100
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Reporter } from './utils/reporter.js';
|
|
2
|
+
import type { GeneratorOptions } from './types/generator-options.js';
|
|
3
|
+
export type { GeneratorOptions } from './types/generator-options.js';
|
|
4
|
+
export type { NamingConvention, OperationDetails, OperationNameTransformer } from './utils/naming-convention.js';
|
|
5
|
+
export declare class Generator {
|
|
6
|
+
private readonly _name;
|
|
7
|
+
private readonly _version;
|
|
8
|
+
private readonly reporter;
|
|
9
|
+
private readonly inputPath;
|
|
10
|
+
private readonly _outputDir;
|
|
11
|
+
private readonly fileReader;
|
|
12
|
+
private readonly fileParser;
|
|
13
|
+
private readonly codeGenerator;
|
|
14
|
+
private readonly fileWriter;
|
|
15
|
+
private readonly outputPath;
|
|
16
|
+
constructor(_name: string, _version: string, reporter: Reporter, inputPath: string, _outputDir: string, options?: GeneratorOptions);
|
|
17
|
+
run(): Promise<number>;
|
|
18
|
+
private readFile;
|
|
19
|
+
private parseFile;
|
|
20
|
+
private generateCode;
|
|
21
|
+
private writeFile;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAMnE,YAAY,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AACnE,YAAY,EAAC,gBAAgB,EAAE,gBAAgB,EAAE,wBAAwB,EAAC,MAAM,8BAA8B,CAAC;AAE/G,qBAAa,SAAS;IAQlB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAX7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAC1D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;IAC7D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiC;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwB;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAGjB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EACnC,OAAO,GAAE,gBAAqB;IAO1B,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;YAqBd,QAAQ;IAItB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,SAAS;CAGlB"}
|
package/dist/src/generator.js
CHANGED
|
@@ -9,10 +9,10 @@ export class Generator {
|
|
|
9
9
|
_outputDir;
|
|
10
10
|
fileReader = new SyncFileReaderService();
|
|
11
11
|
fileParser = new OpenApiFileParserService();
|
|
12
|
-
codeGenerator
|
|
12
|
+
codeGenerator;
|
|
13
13
|
fileWriter;
|
|
14
14
|
outputPath;
|
|
15
|
-
constructor(_name, _version, reporter, inputPath, _outputDir) {
|
|
15
|
+
constructor(_name, _version, reporter, inputPath, _outputDir, options = {}) {
|
|
16
16
|
this._name = _name;
|
|
17
17
|
this._version = _version;
|
|
18
18
|
this.reporter = reporter;
|
|
@@ -20,6 +20,7 @@ export class Generator {
|
|
|
20
20
|
this._outputDir = _outputDir;
|
|
21
21
|
this.fileWriter = new SyncFileWriterService(this._name, this._version, inputPath);
|
|
22
22
|
this.outputPath = this.fileWriter.resolveOutputPath(this._outputDir);
|
|
23
|
+
this.codeGenerator = new TypeScriptCodeGeneratorService(options);
|
|
23
24
|
}
|
|
24
25
|
async run() {
|
|
25
26
|
try {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HttpClient, HttpRequestConfig, HttpResponse } from '../types/http.js';
|
|
2
|
+
export declare class FetchHttpClient implements HttpClient {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly defaultHeaders;
|
|
5
|
+
private readonly fetch;
|
|
6
|
+
private readonly Headers;
|
|
7
|
+
constructor(baseUrl?: string, defaultHeaders?: Record<string, string>);
|
|
8
|
+
request<TResponse = unknown, TRequest = unknown>(config: HttpRequestConfig<TRequest>): Promise<HttpResponse<TResponse>>;
|
|
9
|
+
private buildUrl;
|
|
10
|
+
private buildHeaders;
|
|
11
|
+
private buildBody;
|
|
12
|
+
private extractHeaders;
|
|
13
|
+
private parseResponse;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=fetch-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../../../src/http/fetch-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAclF,qBAAa,eAAgB,YAAW,UAAU;IAK9C,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc;IALjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;gBAG1B,OAAO,SAAK,EACZ,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAoBxD,OAAO,CAAC,SAAS,GAAG,OAAO,EAAE,QAAQ,GAAG,OAAO,EACnD,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAClC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IA4DnC,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,SAAS;IAqBjB,OAAO,CAAC,cAAc;YAQR,aAAa;CAkB5B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OpenApiSpecType } from '../types/openapi.js';
|
|
2
|
+
export interface CodeGenerator {
|
|
3
|
+
generate(spec: OpenApiSpecType): string;
|
|
4
|
+
}
|
|
5
|
+
export interface SchemaBuilder {
|
|
6
|
+
buildSchema(schema: unknown, required?: boolean): unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface TypeBuilder {
|
|
9
|
+
buildType(type: string): unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface ImportBuilder {
|
|
12
|
+
buildImports(): unknown[];
|
|
13
|
+
}
|
|
14
|
+
export interface ClassBuilder {
|
|
15
|
+
buildClass(spec: OpenApiSpecType): unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface FileWriter {
|
|
18
|
+
writeFile(filePath: string, content: string): Promise<void> | void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=code-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-generator.d.ts","sourceRoot":"","sources":["../../../src/interfaces/code-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CAC3D;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,IAAI,OAAO,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC;CAC5C;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface FileReader {
|
|
2
|
+
readFile(path: string): Promise<string> | string;
|
|
3
|
+
}
|
|
4
|
+
export interface FileParser<TInput, TOutput> {
|
|
5
|
+
parse(input: TInput): TOutput;
|
|
6
|
+
}
|
|
7
|
+
export interface OpenApiFileReader extends FileReader {
|
|
8
|
+
readFile(path: string): Promise<string> | string;
|
|
9
|
+
}
|
|
10
|
+
export interface OpenApiFileParser<TOutput> extends FileParser<unknown, TOutput> {
|
|
11
|
+
parse(input: unknown): TOutput;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=file-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-reader.d.ts","sourceRoot":"","sources":["../../../src/interfaces/file-reader.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAClD;AAED,MAAM,WAAW,UAAU,CAAC,MAAM,EAAE,OAAO;IACzC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAClD;AAED,MAAM,WAAW,iBAAiB,CAAC,OAAO,CAAE,SAAQ,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;IAC9E,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/polyfills/fetch.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB1F"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import type { CodeGenerator, SchemaBuilder } from '../interfaces/code-generator.js';
|
|
3
|
+
import type { OpenApiSpecType } from '../types/openapi.js';
|
|
4
|
+
import type { GeneratorOptions } from '../types/generator-options.js';
|
|
5
|
+
export declare class TypeScriptCodeGeneratorService implements CodeGenerator, SchemaBuilder {
|
|
6
|
+
private readonly typeBuilder;
|
|
7
|
+
private readonly importBuilder;
|
|
8
|
+
private readonly printer;
|
|
9
|
+
private readonly namingConvention;
|
|
10
|
+
private readonly operationNameTransformer;
|
|
11
|
+
constructor(options?: GeneratorOptions);
|
|
12
|
+
private readonly ZodAST;
|
|
13
|
+
generate(spec: OpenApiSpecType): string;
|
|
14
|
+
buildSchema(schema: unknown, required?: boolean): ts.CallExpression | ts.Identifier;
|
|
15
|
+
private buildAST;
|
|
16
|
+
private buildSchemas;
|
|
17
|
+
private buildSchemaTypeAliases;
|
|
18
|
+
private buildClientClass;
|
|
19
|
+
private buildConstructor;
|
|
20
|
+
private buildGetBaseRequestOptionsMethod;
|
|
21
|
+
private buildHttpRequestMethod;
|
|
22
|
+
private buildClientMethods;
|
|
23
|
+
/**
|
|
24
|
+
* Transforms operation ID according to the configured naming convention or transformer
|
|
25
|
+
* Ensures the result is a valid TypeScript identifier
|
|
26
|
+
*/
|
|
27
|
+
private transformOperationName;
|
|
28
|
+
private buildEndpointMethod;
|
|
29
|
+
private buildPathExpression;
|
|
30
|
+
private buildMethodParameters;
|
|
31
|
+
private getParameterType;
|
|
32
|
+
private getSchemaTypeName;
|
|
33
|
+
private getResponseSchema;
|
|
34
|
+
private getResponseType;
|
|
35
|
+
private buildServerConfiguration;
|
|
36
|
+
private resolveServerUrl;
|
|
37
|
+
private buildResolveServerUrlFunction;
|
|
38
|
+
private generateClientName;
|
|
39
|
+
private createComment;
|
|
40
|
+
/**
|
|
41
|
+
* Builds a JSDoc comment string from operation metadata
|
|
42
|
+
*/
|
|
43
|
+
private buildJSDocComment;
|
|
44
|
+
private buildZodAST;
|
|
45
|
+
private buildProperty;
|
|
46
|
+
private buildDefaultValue;
|
|
47
|
+
private handleLogicalOperator;
|
|
48
|
+
private buildLogicalOperator;
|
|
49
|
+
private buildSchemaFromLogicalOperator;
|
|
50
|
+
private buildBasicTypeFromSchema;
|
|
51
|
+
private buildObjectTypeFromSchema;
|
|
52
|
+
private buildArrayTypeFromSchema;
|
|
53
|
+
private isReference;
|
|
54
|
+
private buildFromReference;
|
|
55
|
+
private topologicalSort;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=code-generator.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-generator.service.d.ts","sourceRoot":"","sources":["../../../src/services/code-generator.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,iCAAiC,CAAC;AAClF,OAAO,KAAK,EAAmB,eAAe,EAAgB,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAWpE,qBAAa,8BAA+B,YAAW,aAAa,EAAE,aAAa;IACjF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAClE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwC;IACtE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwD;IAChF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA+B;IAChE,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAuC;gBAEpE,OAAO,GAAE,gBAAqB;IAK1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAGpB;IAEH,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM;IAMvC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,UAAO,GAAG,EAAE,CAAC,cAAc,GAAG,EAAE,CAAC,UAAU;IA2BhF,OAAO,CAAC,QAAQ;IAmBhB,OAAO,CAAC,YAAY;IA8BpB,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,gBAAgB;IAmGxB,OAAO,CAAC,gCAAgC;IAwBxC,OAAO,CAAC,sBAAsB;IAqmB9B,OAAO,CAAC,kBAAkB;IAsB1B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA0B9B,OAAO,CAAC,mBAAmB;IAmH3B,OAAO,CAAC,mBAAmB;IA6D3B,OAAO,CAAC,qBAAqB;IAwF7B,OAAO,CAAC,gBAAgB;IA0CxB,OAAO,CAAC,iBAAiB;IAmCzB,OAAO,CAAC,iBAAiB;IA8BzB,OAAO,CAAC,eAAe;IAuDvB,OAAO,CAAC,wBAAwB;IA4IhC,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,6BAA6B;IAkPrC,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,aAAa;IAMrB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAuFzB,OAAO,CAAC,WAAW;IA0CnB,OAAO,CAAC,aAAa;IAmjBrB,OAAO,CAAC,iBAAiB;IAuCzB,OAAO,CAAC,qBAAqB;IAe7B,OAAO,CAAC,oBAAoB;IAyE5B,OAAO,CAAC,8BAA8B;IActC,OAAO,CAAC,wBAAwB;IAyBhC,OAAO,CAAC,yBAAyB;IA8BjC,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,eAAe;CAuCxB"}
|
|
@@ -4,10 +4,17 @@ import { z } from 'zod';
|
|
|
4
4
|
import { MethodSchema, Reference, SchemaProperties } from '../types/openapi.js';
|
|
5
5
|
import { TypeScriptImportBuilderService } from './import-builder.service.js';
|
|
6
6
|
import { TypeScriptTypeBuilderService } from './type-builder.service.js';
|
|
7
|
+
import { transformNamingConvention, } from '../utils/naming-convention.js';
|
|
7
8
|
export class TypeScriptCodeGeneratorService {
|
|
8
9
|
typeBuilder = new TypeScriptTypeBuilderService();
|
|
9
10
|
importBuilder = new TypeScriptImportBuilderService();
|
|
10
11
|
printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
12
|
+
namingConvention;
|
|
13
|
+
operationNameTransformer;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.namingConvention = options.namingConvention;
|
|
16
|
+
this.operationNameTransformer = options.operationNameTransformer;
|
|
17
|
+
}
|
|
11
18
|
ZodAST = z.object({
|
|
12
19
|
type: z.enum(['string', 'number', 'boolean', 'object', 'array', 'unknown', 'record']),
|
|
13
20
|
args: z.array(z.unknown()).optional(),
|
|
@@ -263,6 +270,35 @@ export class TypeScriptCodeGeneratorService {
|
|
|
263
270
|
return [...endpoints, ...methods];
|
|
264
271
|
}, []);
|
|
265
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Transforms operation ID according to the configured naming convention or transformer
|
|
275
|
+
* Ensures the result is a valid TypeScript identifier
|
|
276
|
+
*/
|
|
277
|
+
transformOperationName(operationId, method, path, schema) {
|
|
278
|
+
let transformed;
|
|
279
|
+
// Custom transformer takes precedence
|
|
280
|
+
if (this.operationNameTransformer) {
|
|
281
|
+
const details = {
|
|
282
|
+
operationId,
|
|
283
|
+
method,
|
|
284
|
+
path,
|
|
285
|
+
...(schema.tags !== undefined && { tags: schema.tags }),
|
|
286
|
+
...(schema.summary !== undefined && { summary: schema.summary }),
|
|
287
|
+
...(schema.description !== undefined && { description: schema.description }),
|
|
288
|
+
};
|
|
289
|
+
transformed = this.operationNameTransformer(details);
|
|
290
|
+
}
|
|
291
|
+
else if (this.namingConvention) {
|
|
292
|
+
// Apply naming convention if specified
|
|
293
|
+
transformed = transformNamingConvention(operationId, this.namingConvention);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// Return original operationId if no transformation is configured
|
|
297
|
+
transformed = operationId;
|
|
298
|
+
}
|
|
299
|
+
// Sanitize to ensure valid TypeScript identifier (handles edge cases from custom transformers)
|
|
300
|
+
return this.typeBuilder.sanitizeIdentifier(transformed);
|
|
301
|
+
}
|
|
266
302
|
buildEndpointMethod(method, path, schema, schemas) {
|
|
267
303
|
const { parameters, pathParams, queryParams, hasRequestBody, contentType } = this.buildMethodParameters(schema, schemas);
|
|
268
304
|
const responseType = this.getResponseType(schema, schemas);
|
|
@@ -304,7 +340,8 @@ export class TypeScriptCodeGeneratorService {
|
|
|
304
340
|
else {
|
|
305
341
|
statements.push(ts.factory.createReturnStatement(ts.factory.createAwaitExpression(makeRequestCall)));
|
|
306
342
|
}
|
|
307
|
-
const
|
|
343
|
+
const transformedOperationId = this.transformOperationName(String(schema.operationId), method, path, schema);
|
|
344
|
+
const methodDeclaration = ts.factory.createMethodDeclaration([ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)], undefined, ts.factory.createIdentifier(transformedOperationId), undefined, undefined, parameters, responseType, ts.factory.createBlock(statements, true));
|
|
308
345
|
// Add JSDoc comment if summary or description exists
|
|
309
346
|
const jsdocComment = this.buildJSDocComment(schema.summary, schema.description, schema, responseType);
|
|
310
347
|
if (jsdocComment) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenApiFileParser, OpenApiFileReader } from '../interfaces/file-reader.js';
|
|
2
|
+
import type { OpenApiSpecType } from '../types/openapi.js';
|
|
3
|
+
export declare class SyncFileReaderService implements OpenApiFileReader {
|
|
4
|
+
readFile(path: string): Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
export declare class OpenApiFileParserService implements OpenApiFileParser<OpenApiSpecType> {
|
|
7
|
+
parse(input: unknown): OpenApiSpecType;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=file-reader.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-reader.service.d.ts","sourceRoot":"","sources":["../../../src/services/file-reader.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAGzD,qBAAa,qBAAsB,YAAW,iBAAiB;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAe9C;AAED,qBAAa,wBAAyB,YAAW,iBAAiB,CAAC,eAAe,CAAC;IACjF,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe;CAgBvC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FileWriter } from '../interfaces/code-generator.js';
|
|
2
|
+
export declare class SyncFileWriterService implements FileWriter {
|
|
3
|
+
private readonly name;
|
|
4
|
+
private readonly version;
|
|
5
|
+
private readonly inputPath;
|
|
6
|
+
constructor(name: string, version: string, inputPath: string);
|
|
7
|
+
writeFile(filePath: string, content: string): void;
|
|
8
|
+
resolveOutputPath(outputDir: string, fileName?: string): string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=file-writer.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-writer.service.d.ts","sourceRoot":"","sources":["../../../src/services/file-writer.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iCAAiC,CAAC;AAEhE,qBAAa,qBAAsB,YAAW,UAAU;IAEpD,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAFT,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM;IAGpC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAqBlD,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,SAAY,GAAG,MAAM;CAGnE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ImportBuilder } from '../interfaces/code-generator.js';
|
|
4
|
+
declare const ImportOptions: z.ZodObject<{
|
|
5
|
+
defaultImport: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
6
|
+
namedImports: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
type ImportOptionsType = z.infer<typeof ImportOptions>;
|
|
9
|
+
export declare class TypeScriptImportBuilderService implements ImportBuilder {
|
|
10
|
+
buildImports(): ts.ImportDeclaration[];
|
|
11
|
+
createImport(target: string, options: ImportOptionsType): ts.ImportDeclaration;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=import-builder.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-builder.service.d.ts","sourceRoot":"","sources":["../../../src/services/import-builder.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAC;AAKnE,QAAA,MAAM,aAAa;;;iBAGjB,CAAC;AAEH,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEvD,qBAAa,8BAA+B,YAAW,aAAa;IAClE,YAAY,IAAI,EAAE,CAAC,iBAAiB,EAAE;IAQtC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,EAAE,CAAC,iBAAiB;CAqC/E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import type { TypeBuilder } from '../interfaces/code-generator.js';
|
|
3
|
+
export declare class TypeScriptTypeBuilderService implements TypeBuilder {
|
|
4
|
+
buildType(type: string): ts.TypeNode;
|
|
5
|
+
createProperty(name: string, type: string, isReadonly?: boolean): ts.PropertyDeclaration;
|
|
6
|
+
createParameter(name: string, type?: string | ts.TypeNode, defaultValue?: ts.Expression, isOptional?: boolean): ts.ParameterDeclaration;
|
|
7
|
+
createGenericType(name: string): ts.TypeParameterDeclaration;
|
|
8
|
+
sanitizeIdentifier(name: string): string;
|
|
9
|
+
toCamelCase(word: string): string;
|
|
10
|
+
toPascalCase(word: string): string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=type-builder.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-builder.service.d.ts","sourceRoot":"","sources":["../../../src/services/type-builder.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAEjE,qBAAa,4BAA6B,YAAW,WAAW;IAC9D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,QAAQ;IA6BpC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,EAAE,CAAC,mBAAmB;IAYtF,eAAe,CACb,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC,QAAQ,EAC3B,YAAY,CAAC,EAAE,EAAE,CAAC,UAAU,EAC5B,UAAU,UAAQ,GACjB,EAAE,CAAC,oBAAoB;IAW1B,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,wBAAwB;IAS5D,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMxC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIjC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGnC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { NamingConvention, OperationNameTransformer } from '../utils/naming-convention.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the Generator class.
|
|
4
|
+
*
|
|
5
|
+
* These options control how operation IDs are transformed during code generation.
|
|
6
|
+
* You can either use a predefined naming convention or provide a custom transformer function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Using a naming convention
|
|
11
|
+
* const generator = new Generator(..., {
|
|
12
|
+
* namingConvention: 'camelCase'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Using a custom transformer
|
|
16
|
+
* const generator = new Generator(..., {
|
|
17
|
+
* operationNameTransformer: (details) => {
|
|
18
|
+
* return `${details.method}_${details.operationId}`;
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface GeneratorOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Naming convention to apply to operation IDs.
|
|
26
|
+
*
|
|
27
|
+
* If provided, all operation IDs will be transformed according to the specified convention.
|
|
28
|
+
* This is useful when OpenAPI specs have inconsistent or poorly named operation IDs.
|
|
29
|
+
*
|
|
30
|
+
* **Note:** If `operationNameTransformer` is also provided, it takes precedence.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* { namingConvention: 'camelCase' } // Transforms 'get_user_by_id' → 'getUserById'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
namingConvention?: NamingConvention;
|
|
38
|
+
/**
|
|
39
|
+
* Custom transformer function for operation names.
|
|
40
|
+
*
|
|
41
|
+
* If provided, this function will be called for each operation with full operation details.
|
|
42
|
+
* This allows for advanced customization based on HTTP method, path, tags, etc.
|
|
43
|
+
*
|
|
44
|
+
* **Note:** This takes precedence over `namingConvention` if both are provided.
|
|
45
|
+
* The returned name will be sanitized to ensure it's a valid TypeScript identifier.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* {
|
|
50
|
+
* operationNameTransformer: (details) => {
|
|
51
|
+
* const tag = details.tags?.[0] || 'default';
|
|
52
|
+
* return `${details.method.toUpperCase()}_${tag}_${details.operationId}`;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
operationNameTransformer?: OperationNameTransformer;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=generator-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-options.d.ts","sourceRoot":"","sources":["../../../src/types/generator-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,wBAAwB,EAAC,MAAM,+BAA+B,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;OAYG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;;;;;;;;;;OAkBG;IACH,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;CACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface HttpRequestConfig<TData = unknown> {
|
|
2
|
+
readonly url: string;
|
|
3
|
+
readonly method: HttpMethod;
|
|
4
|
+
readonly headers?: Record<string, string>;
|
|
5
|
+
readonly params?: Record<string, string | number | boolean>;
|
|
6
|
+
readonly data?: TData;
|
|
7
|
+
readonly timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface HttpResponse<TData = unknown> {
|
|
10
|
+
readonly data: TData;
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly statusText: string;
|
|
13
|
+
readonly headers: Record<string, string>;
|
|
14
|
+
readonly url: string;
|
|
15
|
+
}
|
|
16
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
17
|
+
export interface HttpClient {
|
|
18
|
+
request<TResponse = unknown, TRequest = unknown>(config: HttpRequestConfig<TRequest>): Promise<HttpResponse<TResponse>>;
|
|
19
|
+
}
|
|
20
|
+
export declare class HttpError extends Error {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly response?: HttpResponse | undefined;
|
|
23
|
+
constructor(message: string, status: number, response?: HttpResponse | undefined);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/types/http.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB,CAAC,KAAK,GAAG,OAAO;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY,CAAC,KAAK,GAAG,OAAO;IAC3C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1F,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,SAAS,GAAG,OAAO,EAAE,QAAQ,GAAG,OAAO,EAC7C,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAClC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;CACrC;AAED,qBAAa,SAAU,SAAQ,KAAK;aAGhB,MAAM,EAAE,MAAM;aACd,QAAQ,CAAC,EAAE,YAAY;gBAFvC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,YAAY,YAAA;CAK1C"}
|