@kubb/plugin-ts 0.0.0-canary-20241104172400

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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -0
  3. package/dist/chunk-HJ6SFXKJ.js +306 -0
  4. package/dist/chunk-HJ6SFXKJ.js.map +1 -0
  5. package/dist/chunk-HZ6BGJL7.js +2539 -0
  6. package/dist/chunk-HZ6BGJL7.js.map +1 -0
  7. package/dist/chunk-PTC7IOBI.cjs +335 -0
  8. package/dist/chunk-PTC7IOBI.cjs.map +1 -0
  9. package/dist/chunk-RORQTUX5.cjs +2566 -0
  10. package/dist/chunk-RORQTUX5.cjs.map +1 -0
  11. package/dist/components.cjs +16 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +30 -0
  14. package/dist/components.d.ts +30 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +10 -0
  20. package/dist/generators.d.ts +10 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +17 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +9 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.js +4 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-zQCmVvxv.d.cts +97 -0
  30. package/dist/types-zQCmVvxv.d.ts +97 -0
  31. package/package.json +97 -0
  32. package/src/components/OasType.tsx +29 -0
  33. package/src/components/Type.tsx +141 -0
  34. package/src/components/index.ts +2 -0
  35. package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
  36. package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
  37. package/src/generators/__snapshots__/createPet.ts +34 -0
  38. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
  39. package/src/generators/__snapshots__/deletePet.ts +7 -0
  40. package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
  41. package/src/generators/__snapshots__/enumAllOf.ts +10 -0
  42. package/src/generators/__snapshots__/enumArray.ts +19 -0
  43. package/src/generators/__snapshots__/enumInObject.ts +13 -0
  44. package/src/generators/__snapshots__/enumItems.ts +8 -0
  45. package/src/generators/__snapshots__/enumNames.ts +6 -0
  46. package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
  47. package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
  48. package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
  49. package/src/generators/__snapshots__/enumNamesType.ts +8 -0
  50. package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
  51. package/src/generators/__snapshots__/enumNullableType.ts +8 -0
  52. package/src/generators/__snapshots__/enumString.ts +10 -0
  53. package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
  54. package/src/generators/__snapshots__/getPets.ts +26 -0
  55. package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
  56. package/src/generators/__snapshots__/nullConstNull.ts +7 -0
  57. package/src/generators/__snapshots__/numberValueConst.ts +9 -0
  58. package/src/generators/__snapshots__/petMapper.ts +15 -0
  59. package/src/generators/__snapshots__/petQuestionToken.ts +19 -0
  60. package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +19 -0
  61. package/src/generators/__snapshots__/petUndefined.ts +19 -0
  62. package/src/generators/__snapshots__/pets.ts +14 -0
  63. package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +31 -0
  64. package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
  65. package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
  66. package/src/generators/__snapshots__/plainDateDate.ts +1 -0
  67. package/src/generators/__snapshots__/plainDateString.ts +1 -0
  68. package/src/generators/__snapshots__/plainEmail.ts +1 -0
  69. package/src/generators/__snapshots__/plainFile.ts +1 -0
  70. package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
  71. package/src/generators/__snapshots__/plainUuid.ts +1 -0
  72. package/src/generators/__snapshots__/readOnly.ts +20 -0
  73. package/src/generators/__snapshots__/showPetById.ts +31 -0
  74. package/src/generators/__snapshots__/stringValueConst.ts +9 -0
  75. package/src/generators/index.ts +2 -0
  76. package/src/generators/oasGenerator.tsx +29 -0
  77. package/src/generators/typeGenerator.tsx +205 -0
  78. package/src/index.ts +2 -0
  79. package/src/parser/index.ts +279 -0
  80. package/src/plugin.ts +127 -0
  81. package/src/types.ts +97 -0
