type-crafter 0.13.1 → 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 +21 -11
- package/dist/templates/rust/object-syntax.hbs +11 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21521,18 +21521,19 @@ async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes)
|
|
|
21521
21521
|
type: 'string'
|
|
21522
21522
|
}).templateInput.type;
|
|
21523
21523
|
if (typeof typeInfo.additionalProperties === 'boolean') {
|
|
21524
|
+
const unknownType = getPrimitiveType(typeName, {
|
|
21525
|
+
...placeholderTypeInfo,
|
|
21526
|
+
type: 'unknown'
|
|
21527
|
+
});
|
|
21524
21528
|
return {
|
|
21525
21529
|
templateInput: {
|
|
21526
21530
|
keyType: stringKeyType,
|
|
21527
|
-
valueType:
|
|
21528
|
-
...placeholderTypeInfo,
|
|
21529
|
-
type: 'unknown'
|
|
21530
|
-
}).templateInput.type,
|
|
21531
|
+
valueType: unknownType.templateInput.type,
|
|
21531
21532
|
valueTypeReferenced: false,
|
|
21532
21533
|
valuePrimitiveType: 'unknown',
|
|
21533
21534
|
valueComposerType: null
|
|
21534
21535
|
},
|
|
21535
|
-
primitives:
|
|
21536
|
+
primitives: unknownType.primitives
|
|
21536
21537
|
};
|
|
21537
21538
|
}
|
|
21538
21539
|
else if (valueIsKeyedAdditionalProperties(typeInfo.additionalProperties)) {
|
|
@@ -21657,7 +21658,8 @@ async function generateObjectType(typeName, typeInfo, parentTypes) {
|
|
|
21657
21658
|
example: propertyDetails.example,
|
|
21658
21659
|
description: propertyDetails.description,
|
|
21659
21660
|
summary: propertyDetails.summary,
|
|
21660
|
-
optional: typeInfo.optional?.includes(propertyName) ?? false
|
|
21661
|
+
optional: typeInfo.optional?.includes(propertyName) ?? false,
|
|
21662
|
+
customAttributes: propertyDetails.customAttributes ?? null
|
|
21661
21663
|
}
|
|
21662
21664
|
};
|
|
21663
21665
|
}
|
|
@@ -21725,7 +21727,8 @@ async function generateArrayType(typeName, typeInfo, parentTypes) {
|
|
|
21725
21727
|
arrayItemsType.templateInput.type = itemTypeName;
|
|
21726
21728
|
}
|
|
21727
21729
|
else {
|
|
21728
|
-
|
|
21730
|
+
const itemName = toPascalCase(typeName) + 'Item';
|
|
21731
|
+
arrayItemsType = await generateType(itemName, typeInfo.items, parentTypes);
|
|
21729
21732
|
// For referenced types (e.g. enums via $ref), use the type name as the item type
|
|
21730
21733
|
// identifier, consistent with how inline enums are handled above.
|
|
21731
21734
|
// Also only keep the direct reference — the referenced type handles its own imports.
|
|
@@ -21738,6 +21741,11 @@ async function generateArrayType(typeName, typeInfo, parentTypes) {
|
|
|
21738
21741
|
references: new Set([refItemTypeName])
|
|
21739
21742
|
};
|
|
21740
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
|
+
}
|
|
21741
21749
|
}
|
|
21742
21750
|
if (typeof arrayItemsType.templateInput?.type === 'undefined') {
|
|
21743
21751
|
throw new InvalidSpecFileError('Invalid array type for: ' + typeName);
|
|
@@ -22142,7 +22150,9 @@ async function writeTypesToFile(config, types, fileName) {
|
|
|
22142
22150
|
}
|
|
22143
22151
|
async function writeExporterModules(files, folder) {
|
|
22144
22152
|
const exporterModuleContent = Runtime.getExporterModuleTemplate()({
|
|
22145
|
-
modules: [...files]
|
|
22153
|
+
modules: [...files]
|
|
22154
|
+
.map((file) => file.replace(Runtime.getConfig().output.fileExtension, ''))
|
|
22155
|
+
.sort()
|
|
22146
22156
|
});
|
|
22147
22157
|
const config = Runtime.getConfig();
|
|
22148
22158
|
// Merging the contents of exporter module & types file in case their names are same.
|
|
@@ -22343,13 +22353,13 @@ async function config(inputFilePath, outputDirectory, typesWriterMode, groupedTy
|
|
|
22343
22353
|
language: {
|
|
22344
22354
|
exporterModuleName: 'mod',
|
|
22345
22355
|
typeMapper: {
|
|
22346
|
-
string: { default: 'String' },
|
|
22356
|
+
string: { default: 'String', date: 'time::Date', 'date-time': 'time::OffsetDateTime' },
|
|
22347
22357
|
number: { default: 'i32' },
|
|
22348
22358
|
integer: { default: 'i32' },
|
|
22349
22359
|
boolean: 'bool',
|
|
22350
22360
|
array: 'Vec<~ItemType~>',
|
|
22351
22361
|
object: 'type',
|
|
22352
|
-
unknown: '
|
|
22362
|
+
unknown: 'serde_json::Value'
|
|
22353
22363
|
},
|
|
22354
22364
|
modulePathConfig: {
|
|
22355
22365
|
separator: '::',
|
|
@@ -22486,7 +22496,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
|
|
|
22486
22496
|
}
|
|
22487
22497
|
}
|
|
22488
22498
|
greeting();
|
|
22489
|
-
const program = new Command().version('0.13.
|
|
22499
|
+
const program = new Command().version('0.13.3');
|
|
22490
22500
|
program
|
|
22491
22501
|
.command('generate')
|
|
22492
22502
|
.description('Generate types for your language from a type spec file')
|
|
@@ -5,12 +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}}
|
|
20
|
+
{{#unless (eq @key (toSnakeCase @key))}}
|
|
13
21
|
#[serde(rename = "{{@key}}")]
|
|
22
|
+
{{/unless}}
|
|
23
|
+
{{/unless}}
|
|
24
|
+
{{/if}}
|
|
14
25
|
{{#unless this.required}}
|
|
15
26
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
16
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;
|