@amritk/generate-parsers 0.5.0 → 0.6.1
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/generators/build-schema.d.ts +4 -1
- package/dist/generators/generate-files.d.ts +5 -0
- package/dist/generators/generate-parser-function.d.ts +6 -1
- package/dist/helpers/collect-imports.d.ts +6 -0
- package/dist/index.js +113 -80
- package/package.json +2 -2
- package/src/generators/build-schema.test.ts +17 -17
- package/src/generators/build-schema.ts +7 -1
- package/src/generators/generate-files.test.ts +65 -52
- package/src/generators/generate-files.ts +11 -4
- package/src/generators/generate-parser-function.test.ts +254 -258
- package/src/generators/generate-parser-function.ts +87 -58
- package/src/helpers/collect-imports.test.ts +44 -84
- package/src/helpers/collect-imports.ts +8 -1
|
@@ -40,6 +40,9 @@ export type GeneratedFile = {
|
|
|
40
40
|
* directory while the helper sources are emitted once at the output root.
|
|
41
41
|
* @param readonly - When true, every property, array, and record in the generated type
|
|
42
42
|
* definitions is emitted as `readonly`.
|
|
43
|
+
* @param typeSuffix - Suffix appended to every type/parser name derived from a `$ref`
|
|
44
|
+
* (e.g. `'Object'` → `ContactObject`). Defaults to `''` (no suffix). The root type name
|
|
45
|
+
* is used verbatim and is not affected by this suffix.
|
|
43
46
|
* @returns An array of generated TypeScript files
|
|
44
47
|
*
|
|
45
48
|
* @example
|
|
@@ -72,4 +75,4 @@ export type GeneratedFile = {
|
|
|
72
75
|
* });
|
|
73
76
|
* ```
|
|
74
77
|
*/
|
|
75
|
-
export declare const buildSchema: (rootSchema: JSONSchema, rootTypeName: string, extensions?: SchemaExtensions, typesOnly?: boolean, logWarnings?: boolean, strict?: boolean, helpersMode?: HelpersMode, helpersImportPrefix?: string, readonly?: boolean) => Promise<GeneratedFile[]>;
|
|
78
|
+
export declare const buildSchema: (rootSchema: JSONSchema, rootTypeName: string, extensions?: SchemaExtensions, typesOnly?: boolean, logWarnings?: boolean, strict?: boolean, helpersMode?: HelpersMode, helpersImportPrefix?: string, readonly?: boolean, typeSuffix?: string) => Promise<GeneratedFile[]>;
|
|
@@ -49,6 +49,11 @@ type GenerateFileOptions = {
|
|
|
49
49
|
* definitions is emitted as `readonly`.
|
|
50
50
|
*/
|
|
51
51
|
readonly readonly?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Suffix appended to every type/parser name derived from a `$ref`.
|
|
54
|
+
* Defaults to `''` (no suffix). Set to e.g. `'Object'` to emit `ContactObject`.
|
|
55
|
+
*/
|
|
56
|
+
readonly typeSuffix?: string;
|
|
52
57
|
};
|
|
53
58
|
/** Result of generating a single parser file. */
|
|
54
59
|
export type GeneratedFileContent = {
|
|
@@ -20,6 +20,11 @@ type GenerateParserOptions = {
|
|
|
20
20
|
* with a path-aware Error. Unknown extra keys are still allowed.
|
|
21
21
|
*/
|
|
22
22
|
readonly strict?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Suffix appended to every type/parser name derived from a `$ref`. Must match
|
|
25
|
+
* the suffix used when generating the referenced files. Defaults to `''`.
|
|
26
|
+
*/
|
|
27
|
+
readonly typeSuffix?: string;
|
|
23
28
|
};
|
|
24
29
|
/**
|
|
25
30
|
* Generates a safe parser as an arrow function that never throws.
|
|
@@ -49,5 +54,5 @@ export declare const shapeValidatorFunctionName: (typeName: string) => string;
|
|
|
49
54
|
* in additionalProperties). The stub is safe: parents calling it will fall
|
|
50
55
|
* through to the slow path, matching the pre-deep-fast-path behavior.
|
|
51
56
|
*/
|
|
52
|
-
export declare const generateShapeValidator: (schema: JSONSchema, typeName: string, useRefImports: boolean) => string;
|
|
57
|
+
export declare const generateShapeValidator: (schema: JSONSchema, typeName: string, useRefImports: boolean, suffix?: string) => string;
|
|
53
58
|
export {};
|
|
@@ -20,6 +20,12 @@ type CollectImportsOptions = {
|
|
|
20
20
|
* imports for external schemas that were never generated as files.
|
|
21
21
|
*/
|
|
22
22
|
readonly rootSchema?: Record<string, unknown> | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Suffix appended to every type name derived from a `$ref`. Must match the
|
|
25
|
+
* suffix used when generating the referenced files so imports resolve.
|
|
26
|
+
* Defaults to `''` (no suffix).
|
|
27
|
+
*/
|
|
28
|
+
readonly typeSuffix?: string;
|
|
23
29
|
};
|
|
24
30
|
/**
|
|
25
31
|
* Collects all import statements needed for a schema by finding $ref references
|
package/dist/index.js
CHANGED
|
@@ -137,15 +137,15 @@ var refToFilename2 = (ref) => {
|
|
|
137
137
|
}
|
|
138
138
|
return filename;
|
|
139
139
|
};
|
|
140
|
-
var kebabToPascal = (kebab) => {
|
|
140
|
+
var kebabToPascal = (kebab, suffix) => {
|
|
141
141
|
const words = kebab.split("-");
|
|
142
142
|
let pascalCase = "";
|
|
143
143
|
for (const word of words) {
|
|
144
144
|
pascalCase += word.charAt(0).toUpperCase() + word.slice(1);
|
|
145
145
|
}
|
|
146
|
-
return pascalCase +
|
|
146
|
+
return pascalCase + suffix;
|
|
147
147
|
};
|
|
148
|
-
var refToName = (ref) => kebabToPascal(refToFilename2(ref));
|
|
148
|
+
var refToName = (ref, suffix = "") => kebabToPascal(refToFilename2(ref), suffix);
|
|
149
149
|
|
|
150
150
|
// ../helpers/dist/resolve-dynamic-refs.js
|
|
151
151
|
var resolveDynamicRefs = (schema, dynamicRefMap) => {
|
|
@@ -439,15 +439,15 @@ var refToFilename4 = (ref) => {
|
|
|
439
439
|
}
|
|
440
440
|
return filename;
|
|
441
441
|
};
|
|
442
|
-
var kebabToPascal2 = (kebab) => {
|
|
442
|
+
var kebabToPascal2 = (kebab, suffix) => {
|
|
443
443
|
const words = kebab.split("-");
|
|
444
444
|
let pascalCase = "";
|
|
445
445
|
for (const word of words) {
|
|
446
446
|
pascalCase += word.charAt(0).toUpperCase() + word.slice(1);
|
|
447
447
|
}
|
|
448
|
-
return pascalCase +
|
|
448
|
+
return pascalCase + suffix;
|
|
449
449
|
};
|
|
450
|
-
var refToName2 = (ref) => kebabToPascal2(refToFilename4(ref));
|
|
450
|
+
var refToName2 = (ref, suffix = "") => kebabToPascal2(refToFilename4(ref), suffix);
|
|
451
451
|
var JS_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
452
452
|
var safeKey = (key) => {
|
|
453
453
|
if (JS_IDENTIFIER.test(key)) {
|
|
@@ -565,13 +565,13 @@ var getUnbrandedType = (schema, options = {}) => {
|
|
|
565
565
|
if (!schema.$ref.startsWith("#")) {
|
|
566
566
|
return "unknown";
|
|
567
567
|
}
|
|
568
|
-
return refToName2(schema.$ref);
|
|
568
|
+
return refToName2(schema.$ref, options.typeSuffix);
|
|
569
569
|
}
|
|
570
570
|
if (schema.$dynamicRef) {
|
|
571
571
|
if (schema.$dynamicRef === "#meta") {
|
|
572
|
-
return
|
|
572
|
+
return `Schema${options.typeSuffix ?? ""}`;
|
|
573
573
|
}
|
|
574
|
-
return refToName2(schema.$dynamicRef);
|
|
574
|
+
return refToName2(schema.$dynamicRef, options.typeSuffix);
|
|
575
575
|
}
|
|
576
576
|
if (schema.const !== undefined) {
|
|
577
577
|
return JSON.stringify(schema.const);
|
|
@@ -618,7 +618,7 @@ var getUnbrandedType = (schema, options = {}) => {
|
|
|
618
618
|
if (conditionalResult) {
|
|
619
619
|
const baseType = getTypeScriptType(conditionalResult.schema, options);
|
|
620
620
|
if (conditionalResult.thenRef) {
|
|
621
|
-
return `(${baseType}) & ${refToName2(conditionalResult.thenRef)}`;
|
|
621
|
+
return `(${baseType}) & ${refToName2(conditionalResult.thenRef, options.typeSuffix)}`;
|
|
622
622
|
}
|
|
623
623
|
return baseType;
|
|
624
624
|
}
|
|
@@ -699,6 +699,31 @@ var getUnbrandedType = (schema, options = {}) => {
|
|
|
699
699
|
case "object":
|
|
700
700
|
if (schema.properties) {
|
|
701
701
|
const readonlyPrefix = options.readonly ? "readonly " : "";
|
|
702
|
+
const hasDescriptions = Object.values(schema.properties).some((p) => isSchemaObject2(p) && (typeof p.description === "string" || typeof p.$comment === "string"));
|
|
703
|
+
if (hasDescriptions) {
|
|
704
|
+
let properties2 = "";
|
|
705
|
+
let first2 = true;
|
|
706
|
+
for (const key in schema.properties) {
|
|
707
|
+
const propSchema = schema.properties[key];
|
|
708
|
+
const isRequired = schema.required?.includes(key) ?? false;
|
|
709
|
+
const optional = isRequired ? "" : "?";
|
|
710
|
+
const propType = getTypeScriptType(propSchema, options);
|
|
711
|
+
const inlineDescription = isSchemaObject2(propSchema) && typeof propSchema.description === "string" ? propSchema.description : isSchemaObject2(propSchema) && typeof propSchema.$comment === "string" ? propSchema.$comment : undefined;
|
|
712
|
+
if (!first2)
|
|
713
|
+
properties2 += `
|
|
714
|
+
`;
|
|
715
|
+
first2 = false;
|
|
716
|
+
if (inlineDescription) {
|
|
717
|
+
properties2 += " /** " + inlineDescription + ` */
|
|
718
|
+
` + readonlyPrefix + safeKey(key) + optional + ": " + propType + ";";
|
|
719
|
+
} else {
|
|
720
|
+
properties2 += " " + readonlyPrefix + safeKey(key) + optional + ": " + propType + ";";
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return `{
|
|
724
|
+
` + properties2 + `
|
|
725
|
+
}`;
|
|
726
|
+
}
|
|
702
727
|
let properties = "";
|
|
703
728
|
let first = true;
|
|
704
729
|
for (const key in schema.properties) {
|
|
@@ -740,8 +765,9 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
|
|
|
740
765
|
if (!isObjectLikeSchema(schema)) {
|
|
741
766
|
const tsType = getTypeScriptType(schema, options);
|
|
742
767
|
let result = "";
|
|
743
|
-
|
|
744
|
-
|
|
768
|
+
const topLevelComment = isSchemaObject2(schema) && typeof schema.description === "string" && schema.description || isSchemaObject2(schema) && typeof schema.$comment === "string" && schema.$comment || undefined;
|
|
769
|
+
if (topLevelComment) {
|
|
770
|
+
result += buildJsDocBlock(typeName, topLevelComment);
|
|
745
771
|
}
|
|
746
772
|
result += `export type ${typeName} = ${tsType};`;
|
|
747
773
|
return result;
|
|
@@ -752,9 +778,10 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
|
|
|
752
778
|
const conditionalThenRef = conditionalResult?.thenRef ?? null;
|
|
753
779
|
let jsDocTitle;
|
|
754
780
|
let jsDocDescription;
|
|
755
|
-
|
|
781
|
+
const topLevelComment = isSchemaObject2(schema) && typeof schema.description === "string" && schema.description || isSchemaObject2(schema) && typeof schema.$comment === "string" && schema.$comment || undefined;
|
|
782
|
+
if (topLevelComment) {
|
|
756
783
|
jsDocTitle = typeName;
|
|
757
|
-
jsDocDescription =
|
|
784
|
+
jsDocDescription = topLevelComment;
|
|
758
785
|
}
|
|
759
786
|
const hasProperties2 = normalizedSchema.properties && Object.keys(normalizedSchema.properties).length > 0;
|
|
760
787
|
const hasAdditionalProperties2 = normalizedSchema.additionalProperties && typeof normalizedSchema.additionalProperties === "object";
|
|
@@ -811,12 +838,12 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
|
|
|
811
838
|
if (isSchemaObject2(schema) && Array.isArray(schema.allOf)) {
|
|
812
839
|
for (const entry of schema.allOf) {
|
|
813
840
|
if (isSchemaObject2(entry) && entry.$ref) {
|
|
814
|
-
allOfIntersections.push(refToName2(entry.$ref));
|
|
841
|
+
allOfIntersections.push(refToName2(entry.$ref, options.typeSuffix));
|
|
815
842
|
}
|
|
816
843
|
}
|
|
817
844
|
}
|
|
818
845
|
if (isSchemaObject2(schema) && typeof schema.$ref === "string" && schema.$ref.startsWith("#")) {
|
|
819
|
-
allOfIntersections.push(refToName2(schema.$ref));
|
|
846
|
+
allOfIntersections.push(refToName2(schema.$ref, options.typeSuffix));
|
|
820
847
|
}
|
|
821
848
|
let result = "";
|
|
822
849
|
if (jsDocTitle && jsDocDescription) {
|
|
@@ -826,7 +853,7 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
|
|
|
826
853
|
` + properties + `
|
|
827
854
|
}`;
|
|
828
855
|
if (conditionalThenRef) {
|
|
829
|
-
typeBody += " & " + refToName2(conditionalThenRef);
|
|
856
|
+
typeBody += " & " + refToName2(conditionalThenRef, options.typeSuffix);
|
|
830
857
|
}
|
|
831
858
|
for (const intersectionType of allOfIntersections) {
|
|
832
859
|
typeBody += " & " + intersectionType;
|
|
@@ -967,6 +994,7 @@ var collectImports = (schema, options) => {
|
|
|
967
994
|
const typesOnly = options?.typesOnly === true;
|
|
968
995
|
const selfFilename = options?.selfRef ? refToFilename(options.selfRef) : undefined;
|
|
969
996
|
const rootSchema = options?.rootSchema;
|
|
997
|
+
const typeSuffix = options?.typeSuffix;
|
|
970
998
|
const refs = new Set;
|
|
971
999
|
const collectRefsFromValue = (value) => {
|
|
972
1000
|
if (typeof value !== "object" || value === null) {
|
|
@@ -1094,7 +1122,7 @@ var collectImports = (schema, options) => {
|
|
|
1094
1122
|
if (!resolveRef(ref, rootSchema))
|
|
1095
1123
|
continue;
|
|
1096
1124
|
}
|
|
1097
|
-
const typeName = refToName(ref);
|
|
1125
|
+
const typeName = refToName(ref, typeSuffix);
|
|
1098
1126
|
const filename = refToFilename(ref);
|
|
1099
1127
|
if (selfFilename !== undefined && filename === selfFilename) {
|
|
1100
1128
|
continue;
|
|
@@ -1786,33 +1814,33 @@ var isPropertyRequired = (key, schema) => {
|
|
|
1786
1814
|
}
|
|
1787
1815
|
return schema.required.includes(key);
|
|
1788
1816
|
};
|
|
1789
|
-
var generateRequiredRefCall = (key, ref) => {
|
|
1817
|
+
var generateRequiredRefCall = (key, ref, suffix) => {
|
|
1790
1818
|
const acc = safeAccessor("input", key);
|
|
1791
|
-
const parserName = generateParserName(refToName(ref));
|
|
1819
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1792
1820
|
return `${parserName}(${acc})`;
|
|
1793
1821
|
};
|
|
1794
|
-
var generateOptionalRefCall = (key, ref) => {
|
|
1822
|
+
var generateOptionalRefCall = (key, ref, suffix) => {
|
|
1795
1823
|
const acc = safeAccessor("input", key);
|
|
1796
|
-
const parserName = generateParserName(refToName(ref));
|
|
1824
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1797
1825
|
return `...(${acc} && { ${safeKey2(key)}: ${parserName}(${acc}) })`;
|
|
1798
1826
|
};
|
|
1799
|
-
var generateRequiredArrayRefCall = (key, ref) => {
|
|
1800
|
-
const parserName = generateParserName(refToName(ref));
|
|
1827
|
+
var generateRequiredArrayRefCall = (key, ref, suffix) => {
|
|
1828
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1801
1829
|
return `validateArray(${safeAccessor("input", key)}, ${parserName})`;
|
|
1802
1830
|
};
|
|
1803
|
-
var generateOptionalArrayRefCall = (key, ref) => {
|
|
1804
|
-
const parserName = generateParserName(refToName(ref));
|
|
1831
|
+
var generateOptionalArrayRefCall = (key, ref, suffix) => {
|
|
1832
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1805
1833
|
const acc = safeAccessor("input", key);
|
|
1806
1834
|
return `...(${acc} && { ${safeKey2(key)}: validateArray(${acc}, ${parserName}) })`;
|
|
1807
1835
|
};
|
|
1808
|
-
var generateRequiredRecordRefCall = (key, ref) => {
|
|
1836
|
+
var generateRequiredRecordRefCall = (key, ref, suffix) => {
|
|
1809
1837
|
const acc = safeAccessor("input", key);
|
|
1810
|
-
const parserName = generateParserName(refToName(ref));
|
|
1838
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1811
1839
|
return `validateRecord(${acc}, ${parserName})`;
|
|
1812
1840
|
};
|
|
1813
|
-
var generateOptionalRecordRefCall = (key, ref) => {
|
|
1841
|
+
var generateOptionalRecordRefCall = (key, ref, suffix) => {
|
|
1814
1842
|
const acc = safeAccessor("input", key);
|
|
1815
|
-
const parserName = generateParserName(refToName(ref));
|
|
1843
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1816
1844
|
return `...(${acc} && { ${safeKey2(key)}: validateRecord(${acc}, ${parserName}) })`;
|
|
1817
1845
|
};
|
|
1818
1846
|
var generateOptionalInlineProperty = (key, valueExpression) => {
|
|
@@ -1857,20 +1885,20 @@ var shouldUseRecordRefImport = (propSchema, useRefImports) => {
|
|
|
1857
1885
|
const additionalProps = propSchema.additionalProperties;
|
|
1858
1886
|
return isSchemaObject3(additionalProps) && hasRef(additionalProps);
|
|
1859
1887
|
};
|
|
1860
|
-
var generatePropertyValue = (key, propSchema, isRequired, useRefImports) => {
|
|
1888
|
+
var generatePropertyValue = (key, propSchema, isRequired, useRefImports, suffix) => {
|
|
1861
1889
|
if (shouldUseRefImport(propSchema, useRefImports)) {
|
|
1862
1890
|
const ref = propSchema.$ref;
|
|
1863
|
-
return isRequired ? generateRequiredRefCall(key, ref) : generateOptionalRefCall(key, ref);
|
|
1891
|
+
return isRequired ? generateRequiredRefCall(key, ref, suffix) : generateOptionalRefCall(key, ref, suffix);
|
|
1864
1892
|
}
|
|
1865
1893
|
if (shouldUseArrayRefImport(propSchema, useRefImports)) {
|
|
1866
1894
|
const items = propSchema.items;
|
|
1867
1895
|
const ref = items.$ref;
|
|
1868
|
-
return isRequired ? generateRequiredArrayRefCall(key, ref) : generateOptionalArrayRefCall(key, ref);
|
|
1896
|
+
return isRequired ? generateRequiredArrayRefCall(key, ref, suffix) : generateOptionalArrayRefCall(key, ref, suffix);
|
|
1869
1897
|
}
|
|
1870
1898
|
if (shouldUseRecordRefImport(propSchema, useRefImports)) {
|
|
1871
1899
|
const additionalProps = propSchema.additionalProperties;
|
|
1872
1900
|
const ref = additionalProps.$ref;
|
|
1873
|
-
return isRequired ? generateRequiredRecordRefCall(key, ref) : generateOptionalRecordRefCall(key, ref);
|
|
1901
|
+
return isRequired ? generateRequiredRecordRefCall(key, ref, suffix) : generateOptionalRecordRefCall(key, ref, suffix);
|
|
1874
1902
|
}
|
|
1875
1903
|
if (!isSchemaObject3(propSchema)) {
|
|
1876
1904
|
return isRequired ? "undefined" : generateOptionalInlineProperty(key, "undefined");
|
|
@@ -1879,23 +1907,23 @@ var generatePropertyValue = (key, propSchema, isRequired, useRefImports) => {
|
|
|
1879
1907
|
const valueExpression = generateValidationExpression(key, propSchema, defaultValue, isRequired);
|
|
1880
1908
|
return isRequired ? valueExpression : generateOptionalInlineProperty(key, valueExpression);
|
|
1881
1909
|
};
|
|
1882
|
-
var generatePropertyEntries = (schema, useRefImports) => {
|
|
1910
|
+
var generatePropertyEntries = (schema, useRefImports, suffix) => {
|
|
1883
1911
|
if (!hasProperties(schema)) {
|
|
1884
1912
|
return [];
|
|
1885
1913
|
}
|
|
1886
1914
|
const entries = [];
|
|
1887
1915
|
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
1888
1916
|
const isRequired = isPropertyRequired(key, schema);
|
|
1889
|
-
const value = generatePropertyValue(key, propSchema, isRequired, useRefImports);
|
|
1917
|
+
const value = generatePropertyValue(key, propSchema, isRequired, useRefImports, suffix);
|
|
1890
1918
|
const isOptional = value.startsWith("...");
|
|
1891
1919
|
entries.push({ key, value, isOptional });
|
|
1892
1920
|
}
|
|
1893
1921
|
return entries;
|
|
1894
1922
|
};
|
|
1895
|
-
var generateFallbackValue = (_, propSchema, useRefImports) => {
|
|
1923
|
+
var generateFallbackValue = (_, propSchema, useRefImports, suffix) => {
|
|
1896
1924
|
if (useRefImports && hasRef(propSchema)) {
|
|
1897
1925
|
const ref = propSchema.$ref;
|
|
1898
|
-
const parserName = generateParserName(refToName(ref));
|
|
1926
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
1899
1927
|
return `${parserName}(undefined)`;
|
|
1900
1928
|
}
|
|
1901
1929
|
if (useRefImports && isSchemaObject3(propSchema) && propSchema.type === "array" && hasItems(propSchema) && hasRef(propSchema.items)) {
|
|
@@ -1938,7 +1966,7 @@ var generateFallbackValue = (_, propSchema, useRefImports) => {
|
|
|
1938
1966
|
return "undefined";
|
|
1939
1967
|
}
|
|
1940
1968
|
};
|
|
1941
|
-
var generateFallbackObject = (schema, useRefImports, typeName) => {
|
|
1969
|
+
var generateFallbackObject = (schema, useRefImports, typeName, suffix) => {
|
|
1942
1970
|
if (!hasProperties(schema)) {
|
|
1943
1971
|
return `{} as ${typeName}`;
|
|
1944
1972
|
}
|
|
@@ -1949,7 +1977,7 @@ var generateFallbackObject = (schema, useRefImports, typeName) => {
|
|
|
1949
1977
|
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
1950
1978
|
const isRequired = isPropertyRequired(key, schema);
|
|
1951
1979
|
if (isRequired) {
|
|
1952
|
-
const fallbackValue = generateFallbackValue(key, propSchema, useRefImports);
|
|
1980
|
+
const fallbackValue = generateFallbackValue(key, propSchema, useRefImports, suffix);
|
|
1953
1981
|
if (fallbackValue === "undefined") {
|
|
1954
1982
|
return `{} as ${typeName}`;
|
|
1955
1983
|
}
|
|
@@ -2017,11 +2045,11 @@ var toVarName = (key) => {
|
|
|
2017
2045
|
return `_${safe}`;
|
|
2018
2046
|
};
|
|
2019
2047
|
var shapeValidatorName = (typeName) => `validate${typeName}Shape`;
|
|
2020
|
-
var generatePropertyTypeCheck = (varName, schema, useRefImports) => {
|
|
2048
|
+
var generatePropertyTypeCheck = (varName, schema, useRefImports, suffix) => {
|
|
2021
2049
|
if (!isSchemaObject3(schema))
|
|
2022
2050
|
return null;
|
|
2023
2051
|
if (useRefImports && hasRef(schema)) {
|
|
2024
|
-
const refName = refToName(schema.$ref);
|
|
2052
|
+
const refName = refToName(schema.$ref, suffix);
|
|
2025
2053
|
return `${shapeValidatorName(refName)}(${varName})`;
|
|
2026
2054
|
}
|
|
2027
2055
|
if (hasEnum(schema) || hasOneOf(schema) || hasAnyOf(schema) || hasAllOf(schema) || hasRef(schema) || "not" in schema) {
|
|
@@ -2030,7 +2058,7 @@ var generatePropertyTypeCheck = (varName, schema, useRefImports) => {
|
|
|
2030
2058
|
if (!hasType(schema))
|
|
2031
2059
|
return null;
|
|
2032
2060
|
if (useRefImports && schema.type === "array" && hasItems(schema) && isSchemaObject3(schema.items) && hasRef(schema.items)) {
|
|
2033
|
-
const refName = refToName(schema.items.$ref);
|
|
2061
|
+
const refName = refToName(schema.items.$ref, suffix);
|
|
2034
2062
|
return `Array.isArray(${varName}) && ${varName}.every(${shapeValidatorName(refName)})`;
|
|
2035
2063
|
}
|
|
2036
2064
|
const checks = [];
|
|
@@ -2091,7 +2119,7 @@ var generatePropertyTypeCheck = (varName, schema, useRefImports) => {
|
|
|
2091
2119
|
var shouldCacheVariable = (propSchema, _canFastPath, _useRefImports) => {
|
|
2092
2120
|
return isSchemaObject3(propSchema);
|
|
2093
2121
|
};
|
|
2094
|
-
var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict) => {
|
|
2122
|
+
var generateObjectParser = (schema, typeName, useRefImports, suffix, logWarnings, strict) => {
|
|
2095
2123
|
const functionName = generateParserName(typeName);
|
|
2096
2124
|
if (!hasProperties(schema)) {
|
|
2097
2125
|
if (strict) {
|
|
@@ -2102,7 +2130,7 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2102
2130
|
}
|
|
2103
2131
|
return `export const ${functionName} = (input: unknown): ${typeName} => isObject(input) ? input as ${typeName} : {} as ${typeName};`;
|
|
2104
2132
|
}
|
|
2105
|
-
const fallbackObject = generateFallbackObject(schema, useRefImports, typeName);
|
|
2133
|
+
const fallbackObject = generateFallbackObject(schema, useRefImports, typeName, suffix);
|
|
2106
2134
|
const properties = Object.entries(schema.properties);
|
|
2107
2135
|
const lines = [];
|
|
2108
2136
|
lines.push(`export const ${functionName} = (input: unknown): ${typeName} => {`);
|
|
@@ -2125,7 +2153,7 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2125
2153
|
if (shouldUseRecordRefImport(propSchema, useRefImports)) {
|
|
2126
2154
|
canFastPath = false;
|
|
2127
2155
|
} else {
|
|
2128
|
-
const check = generatePropertyTypeCheck(varName, propSchema, useRefImports);
|
|
2156
|
+
const check = generatePropertyTypeCheck(varName, propSchema, useRefImports, suffix);
|
|
2129
2157
|
if (check === null) {
|
|
2130
2158
|
canFastPath = false;
|
|
2131
2159
|
} else {
|
|
@@ -2164,7 +2192,7 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2164
2192
|
if (useRefImports && isSchemaObject3(schema) && hasAllOf(schema)) {
|
|
2165
2193
|
for (const entry of schema.allOf) {
|
|
2166
2194
|
if (isSchemaObject3(entry) && hasRef(entry)) {
|
|
2167
|
-
const parserName = generateParserName(refToName(entry.$ref));
|
|
2195
|
+
const parserName = generateParserName(refToName(entry.$ref, suffix));
|
|
2168
2196
|
objectLines.push(` ...(${parserName}(input) as Record<string, unknown>),`);
|
|
2169
2197
|
}
|
|
2170
2198
|
}
|
|
@@ -2174,7 +2202,7 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2174
2202
|
const accessor = shouldCache ? varName : safeAccessor("input", key);
|
|
2175
2203
|
if (shouldUseRefImport(propSchema, useRefImports)) {
|
|
2176
2204
|
const ref = propSchema.$ref;
|
|
2177
|
-
const parserName = generateParserName(refToName(ref));
|
|
2205
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
2178
2206
|
if (isRequired) {
|
|
2179
2207
|
objectLines.push(` ${safeKey2(key)}: ${parserName}(${accessor}),`);
|
|
2180
2208
|
} else {
|
|
@@ -2185,7 +2213,7 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2185
2213
|
if (shouldUseArrayRefImport(propSchema, useRefImports)) {
|
|
2186
2214
|
const items = propSchema.items;
|
|
2187
2215
|
const ref = items.$ref;
|
|
2188
|
-
const parserName = generateParserName(refToName(ref));
|
|
2216
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
2189
2217
|
if (isRequired) {
|
|
2190
2218
|
objectLines.push(` ${safeKey2(key)}: validateArray(${accessor}, ${parserName}),`);
|
|
2191
2219
|
} else {
|
|
@@ -2196,7 +2224,7 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2196
2224
|
if (shouldUseRecordRefImport(propSchema, useRefImports)) {
|
|
2197
2225
|
const additionalProps = propSchema.additionalProperties;
|
|
2198
2226
|
const ref = additionalProps.$ref;
|
|
2199
|
-
const parserName = generateParserName(refToName(ref));
|
|
2227
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
2200
2228
|
if (isRequired) {
|
|
2201
2229
|
objectLines.push(` ${safeKey2(key)}: validateRecord(${accessor}, ${parserName}),`);
|
|
2202
2230
|
} else {
|
|
@@ -2235,9 +2263,9 @@ var generateObjectParser = (schema, typeName, useRefImports, logWarnings, strict
|
|
|
2235
2263
|
}
|
|
2236
2264
|
return result;
|
|
2237
2265
|
};
|
|
2238
|
-
var generateCombinedObjectParser = (schema, typeName, useRefImports, logWarnings, strict) => {
|
|
2266
|
+
var generateCombinedObjectParser = (schema, typeName, useRefImports, suffix, logWarnings, strict) => {
|
|
2239
2267
|
const functionName = generateParserName(typeName);
|
|
2240
|
-
const entries = generatePropertyEntries(schema, useRefImports);
|
|
2268
|
+
const entries = generatePropertyEntries(schema, useRefImports, suffix);
|
|
2241
2269
|
const propertyLines = entries.map((entry) => {
|
|
2242
2270
|
if (entry.isOptional) {
|
|
2243
2271
|
return ` ${entry.value},`;
|
|
@@ -2245,17 +2273,17 @@ var generateCombinedObjectParser = (schema, typeName, useRefImports, logWarnings
|
|
|
2245
2273
|
return ` ${safeKey2(entry.key)}: ${entry.value},`;
|
|
2246
2274
|
});
|
|
2247
2275
|
if (!isSchemaObject3(schema) || !("patternProperties" in schema)) {
|
|
2248
|
-
return generateObjectParser(schema, typeName, useRefImports, logWarnings, strict);
|
|
2276
|
+
return generateObjectParser(schema, typeName, useRefImports, suffix, logWarnings, strict);
|
|
2249
2277
|
}
|
|
2250
2278
|
const patternProps = schema.patternProperties;
|
|
2251
2279
|
const patterns = Object.entries(patternProps);
|
|
2252
2280
|
const refPattern = patterns.find(([, ps]) => isSchemaObject3(ps) && hasRef(ps));
|
|
2253
2281
|
if (!refPattern || !useRefImports) {
|
|
2254
|
-
return generateObjectParser(schema, typeName, useRefImports, logWarnings, strict);
|
|
2282
|
+
return generateObjectParser(schema, typeName, useRefImports, suffix, logWarnings, strict);
|
|
2255
2283
|
}
|
|
2256
2284
|
const [pattern, patternSchema] = refPattern;
|
|
2257
2285
|
const ref = patternSchema.$ref;
|
|
2258
|
-
const parserName = generateParserName(refToName(ref));
|
|
2286
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
2259
2287
|
const assignmentCode = `(result as Record<string, unknown>)[key] = ${parserName}(value);`;
|
|
2260
2288
|
const escapedPattern = escapeRegexPattern2(pattern);
|
|
2261
2289
|
const inputSpread = " ...input,";
|
|
@@ -2283,7 +2311,7 @@ ${objectProperties}
|
|
|
2283
2311
|
return result;
|
|
2284
2312
|
};`;
|
|
2285
2313
|
};
|
|
2286
|
-
var generateAdditionalPropertiesParser = (schema, typeName, useRefImports, strict) => {
|
|
2314
|
+
var generateAdditionalPropertiesParser = (schema, typeName, useRefImports, suffix, strict) => {
|
|
2287
2315
|
const functionName = generateParserName(typeName);
|
|
2288
2316
|
const additionalProps = schema.additionalProperties;
|
|
2289
2317
|
if (!additionalProps) {
|
|
@@ -2291,7 +2319,7 @@ var generateAdditionalPropertiesParser = (schema, typeName, useRefImports, stric
|
|
|
2291
2319
|
}
|
|
2292
2320
|
if (useRefImports && isSchemaObject3(additionalProps) && hasRef(additionalProps)) {
|
|
2293
2321
|
const ref = additionalProps.$ref;
|
|
2294
|
-
const parserName = generateParserName(refToName(ref));
|
|
2322
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
2295
2323
|
if (strict) {
|
|
2296
2324
|
return `export const ${functionName} = (input: unknown): ${typeName} => {
|
|
2297
2325
|
if (!isObject(input)) throw new Error(\`[${typeName}] expected object, got \${input === null ? "null" : typeof input}\`);
|
|
@@ -2341,7 +2369,7 @@ var generateInlineValueParser = (schema) => {
|
|
|
2341
2369
|
var escapeRegexPattern2 = (pattern) => {
|
|
2342
2370
|
return pattern.replace(/\\/g, "\\\\").replace(/\//g, "\\/");
|
|
2343
2371
|
};
|
|
2344
|
-
var generatePatternPropertiesParser = (schema, typeName, useRefImports, strict) => {
|
|
2372
|
+
var generatePatternPropertiesParser = (schema, typeName, useRefImports, suffix, strict) => {
|
|
2345
2373
|
const functionName = generateParserName(typeName);
|
|
2346
2374
|
if (!("patternProperties" in schema) || typeof schema.patternProperties !== "object") {
|
|
2347
2375
|
return generateEmptyObjectParser(typeName, strict);
|
|
@@ -2355,7 +2383,7 @@ var generatePatternPropertiesParser = (schema, typeName, useRefImports, strict)
|
|
|
2355
2383
|
let patternAssignment = "(result as Record<string, unknown>)[key] = value;";
|
|
2356
2384
|
if (useRefImports && isSchemaObject3(patternSchema) && hasRef(patternSchema)) {
|
|
2357
2385
|
const ref = patternSchema.$ref;
|
|
2358
|
-
const parserName = generateParserName(refToName(ref));
|
|
2386
|
+
const parserName = generateParserName(refToName(ref, suffix));
|
|
2359
2387
|
patternAssignment = `(result as Record<string, unknown>)[key] = ${parserName}(value);`;
|
|
2360
2388
|
} else if (patternSchema === false) {
|
|
2361
2389
|
patternAssignment = "";
|
|
@@ -2378,7 +2406,7 @@ ${notObjectBranch}
|
|
|
2378
2406
|
return result;
|
|
2379
2407
|
};`;
|
|
2380
2408
|
};
|
|
2381
|
-
var generateConditionalParser = (schema, typeName) => {
|
|
2409
|
+
var generateConditionalParser = (schema, typeName, suffix) => {
|
|
2382
2410
|
const functionName = generateParserName(typeName);
|
|
2383
2411
|
const ifSchema = schema.if;
|
|
2384
2412
|
const thenSchema = schema.then;
|
|
@@ -2388,7 +2416,7 @@ var generateConditionalParser = (schema, typeName) => {
|
|
|
2388
2416
|
if (!thenHasRef || !elseHasRef) {
|
|
2389
2417
|
const mergedSchema = getConditionalObjectSchema2(schema);
|
|
2390
2418
|
if (mergedSchema) {
|
|
2391
|
-
return generateObjectParser(mergedSchema, typeName, false);
|
|
2419
|
+
return generateObjectParser(mergedSchema, typeName, false, suffix);
|
|
2392
2420
|
}
|
|
2393
2421
|
return generateEmptyObjectParser(typeName);
|
|
2394
2422
|
}
|
|
@@ -2396,15 +2424,15 @@ var generateConditionalParser = (schema, typeName) => {
|
|
|
2396
2424
|
if (!isRefCondition) {
|
|
2397
2425
|
const mergedSchema = getConditionalObjectSchema2(schema);
|
|
2398
2426
|
if (mergedSchema) {
|
|
2399
|
-
return generateObjectParser(mergedSchema, typeName, false);
|
|
2427
|
+
return generateObjectParser(mergedSchema, typeName, false, suffix);
|
|
2400
2428
|
}
|
|
2401
2429
|
return generateEmptyObjectParser(typeName);
|
|
2402
2430
|
}
|
|
2403
2431
|
const thenRef = thenSchema.$ref;
|
|
2404
2432
|
const elseRef = elseSchema.$ref;
|
|
2405
|
-
const thenParserName = generateParserName(refToName(thenRef));
|
|
2406
|
-
const elseParserName = generateParserName(refToName(elseRef));
|
|
2407
|
-
const thenTypeName = refToName(thenRef);
|
|
2433
|
+
const thenParserName = generateParserName(refToName(thenRef, suffix));
|
|
2434
|
+
const elseParserName = generateParserName(refToName(elseRef, suffix));
|
|
2435
|
+
const thenTypeName = refToName(thenRef, suffix);
|
|
2408
2436
|
return `export const ${functionName} = (input: unknown): ${typeName} | ${thenTypeName} =>
|
|
2409
2437
|
hasRef(input) ? ${thenParserName}(input) : ${elseParserName}(input)
|
|
2410
2438
|
`;
|
|
@@ -2477,7 +2505,8 @@ var selectParserStrategy = (schema, typeName, options) => {
|
|
|
2477
2505
|
const useRefImports = options?.useRefImports ?? false;
|
|
2478
2506
|
const logWarnings = options?.logWarnings ?? false;
|
|
2479
2507
|
const strict = options?.strict ?? false;
|
|
2480
|
-
|
|
2508
|
+
const suffix = options?.typeSuffix ?? "";
|
|
2509
|
+
if (typeName === `Schema${suffix}`) {
|
|
2481
2510
|
return generateSchemaObjectParser(typeName);
|
|
2482
2511
|
}
|
|
2483
2512
|
const isObjectLikeSchema2 = isObjectSchema2(schema) || isSchemaObject3(schema) && (("patternProperties" in schema) || ("additionalProperties" in schema));
|
|
@@ -2485,30 +2514,30 @@ var selectParserStrategy = (schema, typeName, options) => {
|
|
|
2485
2514
|
return generateNonObjectParser(typeName, schema, strict);
|
|
2486
2515
|
}
|
|
2487
2516
|
if (hasProperties(schema) && isSchemaObject3(schema) && "patternProperties" in schema) {
|
|
2488
|
-
return generateCombinedObjectParser(schema, typeName, useRefImports, logWarnings, strict);
|
|
2517
|
+
return generateCombinedObjectParser(schema, typeName, useRefImports, suffix, logWarnings, strict);
|
|
2489
2518
|
}
|
|
2490
2519
|
if (hasProperties(schema)) {
|
|
2491
|
-
return generateObjectParser(schema, typeName, useRefImports, logWarnings, strict);
|
|
2520
|
+
return generateObjectParser(schema, typeName, useRefImports, suffix, logWarnings, strict);
|
|
2492
2521
|
}
|
|
2493
2522
|
if (isSchemaObject3(schema) && "if" in schema && "then" in schema && "else" in schema) {
|
|
2494
|
-
return generateConditionalParser(schema, typeName);
|
|
2523
|
+
return generateConditionalParser(schema, typeName, suffix);
|
|
2495
2524
|
}
|
|
2496
2525
|
const conditionalObjectSchema = getConditionalObjectSchema2(schema);
|
|
2497
2526
|
if (conditionalObjectSchema) {
|
|
2498
|
-
return generateObjectParser(conditionalObjectSchema, typeName, useRefImports, logWarnings, strict);
|
|
2527
|
+
return generateObjectParser(conditionalObjectSchema, typeName, useRefImports, suffix, logWarnings, strict);
|
|
2499
2528
|
}
|
|
2500
2529
|
if (!isObjectLikeSchema2) {
|
|
2501
2530
|
return generateNonObjectParser(typeName, schema, strict);
|
|
2502
2531
|
}
|
|
2503
2532
|
if ("patternProperties" in schema) {
|
|
2504
|
-
return generatePatternPropertiesParser(schema, typeName, useRefImports, strict);
|
|
2533
|
+
return generatePatternPropertiesParser(schema, typeName, useRefImports, suffix, strict);
|
|
2505
2534
|
}
|
|
2506
2535
|
if ("additionalProperties" in schema && !hasProperties(schema)) {
|
|
2507
2536
|
const additionalProps = schema.additionalProperties;
|
|
2508
2537
|
if (additionalProps === true || additionalProps === false) {
|
|
2509
2538
|
return generateEmptyObjectParser(typeName, strict);
|
|
2510
2539
|
}
|
|
2511
|
-
return generateAdditionalPropertiesParser(schema, typeName, useRefImports, strict);
|
|
2540
|
+
return generateAdditionalPropertiesParser(schema, typeName, useRefImports, suffix, strict);
|
|
2512
2541
|
}
|
|
2513
2542
|
if ("type" in schema && schema.type === "object" && !hasProperties(schema)) {
|
|
2514
2543
|
return generateEmptyObjectParser(typeName, strict);
|
|
@@ -2518,7 +2547,7 @@ var selectParserStrategy = (schema, typeName, options) => {
|
|
|
2518
2547
|
var generateParserFunction = (schema, typeName, options) => {
|
|
2519
2548
|
return selectParserStrategy(schema, typeName, options);
|
|
2520
2549
|
};
|
|
2521
|
-
var generateShapeValidator = (schema, typeName, useRefImports) => {
|
|
2550
|
+
var generateShapeValidator = (schema, typeName, useRefImports, suffix = "") => {
|
|
2522
2551
|
const fnName = shapeValidatorName(typeName);
|
|
2523
2552
|
const stub = `export const ${fnName} = (_input: unknown): boolean => false;`;
|
|
2524
2553
|
if (!isSchemaObject3(schema))
|
|
@@ -2536,7 +2565,7 @@ var generateShapeValidator = (schema, typeName, useRefImports) => {
|
|
|
2536
2565
|
}
|
|
2537
2566
|
const accessor = safeAccessor("input", key);
|
|
2538
2567
|
const isRequired = isPropertyRequired(key, schema);
|
|
2539
|
-
const check = generatePropertyTypeCheck(accessor, propSchema, useRefImports);
|
|
2568
|
+
const check = generatePropertyTypeCheck(accessor, propSchema, useRefImports, suffix);
|
|
2540
2569
|
if (check === null) {
|
|
2541
2570
|
return stub;
|
|
2542
2571
|
}
|
|
@@ -2566,9 +2595,10 @@ var generateFile = (schema, typeName, options) => {
|
|
|
2566
2595
|
const selfRef = options?.selfRef;
|
|
2567
2596
|
const rootSchema = options?.rootSchema;
|
|
2568
2597
|
const helpersMode = options?.helpersMode ?? "package";
|
|
2569
|
-
const
|
|
2598
|
+
const typeSuffix = options?.typeSuffix ?? "";
|
|
2599
|
+
const typeDefinition = generateTypeDefinition(schema, typeName, { readonly: options?.readonly ?? false, typeSuffix });
|
|
2570
2600
|
if (typesOnly) {
|
|
2571
|
-
const imports2 = collectImports(schema, { typesOnly: true, selfRef, rootSchema });
|
|
2601
|
+
const imports2 = collectImports(schema, { typesOnly: true, selfRef, rootSchema, typeSuffix });
|
|
2572
2602
|
let result2 = "";
|
|
2573
2603
|
if (imports2.length > 0) {
|
|
2574
2604
|
result2 += imports2[0];
|
|
@@ -2584,15 +2614,16 @@ var generateFile = (schema, typeName, options) => {
|
|
|
2584
2614
|
}
|
|
2585
2615
|
const parserFunction = generateParserFunction(schema, typeName, {
|
|
2586
2616
|
useRefImports: true,
|
|
2617
|
+
typeSuffix,
|
|
2587
2618
|
...options?.logWarnings !== undefined ? { logWarnings: options.logWarnings } : {},
|
|
2588
2619
|
...options?.strict !== undefined ? { strict: options.strict } : {}
|
|
2589
2620
|
});
|
|
2590
|
-
const shapeValidator = generateShapeValidator(schema, typeName, true);
|
|
2621
|
+
const shapeValidator = generateShapeValidator(schema, typeName, true, typeSuffix);
|
|
2591
2622
|
const combinedFunctions = `${shapeValidator}
|
|
2592
2623
|
|
|
2593
2624
|
${parserFunction}`;
|
|
2594
2625
|
const helpers = collectHelpers(combinedFunctions, helpersMode, options?.helpersImportPrefix);
|
|
2595
|
-
const imports = [...collectImports(schema, { selfRef, rootSchema }), ...helpers.imports];
|
|
2626
|
+
const imports = [...collectImports(schema, { selfRef, rootSchema, typeSuffix }), ...helpers.imports];
|
|
2596
2627
|
let result = "";
|
|
2597
2628
|
if (imports.length > 0) {
|
|
2598
2629
|
result += imports[0];
|
|
@@ -2635,7 +2666,7 @@ var extractDynamicAnchorDefs = (schema) => {
|
|
|
2635
2666
|
}
|
|
2636
2667
|
return refs;
|
|
2637
2668
|
};
|
|
2638
|
-
var buildSchema = async (rootSchema, rootTypeName, extensions, typesOnly, logWarnings, strict, helpersMode = "package", helpersImportPrefix = "./", readonly = false) => {
|
|
2669
|
+
var buildSchema = async (rootSchema, rootTypeName, extensions, typesOnly, logWarnings, strict, helpersMode = "package", helpersImportPrefix = "./", readonly = false, typeSuffix = "") => {
|
|
2639
2670
|
rootSchema = upgradeDraft07Schema(rootSchema);
|
|
2640
2671
|
const files = [];
|
|
2641
2672
|
const processedRefs = new Set;
|
|
@@ -2651,6 +2682,7 @@ var buildSchema = async (rootSchema, rootTypeName, extensions, typesOnly, logWar
|
|
|
2651
2682
|
helpersMode,
|
|
2652
2683
|
helpersImportPrefix,
|
|
2653
2684
|
readonly,
|
|
2685
|
+
typeSuffix,
|
|
2654
2686
|
...logWarnings !== undefined ? { logWarnings } : {},
|
|
2655
2687
|
...strict !== undefined ? { strict } : {}
|
|
2656
2688
|
});
|
|
@@ -2677,7 +2709,7 @@ var buildSchema = async (rootSchema, rootTypeName, extensions, typesOnly, logWar
|
|
|
2677
2709
|
console.warn(`Warning: Could not resolve ref: ${ref}`);
|
|
2678
2710
|
continue;
|
|
2679
2711
|
}
|
|
2680
|
-
const typeName = refToName(ref);
|
|
2712
|
+
const typeName = refToName(ref, typeSuffix);
|
|
2681
2713
|
const filename = refToFilename(ref);
|
|
2682
2714
|
const processedSchema = resolveDynamicRefs(resolvedSchema, dynamicRefMap);
|
|
2683
2715
|
const extendedSchema = extensions ? applySchemaExtensions(processedSchema, filename, extensions) : processedSchema;
|
|
@@ -2688,6 +2720,7 @@ var buildSchema = async (rootSchema, rootTypeName, extensions, typesOnly, logWar
|
|
|
2688
2720
|
helpersMode,
|
|
2689
2721
|
helpersImportPrefix,
|
|
2690
2722
|
readonly,
|
|
2723
|
+
typeSuffix,
|
|
2691
2724
|
...logWarnings !== undefined ? { logWarnings } : {},
|
|
2692
2725
|
...strict !== undefined ? { strict } : {}
|
|
2693
2726
|
});
|