@orval/core 8.14.0 → 8.15.0
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.mts +92 -3
- package/dist/index.mjs +155 -102
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -393,6 +393,7 @@ interface FakerMockOptions extends CommonMockOptions {
|
|
|
393
393
|
type: typeof OutputMockType.FAKER;
|
|
394
394
|
schemas?: boolean;
|
|
395
395
|
operationResponses?: boolean;
|
|
396
|
+
arrayItems?: boolean;
|
|
396
397
|
}
|
|
397
398
|
type GlobalMockOptions = MswMockOptions | FakerMockOptions;
|
|
398
399
|
interface OutputMocksConfig {
|
|
@@ -560,8 +561,21 @@ interface OverrideOutputContentType {
|
|
|
560
561
|
include?: string[];
|
|
561
562
|
exclude?: string[];
|
|
562
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Strategy controlling how an existing hono handler file is treated on
|
|
566
|
+
* regeneration.
|
|
567
|
+
*
|
|
568
|
+
* - `smart` (default): non-destructively reconcile orval-owned imports and
|
|
569
|
+
* `zValidator` arguments and append handlers for new operations, preserving
|
|
570
|
+
* all user-authored imports, middleware, bodies, and top-level code.
|
|
571
|
+
* - `skip`: leave an existing handler file byte-for-byte unchanged.
|
|
572
|
+
* - `full`: rebuild the preamble and validator chain from the spec, splicing
|
|
573
|
+
* back only the handler body. Drops custom imports/middleware/helpers.
|
|
574
|
+
*/
|
|
575
|
+
type HonoHandlerStrategy = 'smart' | 'skip' | 'full';
|
|
563
576
|
interface NormalizedHonoOptions {
|
|
564
577
|
handlers?: string;
|
|
578
|
+
handlerGenerationStrategy: HonoHandlerStrategy;
|
|
565
579
|
compositeRoute: string;
|
|
566
580
|
validator: boolean | 'hono';
|
|
567
581
|
validatorOutputPath: string;
|
|
@@ -706,6 +720,7 @@ interface MutationInvalidatesRule {
|
|
|
706
720
|
type MutationInvalidatesConfig = MutationInvalidatesRule[];
|
|
707
721
|
interface HonoOptions {
|
|
708
722
|
handlers?: string;
|
|
723
|
+
handlerGenerationStrategy?: HonoHandlerStrategy;
|
|
709
724
|
compositeRoute?: string;
|
|
710
725
|
validator?: boolean | 'hono';
|
|
711
726
|
validatorOutputPath?: string;
|
|
@@ -745,6 +760,7 @@ interface NormalizedQueryOptions {
|
|
|
745
760
|
shouldExportHttpClient?: boolean;
|
|
746
761
|
shouldExportQueryKey?: boolean;
|
|
747
762
|
shouldFilterQueryKey?: boolean;
|
|
763
|
+
queryKeyFilter?: string;
|
|
748
764
|
shouldSplitQueryKey?: boolean;
|
|
749
765
|
useOperationIdAsQueryKey?: boolean;
|
|
750
766
|
signal?: boolean;
|
|
@@ -771,6 +787,7 @@ interface QueryOptions {
|
|
|
771
787
|
shouldExportHttpClient?: boolean;
|
|
772
788
|
shouldExportQueryKey?: boolean;
|
|
773
789
|
shouldFilterQueryKey?: boolean;
|
|
790
|
+
queryKeyFilter?: string;
|
|
774
791
|
shouldSplitQueryKey?: boolean;
|
|
775
792
|
useOperationIdAsQueryKey?: boolean;
|
|
776
793
|
signal?: boolean;
|
|
@@ -919,6 +936,13 @@ interface ContextSpec {
|
|
|
919
936
|
* entries or generic parameter placeholders. Populated by `buildDynamicScope`.
|
|
920
937
|
*/
|
|
921
938
|
dynamicScope?: Partial<Record<string, DynamicScopeEntry>>;
|
|
939
|
+
/**
|
|
940
|
+
* Tracks array-item mock factory names already emitted per output file scope.
|
|
941
|
+
* Populated by `@orval/mock` when `arrayItems: true` so shared `$ref` item
|
|
942
|
+
* factories are not re-declared within the same file (single/split) or tag
|
|
943
|
+
* bucket (tags/tags-split).
|
|
944
|
+
*/
|
|
945
|
+
arrayItemMockFactories?: Map<string, Set<string>>;
|
|
922
946
|
}
|
|
923
947
|
/**
|
|
924
948
|
* Maps a `$dynamicAnchor` name to its resolution target.
|
|
@@ -2168,6 +2192,7 @@ declare function resolveDynamicRef(anchorName: string, context: ContextSpec, imp
|
|
|
2168
2192
|
schema: OpenApiSchemaObject;
|
|
2169
2193
|
imports: GeneratorImport[];
|
|
2170
2194
|
resolvedTypeName: string;
|
|
2195
|
+
schemaName: string | undefined;
|
|
2171
2196
|
};
|
|
2172
2197
|
/** Recursively resolves `$ref` entries in an examples array or record. */
|
|
2173
2198
|
declare function resolveExampleRefs(examples: Examples, context: ContextSpec): ResolvedExample[] | Record<string, ResolvedExample> | undefined;
|
|
@@ -2204,9 +2229,12 @@ declare function resolveValue({
|
|
|
2204
2229
|
//#endregion
|
|
2205
2230
|
//#region src/utils/assertion.d.ts
|
|
2206
2231
|
/**
|
|
2207
|
-
*
|
|
2232
|
+
* Type guard for an OpenAPI {@link OpenApiReferenceObject}.
|
|
2208
2233
|
*
|
|
2209
|
-
*
|
|
2234
|
+
* Returns `true` when `obj` has a `$ref` property, indicating a static
|
|
2235
|
+
* JSON Pointer reference rather than an inline schema.
|
|
2236
|
+
*
|
|
2237
|
+
* @param obj - Value to test.
|
|
2210
2238
|
*/
|
|
2211
2239
|
declare function isReference(obj: object): obj is OpenApiReferenceObject;
|
|
2212
2240
|
/**
|
|
@@ -2225,24 +2253,85 @@ interface OpenApiDynamicReferenceObject {
|
|
|
2225
2253
|
* Returns `true` when `obj` has a `$dynamicRef` string property,
|
|
2226
2254
|
* indicating it is an OpenAPI 3.1 dynamic reference rather than a
|
|
2227
2255
|
* static `$ref`.
|
|
2256
|
+
*
|
|
2257
|
+
* @param obj - Value to test.
|
|
2258
|
+
*
|
|
2259
|
+
* @see https://json-schema.org/draft/2020-12/json-schema-core#section-8.2.4
|
|
2228
2260
|
*/
|
|
2229
2261
|
declare function isDynamicReference(obj: object): obj is OpenApiDynamicReferenceObject;
|
|
2262
|
+
/**
|
|
2263
|
+
* Returns `true` when `pathValue` has no file extension and is treated as a
|
|
2264
|
+
* directory path.
|
|
2265
|
+
*
|
|
2266
|
+
* @param pathValue - Path string to inspect.
|
|
2267
|
+
*/
|
|
2230
2268
|
declare function isDirectory(pathValue: string): boolean;
|
|
2269
|
+
/**
|
|
2270
|
+
* Type guard for plain objects created with `{}` or `new Object()`.
|
|
2271
|
+
*
|
|
2272
|
+
* Excludes `null`, arrays, dates, and other non-plain object values.
|
|
2273
|
+
*
|
|
2274
|
+
* @param x - Value to test.
|
|
2275
|
+
*/
|
|
2231
2276
|
declare function isObject(x: unknown): x is Record<string, unknown>;
|
|
2277
|
+
/**
|
|
2278
|
+
* Type guard for string primitives and `String` wrapper objects.
|
|
2279
|
+
*
|
|
2280
|
+
* @param val - Value to test.
|
|
2281
|
+
*/
|
|
2232
2282
|
declare function isStringLike(val: unknown): val is string;
|
|
2283
|
+
/**
|
|
2284
|
+
* Type guard for ES module namespace objects.
|
|
2285
|
+
*
|
|
2286
|
+
* @param x - Value to test.
|
|
2287
|
+
*/
|
|
2233
2288
|
declare function isModule(x: unknown): x is Record<string, unknown>;
|
|
2289
|
+
/**
|
|
2290
|
+
* Type guard for integer numbers and numeric strings.
|
|
2291
|
+
*
|
|
2292
|
+
* Accepts finite integers (`42`) and strings that match `/^-?\d+$/`
|
|
2293
|
+
* (`"-1"`, `"0"`). Rejects floats, empty strings, and non-numeric values.
|
|
2294
|
+
*
|
|
2295
|
+
* @param x - Value to test.
|
|
2296
|
+
*/
|
|
2234
2297
|
declare function isNumeric(x: unknown): x is number;
|
|
2298
|
+
/**
|
|
2299
|
+
* Type guard for an inline OpenAPI {@link OpenApiSchemaObject}.
|
|
2300
|
+
*
|
|
2301
|
+
* Returns `true` when `x` looks like a schema definition: it has a known
|
|
2302
|
+
* `type`, composition keywords (`allOf`, `anyOf`, `oneOf`), or `properties`.
|
|
2303
|
+
* Does not match reference objects; use {@link isReference} for those.
|
|
2304
|
+
*
|
|
2305
|
+
* @param x - Value to test.
|
|
2306
|
+
*/
|
|
2235
2307
|
declare function isSchema(x: unknown): x is OpenApiSchemaObject;
|
|
2308
|
+
/**
|
|
2309
|
+
* Type guard for HTTP methods defined in {@link Verbs}.
|
|
2310
|
+
*
|
|
2311
|
+
* @param verb - Method name to test (for example, `"get"`, `"post"`).
|
|
2312
|
+
*/
|
|
2236
2313
|
declare function isVerb(verb: string): verb is Verbs;
|
|
2314
|
+
/**
|
|
2315
|
+
* Returns `true` when `str` is a valid absolute URL with an `http:` or
|
|
2316
|
+
* `https:` protocol.
|
|
2317
|
+
*
|
|
2318
|
+
* Empty or whitespace-only strings are rejected.
|
|
2319
|
+
*
|
|
2320
|
+
* @param str - URL string to validate.
|
|
2321
|
+
*/
|
|
2237
2322
|
declare function isUrl(str: string): boolean;
|
|
2238
2323
|
/**
|
|
2239
2324
|
* Type guard for the MSW mock generator. Use to narrow a
|
|
2240
2325
|
* `GlobalMockOptions | ClientMockBuilder` value to `MswMockOptions`.
|
|
2326
|
+
*
|
|
2327
|
+
* @param mock - Mock configuration or builder to test.
|
|
2241
2328
|
*/
|
|
2242
2329
|
declare function isMswMock(mock: GlobalMockOptions | ClientMockBuilder): mock is MswMockOptions;
|
|
2243
2330
|
/**
|
|
2244
2331
|
* Type guard for the Faker mock generator. Use to narrow a
|
|
2245
2332
|
* `GlobalMockOptions | ClientMockBuilder` value to `FakerMockOptions`.
|
|
2333
|
+
*
|
|
2334
|
+
* @param mock - Mock configuration or builder to test.
|
|
2246
2335
|
*/
|
|
2247
2336
|
declare function isFakerMock(mock: GlobalMockOptions | ClientMockBuilder): mock is FakerMockOptions;
|
|
2248
2337
|
//#endregion
|
|
@@ -2724,5 +2813,5 @@ declare function generateTargetForTags(builder: WriteSpecBuilder, options: Norma
|
|
|
2724
2813
|
declare function getOrvalGeneratedTypes(): string;
|
|
2725
2814
|
declare function getTypedResponse(): string;
|
|
2726
2815
|
//#endregion
|
|
2727
|
-
export { AngularHttpResourceOptions, AngularOptions, BODY_TYPE_NAME, BaseUrlFromConstant, BaseUrlFromSpec, BaseUrlRuntime, BoundAliasInfo, ClientBuilder, ClientDependenciesBuilder, ClientExtraFilesBuilder, ClientFileBuilder, ClientFooterBuilder, ClientGeneratorsBuilder, ClientHeaderBuilder, ClientMockBuilder, ClientMockGeneratorBuilder, ClientMockGeneratorImplementation, ClientTitleBuilder, CommonMockOptions, Config, ConfigExternal, ConfigFn, ContentTypeFilter, ContextSpec, DeepNonNullable, DefaultTag, DynamicScopeEntry, EffectOptions, EnumGeneration, ErrorWithTag, FactoryMethodsMode, FactoryMethodsOptions, FakerMockOptions, FetchOptions, FormDataArrayHandling, FormDataContext, FormDataType, GenerateMockImports, GenerateVerbOptionsParams, GenerateVerbsOptionsParams, GeneratorApiBuilder, GeneratorApiOperations, GeneratorApiResponse, GeneratorClient, GeneratorClientExtra, GeneratorClientFooter, GeneratorClientHeader, GeneratorClientImports, GeneratorClientTitle, GeneratorClients, GeneratorDependency, GeneratorImport, GeneratorMockOutput, GeneratorMockOutputFull, 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, InputFiltersOptions, InputOptions, InputTransformerFn, InvalidateTarget, InvalidateTargetParam, JsDocOptions, LogLevel, LogLevels, LogOptions, LogType, Logger, LoggerOptions, McpOptions, McpServerOptions, MockData, MockDataArray, MockDataArrayFn, MockDataObject, MockDataObjectFn, MockOptions, MockProperties, MockPropertiesObject, MockPropertiesObjectFn, MswMockOptions, MutationInvalidatesConfig, MutationInvalidatesRule, Mutator, MutatorObject, NAMED_COMPONENT_SECTIONS, NamingConvention, NormalizedAngularOptions, NormalizedConfig, NormalizedEffectOptions, NormalizedFactoryMethodsOptions, NormalizedFetchOptions, NormalizedFormDataType, NormalizedHonoOptions, NormalizedHookCommand, NormalizedHookOptions, NormalizedInputOptions, NormalizedJsDocOptions, NormalizedMcpOptions, NormalizedMcpServerOptions, NormalizedMocksConfig, NormalizedMutator, NormalizedOperationOptions, NormalizedOptions, NormalizedOutputOptions, NormalizedOverrideOutput, NormalizedParamsSerializerOptions, NormalizedQueryOptions, NormalizedSchemaOptions, NormalizedZodOptions, OpenApiComponentsObject, OpenApiDocument, OpenApiDynamicReferenceObject, OpenApiEncodingObject, OpenApiExampleObject, OpenApiInfoObject, OpenApiMediaTypeObject, OpenApiOperationObject, OpenApiParameterObject, OpenApiPathItemObject, OpenApiPathsObject, OpenApiReferenceObject, OpenApiRequestBodyObject, OpenApiResponseObject, OpenApiResponsesObject, OpenApiSchemaObject, OpenApiSchemaObjectType, OpenApiSchemasObject, OpenApiServerObject, OperationOptions, Options, OptionsExport, OptionsFn, OutputClient, OutputClientFunc, OutputDocsOptions, OutputHttpClient, OutputMockType, OutputMocksConfig, OutputMocksOption, OutputMode, OutputOptions, OverrideInput, OverrideMockOptions, OverrideOutput, OverrideOutputContentType, PackageJson, ParamsSerializerOptions, PreferredContentType, PropertySortOrder, QueryOptions, ReadonlyRequestBodiesMode, RefComponentSuffix, RefInfo, ResReqTypesValue, ResolverValue, ResponseTypeCategory, ScalarValue, SchemaGenerationType, SchemaOptions, SchemaType, SupportedFormatter, SwrOptions, TEMPLATE_TAG_REGEX, TsConfigModule, TsConfigModuleResolution, TsConfigTarget, Tsconfig, URL_REGEX, VERBS_WITH_BODY, Verbs, WriteModeProps, WriteSpecBuilder, ZodCoerceType, ZodDateTimeOptions, ZodOptions, ZodTimeOptions, addDependency, asyncReduce, buildAngularParamsFilterExpression, buildDynamicScope, camel, collectReferencedComponents, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, createTypeAliasIfNeeded, dedupeUnionType, dynamicAnchorToParamName, dynamicAnchorsToUniqueParamNames, dynamicImport, escape, escapeRegExp, extractBoundAliasInfo, filterByContentType, filteredVerbs, fixCrossDirectoryImports, fixRegularSchemaImports, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFactory, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbOptions, generateVerbsOptions, getAngularFilteredParamsCallExpression, getAngularFilteredParamsExpression, getAngularFilteredParamsHelperBody, getArray, getBaseUrlRuntimeImports, getBodiesByContentType, getBody, getCombinedEnumValue, getDefaultContentType, getDynamicAnchorName, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getEnumUnionFromSchema, getExtension, getFileInfo, getFormDataFieldFileType, getFullRoute, getImportExtension, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getPropertySafe, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getResponseTypeCategory, getRoute, getRouteAsArray, getScalar, getSuccessResponseType, getTypedResponse, getWarningCount, isBinaryContentType, isBinaryScalarSchema, isBoolean, isComponentRef, isDirectory, isDynamicReference, isFakerMock, isFunction, isModule, isMswMock, isNullish, isNumber, isNumeric, isObject, isReference, isSchema, isString, isStringLike, isSyntheticDefaultImportsAllow, isUrl, isVerb, isVerbose, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, logVerbose, logWarning, makeRouteSafe, mergeDeep, mismatchArgsMessage, pascal, removeFilesAndEmptyFolders, resetWarnings, resolveDiscriminators, resolveDynamicRef, resolveExampleRefs, resolveInstalledVersion, resolveInstalledVersions, resolveObject, resolveRef, resolveValue, sanitize, setVerbose, snake, sortByPriority, splitSchemasByType, startMessage, stringify, toObjectString, path_d_exports as upath, upper, wrapRouteParameters, writeGeneratedFile, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
2816
|
+
export { AngularHttpResourceOptions, AngularOptions, BODY_TYPE_NAME, BaseUrlFromConstant, BaseUrlFromSpec, BaseUrlRuntime, BoundAliasInfo, ClientBuilder, ClientDependenciesBuilder, ClientExtraFilesBuilder, ClientFileBuilder, ClientFooterBuilder, ClientGeneratorsBuilder, ClientHeaderBuilder, ClientMockBuilder, ClientMockGeneratorBuilder, ClientMockGeneratorImplementation, ClientTitleBuilder, CommonMockOptions, Config, ConfigExternal, ConfigFn, ContentTypeFilter, ContextSpec, DeepNonNullable, DefaultTag, DynamicScopeEntry, EffectOptions, EnumGeneration, ErrorWithTag, FactoryMethodsMode, FactoryMethodsOptions, FakerMockOptions, FetchOptions, FormDataArrayHandling, FormDataContext, FormDataType, GenerateMockImports, GenerateVerbOptionsParams, GenerateVerbsOptionsParams, GeneratorApiBuilder, GeneratorApiOperations, GeneratorApiResponse, GeneratorClient, GeneratorClientExtra, GeneratorClientFooter, GeneratorClientHeader, GeneratorClientImports, GeneratorClientTitle, GeneratorClients, GeneratorDependency, GeneratorImport, GeneratorMockOutput, GeneratorMockOutputFull, GeneratorMutator, GeneratorMutatorParsingInfo, GeneratorOperation, GeneratorOperations, GeneratorOptions, GeneratorSchema, GeneratorTarget, GeneratorTargetFull, GeneratorVerbOptions, GeneratorVerbsOptions, GetterBody, GetterParam, GetterParameters, GetterParams, GetterProp, GetterPropType, GetterProps, GetterQueryParam, GetterResponse, GlobalMockOptions, GlobalOptions, HonoHandlerStrategy, HonoOptions, Hook, HookCommand, HookFunction, HookOption, HooksOptions, ImportOpenApi, InputFiltersOptions, InputOptions, InputTransformerFn, InvalidateTarget, InvalidateTargetParam, JsDocOptions, LogLevel, LogLevels, LogOptions, LogType, Logger, LoggerOptions, McpOptions, McpServerOptions, MockData, MockDataArray, MockDataArrayFn, MockDataObject, MockDataObjectFn, MockOptions, MockProperties, MockPropertiesObject, MockPropertiesObjectFn, MswMockOptions, MutationInvalidatesConfig, MutationInvalidatesRule, Mutator, MutatorObject, NAMED_COMPONENT_SECTIONS, NamingConvention, NormalizedAngularOptions, NormalizedConfig, NormalizedEffectOptions, NormalizedFactoryMethodsOptions, NormalizedFetchOptions, NormalizedFormDataType, NormalizedHonoOptions, NormalizedHookCommand, NormalizedHookOptions, NormalizedInputOptions, NormalizedJsDocOptions, NormalizedMcpOptions, NormalizedMcpServerOptions, NormalizedMocksConfig, NormalizedMutator, NormalizedOperationOptions, NormalizedOptions, NormalizedOutputOptions, NormalizedOverrideOutput, NormalizedParamsSerializerOptions, NormalizedQueryOptions, NormalizedSchemaOptions, NormalizedZodOptions, OpenApiComponentsObject, OpenApiDocument, OpenApiDynamicReferenceObject, OpenApiEncodingObject, OpenApiExampleObject, OpenApiInfoObject, OpenApiMediaTypeObject, OpenApiOperationObject, OpenApiParameterObject, OpenApiPathItemObject, OpenApiPathsObject, OpenApiReferenceObject, OpenApiRequestBodyObject, OpenApiResponseObject, OpenApiResponsesObject, OpenApiSchemaObject, OpenApiSchemaObjectType, OpenApiSchemasObject, OpenApiServerObject, OperationOptions, Options, OptionsExport, OptionsFn, OutputClient, OutputClientFunc, OutputDocsOptions, OutputHttpClient, OutputMockType, OutputMocksConfig, OutputMocksOption, OutputMode, OutputOptions, OverrideInput, OverrideMockOptions, OverrideOutput, OverrideOutputContentType, PackageJson, ParamsSerializerOptions, PreferredContentType, PropertySortOrder, QueryOptions, ReadonlyRequestBodiesMode, RefComponentSuffix, RefInfo, ResReqTypesValue, ResolverValue, ResponseTypeCategory, ScalarValue, SchemaGenerationType, SchemaOptions, SchemaType, SupportedFormatter, SwrOptions, TEMPLATE_TAG_REGEX, TsConfigModule, TsConfigModuleResolution, TsConfigTarget, Tsconfig, URL_REGEX, VERBS_WITH_BODY, Verbs, WriteModeProps, WriteSpecBuilder, ZodCoerceType, ZodDateTimeOptions, ZodOptions, ZodTimeOptions, addDependency, asyncReduce, buildAngularParamsFilterExpression, buildDynamicScope, camel, collectReferencedComponents, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, createTypeAliasIfNeeded, dedupeUnionType, dynamicAnchorToParamName, dynamicAnchorsToUniqueParamNames, dynamicImport, escape, escapeRegExp, extractBoundAliasInfo, filterByContentType, filteredVerbs, fixCrossDirectoryImports, fixRegularSchemaImports, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFactory, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbOptions, generateVerbsOptions, getAngularFilteredParamsCallExpression, getAngularFilteredParamsExpression, getAngularFilteredParamsHelperBody, getArray, getBaseUrlRuntimeImports, getBodiesByContentType, getBody, getCombinedEnumValue, getDefaultContentType, getDynamicAnchorName, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getEnumUnionFromSchema, getExtension, getFileInfo, getFormDataFieldFileType, getFullRoute, getImportExtension, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getPropertySafe, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getResponseTypeCategory, getRoute, getRouteAsArray, getScalar, getSuccessResponseType, getTypedResponse, getWarningCount, isBinaryContentType, isBinaryScalarSchema, isBoolean, isComponentRef, isDirectory, isDynamicReference, isFakerMock, isFunction, isModule, isMswMock, isNullish, isNumber, isNumeric, isObject, isReference, isSchema, isString, isStringLike, isSyntheticDefaultImportsAllow, isUrl, isVerb, isVerbose, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, logVerbose, logWarning, makeRouteSafe, mergeDeep, mismatchArgsMessage, pascal, removeFilesAndEmptyFolders, resetWarnings, resolveDiscriminators, resolveDynamicRef, resolveExampleRefs, resolveInstalledVersion, resolveInstalledVersions, resolveObject, resolveRef, resolveValue, sanitize, setVerbose, snake, sortByPriority, splitSchemasByType, startMessage, stringify, toObjectString, path_d_exports as upath, upper, wrapRouteParameters, writeGeneratedFile, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
2728
2817
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -137,9 +137,12 @@ const TEMPLATE_TAG_REGEX = /\${(.+?)}/g;
|
|
|
137
137
|
//#endregion
|
|
138
138
|
//#region src/utils/assertion.ts
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
140
|
+
* Type guard for an OpenAPI {@link OpenApiReferenceObject}.
|
|
141
141
|
*
|
|
142
|
-
*
|
|
142
|
+
* Returns `true` when `obj` has a `$ref` property, indicating a static
|
|
143
|
+
* JSON Pointer reference rather than an inline schema.
|
|
144
|
+
*
|
|
145
|
+
* @param obj - Value to test.
|
|
143
146
|
*/
|
|
144
147
|
function isReference(obj) {
|
|
145
148
|
return !isNullish$1(obj) && Object.hasOwn(obj, "$ref");
|
|
@@ -150,27 +153,71 @@ function isReference(obj) {
|
|
|
150
153
|
* Returns `true` when `obj` has a `$dynamicRef` string property,
|
|
151
154
|
* indicating it is an OpenAPI 3.1 dynamic reference rather than a
|
|
152
155
|
* static `$ref`.
|
|
156
|
+
*
|
|
157
|
+
* @param obj - Value to test.
|
|
158
|
+
*
|
|
159
|
+
* @see https://json-schema.org/draft/2020-12/json-schema-core#section-8.2.4
|
|
153
160
|
*/
|
|
154
161
|
function isDynamicReference(obj) {
|
|
155
162
|
return !isNullish$1(obj) && Object.hasOwn(obj, "$dynamicRef") && typeof obj.$dynamicRef === "string";
|
|
156
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns `true` when `pathValue` has no file extension and is treated as a
|
|
166
|
+
* directory path.
|
|
167
|
+
*
|
|
168
|
+
* @param pathValue - Path string to inspect.
|
|
169
|
+
*/
|
|
157
170
|
function isDirectory(pathValue) {
|
|
158
171
|
return !nodePath.extname(pathValue);
|
|
159
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Type guard for plain objects created with `{}` or `new Object()`.
|
|
175
|
+
*
|
|
176
|
+
* Excludes `null`, arrays, dates, and other non-plain object values.
|
|
177
|
+
*
|
|
178
|
+
* @param x - Value to test.
|
|
179
|
+
*/
|
|
160
180
|
function isObject(x) {
|
|
161
181
|
return Object.prototype.toString.call(x) === "[object Object]";
|
|
162
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Type guard for string primitives and `String` wrapper objects.
|
|
185
|
+
*
|
|
186
|
+
* @param val - Value to test.
|
|
187
|
+
*/
|
|
163
188
|
function isStringLike(val) {
|
|
164
189
|
if (isString$1(val)) return true;
|
|
165
190
|
return Object.prototype.toString.call(val) === "[object String]";
|
|
166
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Type guard for ES module namespace objects.
|
|
194
|
+
*
|
|
195
|
+
* @param x - Value to test.
|
|
196
|
+
*/
|
|
167
197
|
function isModule(x) {
|
|
168
198
|
return Object.prototype.toString.call(x) === "[object Module]";
|
|
169
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Type guard for integer numbers and numeric strings.
|
|
202
|
+
*
|
|
203
|
+
* Accepts finite integers (`42`) and strings that match `/^-?\d+$/`
|
|
204
|
+
* (`"-1"`, `"0"`). Rejects floats, empty strings, and non-numeric values.
|
|
205
|
+
*
|
|
206
|
+
* @param x - Value to test.
|
|
207
|
+
*/
|
|
170
208
|
function isNumeric(x) {
|
|
171
209
|
if (typeof x === "number") return Number.isInteger(x);
|
|
172
210
|
return isString$1(x) && /^-?\d+$/.test(x);
|
|
173
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Type guard for an inline OpenAPI {@link OpenApiSchemaObject}.
|
|
214
|
+
*
|
|
215
|
+
* Returns `true` when `x` looks like a schema definition: it has a known
|
|
216
|
+
* `type`, composition keywords (`allOf`, `anyOf`, `oneOf`), or `properties`.
|
|
217
|
+
* Does not match reference objects; use {@link isReference} for those.
|
|
218
|
+
*
|
|
219
|
+
* @param x - Value to test.
|
|
220
|
+
*/
|
|
174
221
|
function isSchema(x) {
|
|
175
222
|
if (!isObject(x)) return false;
|
|
176
223
|
if (isString$1(x.type) && Object.values(SchemaType).includes(x.type)) return true;
|
|
@@ -179,9 +226,22 @@ function isSchema(x) {
|
|
|
179
226
|
if (isObject(x.properties)) return true;
|
|
180
227
|
return false;
|
|
181
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Type guard for HTTP methods defined in {@link Verbs}.
|
|
231
|
+
*
|
|
232
|
+
* @param verb - Method name to test (for example, `"get"`, `"post"`).
|
|
233
|
+
*/
|
|
182
234
|
function isVerb(verb) {
|
|
183
235
|
return Object.values(Verbs).includes(verb);
|
|
184
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns `true` when `str` is a valid absolute URL with an `http:` or
|
|
239
|
+
* `https:` protocol.
|
|
240
|
+
*
|
|
241
|
+
* Empty or whitespace-only strings are rejected.
|
|
242
|
+
*
|
|
243
|
+
* @param str - URL string to validate.
|
|
244
|
+
*/
|
|
185
245
|
function isUrl(str) {
|
|
186
246
|
if (!str.trim()) return false;
|
|
187
247
|
try {
|
|
@@ -194,6 +254,8 @@ function isUrl(str) {
|
|
|
194
254
|
/**
|
|
195
255
|
* Type guard for the MSW mock generator. Use to narrow a
|
|
196
256
|
* `GlobalMockOptions | ClientMockBuilder` value to `MswMockOptions`.
|
|
257
|
+
*
|
|
258
|
+
* @param mock - Mock configuration or builder to test.
|
|
197
259
|
*/
|
|
198
260
|
function isMswMock(mock) {
|
|
199
261
|
return !isFunction$1(mock) && mock.type === OutputMockType.MSW;
|
|
@@ -201,6 +263,8 @@ function isMswMock(mock) {
|
|
|
201
263
|
/**
|
|
202
264
|
* Type guard for the Faker mock generator. Use to narrow a
|
|
203
265
|
* `GlobalMockOptions | ClientMockBuilder` value to `FakerMockOptions`.
|
|
266
|
+
*
|
|
267
|
+
* @param mock - Mock configuration or builder to test.
|
|
204
268
|
*/
|
|
205
269
|
function isFakerMock(mock) {
|
|
206
270
|
return !isFunction$1(mock) && mock.type === OutputMockType.FAKER;
|
|
@@ -267,10 +331,11 @@ const pascalMemory = {};
|
|
|
267
331
|
function pascal(s = "") {
|
|
268
332
|
if (pascalMemory[s]) return pascalMemory[s];
|
|
269
333
|
const isStartWithUnderscore = s.startsWith("_");
|
|
334
|
+
const cacheKey = s;
|
|
270
335
|
if (regexps.upper.test(s)) s = low(s);
|
|
271
336
|
const pascalString = (s.match(/[a-zA-Z0-9\u00C0-\u017F]+/g) ?? []).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
272
337
|
const pascalWithUnderscore = isStartWithUnderscore ? `_${pascalString}` : pascalString;
|
|
273
|
-
pascalMemory[
|
|
338
|
+
pascalMemory[cacheKey] = pascalWithUnderscore;
|
|
274
339
|
return pascalWithUnderscore;
|
|
275
340
|
}
|
|
276
341
|
function camel(s = "") {
|
|
@@ -394,6 +459,20 @@ function createDebugger(ns, options = {}) {
|
|
|
394
459
|
const search = String.raw`\*/`;
|
|
395
460
|
const replacement = String.raw`*\/`;
|
|
396
461
|
const regex = new RegExp(search, "g");
|
|
462
|
+
function trimTrailingEmptyLines(lines) {
|
|
463
|
+
let lastLineIndex = lines.length - 1;
|
|
464
|
+
while (lastLineIndex >= 0 && lines[lastLineIndex]?.trim() === "") lastLineIndex--;
|
|
465
|
+
return lines.slice(0, lastLineIndex + 1);
|
|
466
|
+
}
|
|
467
|
+
function escapeJsDoc(value) {
|
|
468
|
+
return value.replaceAll(regex, replacement);
|
|
469
|
+
}
|
|
470
|
+
function getDescriptionLines(description) {
|
|
471
|
+
return trimTrailingEmptyLines((Array.isArray(description) ? description.filter((line) => !line.includes("eslint-disable")) : [description ?? ""]).flatMap((block) => block.split(/\r?\n/).map((line) => escapeJsDoc(line))));
|
|
472
|
+
}
|
|
473
|
+
function getEslintDisable(description) {
|
|
474
|
+
return Array.isArray(description) ? description.find((line) => line.includes("eslint-disable")) : void 0;
|
|
475
|
+
}
|
|
397
476
|
const itemValidationKeys = [
|
|
398
477
|
"minLength",
|
|
399
478
|
"maxLength",
|
|
@@ -417,93 +496,56 @@ function getItemValidationDocEntries(schema, prefix = "items", visited = /* @__P
|
|
|
417
496
|
}];
|
|
418
497
|
}), ...getItemValidationDocEntries(schema.items, `${prefix}.items`, visited)];
|
|
419
498
|
}
|
|
499
|
+
function toJsDocEntry(key, value) {
|
|
500
|
+
if (value === void 0 || value === false || value === "") return [];
|
|
501
|
+
return [{
|
|
502
|
+
key,
|
|
503
|
+
value
|
|
504
|
+
}];
|
|
505
|
+
}
|
|
506
|
+
function getSchemaDocEntries(schema, itemValidationDocEntries, isNullable) {
|
|
507
|
+
const { deprecated, summary, minLength, maxLength, minimum, maximum, exclusiveMinimum, exclusiveMaximum, minItems, maxItems, pattern } = schema;
|
|
508
|
+
return [
|
|
509
|
+
...toJsDocEntry("deprecated", deprecated),
|
|
510
|
+
...toJsDocEntry("summary", summary),
|
|
511
|
+
...toJsDocEntry("minLength", minLength),
|
|
512
|
+
...toJsDocEntry("maxLength", maxLength),
|
|
513
|
+
...toJsDocEntry("minimum", minimum),
|
|
514
|
+
...toJsDocEntry("maximum", maximum),
|
|
515
|
+
...toJsDocEntry("exclusiveMinimum", exclusiveMinimum),
|
|
516
|
+
...toJsDocEntry("exclusiveMaximum", exclusiveMaximum),
|
|
517
|
+
...toJsDocEntry("minItems", minItems),
|
|
518
|
+
...toJsDocEntry("maxItems", maxItems),
|
|
519
|
+
...toJsDocEntry("nullable", isNullable),
|
|
520
|
+
...toJsDocEntry("pattern", pattern),
|
|
521
|
+
...itemValidationDocEntries.flatMap(({ key, value }) => toJsDocEntry(key, value))
|
|
522
|
+
];
|
|
523
|
+
}
|
|
524
|
+
function formatJsDocEntry({ key, value }) {
|
|
525
|
+
if (value === true) return `@${key}`;
|
|
526
|
+
return `@${key} ${escapeJsDoc(value.toString())}`;
|
|
527
|
+
}
|
|
528
|
+
function renderJsDocBlock(lines, tryOneLine = false) {
|
|
529
|
+
if (lines.length === 0) return "";
|
|
530
|
+
if (lines.length === 1 && tryOneLine) return `/** ${lines[0]} */\n`;
|
|
531
|
+
const linePrefix = `${tryOneLine ? " " : ""} *`;
|
|
532
|
+
const closingPrefix = ` ${tryOneLine ? " " : ""}`;
|
|
533
|
+
return `/**\n${lines.map((line) => `${linePrefix}${line ? ` ${line}` : ""}`).join("\n")}\n${closingPrefix}*/\n`;
|
|
534
|
+
}
|
|
420
535
|
function jsDoc(schema, tryOneLine = false, context) {
|
|
421
536
|
if (context?.output.override.jsDoc) {
|
|
422
537
|
const { filter } = context.output.override.jsDoc;
|
|
423
538
|
if (filter) return keyValuePairsToJsDoc(filter(schema));
|
|
424
539
|
}
|
|
425
|
-
const { description, deprecated, summary, minLength, maxLength, minimum, maximum, exclusiveMinimum, exclusiveMaximum, minItems, maxItems, pattern } = schema;
|
|
426
540
|
const isNullable = schema.type === "null" || Array.isArray(schema.type) && schema.type.includes("null");
|
|
427
541
|
const itemValidationDocEntries = getItemValidationDocEntries(schema.items);
|
|
428
|
-
const lines = (
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
summary,
|
|
433
|
-
minLength?.toString(),
|
|
434
|
-
maxLength?.toString(),
|
|
435
|
-
minimum?.toString(),
|
|
436
|
-
maximum?.toString(),
|
|
437
|
-
exclusiveMinimum?.toString(),
|
|
438
|
-
exclusiveMaximum?.toString(),
|
|
439
|
-
minItems?.toString(),
|
|
440
|
-
maxItems?.toString(),
|
|
441
|
-
isNullable ? "null" : "",
|
|
442
|
-
pattern,
|
|
443
|
-
...itemValidationDocEntries.map(({ value }) => value.toString())
|
|
444
|
-
].filter(Boolean).length;
|
|
445
|
-
if (!count) return "";
|
|
446
|
-
const oneLine = count === 1 && tryOneLine;
|
|
447
|
-
const eslintDisable = Array.isArray(description) ? description.find((d) => d.includes("eslint-disable"))?.replaceAll(regex, replacement) : void 0;
|
|
448
|
-
let doc = `${eslintDisable ? `/* ${eslintDisable} */\n` : ""}/**`;
|
|
449
|
-
if (description) {
|
|
450
|
-
if (!oneLine) doc += `\n${tryOneLine ? " " : ""} *`;
|
|
451
|
-
doc += ` ${lines.join("\n * ")}`;
|
|
452
|
-
}
|
|
453
|
-
function appendPrefix() {
|
|
454
|
-
if (!oneLine) doc += `\n${tryOneLine ? " " : ""} *`;
|
|
455
|
-
}
|
|
456
|
-
function tryAppendStringDocLine(key, value) {
|
|
457
|
-
if (value) {
|
|
458
|
-
appendPrefix();
|
|
459
|
-
doc += ` @${key} ${value.replaceAll(regex, replacement)}`;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
function tryAppendBooleanDocLine(key, value) {
|
|
463
|
-
if (value === true) {
|
|
464
|
-
appendPrefix();
|
|
465
|
-
doc += ` @${key}`;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
function tryAppendNumberDocLine(key, value) {
|
|
469
|
-
if (value !== void 0) {
|
|
470
|
-
appendPrefix();
|
|
471
|
-
doc += ` @${key} ${value}`;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
tryAppendBooleanDocLine("deprecated", deprecated);
|
|
475
|
-
tryAppendStringDocLine("summary", summary?.replaceAll(regex, replacement));
|
|
476
|
-
tryAppendNumberDocLine("minLength", minLength);
|
|
477
|
-
tryAppendNumberDocLine("maxLength", maxLength);
|
|
478
|
-
tryAppendNumberDocLine("minimum", minimum);
|
|
479
|
-
tryAppendNumberDocLine("maximum", maximum);
|
|
480
|
-
tryAppendNumberDocLine("exclusiveMinimum", exclusiveMinimum);
|
|
481
|
-
tryAppendNumberDocLine("exclusiveMaximum", exclusiveMaximum);
|
|
482
|
-
tryAppendNumberDocLine("minItems", minItems);
|
|
483
|
-
tryAppendNumberDocLine("maxItems", maxItems);
|
|
484
|
-
tryAppendBooleanDocLine("nullable", isNullable);
|
|
485
|
-
tryAppendStringDocLine("pattern", pattern);
|
|
486
|
-
for (const { key, value } of itemValidationDocEntries) {
|
|
487
|
-
if (typeof value === "string") {
|
|
488
|
-
tryAppendStringDocLine(key, value);
|
|
489
|
-
continue;
|
|
490
|
-
}
|
|
491
|
-
if (typeof value === "number") {
|
|
492
|
-
tryAppendNumberDocLine(key, value);
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
tryAppendBooleanDocLine(key, value);
|
|
496
|
-
}
|
|
497
|
-
doc += oneLine ? " " : `\n ${tryOneLine ? " " : ""}`;
|
|
498
|
-
doc += "*/\n";
|
|
499
|
-
return doc;
|
|
542
|
+
const lines = [...getDescriptionLines(schema.description), ...getSchemaDocEntries(schema, itemValidationDocEntries, isNullable).map((entry) => formatJsDocEntry(entry))];
|
|
543
|
+
const eslintDisable = getEslintDisable(schema.description);
|
|
544
|
+
const doc = renderJsDocBlock(lines, tryOneLine);
|
|
545
|
+
return `${eslintDisable ? `/* ${escapeJsDoc(eslintDisable)} */\n` : ""}${doc}`;
|
|
500
546
|
}
|
|
501
547
|
function keyValuePairsToJsDoc(keyValues) {
|
|
502
|
-
|
|
503
|
-
let doc = "/**\n";
|
|
504
|
-
for (const { key, value } of keyValues) doc += ` * @${key} ${value}\n`;
|
|
505
|
-
doc += " */\n";
|
|
506
|
-
return doc;
|
|
548
|
+
return renderJsDocBlock(keyValues.map(({ key, value }) => `@${key} ${value}`));
|
|
507
549
|
}
|
|
508
550
|
//#endregion
|
|
509
551
|
//#region src/utils/dynamic-import.ts
|
|
@@ -666,9 +708,6 @@ const LogLevels = {
|
|
|
666
708
|
warn: 2,
|
|
667
709
|
info: 3
|
|
668
710
|
};
|
|
669
|
-
let lastType;
|
|
670
|
-
let lastMsg;
|
|
671
|
-
let sameCount = 0;
|
|
672
711
|
function clearScreen() {
|
|
673
712
|
const repeatCount = process.stdout.rows - 2;
|
|
674
713
|
const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
|
|
@@ -678,6 +717,9 @@ function clearScreen() {
|
|
|
678
717
|
}
|
|
679
718
|
function createLogger(level = "info", options = {}) {
|
|
680
719
|
const { prefix = "[vite]", allowClearScreen = true } = options;
|
|
720
|
+
let lastType;
|
|
721
|
+
let lastMsg;
|
|
722
|
+
let sameCount = 0;
|
|
681
723
|
const thresh = LogLevels[level];
|
|
682
724
|
const clear = allowClearScreen && process.stdout.isTTY && !process.env.CI ? clearScreen : () => {};
|
|
683
725
|
function output(type, msg, options = {}) {
|
|
@@ -1240,7 +1282,7 @@ const getUnion = (value, enumName) => {
|
|
|
1240
1282
|
};
|
|
1241
1283
|
function getEnumUnionFromSchema(schema) {
|
|
1242
1284
|
if (!schema?.enum) return "";
|
|
1243
|
-
return schema.enum.filter((val) => val !== null).map((val) => isString(val) ? `'${
|
|
1285
|
+
return schema.enum.filter((val) => val !== null).map((val) => isString(val) ? `'${jsStringEscape(val)}'` : String(val)).join(" | ");
|
|
1244
1286
|
}
|
|
1245
1287
|
const stripNullUnion = (value) => value.replaceAll(/\s*\|\s*null/g, "").trim();
|
|
1246
1288
|
const isSpreadableEnumRef = (schema, refName) => {
|
|
@@ -1627,13 +1669,13 @@ function getPropertyNamesEnumKeyType(item) {
|
|
|
1627
1669
|
if (Array.isArray(propertyNames.enum)) {
|
|
1628
1670
|
const enumValues = propertyNames.enum.filter((val) => isString(val));
|
|
1629
1671
|
if (enumValues.length > 0) return {
|
|
1630
|
-
value: enumValues.map((val) => `'${
|
|
1672
|
+
value: enumValues.map((val) => `'${jsStringEscape(val)}'`).join(" | "),
|
|
1631
1673
|
imports: [],
|
|
1632
1674
|
dependencies: []
|
|
1633
1675
|
};
|
|
1634
1676
|
}
|
|
1635
1677
|
if (isString(propertyNames.const)) return {
|
|
1636
|
-
value: `'${
|
|
1678
|
+
value: `'${jsStringEscape(propertyNames.const)}'`,
|
|
1637
1679
|
imports: [],
|
|
1638
1680
|
dependencies: []
|
|
1639
1681
|
};
|
|
@@ -1772,7 +1814,7 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
1772
1814
|
const hasConst = constValue !== void 0;
|
|
1773
1815
|
let constLiteral;
|
|
1774
1816
|
if (!hasConst) constLiteral = void 0;
|
|
1775
|
-
else if (isString(constValue)) constLiteral = `'${
|
|
1817
|
+
else if (isString(constValue)) constLiteral = `'${jsStringEscape(constValue)}'`;
|
|
1776
1818
|
else constLiteral = JSON.stringify(constValue);
|
|
1777
1819
|
const needsValueImport = hasConst && (resolvedValue.isEnum || resolvedValue.type === "enum");
|
|
1778
1820
|
const usedResolvedValue = !hasConst || needsValueImport;
|
|
@@ -1905,7 +1947,7 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
1905
1947
|
else if (typeof constValue === "boolean") type = "boolean";
|
|
1906
1948
|
else type = "object";
|
|
1907
1949
|
return {
|
|
1908
|
-
value: typeof constValue === "string" ? `'${
|
|
1950
|
+
value: typeof constValue === "string" ? `'${jsStringEscape(constValue)}'` : JSON.stringify(constValue),
|
|
1909
1951
|
imports: [],
|
|
1910
1952
|
schemas: [],
|
|
1911
1953
|
isEnum: false,
|
|
@@ -2046,7 +2088,7 @@ function getScalar({ item, name, context, formDataContext }) {
|
|
|
2046
2088
|
let value = "string";
|
|
2047
2089
|
let isEnum = false;
|
|
2048
2090
|
if (enumItems) {
|
|
2049
|
-
value = enumItems.map((enumItem) => isString(enumItem) ? `'${
|
|
2091
|
+
value = enumItems.map((enumItem) => isString(enumItem) ? `'${jsStringEscape(enumItem)}'` : `${enumItem}`).filter(Boolean).join(` | `);
|
|
2050
2092
|
isEnum = true;
|
|
2051
2093
|
}
|
|
2052
2094
|
if (!formDataContext?.urlEncoded) {
|
|
@@ -2108,7 +2150,7 @@ function getScalar({ item, name, context, formDataContext }) {
|
|
|
2108
2150
|
nullable
|
|
2109
2151
|
});
|
|
2110
2152
|
if (enumItems) return {
|
|
2111
|
-
value: enumItems.map((enumItem) => isString(enumItem) ? `'${
|
|
2153
|
+
value: enumItems.map((enumItem) => isString(enumItem) ? `'${jsStringEscape(enumItem)}'` : String(enumItem)).filter(Boolean).join(` | `) + nullable,
|
|
2112
2154
|
isEnum: true,
|
|
2113
2155
|
type: "string",
|
|
2114
2156
|
imports: [],
|
|
@@ -2405,12 +2447,14 @@ function resolveDynamicRef(anchorName, context, imports = []) {
|
|
|
2405
2447
|
if (!scopeEntry) return {
|
|
2406
2448
|
schema: {},
|
|
2407
2449
|
imports,
|
|
2408
|
-
resolvedTypeName: "unknown"
|
|
2450
|
+
resolvedTypeName: "unknown",
|
|
2451
|
+
schemaName: void 0
|
|
2409
2452
|
};
|
|
2410
2453
|
if (scopeEntry.isParameter) return {
|
|
2411
2454
|
schema: {},
|
|
2412
2455
|
imports,
|
|
2413
|
-
resolvedTypeName: scopeEntry.name
|
|
2456
|
+
resolvedTypeName: scopeEntry.name,
|
|
2457
|
+
schemaName: void 0
|
|
2414
2458
|
};
|
|
2415
2459
|
const resolvedTypeName = scopeEntry.name;
|
|
2416
2460
|
const schemaRef = `#/components/schemas/${encodeJsonPointerSegment(scopeEntry.schemaName)}`;
|
|
@@ -2419,13 +2463,15 @@ function resolveDynamicRef(anchorName, context, imports = []) {
|
|
|
2419
2463
|
return {
|
|
2420
2464
|
schema: resolvedSchema,
|
|
2421
2465
|
imports: resolvedImports,
|
|
2422
|
-
resolvedTypeName
|
|
2466
|
+
resolvedTypeName,
|
|
2467
|
+
schemaName: scopeEntry.schemaName
|
|
2423
2468
|
};
|
|
2424
2469
|
} catch {
|
|
2425
2470
|
return {
|
|
2426
2471
|
schema: {},
|
|
2427
2472
|
imports,
|
|
2428
|
-
resolvedTypeName: "unknown"
|
|
2473
|
+
resolvedTypeName: "unknown",
|
|
2474
|
+
schemaName: void 0
|
|
2429
2475
|
};
|
|
2430
2476
|
}
|
|
2431
2477
|
}
|
|
@@ -3440,9 +3486,13 @@ function resolveDiscriminators(schemas, context) {
|
|
|
3440
3486
|
}
|
|
3441
3487
|
for (const [parentName, parentSchema] of Object.entries(transformedSchemas)) {
|
|
3442
3488
|
if (isBoolean$1(parentSchema)) continue;
|
|
3443
|
-
|
|
3444
|
-
|
|
3489
|
+
const variants = parentSchema.oneOf ?? parentSchema.anyOf;
|
|
3490
|
+
if (!variants || !parentSchema.discriminator) continue;
|
|
3491
|
+
const { propertyName, mapping } = parentSchema.discriminator;
|
|
3445
3492
|
if (!propertyName) continue;
|
|
3493
|
+
const mappedRefs = mapping ? Object.values(mapping) : [];
|
|
3494
|
+
const variantArrayRefs = variants.filter((item) => isReference(item) && typeof item.$ref === "string").map((item) => item.$ref);
|
|
3495
|
+
const variantRefs = [...new Set([...mappedRefs, ...variantArrayRefs])];
|
|
3446
3496
|
const parentProperties = parentSchema.properties;
|
|
3447
3497
|
const parentRequired = parentSchema.required;
|
|
3448
3498
|
const inheritableProps = {};
|
|
@@ -3451,7 +3501,7 @@ function resolveDiscriminators(schemas, context) {
|
|
|
3451
3501
|
}
|
|
3452
3502
|
const inheritableRequired = parentRequired?.filter((key) => key !== propertyName);
|
|
3453
3503
|
const hasInheritableProps = Object.keys(inheritableProps).length > 0;
|
|
3454
|
-
for (const mappingValue of
|
|
3504
|
+
for (const mappingValue of variantRefs) {
|
|
3455
3505
|
let variantSchema;
|
|
3456
3506
|
try {
|
|
3457
3507
|
const { originalName } = getRefInfo(mappingValue, context);
|
|
@@ -4041,14 +4091,17 @@ function hasCircularReference(target, sourceName, context, visited = /* @__PURE_
|
|
|
4041
4091
|
function buildPayload(target, context, parents, imports) {
|
|
4042
4092
|
if (isReference$1(target)) return buildRefPayload(target, context, parents, imports);
|
|
4043
4093
|
const schema = target;
|
|
4044
|
-
|
|
4045
|
-
if (schema.
|
|
4046
|
-
if (schema.
|
|
4094
|
+
const payloads = [];
|
|
4095
|
+
if (schema.allOf) payloads.push(buildAllOfPayload(getSchemas(schema.allOf) ?? [], context, parents, imports));
|
|
4096
|
+
else if (schema.oneOf) payloads.push(buildFirstOfPayload(getSchemas(schema.oneOf) ?? [], context, parents, imports));
|
|
4097
|
+
else if (schema.anyOf) payloads.push(buildFirstOfPayload(getSchemas(schema.anyOf) ?? [], context, parents, imports));
|
|
4098
|
+
if (Object.keys(getProperties(schema)).length > 0) payloads.push(buildObjectPayload(schema, context, parents, imports));
|
|
4099
|
+
if (payloads.length > 0) return payloads.length === 1 ? payloads[0] : `Object.assign({}, ${payloads.join(", ")})`;
|
|
4047
4100
|
const { constValue } = getExtendedProps(schema);
|
|
4048
4101
|
if (constValue !== void 0) return formatValue(constValue);
|
|
4049
4102
|
if (schema.default !== void 0) return buildDefaultPayload(schema, context);
|
|
4050
4103
|
const schemaType = inferSchemaType(schema);
|
|
4051
|
-
if (schemaType === "object"
|
|
4104
|
+
if (schemaType === "object") return "{}";
|
|
4052
4105
|
if (schemaType === "array") return buildArrayPayload(schema, context, parents, imports);
|
|
4053
4106
|
return buildPrimitivePayload(schema, schemaType, context);
|
|
4054
4107
|
}
|