type-crafter 0.13.2 → 0.13.3
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/dist/index.js
CHANGED
|
@@ -21658,7 +21658,8 @@ async function generateObjectType(typeName, typeInfo, parentTypes) {
|
|
|
21658
21658
|
example: propertyDetails.example,
|
|
21659
21659
|
description: propertyDetails.description,
|
|
21660
21660
|
summary: propertyDetails.summary,
|
|
21661
|
-
optional: typeInfo.optional?.includes(propertyName) ?? false
|
|
21661
|
+
optional: typeInfo.optional?.includes(propertyName) ?? false,
|
|
21662
|
+
customAttributes: propertyDetails.customAttributes ?? null
|
|
21662
21663
|
}
|
|
21663
21664
|
};
|
|
21664
21665
|
}
|
|
@@ -21726,7 +21727,8 @@ async function generateArrayType(typeName, typeInfo, parentTypes) {
|
|
|
21726
21727
|
arrayItemsType.templateInput.type = itemTypeName;
|
|
21727
21728
|
}
|
|
21728
21729
|
else {
|
|
21729
|
-
|
|
21730
|
+
const itemName = toPascalCase(typeName) + 'Item';
|
|
21731
|
+
arrayItemsType = await generateType(itemName, typeInfo.items, parentTypes);
|
|
21730
21732
|
// For referenced types (e.g. enums via $ref), use the type name as the item type
|
|
21731
21733
|
// identifier, consistent with how inline enums are handled above.
|
|
21732
21734
|
// Also only keep the direct reference — the referenced type handles its own imports.
|
|
@@ -21739,6 +21741,11 @@ async function generateArrayType(typeName, typeInfo, parentTypes) {
|
|
|
21739
21741
|
references: new Set([refItemTypeName])
|
|
21740
21742
|
};
|
|
21741
21743
|
}
|
|
21744
|
+
else {
|
|
21745
|
+
// For inline types (e.g. anonymous objects), include the generated type definition
|
|
21746
|
+
// so it is emitted alongside the struct that references it.
|
|
21747
|
+
dynamicGeneratedType += arrayItemsType.content;
|
|
21748
|
+
}
|
|
21742
21749
|
}
|
|
21743
21750
|
if (typeof arrayItemsType.templateInput?.type === 'undefined') {
|
|
21744
21751
|
throw new InvalidSpecFileError('Invalid array type for: ' + typeName);
|
|
@@ -22143,7 +22150,9 @@ async function writeTypesToFile(config, types, fileName) {
|
|
|
22143
22150
|
}
|
|
22144
22151
|
async function writeExporterModules(files, folder) {
|
|
22145
22152
|
const exporterModuleContent = Runtime.getExporterModuleTemplate()({
|
|
22146
|
-
modules: [...files]
|
|
22153
|
+
modules: [...files]
|
|
22154
|
+
.map((file) => file.replace(Runtime.getConfig().output.fileExtension, ''))
|
|
22155
|
+
.sort()
|
|
22147
22156
|
});
|
|
22148
22157
|
const config = Runtime.getConfig();
|
|
22149
22158
|
// Merging the contents of exporter module & types file in case their names are same.
|
|
@@ -22344,13 +22353,13 @@ async function config(inputFilePath, outputDirectory, typesWriterMode, groupedTy
|
|
|
22344
22353
|
language: {
|
|
22345
22354
|
exporterModuleName: 'mod',
|
|
22346
22355
|
typeMapper: {
|
|
22347
|
-
string: { default: 'String' },
|
|
22356
|
+
string: { default: 'String', date: 'time::Date', 'date-time': 'time::OffsetDateTime' },
|
|
22348
22357
|
number: { default: 'i32' },
|
|
22349
22358
|
integer: { default: 'i32' },
|
|
22350
22359
|
boolean: 'bool',
|
|
22351
22360
|
array: 'Vec<~ItemType~>',
|
|
22352
22361
|
object: 'type',
|
|
22353
|
-
unknown: '
|
|
22362
|
+
unknown: 'serde_json::Value'
|
|
22354
22363
|
},
|
|
22355
22364
|
modulePathConfig: {
|
|
22356
22365
|
separator: '::',
|
|
@@ -22487,7 +22496,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
|
|
|
22487
22496
|
}
|
|
22488
22497
|
}
|
|
22489
22498
|
greeting();
|
|
22490
|
-
const program = new Command().version('0.13.
|
|
22499
|
+
const program = new Command().version('0.13.3');
|
|
22491
22500
|
program
|
|
22492
22501
|
.command('generate')
|
|
22493
22502
|
.description('Generate types for your language from a type spec file')
|
|
@@ -5,14 +5,23 @@
|
|
|
5
5
|
/// Example: {{{example}}}
|
|
6
6
|
{{/if}}
|
|
7
7
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
8
|
+
{{#if customAttributes.renameAll}}
|
|
9
|
+
#[serde(rename_all = "{{{customAttributes.renameAll}}}")]
|
|
10
|
+
{{/if}}
|
|
8
11
|
pub struct {{typeName}} {
|
|
9
12
|
{{#each properties}}
|
|
10
13
|
{{#if this.description}}
|
|
11
14
|
/// {{{this.description}}}
|
|
12
15
|
{{/if}}
|
|
16
|
+
{{#if this.customAttributes.[x-name]}}
|
|
17
|
+
#[serde(rename = "{{{this.customAttributes.[x-name]}}}")]
|
|
18
|
+
{{else}}
|
|
19
|
+
{{#unless ../customAttributes.renameAll}}
|
|
13
20
|
{{#unless (eq @key (toSnakeCase @key))}}
|
|
14
21
|
#[serde(rename = "{{@key}}")]
|
|
15
22
|
{{/unless}}
|
|
23
|
+
{{/unless}}
|
|
24
|
+
{{/if}}
|
|
16
25
|
{{#unless this.required}}
|
|
17
26
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
18
27
|
{{/unless}}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -130,6 +130,7 @@ export type ObjectTemplateInputProperty = TypeDescriptors & {
|
|
|
130
130
|
primitiveType: string;
|
|
131
131
|
composerType: string | null;
|
|
132
132
|
optional: boolean;
|
|
133
|
+
customAttributes?: Record<string, unknown> | null;
|
|
133
134
|
};
|
|
134
135
|
export type AdditionalPropertiesTemplateInput = {
|
|
135
136
|
keyType: string;
|