@kubb/swagger-ts 1.12.0-canary.20231012T112940 → 1.12.0-canary.20231013T141355

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.
Files changed (2) hide show
  1. package/dist/index.d.cts +161 -0
  2. package/package.json +4 -5
@@ -0,0 +1,161 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { PluginFactoryOptions, SchemaGenerator, PluginContext, File, PathMode } from '@kubb/core';
3
+ import { SkipBy, ResolvePathOptions, OpenAPIV3, Refs, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, Oas, ContentType, OasBuilder, FileResolver, ResolveProps } from '@kubb/swagger';
4
+ import ts from 'typescript';
5
+ import { Options as Options$3 } from 'change-case';
6
+
7
+ type Options$2 = {
8
+ /**
9
+ * Relative path to save the TypeScript types.
10
+ * When output is a file it will save all models inside that file else it will create a file per schema item.
11
+ * @default 'models'
12
+ */
13
+ output?: string;
14
+ /**
15
+ * Group the TypeScript types based on the provided name.
16
+ */
17
+ groupBy?: {
18
+ /**
19
+ * Tag will group based on the operation tag inside the Swagger file.
20
+ */
21
+ type: 'tag';
22
+ /**
23
+ * Relative path to save the grouped TypeScript Types.
24
+ *
25
+ * `{{tag}}` will be replaced by the current tagName.
26
+ * @example `${output}/{{tag}}Controller` => `models/PetController`
27
+ * @default `${output}/{{tag}}Controller`
28
+ */
29
+ output?: string;
30
+ };
31
+ skipBy?: SkipBy[];
32
+ /**
33
+ * Choose to use `enum` or `as const` for enums
34
+ * @default 'asConst'
35
+ */
36
+ enumType?: 'enum' | 'asConst' | 'asPascalConst';
37
+ /**
38
+ * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
39
+ * @default 'string'
40
+ */
41
+ dateType?: 'string' | 'date';
42
+ /**
43
+ * Choose what to use as mode for an optional value.
44
+ * @examples 'questionToken': type?: string
45
+ * @examples 'undefined': type: string | undefined
46
+ * @examples 'questionTokenAndUndefined': type?: string | undefined
47
+ * @default 'questionToken'
48
+ */
49
+ optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
50
+ transformers?: {
51
+ /**
52
+ * Override the name of the TypeScript type that is getting generated, this will also override the name of the file.
53
+ */
54
+ name?: (name: string) => string;
55
+ };
56
+ };
57
+ type FileMeta = {
58
+ pluginName?: string;
59
+ tag?: string;
60
+ };
61
+ type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$2, false, unknown, ResolvePathOptions>;
62
+
63
+ declare const pluginName: PluginOptions['name'];
64
+ declare const definePlugin: (options: Options$2) => _kubb_core.KubbUserPlugin<PluginOptions>;
65
+
66
+ type Options$1 = {
67
+ withJSDocs?: boolean;
68
+ resolveName: PluginContext['resolveName'];
69
+ enumType: 'enum' | 'asConst' | 'asPascalConst';
70
+ dateType: 'string' | 'date';
71
+ optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
72
+ };
73
+ declare class TypeGenerator extends SchemaGenerator<Options$1, OpenAPIV3.SchemaObject, ts.Node[]> {
74
+ static usedEnumNames: Record<string, number>;
75
+ refs: Refs;
76
+ extraNodes: ts.Node[];
77
+ aliases: ts.TypeAliasDeclaration[];
78
+ usedAliasNames: Record<string, number>;
79
+ caseOptions: Options$3;
80
+ constructor(options?: Options$1);
81
+ build({ schema, baseName, description }: {
82
+ schema: OpenAPIV3.SchemaObject;
83
+ baseName: string;
84
+ description?: string;
85
+ }): ts.Node[];
86
+ /**
87
+ * Creates a type node from a given schema.
88
+ * Delegates to getBaseTypeFromSchema internally and
89
+ * optionally adds a union with null.
90
+ */
91
+ private getTypeFromSchema;
92
+ /**
93
+ * Recursively creates a type literal with the given props.
94
+ */
95
+ private getTypeFromProperties;
96
+ /**
97
+ * Create a type alias for the schema referenced by the given ReferenceObject
98
+ */
99
+ private getRefAlias;
100
+ /**
101
+ * This is the very core of the OpenAPI to TS conversion - it takes a
102
+ * schema and returns the appropriate type.
103
+ */
104
+ private getBaseTypeFromSchema;
105
+ }
106
+
107
+ type Options = {
108
+ oas: Oas;
109
+ contentType?: ContentType;
110
+ skipBy?: SkipBy[];
111
+ resolvePath: PluginContext['resolvePath'];
112
+ resolveName: PluginContext['resolveName'];
113
+ mode: PathMode;
114
+ enumType: 'enum' | 'asConst' | 'asPascalConst';
115
+ dateType: 'string' | 'date';
116
+ optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
117
+ };
118
+ declare class OperationGenerator extends OperationGenerator$1<Options> {
119
+ resolve(operation: Operation): Resolver;
120
+ all(): Promise<File | null>;
121
+ get(operation: Operation, schemas: OperationSchemas): Promise<File<FileMeta> | null>;
122
+ post(operation: Operation, schemas: OperationSchemas): Promise<File<FileMeta> | null>;
123
+ put(operation: Operation, schemas: OperationSchemas): Promise<File<FileMeta> | null>;
124
+ patch(operation: Operation, schemas: OperationSchemas): Promise<File<FileMeta> | null>;
125
+ delete(operation: Operation, schemas: OperationSchemas): Promise<File<FileMeta> | null>;
126
+ }
127
+
128
+ type Config = {
129
+ resolveName: PluginContext['resolveName'];
130
+ fileResolver?: FileResolver;
131
+ withJSDocs?: boolean;
132
+ withImports?: boolean;
133
+ enumType: 'enum' | 'asConst' | 'asPascalConst';
134
+ dateType: 'string' | 'date';
135
+ optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
136
+ };
137
+ declare class TypeBuilder extends OasBuilder<Config> {
138
+ configure(config: Config): this;
139
+ print(name?: string): string;
140
+ }
141
+
142
+ declare const keywordTypeNodes: {
143
+ readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
144
+ readonly number: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
145
+ readonly integer: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
146
+ readonly object: ts.KeywordTypeNode<ts.SyntaxKind.ObjectKeyword>;
147
+ readonly string: ts.KeywordTypeNode<ts.SyntaxKind.StringKeyword>;
148
+ readonly boolean: ts.KeywordTypeNode<ts.SyntaxKind.BooleanKeyword>;
149
+ readonly undefined: ts.KeywordTypeNode<ts.SyntaxKind.UndefinedKeyword>;
150
+ readonly null: ts.LiteralTypeNode;
151
+ };
152
+
153
+ type Props$1 = ResolveProps & {
154
+ pluginName?: never;
155
+ };
156
+ declare function resolve(props: Props$1): Resolver;
157
+
158
+ type Props = Omit<Parameters<typeof resolve>[0], 'operation'>;
159
+ declare function useResolve(props: Props): Resolver;
160
+
161
+ export { FileMeta, OperationGenerator, Options$2 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/swagger-ts",
3
- "version": "1.12.0-canary.20231012T112940",
3
+ "version": "1.12.0-canary.20231013T141355",
4
4
  "description": "Generator swagger-ts",
5
5
  "keywords": [
6
6
  "typescript",
@@ -21,7 +21,6 @@
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
24
- "types": "./dist/index.d.ts",
25
24
  "import": "./dist/index.js",
26
25
  "require": "./dist/index.cjs",
27
26
  "default": "./dist/index.cjs"
@@ -40,9 +39,9 @@
40
39
  "dependencies": {
41
40
  "change-case": "^4.1.2",
42
41
  "typescript": "^5.2.2",
43
- "@kubb/core": "1.11.0",
44
- "@kubb/parser": "1.11.0",
45
- "@kubb/swagger": "1.12.0-canary.20231012T112846"
42
+ "@kubb/core": "1.12.0-canary.20231013T141339",
43
+ "@kubb/parser": "1.12.0-canary.20231013T141212",
44
+ "@kubb/swagger": "1.11.2"
46
45
  },
47
46
  "devDependencies": {
48
47
  "eslint": "^8.51.0",