@orval/core 8.0.0-rc.0 → 8.0.0-rc.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/index.d.ts +3 -4
- package/dist/index.js +44 -26
- package/dist/index.js.map +1 -1
- package/package.json +3 -10
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { allLocales } from "@faker-js/faker";
|
|
|
7
7
|
import { JSONSchema6, JSONSchema7 } from "json-schema";
|
|
8
8
|
import { ComponentsObject, ExampleObject, InfoObject, OpenAPIObject, OperationObject, ParameterObject, PathItemObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemasObject } from "openapi3-ts/oas30";
|
|
9
9
|
import { TypeDocOptions } from "typedoc";
|
|
10
|
-
import { ValueIteratee } from "lodash";
|
|
11
10
|
import { ServerObject } from "openapi3-ts/oas31";
|
|
12
11
|
|
|
13
12
|
//#region src/types.d.ts
|
|
@@ -488,7 +487,7 @@ type NormalizedQueryOptions = {
|
|
|
488
487
|
shouldSplitQueryKey?: boolean;
|
|
489
488
|
useOperationIdAsQueryKey?: boolean;
|
|
490
489
|
signal?: boolean;
|
|
491
|
-
version?: 4 | 5;
|
|
490
|
+
version?: 3 | 4 | 5;
|
|
492
491
|
};
|
|
493
492
|
type QueryOptions = {
|
|
494
493
|
useQuery?: boolean;
|
|
@@ -509,7 +508,7 @@ type QueryOptions = {
|
|
|
509
508
|
shouldSplitQueryKey?: boolean;
|
|
510
509
|
useOperationIdAsQueryKey?: boolean;
|
|
511
510
|
signal?: boolean;
|
|
512
|
-
version?: 4 | 5;
|
|
511
|
+
version?: 3 | 4 | 5;
|
|
513
512
|
};
|
|
514
513
|
type AngularOptions = {
|
|
515
514
|
provideIn?: 'root' | 'any' | boolean;
|
|
@@ -1384,7 +1383,7 @@ interface RefInfo {
|
|
|
1384
1383
|
declare const getRefInfo: ($ref: ReferenceObject["$ref"], context: ContextSpecs) => RefInfo;
|
|
1385
1384
|
//#endregion
|
|
1386
1385
|
//#region src/getters/res-req-types.d.ts
|
|
1387
|
-
declare const getResReqTypes: (responsesOrRequests: [string, ResponseObject | ReferenceObject | RequestBodyObject][], name: string, context: ContextSpecs, defaultType?: string, uniqueKey?:
|
|
1386
|
+
declare const getResReqTypes: (responsesOrRequests: [string, ResponseObject | ReferenceObject | RequestBodyObject][], name: string, context: ContextSpecs, defaultType?: string, uniqueKey?: (item: ResReqTypesValue, index: number, data: ResReqTypesValue[]) => unknown) => ResReqTypesValue[];
|
|
1388
1387
|
//#endregion
|
|
1389
1388
|
//#region src/getters/response.d.ts
|
|
1390
1389
|
declare const getResponse: ({
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __export } from "./chunk-Bp6m_JJh.js";
|
|
2
|
-
import
|
|
2
|
+
import { isEmptyish, unique, uniqueBy, uniqueWith } from "remeda";
|
|
3
3
|
import { keyword } from "esutils";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import fs from "node:fs";
|
|
@@ -12,9 +12,6 @@ import chalk from "chalk";
|
|
|
12
12
|
import { convertObj } from "swagger2openapi";
|
|
13
13
|
import ibmOpenapiRuleset from "@ibm-cloud/openapi-ruleset";
|
|
14
14
|
import stoplight from "@stoplight/spectral-core";
|
|
15
|
-
import uniqBy from "lodash.uniqby";
|
|
16
|
-
import uniq from "lodash.uniq";
|
|
17
|
-
import uniqWith from "lodash.uniqwith";
|
|
18
15
|
import fs$1 from "fs-extra";
|
|
19
16
|
import { Parser } from "acorn";
|
|
20
17
|
import { build } from "esbuild";
|
|
@@ -1170,8 +1167,8 @@ const getResReqContentTypes = ({ mediaType, propName, context }) => {
|
|
|
1170
1167
|
context
|
|
1171
1168
|
});
|
|
1172
1169
|
};
|
|
1173
|
-
const getResReqTypes = (responsesOrRequests, name, context, defaultType = "unknown", uniqueKey =
|
|
1174
|
-
return
|
|
1170
|
+
const getResReqTypes = (responsesOrRequests, name, context, defaultType = "unknown", uniqueKey = (item) => item.value) => {
|
|
1171
|
+
return uniqueBy(responsesOrRequests.filter(([_, res]) => Boolean(res)).map(([key, res]) => {
|
|
1175
1172
|
if (isReference(res)) {
|
|
1176
1173
|
const { schema: bodySchema, imports: [{ name: name$1, specKey, schemaName }] } = resolveRef(res, context);
|
|
1177
1174
|
const [contentType, mediaType] = Object.entries(bodySchema.content ?? {})[0] ?? [];
|
|
@@ -1516,6 +1513,23 @@ const getKey = (key) => {
|
|
|
1516
1513
|
//#endregion
|
|
1517
1514
|
//#region src/getters/object.ts
|
|
1518
1515
|
/**
|
|
1516
|
+
* Extract enum values from propertyNames schema (OpenAPI 3.1)
|
|
1517
|
+
* Returns undefined if propertyNames doesn't have an enum
|
|
1518
|
+
*/
|
|
1519
|
+
const getPropertyNamesEnum = (item) => {
|
|
1520
|
+
const schema31 = item;
|
|
1521
|
+
if ("propertyNames" in schema31 && schema31.propertyNames && "enum" in schema31.propertyNames && Array.isArray(schema31.propertyNames.enum)) return schema31.propertyNames.enum.filter((val) => typeof val === "string");
|
|
1522
|
+
};
|
|
1523
|
+
/**
|
|
1524
|
+
* Generate index signature key type based on propertyNames enum
|
|
1525
|
+
* Returns union type string like "'foo' | 'bar'" or 'string' if no enum
|
|
1526
|
+
*/
|
|
1527
|
+
const getIndexSignatureKey = (item) => {
|
|
1528
|
+
const enumValues = getPropertyNamesEnum(item);
|
|
1529
|
+
if (enumValues && enumValues.length > 0) return enumValues.map((val) => `'${val}'`).join(" | ");
|
|
1530
|
+
return "string";
|
|
1531
|
+
};
|
|
1532
|
+
/**
|
|
1519
1533
|
* Return the output type from an object
|
|
1520
1534
|
*
|
|
1521
1535
|
* @param item item with type === "object"
|
|
@@ -1593,16 +1607,18 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1593
1607
|
acc.value += `\n ${doc ? `${doc} ` : ""}${isReadOnly && !context.output.override.suppressReadonlyModifier ? "readonly " : ""}${getKey(key)}${isRequired ? "" : "?"}: ${propValue};`;
|
|
1594
1608
|
acc.schemas.push(...resolvedValue.schemas);
|
|
1595
1609
|
if (arr.length - 1 === index) {
|
|
1596
|
-
if (item.additionalProperties)
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1610
|
+
if (item.additionalProperties) {
|
|
1611
|
+
const keyType$1 = getIndexSignatureKey(item);
|
|
1612
|
+
if (isBoolean(item.additionalProperties)) acc.value += `\n [key: ${keyType$1}]: unknown;\n }`;
|
|
1613
|
+
else {
|
|
1614
|
+
const resolvedValue$1 = resolveValue({
|
|
1615
|
+
schema: item.additionalProperties,
|
|
1616
|
+
name,
|
|
1617
|
+
context
|
|
1618
|
+
});
|
|
1619
|
+
acc.value += `\n [key: ${keyType$1}]: ${resolvedValue$1.value};\n}`;
|
|
1620
|
+
}
|
|
1621
|
+
} else acc.value += "\n}";
|
|
1606
1622
|
acc.value += nullable;
|
|
1607
1623
|
}
|
|
1608
1624
|
return acc;
|
|
@@ -1620,8 +1636,9 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1620
1636
|
});
|
|
1621
1637
|
}
|
|
1622
1638
|
if (item.additionalProperties) {
|
|
1639
|
+
const keyType$1 = getIndexSignatureKey(item);
|
|
1623
1640
|
if (isBoolean(item.additionalProperties)) return {
|
|
1624
|
-
value: `{ [key:
|
|
1641
|
+
value: `{ [key: ${keyType$1}]: unknown }` + nullable,
|
|
1625
1642
|
imports: [],
|
|
1626
1643
|
schemas: [],
|
|
1627
1644
|
isEnum: false,
|
|
@@ -1635,7 +1652,7 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1635
1652
|
context
|
|
1636
1653
|
});
|
|
1637
1654
|
return {
|
|
1638
|
-
value: `{[key:
|
|
1655
|
+
value: `{[key: ${keyType$1}]: ${resolvedValue.value}}` + nullable,
|
|
1639
1656
|
imports: resolvedValue.imports ?? [],
|
|
1640
1657
|
schemas: resolvedValue.schemas ?? [],
|
|
1641
1658
|
isEnum: false,
|
|
@@ -1654,8 +1671,9 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1654
1671
|
isRef: false,
|
|
1655
1672
|
hasReadonlyProps: item.readOnly || false
|
|
1656
1673
|
};
|
|
1674
|
+
const keyType = item.type === "object" ? getIndexSignatureKey(item) : "string";
|
|
1657
1675
|
return {
|
|
1658
|
-
value: (item.type === "object" ?
|
|
1676
|
+
value: (item.type === "object" ? `{ [key: ${keyType}]: unknown }` : "unknown") + nullable,
|
|
1659
1677
|
imports: [],
|
|
1660
1678
|
schemas: [],
|
|
1661
1679
|
isEnum: false,
|
|
@@ -1820,7 +1838,7 @@ const combineValues = ({ resolvedData, resolvedValue, separator: separator$1, co
|
|
|
1820
1838
|
values.push(resolvedData.values[i]);
|
|
1821
1839
|
continue;
|
|
1822
1840
|
}
|
|
1823
|
-
const missingProperties =
|
|
1841
|
+
const missingProperties = unique(resolvedData.allProperties.filter((p) => !Object.keys(subSchema.properties).includes(p)));
|
|
1824
1842
|
values.push(`${resolvedData.values[i]}${missingProperties.length > 0 ? ` & {${missingProperties.map((p) => `${p}?: never`).join("; ")}}` : ""}`);
|
|
1825
1843
|
}
|
|
1826
1844
|
}
|
|
@@ -2298,7 +2316,7 @@ const getRouteAsArray = (route) => route.replaceAll(TEMPLATE_TAG_IN_PATH_REGEX,
|
|
|
2298
2316
|
//#endregion
|
|
2299
2317
|
//#region src/generators/component-definition.ts
|
|
2300
2318
|
const generateComponentDefinition = (responses = {}, context, suffix) => {
|
|
2301
|
-
if (
|
|
2319
|
+
if (isEmptyish(responses)) return [];
|
|
2302
2320
|
return Object.entries(responses).reduce((acc, [name, response]) => {
|
|
2303
2321
|
const allResponseTypes = getResReqTypes([[suffix, response]], name, context, "void");
|
|
2304
2322
|
const imports = allResponseTypes.flatMap(({ imports: imports$1 }) => imports$1);
|
|
@@ -2326,7 +2344,7 @@ const generateComponentDefinition = (responses = {}, context, suffix) => {
|
|
|
2326
2344
|
//#region src/generators/imports.ts
|
|
2327
2345
|
const generateImports = ({ imports = [], target, isRootKey: isRootKey$1, specsName, specKey: currentSpecKey, namingConvention = NamingConvention.CAMEL_CASE }) => {
|
|
2328
2346
|
if (imports.length === 0) return "";
|
|
2329
|
-
return
|
|
2347
|
+
return uniqueWith(imports, (a, b) => a.name === b.name && a.default === b.default && a.specKey === b.specKey).sort().map(({ specKey, name, values, alias, isConstant }) => {
|
|
2330
2348
|
const isSameSpecKey = currentSpecKey === specKey;
|
|
2331
2349
|
const fileName = conventionName(name, namingConvention);
|
|
2332
2350
|
if (specKey && !isSameSpecKey) {
|
|
@@ -2338,7 +2356,7 @@ const generateImports = ({ imports = [], target, isRootKey: isRootKey$1, specsNa
|
|
|
2338
2356
|
}).join("\n");
|
|
2339
2357
|
};
|
|
2340
2358
|
const generateMutatorImports = ({ mutators, implementation, oneMore }) => {
|
|
2341
|
-
return
|
|
2359
|
+
return uniqueWith(mutators, (a, b) => a.name === b.name && a.default === b.default).reduce((acc, mutator) => {
|
|
2342
2360
|
const path$2 = `${oneMore ? "../" : ""}${mutator.path}`;
|
|
2343
2361
|
const importDefault = mutator.default ? mutator.name : `{ ${mutator.name} }`;
|
|
2344
2362
|
acc += `import ${importDefault} from '${path$2}';`;
|
|
@@ -2361,7 +2379,7 @@ const generateMutatorImports = ({ mutators, implementation, oneMore }) => {
|
|
|
2361
2379
|
const generateDependency = ({ deps, isAllowSyntheticDefaultImports, dependency, specsName, key, onlyTypes }) => {
|
|
2362
2380
|
const defaultDep = deps.find((e) => e.default && (isAllowSyntheticDefaultImports || !e.syntheticDefaultImport));
|
|
2363
2381
|
const namespaceImportDep = defaultDep ? void 0 : deps.find((e) => !!e.namespaceImport || !isAllowSyntheticDefaultImports && e.syntheticDefaultImport);
|
|
2364
|
-
const depsString =
|
|
2382
|
+
const depsString = unique(deps.filter((e) => !e.default && !e.syntheticDefaultImport && !e.namespaceImport).map(({ name, alias }) => alias ? `${name} as ${alias}` : name)).toSorted().join(",\n ");
|
|
2365
2383
|
let importString = "";
|
|
2366
2384
|
const namespaceImportString = namespaceImportDep ? `import * as ${namespaceImportDep.name} from '${dependency}';` : "";
|
|
2367
2385
|
if (namespaceImportString) {
|
|
@@ -2773,7 +2791,7 @@ const generateInterface = ({ name, schema, context, suffix }) => {
|
|
|
2773
2791
|
* @param schemas
|
|
2774
2792
|
*/
|
|
2775
2793
|
const generateSchemasDefinition = (schemas = {}, context, suffix, filters) => {
|
|
2776
|
-
if (
|
|
2794
|
+
if (isEmptyish(schemas)) return [];
|
|
2777
2795
|
const transformedSchemas = resolveDiscriminators(schemas, context);
|
|
2778
2796
|
let generateSchemas = Object.entries(transformedSchemas);
|
|
2779
2797
|
if (filters?.schemas) {
|
|
@@ -3062,7 +3080,7 @@ const writeSchemas = async ({ schemaPath, schemas, target, namingConvention, fil
|
|
|
3062
3080
|
//#endregion
|
|
3063
3081
|
//#region src/writers/generate-imports-for-builder.ts
|
|
3064
3082
|
const generateImportsForBuilder = (output, imports, relativeSchemasPath) => {
|
|
3065
|
-
return output.schemas && !output.indexFiles ?
|
|
3083
|
+
return output.schemas && !output.indexFiles ? uniqueBy(imports, (x) => x.name).map((i) => {
|
|
3066
3084
|
const name = conventionName(i.name, output.namingConvention);
|
|
3067
3085
|
return {
|
|
3068
3086
|
exports: [i],
|