@orval/core 8.0.0-rc.0 → 8.0.0-rc.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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as __export } from "./chunk-Bp6m_JJh.js";
|
|
2
1
|
import { CompareOperator } from "compare-versions";
|
|
3
2
|
import debug from "debug";
|
|
4
3
|
import { ConvertInputOptions } from "swagger2openapi";
|
|
@@ -7,7 +6,6 @@ import { allLocales } from "@faker-js/faker";
|
|
|
7
6
|
import { JSONSchema6, JSONSchema7 } from "json-schema";
|
|
8
7
|
import { ComponentsObject, ExampleObject, InfoObject, OpenAPIObject, OperationObject, ParameterObject, PathItemObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemasObject } from "openapi3-ts/oas30";
|
|
9
8
|
import { TypeDocOptions } from "typedoc";
|
|
10
|
-
import { ValueIteratee } from "lodash";
|
|
11
9
|
import { ServerObject } from "openapi3-ts/oas31";
|
|
12
10
|
|
|
13
11
|
//#region src/types.d.ts
|
|
@@ -29,7 +27,7 @@ interface NormalizedOptions {
|
|
|
29
27
|
}
|
|
30
28
|
type NormalizedOutputOptions = {
|
|
31
29
|
workspace?: string;
|
|
32
|
-
target
|
|
30
|
+
target: string;
|
|
33
31
|
schemas?: string;
|
|
34
32
|
namingConvention: NamingConvention;
|
|
35
33
|
fileExtension: string;
|
|
@@ -60,8 +58,8 @@ type NormalizedOverrideOutput = {
|
|
|
60
58
|
title?: (title: string) => string;
|
|
61
59
|
transformer?: OutputTransformer;
|
|
62
60
|
mutator?: NormalizedMutator;
|
|
63
|
-
operations: Record<string, NormalizedOperationOptions>;
|
|
64
|
-
tags: Record<string, NormalizedOperationOptions>;
|
|
61
|
+
operations: Record<string, NormalizedOperationOptions | undefined>;
|
|
62
|
+
tags: Record<string, NormalizedOperationOptions | undefined>;
|
|
65
63
|
mock?: OverrideMockOptions;
|
|
66
64
|
contentType?: OverrideOutputContentType;
|
|
67
65
|
header: false | ((info: InfoObject) => string[] | string);
|
|
@@ -171,7 +169,7 @@ declare const EnumGeneration: {
|
|
|
171
169
|
type EnumGeneration = (typeof EnumGeneration)[keyof typeof EnumGeneration];
|
|
172
170
|
type OutputOptions = {
|
|
173
171
|
workspace?: string;
|
|
174
|
-
target
|
|
172
|
+
target: string;
|
|
175
173
|
schemas?: string;
|
|
176
174
|
namingConvention?: NamingConvention;
|
|
177
175
|
fileExtension?: string;
|
|
@@ -452,7 +450,7 @@ type NormalizedZodOptions = {
|
|
|
452
450
|
body: boolean | ZodCoerceType[];
|
|
453
451
|
response: boolean | ZodCoerceType[];
|
|
454
452
|
};
|
|
455
|
-
preprocess
|
|
453
|
+
preprocess?: {
|
|
456
454
|
param?: NormalizedMutator;
|
|
457
455
|
query?: NormalizedMutator;
|
|
458
456
|
header?: NormalizedMutator;
|
|
@@ -488,7 +486,7 @@ type NormalizedQueryOptions = {
|
|
|
488
486
|
shouldSplitQueryKey?: boolean;
|
|
489
487
|
useOperationIdAsQueryKey?: boolean;
|
|
490
488
|
signal?: boolean;
|
|
491
|
-
version?: 4 | 5;
|
|
489
|
+
version?: 3 | 4 | 5;
|
|
492
490
|
};
|
|
493
491
|
type QueryOptions = {
|
|
494
492
|
useQuery?: boolean;
|
|
@@ -509,7 +507,7 @@ type QueryOptions = {
|
|
|
509
507
|
shouldSplitQueryKey?: boolean;
|
|
510
508
|
useOperationIdAsQueryKey?: boolean;
|
|
511
509
|
signal?: boolean;
|
|
512
|
-
version?: 4 | 5;
|
|
510
|
+
version?: 3 | 4 | 5;
|
|
513
511
|
};
|
|
514
512
|
type AngularOptions = {
|
|
515
513
|
provideIn?: 'root' | 'any' | boolean;
|
|
@@ -517,9 +515,9 @@ type AngularOptions = {
|
|
|
517
515
|
type SwrOptions = {
|
|
518
516
|
useInfinite?: boolean;
|
|
519
517
|
useSWRMutationForGet?: boolean;
|
|
520
|
-
swrOptions?:
|
|
521
|
-
swrMutationOptions?:
|
|
522
|
-
swrInfiniteOptions?:
|
|
518
|
+
swrOptions?: unknown;
|
|
519
|
+
swrMutationOptions?: unknown;
|
|
520
|
+
swrInfiniteOptions?: unknown;
|
|
523
521
|
};
|
|
524
522
|
type NormalizedFetchOptions = {
|
|
525
523
|
includeHttpResponseReturnType: boolean;
|
|
@@ -562,7 +560,7 @@ interface HookOption {
|
|
|
562
560
|
}
|
|
563
561
|
type HookCommand = string | HookFunction | HookOption | (string | HookFunction | HookOption)[];
|
|
564
562
|
type NormalizedHookCommand = HookCommand[];
|
|
565
|
-
type HooksOptions<T
|
|
563
|
+
type HooksOptions<T = HookCommand | NormalizedHookCommand> = Partial<Record<Hook, T>>;
|
|
566
564
|
type NormalizedHookOptions = HooksOptions<NormalizedHookCommand>;
|
|
567
565
|
type Verbs = 'post' | 'put' | 'get' | 'patch' | 'delete' | 'head';
|
|
568
566
|
declare const Verbs: {
|
|
@@ -589,8 +587,7 @@ interface ContextSpecs {
|
|
|
589
587
|
output: NormalizedOutputOptions;
|
|
590
588
|
}
|
|
591
589
|
interface GlobalOptions {
|
|
592
|
-
|
|
593
|
-
watch?: boolean | string | (string | boolean)[];
|
|
590
|
+
watch?: boolean | string | string[];
|
|
594
591
|
clean?: boolean | string[];
|
|
595
592
|
prettier?: boolean;
|
|
596
593
|
biome?: boolean;
|
|
@@ -1384,7 +1381,7 @@ interface RefInfo {
|
|
|
1384
1381
|
declare const getRefInfo: ($ref: ReferenceObject["$ref"], context: ContextSpecs) => RefInfo;
|
|
1385
1382
|
//#endregion
|
|
1386
1383
|
//#region src/getters/res-req-types.d.ts
|
|
1387
|
-
declare const getResReqTypes: (responsesOrRequests: [string, ResponseObject | ReferenceObject | RequestBodyObject][], name: string, context: ContextSpecs, defaultType?: string, uniqueKey?:
|
|
1384
|
+
declare const getResReqTypes: (responsesOrRequests: [string, ResponseObject | ReferenceObject | RequestBodyObject][], name: string, context: ContextSpecs, defaultType?: string, uniqueKey?: (item: ResReqTypesValue, index: number, data: ResReqTypesValue[]) => unknown) => ResReqTypesValue[];
|
|
1388
1385
|
//#endregion
|
|
1389
1386
|
//#region src/getters/response.d.ts
|
|
1390
1387
|
declare const getResponse: ({
|
|
@@ -1498,7 +1495,7 @@ interface DebuggerOptions {
|
|
|
1498
1495
|
declare function createDebugger(ns: string, options?: DebuggerOptions): debug.Debugger['log'];
|
|
1499
1496
|
//#endregion
|
|
1500
1497
|
//#region src/utils/deep-non-nullable.d.ts
|
|
1501
|
-
type DeepNonNullable<T
|
|
1498
|
+
type DeepNonNullable<T> = T extends Function ? T : T extends readonly (infer U)[] ? DeepNonNullable<NonNullable<U>>[] : T extends object ? { [K in keyof T]: DeepNonNullable<NonNullable<T[K]>> } : NonNullable<T>;
|
|
1502
1499
|
//#endregion
|
|
1503
1500
|
//#region src/utils/doc.d.ts
|
|
1504
1501
|
declare function jsDoc(schema: {
|
|
@@ -1547,6 +1544,24 @@ declare function removeFilesAndEmptyFolders(patterns: string[], dir: string): Pr
|
|
|
1547
1544
|
//#region src/utils/file-extensions.d.ts
|
|
1548
1545
|
declare const getMockFileExtensionByTypeName: (mock: GlobalMockOptions | ClientMockBuilder) => string;
|
|
1549
1546
|
//#endregion
|
|
1547
|
+
//#region src/utils/get-property-safe.d.ts
|
|
1548
|
+
/**
|
|
1549
|
+
* Type safe way to get arbitrary property from an object.
|
|
1550
|
+
*
|
|
1551
|
+
* @param obj - The object from which to retrieve the property.
|
|
1552
|
+
* @param propertyName - The name of the property to retrieve.
|
|
1553
|
+
* @returns Object with `hasProperty: true` and `value` of the property if it exists; otherwise `hasProperty: false` and undefined.
|
|
1554
|
+
*
|
|
1555
|
+
* @remarks Until TypeScript adds type-narrowing for Object.hasOwn we have to use this workaround
|
|
1556
|
+
*/
|
|
1557
|
+
declare function getPropertySafe<T extends object, K$1 extends keyof T>(obj: T, propertyName: K$1 | string): {
|
|
1558
|
+
hasProperty: true;
|
|
1559
|
+
value: T[K$1];
|
|
1560
|
+
} | {
|
|
1561
|
+
hasProperty: false;
|
|
1562
|
+
value: undefined;
|
|
1563
|
+
};
|
|
1564
|
+
//#endregion
|
|
1550
1565
|
//#region src/utils/is-body-verb.d.ts
|
|
1551
1566
|
declare const getIsBodyVerb: (verb: Verbs) => boolean;
|
|
1552
1567
|
//#endregion
|
|
@@ -1594,7 +1609,7 @@ interface LoggerOptions {
|
|
|
1594
1609
|
declare function createLogger(level?: LogLevel, options?: LoggerOptions): Logger;
|
|
1595
1610
|
//#endregion
|
|
1596
1611
|
//#region src/utils/merge-deep.d.ts
|
|
1597
|
-
declare function mergeDeep<T
|
|
1612
|
+
declare function mergeDeep<T extends Record<string, any>, U$1 extends Record<string, any>>(source: T, target: U$1): T & U$1;
|
|
1598
1613
|
//#endregion
|
|
1599
1614
|
//#region src/utils/occurrence.d.ts
|
|
1600
1615
|
declare const count: (str: string | undefined, key: string) => number;
|
|
@@ -1754,5 +1769,5 @@ declare const generateTargetForTags: (builder: WriteSpecsBuilder, options: Norma
|
|
|
1754
1769
|
declare const getOrvalGeneratedTypes: () => string;
|
|
1755
1770
|
declare const getTypedResponse: () => string;
|
|
1756
1771
|
//#endregion
|
|
1757
|
-
export { AngularOptions, BODY_TYPE_NAME, BaseUrlFromConstant, BaseUrlFromSpec, ClientBuilder, ClientDependenciesBuilder, ClientExtraFilesBuilder, ClientFileBuilder, ClientFooterBuilder, ClientGeneratorsBuilder, ClientHeaderBuilder, ClientMockBuilder, ClientMockGeneratorBuilder, ClientMockGeneratorImplementation, ClientTitleBuilder, Config, ConfigExternal, ConfigFn, ContextSpecs, DeepNonNullable, EnumGeneration, ErrorWithTag, FetchOptions, FormDataArrayHandling, FormDataType, GenerateMockImports, GeneratorApiBuilder, GeneratorApiOperations, GeneratorApiResponse, GeneratorClient, GeneratorClientExtra, GeneratorClientFooter, GeneratorClientHeader, GeneratorClientImports, GeneratorClientTitle, GeneratorClients, GeneratorDependency, GeneratorImport, GeneratorMutator, GeneratorMutatorParsingInfo, GeneratorOperation, GeneratorOperations, GeneratorOptions, GeneratorSchema, GeneratorTarget, GeneratorTargetFull, GeneratorVerbOptions, GeneratorVerbsOptions, GetterBody, GetterParam, GetterParameters, GetterParams, GetterProp, GetterPropType, GetterProps, GetterQueryParam, GetterResponse, GlobalMockOptions, GlobalOptions, HonoOptions, Hook, HookCommand, HookFunction, HookOption, HooksOptions, ImportOpenApi, InputFiltersOption, InputOptions, InputTransformerFn, JsDocOptions, LogLevel, LogLevels, LogOptions, LogType, Logger, LoggerOptions, MockData, MockDataArray, MockDataArrayFn, MockDataObject, MockDataObjectFn, MockOptions, MockProperties, MockPropertiesObject, MockPropertiesObjectFn, Mutator, MutatorObject, NamingConvention, NormalizedConfig, NormalizedFetchOptions, NormalizedFormDataType, NormalizedHonoOptions, NormalizedHookCommand, NormalizedHookOptions, NormalizedInputOptions, NormalizedJsDocOptions, NormalizedMutator, NormalizedOperationOptions, NormalizedOptions, NormalizedOutputOptions, NormalizedOverrideOutput, NormalizedParamsSerializerOptions, NormalizedQueryOptions, NormalizedZodOptions, OperationOptions, Options, OptionsExport, OptionsFn, OutputClient, OutputClientFunc, OutputDocsOptions, OutputHttpClient, OutputMockType, OutputMode, OutputOptions, OverrideInput, OverrideMockOptions, OverrideOutput, OverrideOutputContentType, PackageJson, ParamsSerializerOptions, PropertySortOrder, QueryOptions, RefComponentSuffix, RefInfo, ResReqTypesValue, ResolverValue, ScalarValue, SchemaType, SchemaWithConst, SwaggerParserOptions, SwrOptions, TEMPLATE_TAG_REGEX, TsConfigTarget, Tsconfig, URL_REGEX, VERBS_WITH_BODY, Verbs, WriteModeProps, WriteSpecsBuilder, ZodCoerceType, ZodDateTimeOptions, ZodOptions, ZodTimeOptions, _filteredVerbs, addDependency, asyncReduce, camel, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, dynamicImport, escape, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbsOptions, getArray, getBody, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getExtension, getFileInfo, getFullRoute, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getRoute, getRouteAsArray, getScalar, getTypedResponse, ibmOpenapiValidator, ibmOpenapiValidatorErrors, ibmOpenapiValidatorWarnings, isBoolean, isDirectory, isFunction, isModule, isNull, isNumber, isNumeric, isObject, isReference, isRootKey$1 as isRootKey, isSchema, isString, isSyntheticDefaultImportsAllow, isUndefined, isUrl, isVerb, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, mergeDeep, mismatchArgsMessage, openApiConverter, pascal, removeFilesAndEmptyFolders, resolveDiscriminators, resolveExampleRefs, resolveObject, resolveRef, resolveValue, sanitize, snake, sortByPriority, startMessage, stringify, toObjectString, path_d_exports as upath, upper, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
1758
|
-
//# sourceMappingURL=index.d.
|
|
1772
|
+
export { AngularOptions, BODY_TYPE_NAME, BaseUrlFromConstant, BaseUrlFromSpec, ClientBuilder, ClientDependenciesBuilder, ClientExtraFilesBuilder, ClientFileBuilder, ClientFooterBuilder, ClientGeneratorsBuilder, ClientHeaderBuilder, ClientMockBuilder, ClientMockGeneratorBuilder, ClientMockGeneratorImplementation, ClientTitleBuilder, Config, ConfigExternal, ConfigFn, ContextSpecs, DeepNonNullable, EnumGeneration, ErrorWithTag, FetchOptions, FormDataArrayHandling, FormDataType, GenerateMockImports, GeneratorApiBuilder, GeneratorApiOperations, GeneratorApiResponse, GeneratorClient, GeneratorClientExtra, GeneratorClientFooter, GeneratorClientHeader, GeneratorClientImports, GeneratorClientTitle, GeneratorClients, GeneratorDependency, GeneratorImport, GeneratorMutator, GeneratorMutatorParsingInfo, GeneratorOperation, GeneratorOperations, GeneratorOptions, GeneratorSchema, GeneratorTarget, GeneratorTargetFull, GeneratorVerbOptions, GeneratorVerbsOptions, GetterBody, GetterParam, GetterParameters, GetterParams, GetterProp, GetterPropType, GetterProps, GetterQueryParam, GetterResponse, GlobalMockOptions, GlobalOptions, HonoOptions, Hook, HookCommand, HookFunction, HookOption, HooksOptions, ImportOpenApi, InputFiltersOption, InputOptions, InputTransformerFn, JsDocOptions, LogLevel, LogLevels, LogOptions, LogType, Logger, LoggerOptions, MockData, MockDataArray, MockDataArrayFn, MockDataObject, MockDataObjectFn, MockOptions, MockProperties, MockPropertiesObject, MockPropertiesObjectFn, Mutator, MutatorObject, NamingConvention, NormalizedConfig, NormalizedFetchOptions, NormalizedFormDataType, NormalizedHonoOptions, NormalizedHookCommand, NormalizedHookOptions, NormalizedInputOptions, NormalizedJsDocOptions, NormalizedMutator, NormalizedOperationOptions, NormalizedOptions, NormalizedOutputOptions, NormalizedOverrideOutput, NormalizedParamsSerializerOptions, NormalizedQueryOptions, NormalizedZodOptions, OperationOptions, Options, OptionsExport, OptionsFn, OutputClient, OutputClientFunc, OutputDocsOptions, OutputHttpClient, OutputMockType, OutputMode, OutputOptions, OverrideInput, OverrideMockOptions, OverrideOutput, OverrideOutputContentType, PackageJson, ParamsSerializerOptions, PropertySortOrder, QueryOptions, RefComponentSuffix, RefInfo, ResReqTypesValue, ResolverValue, ScalarValue, SchemaType, SchemaWithConst, SwaggerParserOptions, SwrOptions, TEMPLATE_TAG_REGEX, TsConfigTarget, Tsconfig, URL_REGEX, VERBS_WITH_BODY, Verbs, WriteModeProps, WriteSpecsBuilder, ZodCoerceType, ZodDateTimeOptions, ZodOptions, ZodTimeOptions, _filteredVerbs, addDependency, asyncReduce, camel, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, dynamicImport, escape, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbsOptions, getArray, getBody, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getExtension, getFileInfo, getFullRoute, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getPropertySafe, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getRoute, getRouteAsArray, getScalar, getTypedResponse, ibmOpenapiValidator, ibmOpenapiValidatorErrors, ibmOpenapiValidatorWarnings, isBoolean, isDirectory, isFunction, isModule, isNull, isNumber, isNumeric, isObject, isReference, isRootKey$1 as isRootKey, isSchema, isString, isSyntheticDefaultImportsAllow, isUndefined, isUrl, isVerb, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, mergeDeep, mismatchArgsMessage, openApiConverter, pascal, removeFilesAndEmptyFolders, resolveDiscriminators, resolveExampleRefs, resolveObject, resolveRef, resolveValue, sanitize, snake, sortByPriority, startMessage, stringify, toObjectString, path_d_exports as upath, upper, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
1773
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __export } from "./chunk-
|
|
2
|
-
import
|
|
1
|
+
import { t as __export } from "./chunk-jass6xSI.mjs";
|
|
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";
|
|
@@ -522,6 +519,28 @@ const getMockFileExtensionByTypeName = (mock) => {
|
|
|
522
519
|
}
|
|
523
520
|
};
|
|
524
521
|
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/utils/get-property-safe.ts
|
|
524
|
+
/**
|
|
525
|
+
* Type safe way to get arbitrary property from an object.
|
|
526
|
+
*
|
|
527
|
+
* @param obj - The object from which to retrieve the property.
|
|
528
|
+
* @param propertyName - The name of the property to retrieve.
|
|
529
|
+
* @returns Object with `hasProperty: true` and `value` of the property if it exists; otherwise `hasProperty: false` and undefined.
|
|
530
|
+
*
|
|
531
|
+
* @remarks Until TypeScript adds type-narrowing for Object.hasOwn we have to use this workaround
|
|
532
|
+
*/
|
|
533
|
+
function getPropertySafe(obj, propertyName) {
|
|
534
|
+
if (Object.hasOwn(obj, propertyName)) return {
|
|
535
|
+
hasProperty: true,
|
|
536
|
+
value: obj[propertyName]
|
|
537
|
+
};
|
|
538
|
+
return {
|
|
539
|
+
hasProperty: false,
|
|
540
|
+
value: void 0
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
525
544
|
//#endregion
|
|
526
545
|
//#region src/utils/is-body-verb.ts
|
|
527
546
|
const getIsBodyVerb = (verb) => VERBS_WITH_BODY.includes(verb);
|
|
@@ -1170,8 +1189,8 @@ const getResReqContentTypes = ({ mediaType, propName, context }) => {
|
|
|
1170
1189
|
context
|
|
1171
1190
|
});
|
|
1172
1191
|
};
|
|
1173
|
-
const getResReqTypes = (responsesOrRequests, name, context, defaultType = "unknown", uniqueKey =
|
|
1174
|
-
return
|
|
1192
|
+
const getResReqTypes = (responsesOrRequests, name, context, defaultType = "unknown", uniqueKey = (item) => item.value) => {
|
|
1193
|
+
return uniqueBy(responsesOrRequests.filter(([_, res]) => Boolean(res)).map(([key, res]) => {
|
|
1175
1194
|
if (isReference(res)) {
|
|
1176
1195
|
const { schema: bodySchema, imports: [{ name: name$1, specKey, schemaName }] } = resolveRef(res, context);
|
|
1177
1196
|
const [contentType, mediaType] = Object.entries(bodySchema.content ?? {})[0] ?? [];
|
|
@@ -1516,6 +1535,23 @@ const getKey = (key) => {
|
|
|
1516
1535
|
//#endregion
|
|
1517
1536
|
//#region src/getters/object.ts
|
|
1518
1537
|
/**
|
|
1538
|
+
* Extract enum values from propertyNames schema (OpenAPI 3.1)
|
|
1539
|
+
* Returns undefined if propertyNames doesn't have an enum
|
|
1540
|
+
*/
|
|
1541
|
+
const getPropertyNamesEnum = (item) => {
|
|
1542
|
+
const schema31 = item;
|
|
1543
|
+
if ("propertyNames" in schema31 && schema31.propertyNames && "enum" in schema31.propertyNames && Array.isArray(schema31.propertyNames.enum)) return schema31.propertyNames.enum.filter((val) => typeof val === "string");
|
|
1544
|
+
};
|
|
1545
|
+
/**
|
|
1546
|
+
* Generate index signature key type based on propertyNames enum
|
|
1547
|
+
* Returns union type string like "'foo' | 'bar'" or 'string' if no enum
|
|
1548
|
+
*/
|
|
1549
|
+
const getIndexSignatureKey = (item) => {
|
|
1550
|
+
const enumValues = getPropertyNamesEnum(item);
|
|
1551
|
+
if (enumValues && enumValues.length > 0) return enumValues.map((val) => `'${val}'`).join(" | ");
|
|
1552
|
+
return "string";
|
|
1553
|
+
};
|
|
1554
|
+
/**
|
|
1519
1555
|
* Return the output type from an object
|
|
1520
1556
|
*
|
|
1521
1557
|
* @param item item with type === "object"
|
|
@@ -1593,16 +1629,18 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1593
1629
|
acc.value += `\n ${doc ? `${doc} ` : ""}${isReadOnly && !context.output.override.suppressReadonlyModifier ? "readonly " : ""}${getKey(key)}${isRequired ? "" : "?"}: ${propValue};`;
|
|
1594
1630
|
acc.schemas.push(...resolvedValue.schemas);
|
|
1595
1631
|
if (arr.length - 1 === index) {
|
|
1596
|
-
if (item.additionalProperties)
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1632
|
+
if (item.additionalProperties) {
|
|
1633
|
+
const keyType$1 = getIndexSignatureKey(item);
|
|
1634
|
+
if (isBoolean(item.additionalProperties)) acc.value += `\n [key: ${keyType$1}]: unknown;\n }`;
|
|
1635
|
+
else {
|
|
1636
|
+
const resolvedValue$1 = resolveValue({
|
|
1637
|
+
schema: item.additionalProperties,
|
|
1638
|
+
name,
|
|
1639
|
+
context
|
|
1640
|
+
});
|
|
1641
|
+
acc.value += `\n [key: ${keyType$1}]: ${resolvedValue$1.value};\n}`;
|
|
1642
|
+
}
|
|
1643
|
+
} else acc.value += "\n}";
|
|
1606
1644
|
acc.value += nullable;
|
|
1607
1645
|
}
|
|
1608
1646
|
return acc;
|
|
@@ -1620,8 +1658,9 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1620
1658
|
});
|
|
1621
1659
|
}
|
|
1622
1660
|
if (item.additionalProperties) {
|
|
1661
|
+
const keyType$1 = getIndexSignatureKey(item);
|
|
1623
1662
|
if (isBoolean(item.additionalProperties)) return {
|
|
1624
|
-
value: `{ [key:
|
|
1663
|
+
value: `{ [key: ${keyType$1}]: unknown }` + nullable,
|
|
1625
1664
|
imports: [],
|
|
1626
1665
|
schemas: [],
|
|
1627
1666
|
isEnum: false,
|
|
@@ -1635,7 +1674,7 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1635
1674
|
context
|
|
1636
1675
|
});
|
|
1637
1676
|
return {
|
|
1638
|
-
value: `{[key:
|
|
1677
|
+
value: `{[key: ${keyType$1}]: ${resolvedValue.value}}` + nullable,
|
|
1639
1678
|
imports: resolvedValue.imports ?? [],
|
|
1640
1679
|
schemas: resolvedValue.schemas ?? [],
|
|
1641
1680
|
isEnum: false,
|
|
@@ -1654,8 +1693,9 @@ const getObject = ({ item, name, context, nullable }) => {
|
|
|
1654
1693
|
isRef: false,
|
|
1655
1694
|
hasReadonlyProps: item.readOnly || false
|
|
1656
1695
|
};
|
|
1696
|
+
const keyType = item.type === "object" ? getIndexSignatureKey(item) : "string";
|
|
1657
1697
|
return {
|
|
1658
|
-
value: (item.type === "object" ?
|
|
1698
|
+
value: (item.type === "object" ? `{ [key: ${keyType}]: unknown }` : "unknown") + nullable,
|
|
1659
1699
|
imports: [],
|
|
1660
1700
|
schemas: [],
|
|
1661
1701
|
isEnum: false,
|
|
@@ -1717,7 +1757,7 @@ const getScalar = ({ item, name, context }) => {
|
|
|
1717
1757
|
};
|
|
1718
1758
|
}
|
|
1719
1759
|
case "array": {
|
|
1720
|
-
const { value
|
|
1760
|
+
const { value, ...rest } = getArray({
|
|
1721
1761
|
schema: item,
|
|
1722
1762
|
name,
|
|
1723
1763
|
context
|
|
@@ -1782,7 +1822,7 @@ const getScalar = ({ item, name, context }) => {
|
|
|
1782
1822
|
example: item.example,
|
|
1783
1823
|
examples: resolveExampleRefs(item.examples, context)
|
|
1784
1824
|
};
|
|
1785
|
-
const { value
|
|
1825
|
+
const { value, ...rest } = getObject({
|
|
1786
1826
|
item,
|
|
1787
1827
|
name,
|
|
1788
1828
|
context,
|
|
@@ -1820,7 +1860,7 @@ const combineValues = ({ resolvedData, resolvedValue, separator: separator$1, co
|
|
|
1820
1860
|
values.push(resolvedData.values[i]);
|
|
1821
1861
|
continue;
|
|
1822
1862
|
}
|
|
1823
|
-
const missingProperties =
|
|
1863
|
+
const missingProperties = unique(resolvedData.allProperties.filter((p) => !Object.keys(subSchema.properties).includes(p)));
|
|
1824
1864
|
values.push(`${resolvedData.values[i]}${missingProperties.length > 0 ? ` & {${missingProperties.map((p) => `${p}?: never`).join("; ")}}` : ""}`);
|
|
1825
1865
|
}
|
|
1826
1866
|
}
|
|
@@ -1874,7 +1914,7 @@ const combineSchemas = ({ name, schema, separator: separator$1, context, nullabl
|
|
|
1874
1914
|
examples: resolveExampleRefs(schema.examples, context),
|
|
1875
1915
|
requiredProperties: separator$1 === "allOf" ? schema.required ?? [] : []
|
|
1876
1916
|
});
|
|
1877
|
-
if (resolvedData.isEnum.every(Boolean) && name && items.length > 1) {
|
|
1917
|
+
if (resolvedData.isEnum.every(Boolean) && name && items.length > 1 && separator$1 !== "oneOf") {
|
|
1878
1918
|
const newEnum = `// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport const ${pascal(name)} = ${getCombineEnumValue(resolvedData)}`;
|
|
1879
1919
|
return {
|
|
1880
1920
|
value: `typeof ${pascal(name)}[keyof typeof ${pascal(name)}] ${nullable}`,
|
|
@@ -2298,7 +2338,7 @@ const getRouteAsArray = (route) => route.replaceAll(TEMPLATE_TAG_IN_PATH_REGEX,
|
|
|
2298
2338
|
//#endregion
|
|
2299
2339
|
//#region src/generators/component-definition.ts
|
|
2300
2340
|
const generateComponentDefinition = (responses = {}, context, suffix) => {
|
|
2301
|
-
if (
|
|
2341
|
+
if (isEmptyish(responses)) return [];
|
|
2302
2342
|
return Object.entries(responses).reduce((acc, [name, response]) => {
|
|
2303
2343
|
const allResponseTypes = getResReqTypes([[suffix, response]], name, context, "void");
|
|
2304
2344
|
const imports = allResponseTypes.flatMap(({ imports: imports$1 }) => imports$1);
|
|
@@ -2326,7 +2366,7 @@ const generateComponentDefinition = (responses = {}, context, suffix) => {
|
|
|
2326
2366
|
//#region src/generators/imports.ts
|
|
2327
2367
|
const generateImports = ({ imports = [], target, isRootKey: isRootKey$1, specsName, specKey: currentSpecKey, namingConvention = NamingConvention.CAMEL_CASE }) => {
|
|
2328
2368
|
if (imports.length === 0) return "";
|
|
2329
|
-
return
|
|
2369
|
+
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
2370
|
const isSameSpecKey = currentSpecKey === specKey;
|
|
2331
2371
|
const fileName = conventionName(name, namingConvention);
|
|
2332
2372
|
if (specKey && !isSameSpecKey) {
|
|
@@ -2338,7 +2378,7 @@ const generateImports = ({ imports = [], target, isRootKey: isRootKey$1, specsNa
|
|
|
2338
2378
|
}).join("\n");
|
|
2339
2379
|
};
|
|
2340
2380
|
const generateMutatorImports = ({ mutators, implementation, oneMore }) => {
|
|
2341
|
-
return
|
|
2381
|
+
return uniqueWith(mutators, (a, b) => a.name === b.name && a.default === b.default).reduce((acc, mutator) => {
|
|
2342
2382
|
const path$2 = `${oneMore ? "../" : ""}${mutator.path}`;
|
|
2343
2383
|
const importDefault = mutator.default ? mutator.name : `{ ${mutator.name} }`;
|
|
2344
2384
|
acc += `import ${importDefault} from '${path$2}';`;
|
|
@@ -2361,7 +2401,7 @@ const generateMutatorImports = ({ mutators, implementation, oneMore }) => {
|
|
|
2361
2401
|
const generateDependency = ({ deps, isAllowSyntheticDefaultImports, dependency, specsName, key, onlyTypes }) => {
|
|
2362
2402
|
const defaultDep = deps.find((e) => e.default && (isAllowSyntheticDefaultImports || !e.syntheticDefaultImport));
|
|
2363
2403
|
const namespaceImportDep = defaultDep ? void 0 : deps.find((e) => !!e.namespaceImport || !isAllowSyntheticDefaultImports && e.syntheticDefaultImport);
|
|
2364
|
-
const depsString =
|
|
2404
|
+
const depsString = unique(deps.filter((e) => !e.default && !e.syntheticDefaultImport && !e.namespaceImport).map(({ name, alias }) => alias ? `${name} as ${alias}` : name)).toSorted().join(",\n ");
|
|
2365
2405
|
let importString = "";
|
|
2366
2406
|
const namespaceImportString = namespaceImportDep ? `import * as ${namespaceImportDep.name} from '${dependency}';` : "";
|
|
2367
2407
|
if (namespaceImportString) {
|
|
@@ -2773,7 +2813,7 @@ const generateInterface = ({ name, schema, context, suffix }) => {
|
|
|
2773
2813
|
* @param schemas
|
|
2774
2814
|
*/
|
|
2775
2815
|
const generateSchemasDefinition = (schemas = {}, context, suffix, filters) => {
|
|
2776
|
-
if (
|
|
2816
|
+
if (isEmptyish(schemas)) return [];
|
|
2777
2817
|
const transformedSchemas = resolveDiscriminators(schemas, context);
|
|
2778
2818
|
let generateSchemas = Object.entries(transformedSchemas);
|
|
2779
2819
|
if (filters?.schemas) {
|
|
@@ -2784,7 +2824,7 @@ const generateSchemasDefinition = (schemas = {}, context, suffix, filters) => {
|
|
|
2784
2824
|
return mode === "include" ? isMatch : !isMatch;
|
|
2785
2825
|
});
|
|
2786
2826
|
}
|
|
2787
|
-
|
|
2827
|
+
const models = generateSchemas.reduce((acc, [name, schema]) => {
|
|
2788
2828
|
const schemaName = sanitize(`${pascal(name)}${suffix}`, {
|
|
2789
2829
|
underscore: "_",
|
|
2790
2830
|
whitespace: "_",
|
|
@@ -2840,6 +2880,16 @@ const generateSchemasDefinition = (schemas = {}, context, suffix, filters) => {
|
|
|
2840
2880
|
return acc;
|
|
2841
2881
|
}
|
|
2842
2882
|
}, []);
|
|
2883
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
2884
|
+
const deduplicatedModels = [];
|
|
2885
|
+
for (const schema of models) {
|
|
2886
|
+
const normalizedName = conventionName(schema.name, context.output.namingConvention);
|
|
2887
|
+
if (!seenNames.has(normalizedName)) {
|
|
2888
|
+
seenNames.add(normalizedName);
|
|
2889
|
+
deduplicatedModels.push(schema);
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
return deduplicatedModels;
|
|
2843
2893
|
};
|
|
2844
2894
|
function shouldCreateInterface(schema) {
|
|
2845
2895
|
return (!schema.type || schema.type === "object") && !schema.allOf && !schema.oneOf && !schema.anyOf && !isReference(schema) && !schema.nullable && !schema.enum;
|
|
@@ -3039,20 +3089,18 @@ const writeSchemas = async ({ schemaPath, schemas, target, namingConvention, fil
|
|
|
3039
3089
|
if (indexFiles) {
|
|
3040
3090
|
const schemaFilePath = join(schemaPath, `/index${fileExtension}`);
|
|
3041
3091
|
await fs$1.ensureFile(schemaFilePath);
|
|
3042
|
-
const
|
|
3092
|
+
const ext = fileExtension.endsWith(".ts") ? fileExtension.slice(0, -3) : fileExtension;
|
|
3093
|
+
const conventionNamesSet = /* @__PURE__ */ new Set();
|
|
3043
3094
|
const duplicateNamesMap = /* @__PURE__ */ new Map();
|
|
3044
|
-
for (const schema of schemas)
|
|
3045
|
-
|
|
3046
|
-
|
|
3095
|
+
for (const schema of schemas) {
|
|
3096
|
+
const conventionNameValue = conventionName(schema.name, namingConvention);
|
|
3097
|
+
if (conventionNamesSet.has(conventionNameValue)) duplicateNamesMap.set(conventionNameValue, (duplicateNamesMap.get(conventionNameValue) ?? 0) + 1);
|
|
3098
|
+
else conventionNamesSet.add(conventionNameValue);
|
|
3099
|
+
}
|
|
3100
|
+
if (duplicateNamesMap.size > 0) throw new Error("Duplicate schema names detected (after naming convention):\n" + [...duplicateNamesMap].map((duplicate) => ` ${duplicate[1] + 1}x ${duplicate[0]}`).join("\n"));
|
|
3047
3101
|
try {
|
|
3048
|
-
const
|
|
3049
|
-
|
|
3050
|
-
const importStatements = schemas.filter((schema) => {
|
|
3051
|
-
const name = conventionName(schema.name, namingConvention);
|
|
3052
|
-
return !stringData.includes(`export * from './${name}${ext}'`) && !stringData.includes(`export * from "./${name}${ext}"`);
|
|
3053
|
-
}).map((schema) => `export * from './${conventionName(schema.name, namingConvention)}${ext}';`);
|
|
3054
|
-
const fileContent = `${header}\n${[...stringData.match(/export \* from(.*)('|")/g)?.map((s) => s + ";") ?? [], ...importStatements].sort().join("\n")}`;
|
|
3055
|
-
await fs$1.writeFile(schemaFilePath, fileContent);
|
|
3102
|
+
const fileContent = `${header}\n${[...conventionNamesSet].map((schemaName) => `export * from './${schemaName}${ext}';`).toSorted((a, b) => a.localeCompare(b)).join("\n")}`;
|
|
3103
|
+
await fs$1.writeFile(schemaFilePath, fileContent, { encoding: "utf8" });
|
|
3056
3104
|
} catch (error) {
|
|
3057
3105
|
throw new Error(`Oups... 🍻. An Error occurred while writing schema index file ${schemaFilePath} => ${error}`);
|
|
3058
3106
|
}
|
|
@@ -3062,7 +3110,7 @@ const writeSchemas = async ({ schemaPath, schemas, target, namingConvention, fil
|
|
|
3062
3110
|
//#endregion
|
|
3063
3111
|
//#region src/writers/generate-imports-for-builder.ts
|
|
3064
3112
|
const generateImportsForBuilder = (output, imports, relativeSchemasPath) => {
|
|
3065
|
-
return output.schemas && !output.indexFiles ?
|
|
3113
|
+
return output.schemas && !output.indexFiles ? uniqueBy(imports, (x) => x.name).map((i) => {
|
|
3066
3114
|
const name = conventionName(i.name, output.namingConvention);
|
|
3067
3115
|
return {
|
|
3068
3116
|
exports: [i],
|
|
@@ -3616,5 +3664,5 @@ const writeTagsMode = async ({ builder, output, specsName, header, needSchema })
|
|
|
3616
3664
|
};
|
|
3617
3665
|
|
|
3618
3666
|
//#endregion
|
|
3619
|
-
export { BODY_TYPE_NAME, EnumGeneration, ErrorWithTag, FormDataArrayHandling, GetterPropType, LogLevels, NamingConvention, OutputClient, OutputHttpClient, OutputMockType, OutputMode, PropertySortOrder, RefComponentSuffix, SchemaType, TEMPLATE_TAG_REGEX, URL_REGEX, VERBS_WITH_BODY, Verbs, _filteredVerbs, addDependency, asyncReduce, camel, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, dynamicImport, escape, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbsOptions, getArray, getBody, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getExtension, getFileInfo, getFullRoute, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getRoute, getRouteAsArray, getScalar, getTypedResponse, ibmOpenapiValidator, ibmOpenapiValidatorErrors, ibmOpenapiValidatorWarnings, isBoolean, isDirectory, isFunction, isModule, isNull, isNumber, isNumeric, isObject, isReference, isRootKey, isSchema, isString, isSyntheticDefaultImportsAllow, isUndefined, isUrl, isVerb, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, mergeDeep, mismatchArgsMessage, openApiConverter, pascal, removeFilesAndEmptyFolders, resolveDiscriminators, resolveExampleRefs, resolveObject, resolveRef, resolveValue, sanitize, snake, sortByPriority, startMessage, stringify, toObjectString, path_exports as upath, upper, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
3620
|
-
//# sourceMappingURL=index.
|
|
3667
|
+
export { BODY_TYPE_NAME, EnumGeneration, ErrorWithTag, FormDataArrayHandling, GetterPropType, LogLevels, NamingConvention, OutputClient, OutputHttpClient, OutputMockType, OutputMode, PropertySortOrder, RefComponentSuffix, SchemaType, TEMPLATE_TAG_REGEX, URL_REGEX, VERBS_WITH_BODY, Verbs, _filteredVerbs, addDependency, asyncReduce, camel, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, dynamicImport, escape, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbsOptions, getArray, getBody, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getExtension, getFileInfo, getFullRoute, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getPropertySafe, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getRoute, getRouteAsArray, getScalar, getTypedResponse, ibmOpenapiValidator, ibmOpenapiValidatorErrors, ibmOpenapiValidatorWarnings, isBoolean, isDirectory, isFunction, isModule, isNull, isNumber, isNumeric, isObject, isReference, isRootKey, isSchema, isString, isSyntheticDefaultImportsAllow, isUndefined, isUrl, isVerb, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, mergeDeep, mismatchArgsMessage, openApiConverter, pascal, removeFilesAndEmptyFolders, resolveDiscriminators, resolveExampleRefs, resolveObject, resolveRef, resolveValue, sanitize, snake, sortByPriority, startMessage, stringify, toObjectString, path_exports as upath, upper, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
3668
|
+
//# sourceMappingURL=index.mjs.map
|