@@ -0,0 +1,13 @@
1
+ export const enumInObjectReasonEnum2 = {
2
+ "created_at": "created_at",
3
+ "description": "description"
4
+ } as const;
5
+
6
+ export type EnumInObjectReasonEnum2 = (typeof enumInObjectReasonEnum2)[keyof typeof enumInObjectReasonEnum2];
7
+
8
+ export type enumInObject = {
9
+ /**
10
+ * @type string | undefined
11
+ */
12
+ reason?: EnumInObjectReasonEnum2;
13
+ };
@@ -0,0 +1,8 @@
1
+ export const enumItemsEnum2 = {
2
+ "created_at": "created_at",
3
+ "description": "description"
4
+ } as const;
5
+
6
+ export type EnumItemsEnum2 = (typeof enumItemsEnum2)[keyof typeof enumItemsEnum2];
7
+
8
+ export type enumItems = EnumItemsEnum2[];
@@ -0,0 +1,6 @@
1
+ export enum EnumNamesTypeEnum2 {
2
+ "Pending" = 0,
3
+ "Received" = 1
4
+ }
5
+
6
+ export type enumNamesType = EnumNamesTypeEnum2;
@@ -0,0 +1,6 @@
1
+ export const enum EnumNamesTypeEnum2 {
2
+ "Pending" = 0,
3
+ "Received" = 1
4
+ }
5
+
6
+ export type enumNamesType = EnumNamesTypeEnum2;
@@ -0,0 +1,3 @@
1
+ export type EnumNamesTypeEnum2 = 0 | 1;
2
+
3
+ export type enumNamesType = EnumNamesTypeEnum2;
@@ -0,0 +1,8 @@
1
+ export const EnumNamesTypeEnum2 = {
2
+ "Pending": 0,
3
+ "Received": 1
4
+ } as const;
5
+
6
+ type EnumNamesTypeEnum2 = (typeof EnumNamesTypeEnum2)[keyof typeof EnumNamesTypeEnum2];
7
+
8
+ export type enumNamesType = EnumNamesTypeEnum2;
@@ -0,0 +1,8 @@
1
+ export const enumNamesType = {
2
+ "Pending": 0,
3
+ "Received": 1
4
+ } as const;
5
+
6
+ export type EnumNamesTypeEnum2 = (typeof enumNamesType)[keyof typeof enumNamesType];
7
+
8
+ export type enumNamesType = EnumNamesTypeEnum2;
@@ -0,0 +1,8 @@
1
+ export const enumNullableMemberEnum2 = {
2
+ "first": "first",
3
+ "second": "second"
4
+ } as const;
5
+
6
+ export type EnumNullableMemberEnum2 = (typeof enumNullableMemberEnum2)[keyof typeof enumNullableMemberEnum2];
7
+
8
+ export type enumNullableMember = EnumNullableMemberEnum2 | null;
@@ -0,0 +1,8 @@
1
+ export const enumNullableTypeEnum2 = {
2
+ "first": "first",
3
+ "second": "second"
4
+ } as const;
5
+
6
+ export type EnumNullableTypeEnum2 = (typeof enumNullableTypeEnum2)[keyof typeof enumNullableTypeEnum2];
7
+
8
+ export type enumNullableType = EnumNullableTypeEnum2 | null;
@@ -0,0 +1,10 @@
1
+ export const enumStringEnum2 = {
2
+ "created_at": "created_at",
3
+ "description": "description",
4
+ "FILE.UPLOADED": "FILE.UPLOADED",
5
+ "FILE.DOWNLOADED": "FILE.DOWNLOADED"
6
+ } as const;
7
+
8
+ export type EnumStringEnum2 = (typeof enumStringEnum2)[keyof typeof enumStringEnum2];
9
+
10
+ export type enumString = EnumStringEnum2;
@@ -0,0 +1,8 @@
1
+ export const enumVarNamesTypeEnum2 = {
2
+ "Pending": 0,
3
+ "Received": 1
4
+ } as const;
5
+
6
+ export type EnumVarNamesTypeEnum2 = (typeof enumVarNamesTypeEnum2)[keyof typeof enumVarNamesTypeEnum2];
7
+
8
+ export type enumVarNamesType = EnumVarNamesTypeEnum2;
@@ -0,0 +1,26 @@
1
+
2
+ export type ListPetsQueryParams = {
3
+ /**
4
+ * @description How many items to return at one time (max 100)
5
+ * @type string | undefined
6
+ */
7
+ limit?: string;
8
+ };
9
+
10
+ /**
11
+ * @description A paged array of pets
12
+ */
13
+ export type ListPets200 = pets;
14
+
15
+ /**
16
+ * @description unexpected error
17
+ */
18
+ export type ListPetsError = error;
19
+
20
+ export type ListPetsQueryResponse = listPets200;
21
+
22
+ export type listPetsQuery = {
23
+ Response: listPets200;
24
+ QueryParams: listPetsQueryParams;
25
+ Errors: any;
26
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description This probably should fail miserably
3
+ */
4
+ export type mixedValueTypeConst = {
5
+ /**
6
+ * @type number | undefined
7
+ */
8
+ foobar?: "foobar";
9
+ };
@@ -0,0 +1,7 @@
1
+
2
+ /**
3
+ * @description The value of this keyword MAY be null.\nUse of this keyword is functionally equivalent to an \"enum\" (Section 6.1.2) with a single value.\nAn instance validates successfully against this keyword if its value is equal to the value of the keyword.\n
4
+ */
5
+ export type nullConst = {
6
+ withoutValue?: null;
7
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description its value is equal to the value of the keyword
3
+ */
4
+ export type numberValueConst = {
5
+ /**
6
+ * @type number | undefined
7
+ */
8
+ foobar?: 42;
9
+ };
@@ -0,0 +1,15 @@
1
+ export type pet = {
2
+ /**
3
+ * @type integer, int64
4
+ */
5
+ id: number;
6
+ /**
7
+ * @type string
8
+ */
9
+ name: string;
10
+ /**
11
+ * @type string | undefined
12
+ */
13
+ tag?: string;
14
+ category?: string;
15
+ };
@@ -0,0 +1,19 @@
1
+
2
+ export type pet = {
3
+ /**
4
+ * @type integer, int64
5
+ */
6
+ id: number;
7
+ /**
8
+ * @type string
9
+ */
10
+ name: string;
11
+ /**
12
+ * @type string | undefined
13
+ */
14
+ tag?: string;
15
+ /**
16
+ * @type object | undefined
17
+ */
18
+ category?: category;
19
+ };
@@ -0,0 +1,19 @@
1
+
2
+ export type pet = {
3
+ /**
4
+ * @type integer, int64
5
+ */
6
+ id: number;
7
+ /**
8
+ * @type string
9
+ */
10
+ name: string;
11
+ /**
12
+ * @type string | undefined
13
+ */
14
+ tag?: string | undefined;
15
+ /**
16
+ * @type object | undefined
17
+ */
18
+ category?: category | undefined;
19
+ };
@@ -0,0 +1,19 @@
1
+
2
+ export type pet = {
3
+ /**
4
+ * @type integer, int64
5
+ */
6
+ id: number;
7
+ /**
8
+ * @type string
9
+ */
10
+ name: string;
11
+ /**
12
+ * @type string | undefined
13
+ */
14
+ tag: string | undefined;
15
+ /**
16
+ * @type object | undefined
17
+ */
18
+ category: category | undefined;
19
+ };
@@ -0,0 +1,14 @@
1
+ export type pets = {
2
+ /**
3
+ * @type integer, int64
4
+ */
5
+ id: number;
6
+ /**
7
+ * @type string
8
+ */
9
+ name: string;
10
+ /**
11
+ * @type string | undefined
12
+ */
13
+ tag?: string;
14
+ }[];
@@ -0,0 +1,31 @@
1
+
2
+ export const advancedTypeEnum2 = {
3
+ "enum": "enum",
4
+ "range": "range",
5
+ "regex": "regex",
6
+ "slider": "slider"
7
+ } as const;
8
+
9
+ export type AdvancedTypeEnum2 = (typeof advancedTypeEnum2)[keyof typeof advancedTypeEnum2];
10
+
11
+ export type advanced = ((enumerationValueSpecificationDto & {
12
+ /**
13
+ * @type string
14
+ */
15
+ readonly type: AdvancedTypeEnum2;
16
+ }) | (rangeValueSpecificationDto & {
17
+ /**
18
+ * @type string
19
+ */
20
+ readonly type: AdvancedTypeEnum2;
21
+ }) | (regexValueSpecificationDto & {
22
+ /**
23
+ * @type string
24
+ */
25
+ readonly type: AdvancedTypeEnum2;
26
+ }) | (sliderValueSpecificationDto & {
27
+ /**
28
+ * @type string
29
+ */
30
+ readonly type: AdvancedTypeEnum2;
31
+ }));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @description A project is an analysis project. It has a name, an id, and has a dataset
3
+ */
4
+ export type petstore = {
5
+ /**
6
+ * @type integer
7
+ */
8
+ id: number;
9
+ /**
10
+ * @type array | undefined
11
+ */
12
+ pets?: (cat | dog)[];
13
+ };
@@ -0,0 +1 @@
1
+ export type pets = pet[];
@@ -0,0 +1 @@
1
+ export type plainDate = Date;
@@ -0,0 +1 @@
1
+ export type plainDate = string;
@@ -0,0 +1 @@
1
+ export type plainEmail = string;
@@ -0,0 +1 @@
1
+ export type plainFile = Blob;
@@ -0,0 +1 @@
1
+ export type plainTime = Date;
@@ -0,0 +1 @@
1
+ export type plainUuid = string;
@@ -0,0 +1,20 @@
1
+
2
+ export type demo = {
3
+ /**
4
+ * @type integer | undefined
5
+ */
6
+ readonly attribute_readonly?: number;
7
+ /**
8
+ * @description not required
9
+ * @type integer | undefined
10
+ */
11
+ attribute_writeOnly?: number;
12
+ /**
13
+ * @type integer | undefined
14
+ */
15
+ readonly attribute_with_ref?: attributeReadonly;
16
+ /**
17
+ * @type integer | undefined
18
+ */
19
+ attribute_with_ref_readonly?: attributeWriteOnly;
20
+ };
@@ -0,0 +1,31 @@
1
+
2
+ export type ShowPetByIdPathParams = {
3
+ /**
4
+ * @description The id of the pet to retrieve
5
+ * @type string
6
+ */
7
+ petId: string;
8
+ /**
9
+ * @description The id of the pet to retrieve
10
+ * @type string
11
+ */
12
+ testId: string;
13
+ };
14
+
15
+ /**
16
+ * @description Expected response to a valid request
17
+ */
18
+ export type ShowPetById200 = pet;
19
+
20
+ /**
21
+ * @description unexpected error
22
+ */
23
+ export type ShowPetByIdError = error;
24
+
25
+ export type ShowPetByIdQueryResponse = showPetById200;
26
+
27
+ export type showPetByIdQuery = {
28
+ Response: showPetById200;
29
+ PathParams: showPetByIdPathParams;
30
+ Errors: any;
31
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description its value is equal to the value of the keyword
3
+ */
4
+ export type stringValueConst = {
5
+ /**
6
+ * @type string | undefined
7
+ */
8
+ foobar?: "foobar";
9
+ };
@@ -0,0 +1,2 @@
1
+ export { typeGenerator } from './typeGenerator.tsx'
2
+ export { oasGenerator } from './oasGenerator.tsx'
@@ -0,0 +1,29 @@
1
+ import { createReactGenerator } from '@kubb/plugin-oas'
2
+ import { useOas } from '@kubb/plugin-oas/hooks'
3
+ import { File, useApp } from '@kubb/react'
4
+ import { OasType } from '../components'
5
+ import type { PluginTs } from '../types.ts'
6
+
7
+ export const oasGenerator = createReactGenerator<PluginTs>({
8
+ name: 'oas',
9
+ Operations() {
10
+ const {
11
+ pluginManager,
12
+ plugin: {
13
+ options: { output },
14
+ key: pluginKey,
15
+ },
16
+ } = useApp<PluginTs>()
17
+ const oas = useOas()
18
+
19
+ const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })
20
+
21
+ return (
22
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>
23
+ <File.Import name={['Infer']} path="@kubb/oas" isTypeOnly />
24
+
25
+ <OasType name={'oas'} typeName={'Oas'} api={oas.api} />
26
+ </File>
27
+ )
28
+ },
29
+ })
@@ -0,0 +1,205 @@
1
+ import type { PluginManager } from '@kubb/core'
2
+ import transformers from '@kubb/core/transformers'
3
+ import { print } from '@kubb/parser-ts'
4
+ import * as factory from '@kubb/parser-ts/factory'
5
+ import { createPropertySignature, modifiers } from '@kubb/parser-ts/factory'
6
+ import { type OperationSchema as OperationSchemaType, type OperationSchemas, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'
7
+ import { Oas } from '@kubb/plugin-oas/components'
8
+ import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
9
+ import { pluginTsName } from '@kubb/plugin-ts'
10
+ import { File, useApp } from '@kubb/react'
11
+ import type ts from 'typescript'
12
+ import { Type } from '../components'
13
+ import type { PluginTs } from '../types'
14
+
15
+ function printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {
16
+ const properties: Record<string, ts.TypeNode> = {}
17
+
18
+ if (schemas.response) {
19
+ properties['response'] = factory.createUnionDeclaration({
20
+ nodes: schemas.responses.map((res) => {
21
+ const identifier = pluginManager.resolveName({
22
+ name: res.name,
23
+ pluginKey: [pluginTsName],
24
+ type: 'function',
25
+ })
26
+
27
+ return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
28
+ }),
29
+ })!
30
+ }
31
+
32
+ if (schemas.request) {
33
+ const identifier = pluginManager.resolveName({
34
+ name: schemas.request.name,
35
+ pluginKey: [pluginTsName],
36
+ type: 'function',
37
+ })
38
+ properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
39
+ }
40
+
41
+ if (schemas.pathParams) {
42
+ const identifier = pluginManager.resolveName({
43
+ name: schemas.pathParams.name,
44
+ pluginKey: [pluginTsName],
45
+ type: 'function',
46
+ })
47
+ properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
48
+ }
49
+
50
+ if (schemas.queryParams) {
51
+ const identifier = pluginManager.resolveName({
52
+ name: schemas.queryParams.name,
53
+ pluginKey: [pluginTsName],
54
+ type: 'function',
55
+ })
56
+ properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
57
+ }
58
+
59
+ if (schemas.headerParams) {
60
+ const identifier = pluginManager.resolveName({
61
+ name: schemas.headerParams.name,
62
+ pluginKey: [pluginTsName],
63
+ type: 'function',
64
+ })
65
+ properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
66
+ }
67
+
68
+ if (schemas.errors) {
69
+ properties['errors'] = factory.createUnionDeclaration({
70
+ nodes: schemas.errors.map((error) => {
71
+ const identifier = pluginManager.resolveName({
72
+ name: error.name,
73
+ pluginKey: [pluginTsName],
74
+ type: 'function',
75
+ })
76
+
77
+ return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
78
+ }),
79
+ })!
80
+ }
81
+
82
+ const namespaceNode = factory.createTypeAliasDeclaration({
83
+ name,
84
+ type: factory.createTypeLiteralNode(
85
+ Object.keys(properties)
86
+ .map((key) => {
87
+ const type = properties[key]
88
+ if (!type) {
89
+ return undefined
90
+ }
91
+
92
+ return factory.createPropertySignature({
93
+ name: transformers.pascalCase(key),
94
+ type,
95
+ })
96
+ })
97
+ .filter(Boolean),
98
+ ),
99
+ modifiers: [factory.modifiers.export],
100
+ })
101
+
102
+ return print([namespaceNode])
103
+ }
104
+
105
+ export const typeGenerator = createReactGenerator<PluginTs>({
106
+ name: 'typescript',
107
+ Operation({ operation, options }) {
108
+ const { mapper, enumType, optionalType } = options
109
+
110
+ const { plugin, pluginManager, mode } = useApp<PluginTs>()
111
+ const oas = useOas()
112
+ const { getSchemas, getFile, getName } = useOperationManager()
113
+ const schemaManager = useSchemaManager()
114
+
115
+ const file = getFile(operation)
116
+ const schemas = getSchemas(operation)
117
+ const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })
118
+ const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`
119
+ const schemaGenerator = new SchemaGenerator(options, {
120
+ oas,
121
+ plugin,
122
+ pluginManager,
123
+ mode,
124
+ override: options.override,
125
+ })
126
+
127
+ const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]
128
+ .flat()
129
+ .filter(Boolean)
130
+
131
+ const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {
132
+ const tree = schemaGenerator.parse({ schema, name })
133
+ const imports = schemaManager.getImports(tree)
134
+
135
+ const type = {
136
+ name: schemaManager.getName(name, { type: 'type' }),
137
+ typedName: schemaManager.getName(name, { type: 'type' }),
138
+ file: schemaManager.getFile(options.operationName || name, { tag: options.operation?.getTags()[0]?.name }),
139
+ }
140
+
141
+ return (
142
+ <Oas.Schema key={i} name={name} value={schema} tree={tree}>
143
+ {mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={file.path} path={imp.path} name={imp.name} isTypeOnly />)}
144
+ <Type
145
+ name={type.name}
146
+ typedName={type.typedName}
147
+ description={description}
148
+ tree={tree}
149
+ mapper={mapper}
150
+ enumType={enumType}
151
+ optionalType={optionalType}
152
+ keysToOmit={keysToOmit}
153
+ />
154
+ </Oas.Schema>
155
+ )
156
+ }
157
+
158
+ return (
159
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
160
+ {operationSchemas.map(mapOperationSchema)}
161
+
162
+ <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>
163
+ {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}
164
+ </File.Source>
165
+ </File>
166
+ )
167
+ },
168
+ Schema({ schema, options }) {
169
+ const { mapper, enumType, optionalType } = options
170
+ const {
171
+ mode,
172
+ plugin: {
173
+ options: { output },
174
+ },
175
+ } = useApp<PluginTs>()
176
+
177
+ const { getName, getImports, getFile } = useSchemaManager()
178
+ const imports = getImports(schema.tree)
179
+
180
+ if (enumType === 'asPascalConst') {
181
+ console.warn(`enumType '${enumType}' is deprecated`)
182
+ }
183
+
184
+ const type = {
185
+ name: getName(schema.name, { type: 'function' }),
186
+ typedName: getName(schema.name, { type: 'type' }),
187
+ file: getFile(schema.name),
188
+ }
189
+
190
+ return (
191
+ <File baseName={type.file.baseName} path={type.file.path} meta={type.file.meta} banner={output?.banner} footer={output?.footer}>
192
+ {mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />)}
193
+ <Type
194
+ name={type.name}
195
+ typedName={type.typedName}
196
+ description={schema.value.description}
197
+ tree={schema.tree}
198
+ mapper={mapper}
199
+ enumType={enumType}
200
+ optionalType={optionalType}
201
+ />
202
+ </File>
203
+ )
204
+ },
205
+ })
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { pluginTs, pluginTsName } from './plugin.ts'
2
+ export type { PluginTs } from './types.ts'