@goast/core 0.6.0-beta.1 → 0.6.0-beta.2
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/LICENSE +21 -21
- package/README.md +67 -67
- package/esm/src/codegen/config.d.ts +11 -2
- package/esm/src/codegen/config.d.ts.map +1 -1
- package/esm/src/parse/openapi-types.d.ts +4 -0
- package/esm/src/parse/openapi-types.d.ts.map +1 -1
- package/esm/src/transform/api-types.d.ts +14 -0
- package/esm/src/transform/api-types.d.ts.map +1 -1
- package/esm/src/transform/helpers.d.ts +6 -0
- package/esm/src/transform/helpers.d.ts.map +1 -1
- package/esm/src/transform/helpers.js +34 -5
- package/esm/src/transform/transform-endpoint.js +1 -0
- package/esm/src/transform/transform-schema.d.ts.map +1 -1
- package/esm/src/transform/transform-schema.js +32 -21
- package/esm/src/utils/file-system.utils.d.ts.map +1 -1
- package/esm/src/utils/file-system.utils.js +36 -4
- package/esm/src/utils/schema.utils.d.ts.map +1 -1
- package/esm/src/utils/schema.utils.js +91 -11
- package/esm/src/utils/string.utils.d.ts +19 -0
- package/esm/src/utils/string.utils.d.ts.map +1 -1
- package/esm/src/utils/string.utils.js +25 -0
- package/package.json +1 -1
- package/script/src/codegen/config.d.ts +11 -2
- package/script/src/codegen/config.d.ts.map +1 -1
- package/script/src/parse/openapi-types.d.ts +4 -0
- package/script/src/parse/openapi-types.d.ts.map +1 -1
- package/script/src/transform/api-types.d.ts +14 -0
- package/script/src/transform/api-types.d.ts.map +1 -1
- package/script/src/transform/helpers.d.ts +6 -0
- package/script/src/transform/helpers.d.ts.map +1 -1
- package/script/src/transform/helpers.js +37 -5
- package/script/src/transform/transform-endpoint.js +1 -0
- package/script/src/transform/transform-schema.d.ts.map +1 -1
- package/script/src/transform/transform-schema.js +31 -20
- package/script/src/utils/file-system.utils.d.ts.map +1 -1
- package/script/src/utils/file-system.utils.js +35 -3
- package/script/src/utils/schema.utils.d.ts.map +1 -1
- package/script/src/utils/schema.utils.js +91 -11
- package/script/src/utils/string.utils.d.ts +19 -0
- package/script/src/utils/string.utils.d.ts.map +1 -1
- package/script/src/utils/string.utils.js +26 -0
|
@@ -35,13 +35,45 @@ async function getFilesImpl(dir, options, files, currentDepth) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Splits a file name into its base and extension, treating the extension as everything from the last dot onward
|
|
40
|
+
* (including the dot). A name with no dot has an empty extension. A name that is nothing but an extension (e.g.
|
|
41
|
+
* `.kt`) has an empty base.
|
|
42
|
+
*/
|
|
43
|
+
function splitFileName(fileName) {
|
|
44
|
+
const dotIndex = fileName.lastIndexOf('.');
|
|
45
|
+
if (dotIndex === -1) {
|
|
46
|
+
return { base: fileName, ext: '' };
|
|
47
|
+
}
|
|
48
|
+
return { base: fileName.slice(0, dotIndex), ext: fileName.slice(dotIndex) };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Finds an unused path derived from `filePath` by inserting `_1` before the extension, then `_2`, and so on, until
|
|
52
|
+
* a path that does not yet exist is found.
|
|
53
|
+
*/
|
|
54
|
+
function getCountedFilePath(filePath) {
|
|
55
|
+
const dir = (0, node_path_1.dirname)(filePath);
|
|
56
|
+
const { base, ext } = splitFileName((0, node_path_1.basename)(filePath));
|
|
57
|
+
let counter = 1;
|
|
58
|
+
let candidate = (0, node_path_1.join)(dir, `${base}_${counter}${ext}`);
|
|
59
|
+
while (fs_extra_1.default.existsSync(candidate)) {
|
|
60
|
+
counter++;
|
|
61
|
+
candidate = (0, node_path_1.join)(dir, `${base}_${counter}${ext}`);
|
|
62
|
+
}
|
|
63
|
+
return candidate;
|
|
64
|
+
}
|
|
38
65
|
function writeGeneratedFile(config, filePath, content) {
|
|
66
|
+
let targetPath = filePath;
|
|
39
67
|
if (config.existingFileBehavior !== 'override' && fs_extra_1.default.existsSync(filePath)) {
|
|
40
68
|
if (config.existingFileBehavior === 'error') {
|
|
41
69
|
throw new Error(`File already exists: ${filePath}`);
|
|
42
70
|
}
|
|
43
|
-
|
|
71
|
+
if (config.existingFileBehavior === 'skip') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// config.existingFileBehavior === 'count'
|
|
75
|
+
targetPath = getCountedFilePath(filePath);
|
|
44
76
|
}
|
|
45
|
-
fs_extra_1.default.ensureDirSync((0, node_path_1.dirname)(
|
|
46
|
-
fs_extra_1.default.writeFileSync(
|
|
77
|
+
fs_extra_1.default.ensureDirSync((0, node_path_1.dirname)(targetPath));
|
|
78
|
+
fs_extra_1.default.writeFileSync(targetPath, content);
|
|
47
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/schema.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAA0C,MAAM,2BAA2B,CAAC;AAEnG,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC,EACxC,oBAAoB,EAAE,OAAO,GAC5B,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS,CAgCjC;
|
|
1
|
+
{"version":3,"file":"schema.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/schema.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAA0C,MAAM,2BAA2B,CAAC;AAEnG,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC,EACxC,oBAAoB,EAAE,OAAO,GAC5B,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS,CAgCjC;AAsLD,eAAO,MAAM,iCAAiC,EAAE,CAAC,MAAM,aAAa,CAAC,EAIpE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,MAAM,aAAa,CAAC,EAAE,GAAG,SAAS,CAM5G"}
|
|
@@ -33,30 +33,105 @@ function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
|
33
33
|
additionalProperties,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
function collectSubSchemaProperties(subSchemas, properties, required, optional) {
|
|
36
|
+
function collectSubSchemaProperties(subSchemas, properties, required, optional, collected = { required: new Set(), optional: new Set() }) {
|
|
37
|
+
const seen = optional ? collected.optional : collected.required;
|
|
37
38
|
for (const subSchema of subSchemas) {
|
|
39
|
+
if (seen.has(subSchema))
|
|
40
|
+
continue;
|
|
41
|
+
seen.add(subSchema);
|
|
38
42
|
if (subSchema.kind === 'object') {
|
|
39
43
|
for (const prop of subSchema.properties.values()) {
|
|
40
|
-
|
|
44
|
+
const existing = properties.get(prop.name);
|
|
45
|
+
if (!existing) {
|
|
41
46
|
properties.set(prop.name, prop);
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
else if (hasConflictingType(existing.schema, prop.schema)) {
|
|
49
|
+
// Two branches declare the same property with types that cannot both hold. Picking one and
|
|
50
|
+
// discarding the other would make the merged schema assert something the source contradicts, so
|
|
51
|
+
// widen to a schema that admits both instead.
|
|
52
|
+
properties.set(prop.name, { name: prop.name, schema: widenSchemas(existing.schema, prop.schema) });
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
}
|
|
56
|
+
// A branch does not have to contribute properties to contribute requiredness: `allOf: [{ required: [x] }]`
|
|
57
|
+
// only tightens a property inherited from a sibling branch and has no type or properties of its own.
|
|
58
|
+
if (!optional) {
|
|
59
|
+
for (const prop of subSchema.required) {
|
|
60
|
+
required.add(prop);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
51
|
-
collectSubSchemaProperties(subSchema.allOf, properties, required, optional);
|
|
52
|
-
collectSubSchemaProperties(subSchema.anyOf, properties, required, true);
|
|
64
|
+
collectSubSchemaProperties(subSchema.allOf, properties, required, optional, collected);
|
|
65
|
+
collectSubSchemaProperties(subSchema.anyOf, properties, required, true, collected);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Exactly one branch of a composed `oneOf` applies to any given instance, so its properties are
|
|
69
|
+
// collected but none of its requiredness is — the same treatment an `anyOf` branch gets.
|
|
70
|
+
const oneOf = composedOneOf(subSchema);
|
|
71
|
+
if (oneOf)
|
|
72
|
+
collectSubSchemaProperties(oneOf, properties, required, true, collected);
|
|
53
73
|
}
|
|
54
74
|
}
|
|
55
75
|
}
|
|
56
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The branches of a `oneOf` sub-schema that describe the same instance as the schema composing it, or
|
|
78
|
+
* `undefined` if it has none.
|
|
79
|
+
*
|
|
80
|
+
* An undiscriminated `oneOf` inside a composition constrains the very instance being composed:
|
|
81
|
+
* `allOf: [{ oneOf: [A, B] }, C]` is "A or B, *and* C", so whichever branch applies contributes its
|
|
82
|
+
* properties to the whole. A `oneOf` that declares a `discriminator` is not a composition but a list of
|
|
83
|
+
* subtypes, and `allOf: [Base]` against such a schema means "is a Base" — the sibling subtypes' properties
|
|
84
|
+
* belong to those siblings, not to the schema inheriting from the base.
|
|
85
|
+
*/
|
|
86
|
+
function composedOneOf(schema) {
|
|
87
|
+
return schema.kind === 'oneOf' && !schema.discriminator ? schema.oneOf : undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether two declarations of one property name state types that cannot both hold. A branch that says
|
|
91
|
+
* nothing about the type (`unknown`) constrains nothing and so never conflicts, and two declarations of the
|
|
92
|
+
* same kind are treated as a refinement of one another rather than a conflict, so the first still wins.
|
|
93
|
+
*/
|
|
94
|
+
function hasConflictingType(a, b) {
|
|
95
|
+
return a.kind !== b.kind && a.kind !== 'unknown' && b.kind !== 'unknown';
|
|
96
|
+
}
|
|
97
|
+
/** The branches a schema contributes to a widened `oneOf`, flattened so widening stays a single level. */
|
|
98
|
+
function conflictBranches(schema) {
|
|
99
|
+
return schema.kind === 'oneOf' ? schema.oneOf : [schema];
|
|
100
|
+
}
|
|
101
|
+
/** A `oneOf` admitting either side of a conflicting merge, so neither side is silently discarded. */
|
|
102
|
+
function widenSchemas(a, b) {
|
|
103
|
+
const oneOf = [];
|
|
104
|
+
for (const branch of [...conflictBranches(a), ...conflictBranches(b)]) {
|
|
105
|
+
if (!oneOf.some((x) => x.id === branch.id))
|
|
106
|
+
oneOf.push(branch);
|
|
107
|
+
}
|
|
108
|
+
// Derived from the branch ids rather than generated, so the same conflict always yields the same schema.
|
|
109
|
+
const id = `conflict-${oneOf.map((x) => x.id).join('+')}`;
|
|
110
|
+
return {
|
|
111
|
+
...a,
|
|
112
|
+
$ref: undefined,
|
|
113
|
+
id,
|
|
114
|
+
name: id,
|
|
115
|
+
isNameGenerated: true,
|
|
116
|
+
kind: 'oneOf',
|
|
117
|
+
enum: undefined,
|
|
118
|
+
const: undefined,
|
|
119
|
+
default: undefined,
|
|
120
|
+
discriminator: undefined,
|
|
121
|
+
inheritedSchemas: [],
|
|
122
|
+
nullable: a.nullable || b.nullable,
|
|
123
|
+
oneOf,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function combineAdditionalProperties(subSchemas, current,
|
|
127
|
+
/** Guards the same composition cycle `collectSubSchemaProperties` guards; see `CollectedSubSchemas`. */
|
|
128
|
+
visited = new Set()) {
|
|
57
129
|
if (current === true)
|
|
58
130
|
return true;
|
|
59
131
|
for (const subSchema of subSchemas) {
|
|
132
|
+
if (visited.has(subSchema))
|
|
133
|
+
continue;
|
|
134
|
+
visited.add(subSchema);
|
|
60
135
|
if (subSchema.kind === 'object' && subSchema.additionalProperties) {
|
|
61
136
|
if (subSchema.additionalProperties === true)
|
|
62
137
|
return true;
|
|
@@ -95,8 +170,13 @@ function combineAdditionalProperties(subSchemas, current) {
|
|
|
95
170
|
}
|
|
96
171
|
}
|
|
97
172
|
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
98
|
-
current = combineAdditionalProperties(subSchema.allOf, current);
|
|
99
|
-
current = combineAdditionalProperties(subSchema.anyOf, current);
|
|
173
|
+
current = combineAdditionalProperties(subSchema.allOf, current, visited);
|
|
174
|
+
current = combineAdditionalProperties(subSchema.anyOf, current, visited);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const oneOf = composedOneOf(subSchema);
|
|
178
|
+
if (oneOf)
|
|
179
|
+
current = combineAdditionalProperties(oneOf, current, visited);
|
|
100
180
|
}
|
|
101
181
|
if (current === true)
|
|
102
182
|
return true;
|
|
@@ -109,6 +109,25 @@ export declare function toCustomCase(str: Nullable<string>, options: CustomCaseO
|
|
|
109
109
|
* @param str The string to escape.
|
|
110
110
|
*/
|
|
111
111
|
export declare function escapeRegExp(str: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Compares two strings for sorting, case-insensitively, without any dependency on the host locale.
|
|
114
|
+
*
|
|
115
|
+
* Deliberately not `String.prototype.localeCompare`: its collation depends on the host locale and ICU
|
|
116
|
+
* version, so the same input would sort differently on different machines — which would make
|
|
117
|
+
* generated output non-reproducible. `toLowerCase` is Unicode default case conversion and carries no
|
|
118
|
+
* locale dependency.
|
|
119
|
+
*
|
|
120
|
+
* Comparison is case-insensitive so that, for example, `awaitBody` sorts alphabetically beside
|
|
121
|
+
* `WebClient` rather than after every capitalized name. Strings differing only in case fall back to a
|
|
122
|
+
* case-sensitive comparison, so their relative order is still stable. Non-ASCII characters order by
|
|
123
|
+
* code point rather than alphabetically — `Ähre` sorts after `Zebra` — which is less pretty than
|
|
124
|
+
* locale collation but entirely reproducible.
|
|
125
|
+
*
|
|
126
|
+
* @param a The first string.
|
|
127
|
+
* @param b The second string.
|
|
128
|
+
* @returns A negative number if `a` sorts first, a positive number if `b` does, otherwise 0.
|
|
129
|
+
*/
|
|
130
|
+
export declare function compareString(a: string, b: string): number;
|
|
112
131
|
/**
|
|
113
132
|
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
114
133
|
* @param str The string to splice.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/string.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,gBAAgB,EAEhB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,EACvB,UAAU,EACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY,CAAC;AAC7E,wBAAgB,YAAY,CAC1B,CAAC,EAAE,YAAY,GAAG,uBAAuB,EACzC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,uBAAuB,CAAC,GACjD,uBAAuB,CAAC;AAkB3B,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CASxD;AAED;;;;;;;;;;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AYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAUtF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpG;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI9C;AA6BD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAK3E;AACD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAK7E;AACD,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAOxE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAW1D"}
|
|
@@ -14,6 +14,7 @@ exports.toKebabCase = toKebabCase;
|
|
|
14
14
|
exports.toSnakeCase = toSnakeCase;
|
|
15
15
|
exports.toCustomCase = toCustomCase;
|
|
16
16
|
exports.escapeRegExp = escapeRegExp;
|
|
17
|
+
exports.compareString = compareString;
|
|
17
18
|
exports.spliceString = spliceString;
|
|
18
19
|
exports.trimIndent = trimIndent;
|
|
19
20
|
exports.trimEnd = trimEnd;
|
|
@@ -267,6 +268,31 @@ function toCustomCase(str, options) {
|
|
|
267
268
|
function escapeRegExp(str) {
|
|
268
269
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
269
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Compares two strings for sorting, case-insensitively, without any dependency on the host locale.
|
|
273
|
+
*
|
|
274
|
+
* Deliberately not `String.prototype.localeCompare`: its collation depends on the host locale and ICU
|
|
275
|
+
* version, so the same input would sort differently on different machines — which would make
|
|
276
|
+
* generated output non-reproducible. `toLowerCase` is Unicode default case conversion and carries no
|
|
277
|
+
* locale dependency.
|
|
278
|
+
*
|
|
279
|
+
* Comparison is case-insensitive so that, for example, `awaitBody` sorts alphabetically beside
|
|
280
|
+
* `WebClient` rather than after every capitalized name. Strings differing only in case fall back to a
|
|
281
|
+
* case-sensitive comparison, so their relative order is still stable. Non-ASCII characters order by
|
|
282
|
+
* code point rather than alphabetically — `Ähre` sorts after `Zebra` — which is less pretty than
|
|
283
|
+
* locale collation but entirely reproducible.
|
|
284
|
+
*
|
|
285
|
+
* @param a The first string.
|
|
286
|
+
* @param b The second string.
|
|
287
|
+
* @returns A negative number if `a` sorts first, a positive number if `b` does, otherwise 0.
|
|
288
|
+
*/
|
|
289
|
+
function compareString(a, b) {
|
|
290
|
+
const lowerA = a.toLowerCase();
|
|
291
|
+
const lowerB = b.toLowerCase();
|
|
292
|
+
if (lowerA !== lowerB)
|
|
293
|
+
return lowerA < lowerB ? -1 : 1;
|
|
294
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
295
|
+
}
|
|
270
296
|
/**
|
|
271
297
|
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
272
298
|
* @param str The string to splice.
|