@typia/utils 12.0.0-dev.20260225
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/lib/converters/LlmSchemaConverter.d.ts +102 -0
- package/lib/converters/LlmSchemaConverter.js +652 -0
- package/lib/converters/LlmSchemaConverter.js.map +1 -0
- package/lib/converters/LlmSchemaConverter.mjs +771 -0
- package/lib/converters/LlmSchemaConverter.mjs.map +1 -0
- package/lib/converters/OpenApiConverter.d.ts +135 -0
- package/lib/converters/OpenApiConverter.js +130 -0
- package/lib/converters/OpenApiConverter.js.map +1 -0
- package/lib/converters/OpenApiConverter.mjs +128 -0
- package/lib/converters/OpenApiConverter.mjs.map +1 -0
- package/lib/converters/index.d.ts +2 -0
- package/lib/converters/index.js +21 -0
- package/lib/converters/index.js.map +1 -0
- package/lib/converters/index.mjs +4 -0
- package/lib/converters/index.mjs.map +1 -0
- package/lib/converters/internal/LlmDescriptionInverter.d.ts +6 -0
- package/lib/converters/internal/LlmDescriptionInverter.js +141 -0
- package/lib/converters/internal/LlmDescriptionInverter.js.map +1 -0
- package/lib/converters/internal/LlmDescriptionInverter.mjs +141 -0
- package/lib/converters/internal/LlmDescriptionInverter.mjs.map +1 -0
- package/lib/converters/internal/LlmParametersComposer.d.ts +1 -0
- package/lib/converters/internal/LlmParametersComposer.js +39 -0
- package/lib/converters/internal/LlmParametersComposer.js.map +1 -0
- package/lib/converters/internal/LlmParametersComposer.mjs +42 -0
- package/lib/converters/internal/LlmParametersComposer.mjs.map +1 -0
- package/lib/converters/internal/OpenApiConstraintShifter.d.ts +6 -0
- package/lib/converters/internal/OpenApiConstraintShifter.js +103 -0
- package/lib/converters/internal/OpenApiConstraintShifter.js.map +1 -0
- package/lib/converters/internal/OpenApiConstraintShifter.mjs +102 -0
- package/lib/converters/internal/OpenApiConstraintShifter.mjs.map +1 -0
- package/lib/converters/internal/OpenApiExclusiveEmender.d.ts +4 -0
- package/lib/converters/internal/OpenApiExclusiveEmender.js +32 -0
- package/lib/converters/internal/OpenApiExclusiveEmender.js.map +1 -0
- package/lib/converters/internal/OpenApiExclusiveEmender.mjs +35 -0
- package/lib/converters/internal/OpenApiExclusiveEmender.mjs.map +1 -0
- package/lib/converters/internal/OpenApiV3Downgrader.d.ts +10 -0
- package/lib/converters/internal/OpenApiV3Downgrader.js +214 -0
- package/lib/converters/internal/OpenApiV3Downgrader.js.map +1 -0
- package/lib/converters/internal/OpenApiV3Downgrader.mjs +279 -0
- package/lib/converters/internal/OpenApiV3Downgrader.mjs.map +1 -0
- package/lib/converters/internal/OpenApiV3Upgrader.d.ts +6 -0
- package/lib/converters/internal/OpenApiV3Upgrader.js +285 -0
- package/lib/converters/internal/OpenApiV3Upgrader.js.map +1 -0
- package/lib/converters/internal/OpenApiV3Upgrader.mjs +349 -0
- package/lib/converters/internal/OpenApiV3Upgrader.mjs.map +1 -0
- package/lib/converters/internal/OpenApiV3_1Upgrader.d.ts +6 -0
- package/lib/converters/internal/OpenApiV3_1Upgrader.js +405 -0
- package/lib/converters/internal/OpenApiV3_1Upgrader.js.map +1 -0
- package/lib/converters/internal/OpenApiV3_1Upgrader.mjs +545 -0
- package/lib/converters/internal/OpenApiV3_1Upgrader.mjs.map +1 -0
- package/lib/converters/internal/SwaggerV2Downgrader.d.ts +10 -0
- package/lib/converters/internal/SwaggerV2Downgrader.js +294 -0
- package/lib/converters/internal/SwaggerV2Downgrader.js.map +1 -0
- package/lib/converters/internal/SwaggerV2Downgrader.mjs +332 -0
- package/lib/converters/internal/SwaggerV2Downgrader.mjs.map +1 -0
- package/lib/converters/internal/SwaggerV2Upgrader.d.ts +6 -0
- package/lib/converters/internal/SwaggerV2Upgrader.js +357 -0
- package/lib/converters/internal/SwaggerV2Upgrader.js.map +1 -0
- package/lib/converters/internal/SwaggerV2Upgrader.mjs +403 -0
- package/lib/converters/internal/SwaggerV2Upgrader.mjs.map +1 -0
- package/lib/http/HttpError.d.ts +61 -0
- package/lib/http/HttpError.js +70 -0
- package/lib/http/HttpError.js.map +1 -0
- package/lib/http/HttpError.mjs +76 -0
- package/lib/http/HttpError.mjs.map +1 -0
- package/lib/http/HttpLlm.d.ts +130 -0
- package/lib/http/HttpLlm.js +124 -0
- package/lib/http/HttpLlm.js.map +1 -0
- package/lib/http/HttpLlm.mjs +123 -0
- package/lib/http/HttpLlm.mjs.map +1 -0
- package/lib/http/HttpMigration.d.ts +58 -0
- package/lib/http/HttpMigration.js +52 -0
- package/lib/http/HttpMigration.js.map +1 -0
- package/lib/http/HttpMigration.mjs +52 -0
- package/lib/http/HttpMigration.mjs.map +1 -0
- package/lib/http/index.d.ts +3 -0
- package/lib/http/index.js +20 -0
- package/lib/http/index.js.map +1 -0
- package/lib/http/index.mjs +4 -0
- package/lib/http/index.mjs.map +1 -0
- package/lib/http/internal/HttpLlmApplicationComposer.d.ts +8 -0
- package/lib/http/internal/HttpLlmApplicationComposer.js +254 -0
- package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -0
- package/lib/http/internal/HttpLlmApplicationComposer.mjs +256 -0
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -0
- package/lib/http/internal/HttpLlmFunctionFetcher.d.ts +6 -0
- package/lib/http/internal/HttpLlmFunctionFetcher.js +24 -0
- package/lib/http/internal/HttpLlmFunctionFetcher.js.map +1 -0
- package/lib/http/internal/HttpLlmFunctionFetcher.mjs +24 -0
- package/lib/http/internal/HttpLlmFunctionFetcher.mjs.map +1 -0
- package/lib/http/internal/HttpMigrateApplicationComposer.d.ts +4 -0
- package/lib/http/internal/HttpMigrateApplicationComposer.js +45 -0
- package/lib/http/internal/HttpMigrateApplicationComposer.js.map +1 -0
- package/lib/http/internal/HttpMigrateApplicationComposer.mjs +47 -0
- package/lib/http/internal/HttpMigrateApplicationComposer.mjs.map +1 -0
- package/lib/http/internal/HttpMigrateRouteAccessor.d.ts +4 -0
- package/lib/http/internal/HttpMigrateRouteAccessor.js +107 -0
- package/lib/http/internal/HttpMigrateRouteAccessor.js.map +1 -0
- package/lib/http/internal/HttpMigrateRouteAccessor.mjs +106 -0
- package/lib/http/internal/HttpMigrateRouteAccessor.mjs.map +1 -0
- package/lib/http/internal/HttpMigrateRouteComposer.d.ts +11 -0
- package/lib/http/internal/HttpMigrateRouteComposer.js +398 -0
- package/lib/http/internal/HttpMigrateRouteComposer.js.map +1 -0
- package/lib/http/internal/HttpMigrateRouteComposer.mjs +392 -0
- package/lib/http/internal/HttpMigrateRouteComposer.mjs.map +1 -0
- package/lib/http/internal/HttpMigrateRouteFetcher.d.ts +6 -0
- package/lib/http/internal/HttpMigrateRouteFetcher.js +179 -0
- package/lib/http/internal/HttpMigrateRouteFetcher.js.map +1 -0
- package/lib/http/internal/HttpMigrateRouteFetcher.mjs +174 -0
- package/lib/http/internal/HttpMigrateRouteFetcher.mjs.map +1 -0
- package/lib/http/internal/LlmDataMerger.d.ts +48 -0
- package/lib/http/internal/LlmDataMerger.js +60 -0
- package/lib/http/internal/LlmDataMerger.js.map +1 -0
- package/lib/http/internal/LlmDataMerger.mjs +59 -0
- package/lib/http/internal/LlmDataMerger.mjs.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +20 -0
- package/lib/index.mjs.map +1 -0
- package/lib/utils/ArrayUtil.d.ts +1 -0
- package/lib/utils/ArrayUtil.js +29 -0
- package/lib/utils/ArrayUtil.js.map +1 -0
- package/lib/utils/ArrayUtil.mjs +28 -0
- package/lib/utils/ArrayUtil.mjs.map +1 -0
- package/lib/utils/MapUtil.d.ts +1 -0
- package/lib/utils/MapUtil.js +16 -0
- package/lib/utils/MapUtil.js.map +1 -0
- package/lib/utils/MapUtil.mjs +15 -0
- package/lib/utils/MapUtil.mjs.map +1 -0
- package/lib/utils/NamingConvention.d.ts +68 -0
- package/lib/utils/NamingConvention.js +199 -0
- package/lib/utils/NamingConvention.js.map +1 -0
- package/lib/utils/NamingConvention.mjs +198 -0
- package/lib/utils/NamingConvention.mjs.map +1 -0
- package/lib/utils/Singleton.d.ts +1 -0
- package/lib/utils/Singleton.js +18 -0
- package/lib/utils/Singleton.js.map +1 -0
- package/lib/utils/Singleton.mjs +18 -0
- package/lib/utils/Singleton.mjs.map +1 -0
- package/lib/utils/StringUtil.d.ts +1 -0
- package/lib/utils/StringUtil.js +17 -0
- package/lib/utils/StringUtil.js.map +1 -0
- package/lib/utils/StringUtil.mjs +13 -0
- package/lib/utils/StringUtil.mjs.map +1 -0
- package/lib/utils/dedent.d.ts +12 -0
- package/lib/utils/dedent.js +51 -0
- package/lib/utils/dedent.js.map +1 -0
- package/lib/utils/dedent.mjs +50 -0
- package/lib/utils/dedent.mjs.map +1 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.js +24 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/index.mjs +8 -0
- package/lib/utils/index.mjs.map +1 -0
- package/lib/utils/internal/EndpointUtil.d.ts +8 -0
- package/lib/utils/internal/EndpointUtil.js +37 -0
- package/lib/utils/internal/EndpointUtil.js.map +1 -0
- package/lib/utils/internal/EndpointUtil.mjs +37 -0
- package/lib/utils/internal/EndpointUtil.mjs.map +1 -0
- package/lib/utils/internal/JsonDescriptor.d.ts +10 -0
- package/lib/utils/internal/JsonDescriptor.js +58 -0
- package/lib/utils/internal/JsonDescriptor.js.map +1 -0
- package/lib/utils/internal/JsonDescriptor.mjs +48 -0
- package/lib/utils/internal/JsonDescriptor.mjs.map +1 -0
- package/lib/utils/internal/OpenApiTypeCheckerBase.d.ts +1 -0
- package/lib/utils/internal/OpenApiTypeCheckerBase.js +520 -0
- package/lib/utils/internal/OpenApiTypeCheckerBase.js.map +1 -0
- package/lib/utils/internal/OpenApiTypeCheckerBase.mjs +584 -0
- package/lib/utils/internal/OpenApiTypeCheckerBase.mjs.map +1 -0
- package/lib/utils/stringifyValidationFailure.d.ts +25 -0
- package/lib/utils/stringifyValidationFailure.js +326 -0
- package/lib/utils/stringifyValidationFailure.js.map +1 -0
- package/lib/utils/stringifyValidationFailure.mjs +325 -0
- package/lib/utils/stringifyValidationFailure.mjs.map +1 -0
- package/lib/validators/LlmTypeChecker.d.ts +117 -0
- package/lib/validators/LlmTypeChecker.js +309 -0
- package/lib/validators/LlmTypeChecker.js.map +1 -0
- package/lib/validators/LlmTypeChecker.mjs +300 -0
- package/lib/validators/LlmTypeChecker.mjs.map +1 -0
- package/lib/validators/OpenApiTypeChecker.d.ts +211 -0
- package/lib/validators/OpenApiTypeChecker.js +207 -0
- package/lib/validators/OpenApiTypeChecker.js.map +1 -0
- package/lib/validators/OpenApiTypeChecker.mjs +218 -0
- package/lib/validators/OpenApiTypeChecker.mjs.map +1 -0
- package/lib/validators/OpenApiV3TypeChecker.d.ts +26 -0
- package/lib/validators/OpenApiV3TypeChecker.js +30 -0
- package/lib/validators/OpenApiV3TypeChecker.js.map +1 -0
- package/lib/validators/OpenApiV3TypeChecker.mjs +29 -0
- package/lib/validators/OpenApiV3TypeChecker.mjs.map +1 -0
- package/lib/validators/OpenApiV3_1TypeChecker.d.ts +29 -0
- package/lib/validators/OpenApiV3_1TypeChecker.js +34 -0
- package/lib/validators/OpenApiV3_1TypeChecker.js.map +1 -0
- package/lib/validators/OpenApiV3_1TypeChecker.mjs +33 -0
- package/lib/validators/OpenApiV3_1TypeChecker.mjs.map +1 -0
- package/lib/validators/OpenApiValidator.d.ts +36 -0
- package/lib/validators/OpenApiValidator.js +71 -0
- package/lib/validators/OpenApiValidator.js.map +1 -0
- package/lib/validators/OpenApiValidator.mjs +75 -0
- package/lib/validators/OpenApiValidator.mjs.map +1 -0
- package/lib/validators/SwaggerV2TypeChecker.d.ts +27 -0
- package/lib/validators/SwaggerV2TypeChecker.js +31 -0
- package/lib/validators/SwaggerV2TypeChecker.js.map +1 -0
- package/lib/validators/SwaggerV2TypeChecker.mjs +30 -0
- package/lib/validators/SwaggerV2TypeChecker.mjs.map +1 -0
- package/lib/validators/functional/_isBigintString.d.ts +1 -0
- package/lib/validators/functional/_isBigintString.js +14 -0
- package/lib/validators/functional/_isBigintString.js.map +1 -0
- package/lib/validators/functional/_isBigintString.mjs +12 -0
- package/lib/validators/functional/_isBigintString.mjs.map +1 -0
- package/lib/validators/functional/_isFormatByte.d.ts +1 -0
- package/lib/validators/functional/_isFormatByte.js +10 -0
- package/lib/validators/functional/_isFormatByte.js.map +1 -0
- package/lib/validators/functional/_isFormatByte.mjs +8 -0
- package/lib/validators/functional/_isFormatByte.mjs.map +1 -0
- package/lib/validators/functional/_isFormatDate.d.ts +1 -0
- package/lib/validators/functional/_isFormatDate.js +7 -0
- package/lib/validators/functional/_isFormatDate.js.map +1 -0
- package/lib/validators/functional/_isFormatDate.mjs +5 -0
- package/lib/validators/functional/_isFormatDate.mjs.map +1 -0
- package/lib/validators/functional/_isFormatDateTime.d.ts +1 -0
- package/lib/validators/functional/_isFormatDateTime.js +7 -0
- package/lib/validators/functional/_isFormatDateTime.js.map +1 -0
- package/lib/validators/functional/_isFormatDateTime.mjs +5 -0
- package/lib/validators/functional/_isFormatDateTime.mjs.map +1 -0
- package/lib/validators/functional/_isFormatDuration.d.ts +1 -0
- package/lib/validators/functional/_isFormatDuration.js +7 -0
- package/lib/validators/functional/_isFormatDuration.js.map +1 -0
- package/lib/validators/functional/_isFormatDuration.mjs +5 -0
- package/lib/validators/functional/_isFormatDuration.mjs.map +1 -0
- package/lib/validators/functional/_isFormatEmail.d.ts +1 -0
- package/lib/validators/functional/_isFormatEmail.js +7 -0
- package/lib/validators/functional/_isFormatEmail.js.map +1 -0
- package/lib/validators/functional/_isFormatEmail.mjs +5 -0
- package/lib/validators/functional/_isFormatEmail.mjs.map +1 -0
- package/lib/validators/functional/_isFormatHostname.d.ts +1 -0
- package/lib/validators/functional/_isFormatHostname.js +7 -0
- package/lib/validators/functional/_isFormatHostname.js.map +1 -0
- package/lib/validators/functional/_isFormatHostname.mjs +5 -0
- package/lib/validators/functional/_isFormatHostname.mjs.map +1 -0
- package/lib/validators/functional/_isFormatIdnEmail.d.ts +1 -0
- package/lib/validators/functional/_isFormatIdnEmail.js +7 -0
- package/lib/validators/functional/_isFormatIdnEmail.js.map +1 -0
- package/lib/validators/functional/_isFormatIdnEmail.mjs +5 -0
- package/lib/validators/functional/_isFormatIdnEmail.mjs.map +1 -0
- package/lib/validators/functional/_isFormatIdnHostname.d.ts +1 -0
- package/lib/validators/functional/_isFormatIdnHostname.js +7 -0
- package/lib/validators/functional/_isFormatIdnHostname.js.map +1 -0
- package/lib/validators/functional/_isFormatIdnHostname.mjs +5 -0
- package/lib/validators/functional/_isFormatIdnHostname.mjs.map +1 -0
- package/lib/validators/functional/_isFormatIpv4.d.ts +1 -0
- package/lib/validators/functional/_isFormatIpv4.js +7 -0
- package/lib/validators/functional/_isFormatIpv4.js.map +1 -0
- package/lib/validators/functional/_isFormatIpv4.mjs +5 -0
- package/lib/validators/functional/_isFormatIpv4.mjs.map +1 -0
- package/lib/validators/functional/_isFormatIpv6.d.ts +1 -0
- package/lib/validators/functional/_isFormatIpv6.js +7 -0
- package/lib/validators/functional/_isFormatIpv6.js.map +1 -0
- package/lib/validators/functional/_isFormatIpv6.mjs +5 -0
- package/lib/validators/functional/_isFormatIpv6.mjs.map +1 -0
- package/lib/validators/functional/_isFormatIri.d.ts +1 -0
- package/lib/validators/functional/_isFormatIri.js +7 -0
- package/lib/validators/functional/_isFormatIri.js.map +1 -0
- package/lib/validators/functional/_isFormatIri.mjs +5 -0
- package/lib/validators/functional/_isFormatIri.mjs.map +1 -0
- package/lib/validators/functional/_isFormatIriReference.d.ts +1 -0
- package/lib/validators/functional/_isFormatIriReference.js +7 -0
- package/lib/validators/functional/_isFormatIriReference.js.map +1 -0
- package/lib/validators/functional/_isFormatIriReference.mjs +5 -0
- package/lib/validators/functional/_isFormatIriReference.mjs.map +1 -0
- package/lib/validators/functional/_isFormatJsonPointer.d.ts +1 -0
- package/lib/validators/functional/_isFormatJsonPointer.js +7 -0
- package/lib/validators/functional/_isFormatJsonPointer.js.map +1 -0
- package/lib/validators/functional/_isFormatJsonPointer.mjs +5 -0
- package/lib/validators/functional/_isFormatJsonPointer.mjs.map +1 -0
- package/lib/validators/functional/_isFormatPassword.d.ts +1 -0
- package/lib/validators/functional/_isFormatPassword.js +6 -0
- package/lib/validators/functional/_isFormatPassword.js.map +1 -0
- package/lib/validators/functional/_isFormatPassword.mjs +4 -0
- package/lib/validators/functional/_isFormatPassword.mjs.map +1 -0
- package/lib/validators/functional/_isFormatRegex.d.ts +1 -0
- package/lib/validators/functional/_isFormatRegex.js +14 -0
- package/lib/validators/functional/_isFormatRegex.js.map +1 -0
- package/lib/validators/functional/_isFormatRegex.mjs +12 -0
- package/lib/validators/functional/_isFormatRegex.mjs.map +1 -0
- package/lib/validators/functional/_isFormatRelativeJsonPointer.d.ts +1 -0
- package/lib/validators/functional/_isFormatRelativeJsonPointer.js +7 -0
- package/lib/validators/functional/_isFormatRelativeJsonPointer.js.map +1 -0
- package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs +5 -0
- package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs.map +1 -0
- package/lib/validators/functional/_isFormatTime.d.ts +1 -0
- package/lib/validators/functional/_isFormatTime.js +7 -0
- package/lib/validators/functional/_isFormatTime.js.map +1 -0
- package/lib/validators/functional/_isFormatTime.mjs +5 -0
- package/lib/validators/functional/_isFormatTime.mjs.map +1 -0
- package/lib/validators/functional/_isFormatUri.d.ts +1 -0
- package/lib/validators/functional/_isFormatUri.js +8 -0
- package/lib/validators/functional/_isFormatUri.js.map +1 -0
- package/lib/validators/functional/_isFormatUri.mjs +6 -0
- package/lib/validators/functional/_isFormatUri.mjs.map +1 -0
- package/lib/validators/functional/_isFormatUriReference.d.ts +1 -0
- package/lib/validators/functional/_isFormatUriReference.js +7 -0
- package/lib/validators/functional/_isFormatUriReference.js.map +1 -0
- package/lib/validators/functional/_isFormatUriReference.mjs +5 -0
- package/lib/validators/functional/_isFormatUriReference.mjs.map +1 -0
- package/lib/validators/functional/_isFormatUriTemplate.d.ts +1 -0
- package/lib/validators/functional/_isFormatUriTemplate.js +7 -0
- package/lib/validators/functional/_isFormatUriTemplate.js.map +1 -0
- package/lib/validators/functional/_isFormatUriTemplate.mjs +5 -0
- package/lib/validators/functional/_isFormatUriTemplate.mjs.map +1 -0
- package/lib/validators/functional/_isFormatUrl.d.ts +1 -0
- package/lib/validators/functional/_isFormatUrl.js +7 -0
- package/lib/validators/functional/_isFormatUrl.js.map +1 -0
- package/lib/validators/functional/_isFormatUrl.mjs +5 -0
- package/lib/validators/functional/_isFormatUrl.mjs.map +1 -0
- package/lib/validators/functional/_isFormatUuid.d.ts +1 -0
- package/lib/validators/functional/_isFormatUuid.js +7 -0
- package/lib/validators/functional/_isFormatUuid.js.map +1 -0
- package/lib/validators/functional/_isFormatUuid.mjs +5 -0
- package/lib/validators/functional/_isFormatUuid.mjs.map +1 -0
- package/lib/validators/functional/_isUniqueItems.d.ts +1 -0
- package/lib/validators/functional/_isUniqueItems.js +140 -0
- package/lib/validators/functional/_isUniqueItems.js.map +1 -0
- package/lib/validators/functional/_isUniqueItems.mjs +138 -0
- package/lib/validators/functional/_isUniqueItems.mjs.map +1 -0
- package/lib/validators/index.d.ts +2 -0
- package/lib/validators/index.js +27 -0
- package/lib/validators/index.js.map +1 -0
- package/lib/validators/index.mjs +7 -0
- package/lib/validators/index.mjs.map +1 -0
- package/lib/validators/internal/IOpenApiValidatorContext.d.ts +14 -0
- package/lib/validators/internal/IOpenApiValidatorContext.js +3 -0
- package/lib/validators/internal/IOpenApiValidatorContext.js.map +1 -0
- package/lib/validators/internal/IOpenApiValidatorContext.mjs +2 -0
- package/lib/validators/internal/IOpenApiValidatorContext.mjs.map +1 -0
- package/lib/validators/internal/OpenApiArrayValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiArrayValidator.js +32 -0
- package/lib/validators/internal/OpenApiArrayValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiArrayValidator.mjs +47 -0
- package/lib/validators/internal/OpenApiArrayValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiBooleanValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiBooleanValidator.js +10 -0
- package/lib/validators/internal/OpenApiBooleanValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiBooleanValidator.mjs +9 -0
- package/lib/validators/internal/OpenApiBooleanValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiConstantValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiConstantValidator.js +10 -0
- package/lib/validators/internal/OpenApiConstantValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiConstantValidator.mjs +9 -0
- package/lib/validators/internal/OpenApiConstantValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiIntegerValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiIntegerValidator.js +33 -0
- package/lib/validators/internal/OpenApiIntegerValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiIntegerValidator.mjs +47 -0
- package/lib/validators/internal/OpenApiIntegerValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiNumberValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiNumberValidator.js +33 -0
- package/lib/validators/internal/OpenApiNumberValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiNumberValidator.mjs +47 -0
- package/lib/validators/internal/OpenApiNumberValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiObjectValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiObjectValidator.js +58 -0
- package/lib/validators/internal/OpenApiObjectValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiObjectValidator.mjs +68 -0
- package/lib/validators/internal/OpenApiObjectValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiOneOfValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiOneOfValidator.js +182 -0
- package/lib/validators/internal/OpenApiOneOfValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +206 -0
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiSchemaNamingRule.d.ts +4 -0
- package/lib/validators/internal/OpenApiSchemaNamingRule.js +122 -0
- package/lib/validators/internal/OpenApiSchemaNamingRule.js.map +1 -0
- package/lib/validators/internal/OpenApiSchemaNamingRule.mjs +121 -0
- package/lib/validators/internal/OpenApiSchemaNamingRule.mjs.map +1 -0
- package/lib/validators/internal/OpenApiStationValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiStationValidator.js +63 -0
- package/lib/validators/internal/OpenApiStationValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiStationValidator.mjs +107 -0
- package/lib/validators/internal/OpenApiStationValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiStringValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiStringValidator.js +73 -0
- package/lib/validators/internal/OpenApiStringValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiStringValidator.mjs +85 -0
- package/lib/validators/internal/OpenApiStringValidator.mjs.map +1 -0
- package/lib/validators/internal/OpenApiTupleValidator.d.ts +5 -0
- package/lib/validators/internal/OpenApiTupleValidator.js +31 -0
- package/lib/validators/internal/OpenApiTupleValidator.js.map +1 -0
- package/lib/validators/internal/OpenApiTupleValidator.mjs +46 -0
- package/lib/validators/internal/OpenApiTupleValidator.mjs.map +1 -0
- package/package.json +91 -0
- package/src/converters/LlmSchemaConverter.ts +924 -0
- package/src/converters/OpenApiConverter.ts +285 -0
- package/src/converters/index.ts +5 -0
- package/src/converters/internal/LlmDescriptionInverter.ts +178 -0
- package/src/converters/internal/LlmParametersComposer.ts +52 -0
- package/src/converters/internal/OpenApiConstraintShifter.ts +154 -0
- package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -0
- package/src/converters/internal/OpenApiV3Downgrader.ts +355 -0
- package/src/converters/internal/OpenApiV3Upgrader.ts +470 -0
- package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -0
- package/src/converters/internal/SwaggerV2Downgrader.ts +424 -0
- package/src/converters/internal/SwaggerV2Upgrader.ts +523 -0
- package/src/http/HttpError.ts +107 -0
- package/src/http/HttpLlm.ts +210 -0
- package/src/http/HttpMigration.ts +92 -0
- package/src/http/index.ts +3 -0
- package/src/http/internal/HttpLlmApplicationComposer.ts +308 -0
- package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -0
- package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -0
- package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -0
- package/src/http/internal/HttpMigrateRouteComposer.ts +513 -0
- package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -0
- package/src/http/internal/LlmDataMerger.ts +73 -0
- package/src/index.ts +4 -0
- package/src/utils/ArrayUtil.ts +42 -0
- package/src/utils/MapUtil.ts +15 -0
- package/src/utils/NamingConvention.ts +205 -0
- package/src/utils/Singleton.ts +17 -0
- package/src/utils/StringUtil.ts +14 -0
- package/src/utils/dedent.ts +57 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/internal/EndpointUtil.ts +44 -0
- package/src/utils/internal/JsonDescriptor.ts +70 -0
- package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -0
- package/src/utils/stringifyValidationFailure.ts +415 -0
- package/src/validators/LlmTypeChecker.ts +402 -0
- package/src/validators/OpenApiTypeChecker.ts +297 -0
- package/src/validators/OpenApiV3TypeChecker.ts +70 -0
- package/src/validators/OpenApiV3_1TypeChecker.ts +86 -0
- package/src/validators/OpenApiValidator.ts +94 -0
- package/src/validators/SwaggerV2TypeChecker.ts +71 -0
- package/src/validators/functional/_isBigintString.ts +8 -0
- package/src/validators/functional/_isFormatByte.ts +7 -0
- package/src/validators/functional/_isFormatDate.ts +3 -0
- package/src/validators/functional/_isFormatDateTime.ts +4 -0
- package/src/validators/functional/_isFormatDuration.ts +4 -0
- package/src/validators/functional/_isFormatEmail.ts +4 -0
- package/src/validators/functional/_isFormatHostname.ts +4 -0
- package/src/validators/functional/_isFormatIdnEmail.ts +4 -0
- package/src/validators/functional/_isFormatIdnHostname.ts +4 -0
- package/src/validators/functional/_isFormatIpv4.ts +4 -0
- package/src/validators/functional/_isFormatIpv6.ts +4 -0
- package/src/validators/functional/_isFormatIri.ts +3 -0
- package/src/validators/functional/_isFormatIriReference.ts +4 -0
- package/src/validators/functional/_isFormatJsonPointer.ts +3 -0
- package/src/validators/functional/_isFormatPassword.ts +1 -0
- package/src/validators/functional/_isFormatRegex.ts +8 -0
- package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -0
- package/src/validators/functional/_isFormatTime.ts +4 -0
- package/src/validators/functional/_isFormatUri.ts +6 -0
- package/src/validators/functional/_isFormatUriReference.ts +5 -0
- package/src/validators/functional/_isFormatUriTemplate.ts +4 -0
- package/src/validators/functional/_isFormatUrl.ts +4 -0
- package/src/validators/functional/_isFormatUuid.ts +3 -0
- package/src/validators/functional/_isUniqueItems.ts +159 -0
- package/src/validators/index.ts +14 -0
- package/src/validators/internal/IOpenApiValidatorContext.ts +17 -0
- package/src/validators/internal/OpenApiArrayValidator.ts +49 -0
- package/src/validators/internal/OpenApiBooleanValidator.ts +11 -0
- package/src/validators/internal/OpenApiConstantValidator.ts +11 -0
- package/src/validators/internal/OpenApiIntegerValidator.ts +49 -0
- package/src/validators/internal/OpenApiNumberValidator.ts +48 -0
- package/src/validators/internal/OpenApiObjectValidator.ts +83 -0
- package/src/validators/internal/OpenApiOneOfValidator.ts +309 -0
- package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -0
- package/src/validators/internal/OpenApiStationValidator.ts +115 -0
- package/src/validators/internal/OpenApiStringValidator.ts +88 -0
- package/src/validators/internal/OpenApiTupleValidator.ts +55 -0
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
import { IJsonSchemaTransformError, IResult, OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { MapUtil } from "../MapUtil";
|
|
4
|
+
import { JsonDescriptor } from "./JsonDescriptor";
|
|
5
|
+
|
|
6
|
+
/** @internal */
|
|
7
|
+
export namespace OpenApiTypeCheckerBase {
|
|
8
|
+
/* -----------------------------------------------------------
|
|
9
|
+
TYPE CHECKERS
|
|
10
|
+
----------------------------------------------------------- */
|
|
11
|
+
export const isNull = (
|
|
12
|
+
schema: OpenApi.IJsonSchema,
|
|
13
|
+
): schema is OpenApi.IJsonSchema.INull =>
|
|
14
|
+
(schema as OpenApi.IJsonSchema.INull).type === "null";
|
|
15
|
+
|
|
16
|
+
export const isUnknown = (
|
|
17
|
+
schema: OpenApi.IJsonSchema,
|
|
18
|
+
): schema is OpenApi.IJsonSchema.IUnknown =>
|
|
19
|
+
(schema as OpenApi.IJsonSchema.IUnknown).type === undefined &&
|
|
20
|
+
!isConstant(schema) &&
|
|
21
|
+
!isOneOf(schema) &&
|
|
22
|
+
!isReference(schema);
|
|
23
|
+
|
|
24
|
+
export const isConstant = (
|
|
25
|
+
schema: OpenApi.IJsonSchema,
|
|
26
|
+
): schema is OpenApi.IJsonSchema.IConstant =>
|
|
27
|
+
(schema as OpenApi.IJsonSchema.IConstant).const !== undefined;
|
|
28
|
+
|
|
29
|
+
export const isBoolean = (
|
|
30
|
+
schema: OpenApi.IJsonSchema,
|
|
31
|
+
): schema is OpenApi.IJsonSchema.IBoolean =>
|
|
32
|
+
(schema as OpenApi.IJsonSchema.IBoolean).type === "boolean";
|
|
33
|
+
|
|
34
|
+
export const isInteger = (
|
|
35
|
+
schema: OpenApi.IJsonSchema,
|
|
36
|
+
): schema is OpenApi.IJsonSchema.IInteger =>
|
|
37
|
+
(schema as OpenApi.IJsonSchema.IInteger).type === "integer";
|
|
38
|
+
|
|
39
|
+
export const isNumber = (
|
|
40
|
+
schema: OpenApi.IJsonSchema,
|
|
41
|
+
): schema is OpenApi.IJsonSchema.INumber =>
|
|
42
|
+
(schema as OpenApi.IJsonSchema.INumber).type === "number";
|
|
43
|
+
|
|
44
|
+
export const isString = (
|
|
45
|
+
schema: OpenApi.IJsonSchema,
|
|
46
|
+
): schema is OpenApi.IJsonSchema.IString =>
|
|
47
|
+
(schema as OpenApi.IJsonSchema.IString).type === "string";
|
|
48
|
+
|
|
49
|
+
export const isArray = (
|
|
50
|
+
schema: OpenApi.IJsonSchema,
|
|
51
|
+
): schema is OpenApi.IJsonSchema.IArray =>
|
|
52
|
+
(schema as OpenApi.IJsonSchema.IArray).type === "array" &&
|
|
53
|
+
(schema as OpenApi.IJsonSchema.IArray).items !== undefined;
|
|
54
|
+
|
|
55
|
+
export const isTuple = (
|
|
56
|
+
schema: OpenApi.IJsonSchema,
|
|
57
|
+
): schema is OpenApi.IJsonSchema.ITuple =>
|
|
58
|
+
(schema as OpenApi.IJsonSchema.ITuple).type === "array" &&
|
|
59
|
+
(schema as OpenApi.IJsonSchema.ITuple).prefixItems !== undefined;
|
|
60
|
+
|
|
61
|
+
export const isObject = (
|
|
62
|
+
schema: OpenApi.IJsonSchema,
|
|
63
|
+
): schema is OpenApi.IJsonSchema.IObject =>
|
|
64
|
+
(schema as OpenApi.IJsonSchema.IObject).type === "object";
|
|
65
|
+
|
|
66
|
+
export const isReference = (
|
|
67
|
+
schema: OpenApi.IJsonSchema,
|
|
68
|
+
): schema is OpenApi.IJsonSchema.IReference =>
|
|
69
|
+
(schema as any).$ref !== undefined;
|
|
70
|
+
|
|
71
|
+
export const isOneOf = (
|
|
72
|
+
schema: OpenApi.IJsonSchema,
|
|
73
|
+
): schema is OpenApi.IJsonSchema.IOneOf =>
|
|
74
|
+
(schema as OpenApi.IJsonSchema.IOneOf).oneOf !== undefined;
|
|
75
|
+
|
|
76
|
+
export const isRecursiveReference = (props: {
|
|
77
|
+
prefix: string;
|
|
78
|
+
components: OpenApi.IComponents;
|
|
79
|
+
schema: OpenApi.IJsonSchema;
|
|
80
|
+
}): boolean => {
|
|
81
|
+
if (isReference(props.schema) === false) return false;
|
|
82
|
+
const current: string =
|
|
83
|
+
props.schema.$ref.split(props.prefix)[1] ??
|
|
84
|
+
props.schema.$ref.split("/").at(-1)!;
|
|
85
|
+
let counter: number = 0;
|
|
86
|
+
visit({
|
|
87
|
+
prefix: props.prefix,
|
|
88
|
+
components: props.components,
|
|
89
|
+
schema: props.schema,
|
|
90
|
+
closure: (schema) => {
|
|
91
|
+
if (isReference(schema)) {
|
|
92
|
+
const next: string =
|
|
93
|
+
schema.$ref.split(props.prefix)[1] ??
|
|
94
|
+
schema.$ref.split("/").at(-1)!;
|
|
95
|
+
if (current === next) ++counter;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return counter > 1;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/* -----------------------------------------------------------
|
|
103
|
+
OPERATORS
|
|
104
|
+
----------------------------------------------------------- */
|
|
105
|
+
export const unreference = (props: {
|
|
106
|
+
prefix: string;
|
|
107
|
+
method: string;
|
|
108
|
+
components: OpenApi.IComponents;
|
|
109
|
+
schema: OpenApi.IJsonSchema;
|
|
110
|
+
accessor?: string;
|
|
111
|
+
refAccessor?: string;
|
|
112
|
+
}): IResult<OpenApi.IJsonSchema, IJsonSchemaTransformError> => {
|
|
113
|
+
const reasons: IJsonSchemaTransformError.IReason[] = [];
|
|
114
|
+
const result: OpenApi.IJsonSchema | null = unreferenceSchema({
|
|
115
|
+
prefix: props.prefix,
|
|
116
|
+
refAccessor:
|
|
117
|
+
props.refAccessor ??
|
|
118
|
+
`$input.${props.prefix
|
|
119
|
+
.substring(2)
|
|
120
|
+
.split("/")
|
|
121
|
+
.filter((s) => !!s.length)
|
|
122
|
+
.join(".")}`,
|
|
123
|
+
accessor: props.accessor ?? "$input.schema",
|
|
124
|
+
components: props.components,
|
|
125
|
+
schema: props.schema,
|
|
126
|
+
reasons,
|
|
127
|
+
});
|
|
128
|
+
if (result === null)
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: {
|
|
132
|
+
method: props.method,
|
|
133
|
+
message: `failed to unreference due to unable to find.`,
|
|
134
|
+
reasons,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
success: true,
|
|
139
|
+
value: result,
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const escape = (props: {
|
|
144
|
+
prefix: string;
|
|
145
|
+
method: string;
|
|
146
|
+
components: OpenApi.IComponents;
|
|
147
|
+
schema: OpenApi.IJsonSchema;
|
|
148
|
+
recursive: false | number;
|
|
149
|
+
accessor?: string;
|
|
150
|
+
refAccessor?: string;
|
|
151
|
+
}): IResult<OpenApi.IJsonSchema, IJsonSchemaTransformError> => {
|
|
152
|
+
const reasons: IJsonSchemaTransformError.IReason[] = [];
|
|
153
|
+
const result: OpenApi.IJsonSchema | null =
|
|
154
|
+
escapeSchema({
|
|
155
|
+
...props,
|
|
156
|
+
reasons,
|
|
157
|
+
visited: new Map(),
|
|
158
|
+
accessor: props.accessor ?? "$input.schema",
|
|
159
|
+
refAccessor: props.refAccessor ?? getReference(props.prefix),
|
|
160
|
+
}) || null;
|
|
161
|
+
if (result === null)
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: {
|
|
165
|
+
method: props.method,
|
|
166
|
+
message: `failed to escape some reference type(s) due to unable to find${Number(props.recursive) === 0 ? " or recursive relationship" : ""}.`,
|
|
167
|
+
reasons,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
value: result,
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const visit = (props: {
|
|
177
|
+
prefix: string;
|
|
178
|
+
closure: (schema: OpenApi.IJsonSchema, accessor: string) => void;
|
|
179
|
+
components: OpenApi.IComponents;
|
|
180
|
+
schema: OpenApi.IJsonSchema;
|
|
181
|
+
accessor?: string;
|
|
182
|
+
refAccessor?: string;
|
|
183
|
+
}): void => {
|
|
184
|
+
const already: Set<string> = new Set();
|
|
185
|
+
const refAccessor: string =
|
|
186
|
+
props.refAccessor ?? `$input.${getReference(props.prefix)}`;
|
|
187
|
+
const next = (schema: OpenApi.IJsonSchema, accessor: string): void => {
|
|
188
|
+
props.closure(schema, accessor);
|
|
189
|
+
if (isReference(schema)) {
|
|
190
|
+
const key: string = schema.$ref.split(props.prefix).pop()!;
|
|
191
|
+
if (already.has(key) === true) return;
|
|
192
|
+
already.add(key);
|
|
193
|
+
const found: OpenApi.IJsonSchema | undefined =
|
|
194
|
+
props.components.schemas?.[key];
|
|
195
|
+
if (found !== undefined)
|
|
196
|
+
next(found, `${refAccessor}[${JSON.stringify(key)}]`);
|
|
197
|
+
} else if (isOneOf(schema))
|
|
198
|
+
schema.oneOf.forEach((s, i) => next(s, `${accessor}.oneOf[${i}]`));
|
|
199
|
+
else if (isObject(schema)) {
|
|
200
|
+
for (const [key, value] of Object.entries(schema.properties ?? {}))
|
|
201
|
+
next(value, `${accessor}.properties[${JSON.stringify(key)}]`);
|
|
202
|
+
if (
|
|
203
|
+
typeof schema.additionalProperties === "object" &&
|
|
204
|
+
schema.additionalProperties !== null
|
|
205
|
+
)
|
|
206
|
+
next(schema.additionalProperties, `${accessor}.additionalProperties`);
|
|
207
|
+
} else if (isArray(schema)) next(schema.items, `${accessor}.items`);
|
|
208
|
+
else if (isTuple(schema)) {
|
|
209
|
+
(schema.prefixItems ?? []).forEach((s, i) =>
|
|
210
|
+
next(s, `${accessor}.prefixItems[${i}]`),
|
|
211
|
+
);
|
|
212
|
+
if (
|
|
213
|
+
typeof schema.additionalItems === "object" &&
|
|
214
|
+
schema.additionalItems !== null
|
|
215
|
+
)
|
|
216
|
+
next(schema.additionalItems, `${accessor}.additionalItems`);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
next(props.schema, props.accessor ?? "$input.schema");
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export const covers = (props: {
|
|
223
|
+
prefix: string;
|
|
224
|
+
components: OpenApi.IComponents;
|
|
225
|
+
x: OpenApi.IJsonSchema;
|
|
226
|
+
y: OpenApi.IJsonSchema;
|
|
227
|
+
}): boolean =>
|
|
228
|
+
coverStation({
|
|
229
|
+
prefix: props.prefix,
|
|
230
|
+
components: props.components,
|
|
231
|
+
x: props.x,
|
|
232
|
+
y: props.y,
|
|
233
|
+
visited: new Map(),
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const unreferenceSchema = (props: {
|
|
237
|
+
prefix: string;
|
|
238
|
+
refAccessor: string;
|
|
239
|
+
accessor: string;
|
|
240
|
+
components: OpenApi.IComponents;
|
|
241
|
+
schema: OpenApi.IJsonSchema;
|
|
242
|
+
reasons: IJsonSchemaTransformError.IReason[];
|
|
243
|
+
first?: string;
|
|
244
|
+
}): OpenApi.IJsonSchema | null => {
|
|
245
|
+
if (isReference(props.schema) === false) return props.schema;
|
|
246
|
+
const key: string = props.schema.$ref.split(props.prefix).pop()!;
|
|
247
|
+
const found: OpenApi.IJsonSchema | undefined =
|
|
248
|
+
props.components.schemas?.[key];
|
|
249
|
+
if (found === undefined) {
|
|
250
|
+
props.reasons.push({
|
|
251
|
+
schema: props.schema,
|
|
252
|
+
accessor: props.accessor,
|
|
253
|
+
message: `unable to find reference type ${JSON.stringify(key)}.`,
|
|
254
|
+
});
|
|
255
|
+
return null;
|
|
256
|
+
} else if (isReference(found) === false) return found;
|
|
257
|
+
else if (props.first === key) {
|
|
258
|
+
props.reasons.push({
|
|
259
|
+
schema: props.schema,
|
|
260
|
+
accessor: props.accessor,
|
|
261
|
+
message: `recursive reference type ${JSON.stringify(key)}.`,
|
|
262
|
+
});
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
return unreferenceSchema({
|
|
266
|
+
...props,
|
|
267
|
+
accessor: `${props.refAccessor}[${JSON.stringify(key)}]`,
|
|
268
|
+
first: key,
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const escapeSchema = (props: {
|
|
273
|
+
components: OpenApi.IComponents;
|
|
274
|
+
prefix: string;
|
|
275
|
+
schema: OpenApi.IJsonSchema;
|
|
276
|
+
recursive: false | number;
|
|
277
|
+
visited: Map<string, number>;
|
|
278
|
+
reasons: IJsonSchemaTransformError.IReason[];
|
|
279
|
+
accessor: string;
|
|
280
|
+
refAccessor: string;
|
|
281
|
+
}): OpenApi.IJsonSchema | null | undefined => {
|
|
282
|
+
if (isReference(props.schema)) {
|
|
283
|
+
// REFERENCE
|
|
284
|
+
const key: string =
|
|
285
|
+
props.schema.$ref.split(props.prefix)[1] ??
|
|
286
|
+
props.schema.$ref.split("/").at(-1)!;
|
|
287
|
+
const target: OpenApi.IJsonSchema | undefined =
|
|
288
|
+
props.components.schemas?.[key];
|
|
289
|
+
if (target === undefined) {
|
|
290
|
+
props.reasons.push({
|
|
291
|
+
schema: props.schema,
|
|
292
|
+
accessor: props.accessor,
|
|
293
|
+
message: `unable to find reference type ${JSON.stringify(key)}.`,
|
|
294
|
+
});
|
|
295
|
+
return null;
|
|
296
|
+
} else if (props.visited.has(key) === true) {
|
|
297
|
+
if (props.recursive === false) return null;
|
|
298
|
+
const depth: number = props.visited.get(key)!;
|
|
299
|
+
if (depth > props.recursive) {
|
|
300
|
+
if (props.recursive === 0) {
|
|
301
|
+
props.reasons.push({
|
|
302
|
+
schema: props.schema,
|
|
303
|
+
accessor: props.accessor,
|
|
304
|
+
message: `recursive reference type ${JSON.stringify(key)}.`,
|
|
305
|
+
});
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
props.visited.set(key, depth + 1);
|
|
311
|
+
const res: OpenApi.IJsonSchema | null | undefined = escapeSchema({
|
|
312
|
+
...props,
|
|
313
|
+
schema: target,
|
|
314
|
+
accessor: `${props.refAccessor}[${JSON.stringify(key)}]`,
|
|
315
|
+
});
|
|
316
|
+
return res
|
|
317
|
+
? {
|
|
318
|
+
...res,
|
|
319
|
+
description: JsonDescriptor.cascade({
|
|
320
|
+
prefix: props.prefix,
|
|
321
|
+
components: props.components,
|
|
322
|
+
schema: props.schema,
|
|
323
|
+
escape: true,
|
|
324
|
+
}),
|
|
325
|
+
}
|
|
326
|
+
: res;
|
|
327
|
+
} else {
|
|
328
|
+
const res: OpenApi.IJsonSchema | null | undefined = escapeSchema({
|
|
329
|
+
...props,
|
|
330
|
+
schema: target,
|
|
331
|
+
accessor: `${props.refAccessor}[${JSON.stringify(key)}]`,
|
|
332
|
+
visited: new Map([...props.visited, [key, 1]]),
|
|
333
|
+
});
|
|
334
|
+
return res
|
|
335
|
+
? {
|
|
336
|
+
...res,
|
|
337
|
+
description: JsonDescriptor.cascade({
|
|
338
|
+
prefix: props.prefix,
|
|
339
|
+
components: props.components,
|
|
340
|
+
schema: props.schema,
|
|
341
|
+
escape: true,
|
|
342
|
+
}),
|
|
343
|
+
}
|
|
344
|
+
: res;
|
|
345
|
+
}
|
|
346
|
+
} else if (isOneOf(props.schema)) {
|
|
347
|
+
// UNION
|
|
348
|
+
const elements: Array<OpenApi.IJsonSchema | null | undefined> =
|
|
349
|
+
props.schema.oneOf.map((s, i) =>
|
|
350
|
+
escapeSchema({
|
|
351
|
+
...props,
|
|
352
|
+
schema: s,
|
|
353
|
+
accessor: `${props.accessor}.oneOf[${i}]`,
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
if (elements.some((v) => v === null)) return null;
|
|
357
|
+
const filtered: OpenApi.IJsonSchema[] = elements.filter(
|
|
358
|
+
(v) => v !== undefined,
|
|
359
|
+
) as OpenApi.IJsonSchema[];
|
|
360
|
+
if (filtered.length === 0) return undefined;
|
|
361
|
+
return {
|
|
362
|
+
...props.schema,
|
|
363
|
+
oneOf: filtered
|
|
364
|
+
.map((v) =>
|
|
365
|
+
flatSchema({
|
|
366
|
+
prefix: props.prefix,
|
|
367
|
+
components: props.components,
|
|
368
|
+
schema: v,
|
|
369
|
+
}),
|
|
370
|
+
)
|
|
371
|
+
.flat(),
|
|
372
|
+
};
|
|
373
|
+
} else if (isObject(props.schema)) {
|
|
374
|
+
// OBJECT
|
|
375
|
+
const object: OpenApi.IJsonSchema.IObject = props.schema;
|
|
376
|
+
const properties: Array<
|
|
377
|
+
[string, OpenApi.IJsonSchema | null | undefined]
|
|
378
|
+
> = Object.entries(object.properties ?? {}).map(([k, s]) => [
|
|
379
|
+
k,
|
|
380
|
+
escapeSchema({
|
|
381
|
+
...props,
|
|
382
|
+
schema: s,
|
|
383
|
+
visited: props.visited,
|
|
384
|
+
accessor: `${props.accessor}.properties[${JSON.stringify(k)}]`,
|
|
385
|
+
}),
|
|
386
|
+
]);
|
|
387
|
+
const additionalProperties:
|
|
388
|
+
| OpenApi.IJsonSchema
|
|
389
|
+
| null
|
|
390
|
+
| boolean
|
|
391
|
+
| undefined = object.additionalProperties
|
|
392
|
+
? typeof object.additionalProperties === "object" &&
|
|
393
|
+
object.additionalProperties !== null
|
|
394
|
+
? escapeSchema({
|
|
395
|
+
...props,
|
|
396
|
+
schema: object.additionalProperties,
|
|
397
|
+
accessor: `${props.accessor}.additionalProperties`,
|
|
398
|
+
})
|
|
399
|
+
: object.additionalProperties
|
|
400
|
+
: false;
|
|
401
|
+
if (
|
|
402
|
+
properties.some(([_k, v]) => v === null) ||
|
|
403
|
+
additionalProperties === null
|
|
404
|
+
)
|
|
405
|
+
return null;
|
|
406
|
+
else if (
|
|
407
|
+
properties.some(
|
|
408
|
+
([k, v]) => v === undefined && object.required?.includes(k) === true,
|
|
409
|
+
) === true
|
|
410
|
+
)
|
|
411
|
+
return undefined;
|
|
412
|
+
return {
|
|
413
|
+
...object,
|
|
414
|
+
properties: Object.fromEntries(
|
|
415
|
+
properties.filter(([_k, v]) => v !== undefined) as Array<
|
|
416
|
+
[string, OpenApi.IJsonSchema]
|
|
417
|
+
>,
|
|
418
|
+
),
|
|
419
|
+
additionalProperties: additionalProperties ?? false,
|
|
420
|
+
required:
|
|
421
|
+
object.required?.filter((k) =>
|
|
422
|
+
properties.some(([key, value]) => key === k && value !== undefined),
|
|
423
|
+
) ?? [],
|
|
424
|
+
};
|
|
425
|
+
} else if (isTuple(props.schema)) {
|
|
426
|
+
// TUPLE
|
|
427
|
+
const elements: Array<OpenApi.IJsonSchema | null | undefined> =
|
|
428
|
+
props.schema.prefixItems.map((s, i) =>
|
|
429
|
+
escapeSchema({
|
|
430
|
+
...props,
|
|
431
|
+
schema: s,
|
|
432
|
+
accessor: `${props.accessor}.prefixItems[${i}]`,
|
|
433
|
+
}),
|
|
434
|
+
);
|
|
435
|
+
const additionalItems: OpenApi.IJsonSchema | null | boolean | undefined =
|
|
436
|
+
props.schema.additionalItems
|
|
437
|
+
? typeof props.schema.additionalItems === "object" &&
|
|
438
|
+
props.schema.additionalItems !== null
|
|
439
|
+
? escapeSchema({
|
|
440
|
+
...props,
|
|
441
|
+
schema: props.schema.additionalItems,
|
|
442
|
+
accessor: `${props.accessor}.additionalItems`,
|
|
443
|
+
})
|
|
444
|
+
: props.schema.additionalItems
|
|
445
|
+
: false;
|
|
446
|
+
if (elements.some((v) => v === null) || additionalItems === null)
|
|
447
|
+
return null;
|
|
448
|
+
else if (elements.some((v) => v === undefined)) return undefined;
|
|
449
|
+
return {
|
|
450
|
+
...props.schema,
|
|
451
|
+
prefixItems: elements as OpenApi.IJsonSchema[],
|
|
452
|
+
additionalItems: additionalItems ?? false,
|
|
453
|
+
};
|
|
454
|
+
} else if (isArray(props.schema)) {
|
|
455
|
+
// ARRAY
|
|
456
|
+
const items: OpenApi.IJsonSchema | null | undefined = escapeSchema({
|
|
457
|
+
...props,
|
|
458
|
+
schema: props.schema.items,
|
|
459
|
+
accessor: `${props.accessor}.items`,
|
|
460
|
+
});
|
|
461
|
+
if (items === null) return null;
|
|
462
|
+
else if (items === undefined)
|
|
463
|
+
return {
|
|
464
|
+
...props.schema,
|
|
465
|
+
minItems: undefined,
|
|
466
|
+
maxItems: 0,
|
|
467
|
+
items: {},
|
|
468
|
+
};
|
|
469
|
+
return {
|
|
470
|
+
...props.schema,
|
|
471
|
+
items: items,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
return props.schema;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
const coverStation = (p: {
|
|
478
|
+
prefix: string;
|
|
479
|
+
components: OpenApi.IComponents;
|
|
480
|
+
visited: Map<OpenApi.IJsonSchema, Map<OpenApi.IJsonSchema, boolean>>;
|
|
481
|
+
x: OpenApi.IJsonSchema;
|
|
482
|
+
y: OpenApi.IJsonSchema;
|
|
483
|
+
}): boolean => {
|
|
484
|
+
const cache: boolean | undefined = p.visited.get(p.x)?.get(p.y);
|
|
485
|
+
if (cache !== undefined) return cache;
|
|
486
|
+
|
|
487
|
+
// FOR RECURSIVE CASE
|
|
488
|
+
const nested: Map<OpenApi.IJsonSchema, boolean> = MapUtil.take(
|
|
489
|
+
p.visited,
|
|
490
|
+
p.x,
|
|
491
|
+
() => new Map(),
|
|
492
|
+
);
|
|
493
|
+
nested.set(p.y, true);
|
|
494
|
+
|
|
495
|
+
// COMPUTE IT
|
|
496
|
+
const result: boolean = coverSchema(p);
|
|
497
|
+
nested.set(p.y, result);
|
|
498
|
+
return result;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
const coverSchema = (p: {
|
|
502
|
+
prefix: string;
|
|
503
|
+
components: OpenApi.IComponents;
|
|
504
|
+
visited: Map<OpenApi.IJsonSchema, Map<OpenApi.IJsonSchema, boolean>>;
|
|
505
|
+
x: OpenApi.IJsonSchema;
|
|
506
|
+
y: OpenApi.IJsonSchema;
|
|
507
|
+
}): boolean => {
|
|
508
|
+
// CHECK EQUALITY
|
|
509
|
+
if (p.x === p.y) return true;
|
|
510
|
+
else if (isReference(p.x) && isReference(p.y) && p.x.$ref === p.y.$ref)
|
|
511
|
+
return true;
|
|
512
|
+
|
|
513
|
+
// COMPARE WITH FLATTENING
|
|
514
|
+
const alpha: OpenApi.IJsonSchema[] = flatSchema({
|
|
515
|
+
prefix: p.prefix,
|
|
516
|
+
components: p.components,
|
|
517
|
+
schema: p.x,
|
|
518
|
+
});
|
|
519
|
+
const beta: OpenApi.IJsonSchema[] = flatSchema({
|
|
520
|
+
prefix: p.prefix,
|
|
521
|
+
components: p.components,
|
|
522
|
+
schema: p.y,
|
|
523
|
+
});
|
|
524
|
+
if (alpha.some((x) => isUnknown(x))) return true;
|
|
525
|
+
else if (beta.some((x) => isUnknown(x))) return false;
|
|
526
|
+
return beta.every((b) =>
|
|
527
|
+
alpha.some((a) =>
|
|
528
|
+
coverEscapedSchema({
|
|
529
|
+
prefix: p.prefix,
|
|
530
|
+
components: p.components,
|
|
531
|
+
visited: p.visited,
|
|
532
|
+
x: a,
|
|
533
|
+
y: b,
|
|
534
|
+
}),
|
|
535
|
+
),
|
|
536
|
+
);
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const coverEscapedSchema = (p: {
|
|
540
|
+
prefix: string;
|
|
541
|
+
components: OpenApi.IComponents;
|
|
542
|
+
visited: Map<OpenApi.IJsonSchema, Map<OpenApi.IJsonSchema, boolean>>;
|
|
543
|
+
x: OpenApi.IJsonSchema;
|
|
544
|
+
y: OpenApi.IJsonSchema;
|
|
545
|
+
}): boolean => {
|
|
546
|
+
// CHECK EQUALITY
|
|
547
|
+
if (p.x === p.y) return true;
|
|
548
|
+
else if (isUnknown(p.x)) return true;
|
|
549
|
+
else if (isUnknown(p.y)) return false;
|
|
550
|
+
else if (isNull(p.x)) return isNull(p.y);
|
|
551
|
+
// ATOMIC CASE
|
|
552
|
+
else if (isConstant(p.x)) return isConstant(p.y) && p.x.const === p.y.const;
|
|
553
|
+
else if (isBoolean(p.x))
|
|
554
|
+
return (
|
|
555
|
+
isBoolean(p.y) || (isConstant(p.y) && typeof p.y.const === "boolean")
|
|
556
|
+
);
|
|
557
|
+
else if (isInteger(p.x))
|
|
558
|
+
return (isInteger(p.y) || isConstant(p.y)) && coverInteger(p.x, p.y);
|
|
559
|
+
else if (isNumber(p.x))
|
|
560
|
+
return (
|
|
561
|
+
(isConstant(p.y) || isInteger(p.y) || isNumber(p.y)) &&
|
|
562
|
+
coverNumber(p.x, p.y)
|
|
563
|
+
);
|
|
564
|
+
else if (isString(p.x))
|
|
565
|
+
return (isConstant(p.y) || isString(p.y)) && coverString(p.x, p.y);
|
|
566
|
+
// INSTANCE CASE
|
|
567
|
+
else if (isArray(p.x))
|
|
568
|
+
return (
|
|
569
|
+
(isArray(p.y) || isTuple(p.y)) &&
|
|
570
|
+
coverArray({
|
|
571
|
+
prefix: p.prefix,
|
|
572
|
+
components: p.components,
|
|
573
|
+
visited: p.visited,
|
|
574
|
+
x: p.x,
|
|
575
|
+
y: p.y,
|
|
576
|
+
})
|
|
577
|
+
);
|
|
578
|
+
else if (isObject(p.x))
|
|
579
|
+
return (
|
|
580
|
+
isObject(p.y) &&
|
|
581
|
+
coverObject({
|
|
582
|
+
prefix: p.prefix,
|
|
583
|
+
components: p.components,
|
|
584
|
+
visited: p.visited,
|
|
585
|
+
x: p.x,
|
|
586
|
+
y: p.y,
|
|
587
|
+
})
|
|
588
|
+
);
|
|
589
|
+
else if (isReference(p.x)) return isReference(p.y) && p.x.$ref === p.y.$ref;
|
|
590
|
+
return false;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const coverArray = (p: {
|
|
594
|
+
prefix: string;
|
|
595
|
+
components: OpenApi.IComponents;
|
|
596
|
+
visited: Map<OpenApi.IJsonSchema, Map<OpenApi.IJsonSchema, boolean>>;
|
|
597
|
+
x: OpenApi.IJsonSchema.IArray;
|
|
598
|
+
y: OpenApi.IJsonSchema.IArray | OpenApi.IJsonSchema.ITuple;
|
|
599
|
+
}): boolean => {
|
|
600
|
+
if (isTuple(p.y))
|
|
601
|
+
return (
|
|
602
|
+
p.y.prefixItems.every((v) =>
|
|
603
|
+
coverStation({
|
|
604
|
+
prefix: p.prefix,
|
|
605
|
+
components: p.components,
|
|
606
|
+
visited: p.visited,
|
|
607
|
+
x: p.x.items,
|
|
608
|
+
y: v,
|
|
609
|
+
}),
|
|
610
|
+
) &&
|
|
611
|
+
(p.y.additionalItems === undefined ||
|
|
612
|
+
(typeof p.y.additionalItems === "object" &&
|
|
613
|
+
coverStation({
|
|
614
|
+
prefix: p.prefix,
|
|
615
|
+
components: p.components,
|
|
616
|
+
visited: p.visited,
|
|
617
|
+
x: p.x.items,
|
|
618
|
+
y: p.y.additionalItems,
|
|
619
|
+
})))
|
|
620
|
+
);
|
|
621
|
+
else if (
|
|
622
|
+
!(
|
|
623
|
+
p.x.minItems === undefined ||
|
|
624
|
+
(p.y.minItems !== undefined && p.x.minItems <= p.y.minItems)
|
|
625
|
+
)
|
|
626
|
+
)
|
|
627
|
+
return false;
|
|
628
|
+
else if (
|
|
629
|
+
!(
|
|
630
|
+
p.x.maxItems === undefined ||
|
|
631
|
+
(p.y.maxItems !== undefined && p.x.maxItems >= p.y.maxItems)
|
|
632
|
+
)
|
|
633
|
+
)
|
|
634
|
+
return false;
|
|
635
|
+
return coverStation({
|
|
636
|
+
prefix: p.prefix,
|
|
637
|
+
components: p.components,
|
|
638
|
+
visited: p.visited,
|
|
639
|
+
x: p.x.items,
|
|
640
|
+
y: p.y.items,
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
const coverObject = (p: {
|
|
645
|
+
prefix: string;
|
|
646
|
+
components: OpenApi.IComponents;
|
|
647
|
+
visited: Map<OpenApi.IJsonSchema, Map<OpenApi.IJsonSchema, boolean>>;
|
|
648
|
+
x: OpenApi.IJsonSchema.IObject;
|
|
649
|
+
y: OpenApi.IJsonSchema.IObject;
|
|
650
|
+
}): boolean => {
|
|
651
|
+
if (!p.x.additionalProperties && !!p.y.additionalProperties) return false;
|
|
652
|
+
else if (
|
|
653
|
+
!!p.x.additionalProperties &&
|
|
654
|
+
!!p.y.additionalProperties &&
|
|
655
|
+
((typeof p.x.additionalProperties === "object" &&
|
|
656
|
+
p.y.additionalProperties === true) ||
|
|
657
|
+
(typeof p.x.additionalProperties === "object" &&
|
|
658
|
+
typeof p.y.additionalProperties === "object" &&
|
|
659
|
+
!coverStation({
|
|
660
|
+
prefix: p.prefix,
|
|
661
|
+
components: p.components,
|
|
662
|
+
visited: p.visited,
|
|
663
|
+
x: p.x.additionalProperties,
|
|
664
|
+
y: p.y.additionalProperties,
|
|
665
|
+
})))
|
|
666
|
+
)
|
|
667
|
+
return false;
|
|
668
|
+
return Object.entries(p.y.properties ?? {}).every(([key, b]) => {
|
|
669
|
+
const a: OpenApi.IJsonSchema | undefined = p.x.properties?.[key];
|
|
670
|
+
if (a === undefined) return false;
|
|
671
|
+
else if (
|
|
672
|
+
p.x.required?.includes(key) === true &&
|
|
673
|
+
(p.y.required?.includes(key) ?? false) === false
|
|
674
|
+
)
|
|
675
|
+
return false;
|
|
676
|
+
return coverStation({
|
|
677
|
+
prefix: p.prefix,
|
|
678
|
+
components: p.components,
|
|
679
|
+
visited: p.visited,
|
|
680
|
+
x: a,
|
|
681
|
+
y: b,
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
export const coverInteger = (
|
|
687
|
+
x: OpenApi.IJsonSchema.IInteger,
|
|
688
|
+
y: OpenApi.IJsonSchema.IConstant | OpenApi.IJsonSchema.IInteger,
|
|
689
|
+
): boolean => {
|
|
690
|
+
if (isConstant(y))
|
|
691
|
+
return typeof y.const === "number" && Number.isInteger(y.const);
|
|
692
|
+
return x.type === y.type && coverNumericRange(x, y);
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
export const coverNumber = (
|
|
696
|
+
x: OpenApi.IJsonSchema.INumber,
|
|
697
|
+
y:
|
|
698
|
+
| OpenApi.IJsonSchema.IConstant
|
|
699
|
+
| OpenApi.IJsonSchema.IInteger
|
|
700
|
+
| OpenApi.IJsonSchema.INumber,
|
|
701
|
+
): boolean => {
|
|
702
|
+
if (isConstant(y)) return typeof y.const === "number";
|
|
703
|
+
return (
|
|
704
|
+
(x.type === y.type || (x.type === "number" && y.type === "integer")) &&
|
|
705
|
+
coverNumericRange(x, y)
|
|
706
|
+
);
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
export const coverString = (
|
|
710
|
+
x: OpenApi.IJsonSchema.IString,
|
|
711
|
+
y: OpenApi.IJsonSchema.IConstant | OpenApi.IJsonSchema.IString,
|
|
712
|
+
): boolean => {
|
|
713
|
+
if (isConstant(y)) return typeof y.const === "string";
|
|
714
|
+
return [
|
|
715
|
+
x.format === undefined ||
|
|
716
|
+
(y.format !== undefined && coverFormat(x.format, y.format)),
|
|
717
|
+
x.pattern === undefined || x.pattern === y.pattern,
|
|
718
|
+
x.minLength === undefined ||
|
|
719
|
+
(y.minLength !== undefined && x.minLength <= y.minLength),
|
|
720
|
+
x.maxLength === undefined ||
|
|
721
|
+
(y.maxLength !== undefined && x.maxLength >= y.maxLength),
|
|
722
|
+
].every((v) => v);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
const coverFormat = (
|
|
726
|
+
x: Required<OpenApi.IJsonSchema.IString>["format"],
|
|
727
|
+
y: Required<OpenApi.IJsonSchema.IString>["format"],
|
|
728
|
+
): boolean =>
|
|
729
|
+
x === y ||
|
|
730
|
+
(x === "idn-email" && y === "email") ||
|
|
731
|
+
(x === "idn-hostname" && y === "hostname") ||
|
|
732
|
+
(["uri", "iri"].includes(x) && y === "url") ||
|
|
733
|
+
(x === "iri" && y === "uri") ||
|
|
734
|
+
(x === "iri-reference" && y === "uri-reference");
|
|
735
|
+
|
|
736
|
+
const flatSchema = (props: {
|
|
737
|
+
prefix: string;
|
|
738
|
+
components: OpenApi.IComponents;
|
|
739
|
+
schema: OpenApi.IJsonSchema;
|
|
740
|
+
}): OpenApi.IJsonSchema[] => {
|
|
741
|
+
const schema = escapeReferenceOfFlatSchema(props);
|
|
742
|
+
if (isOneOf(schema))
|
|
743
|
+
return schema.oneOf
|
|
744
|
+
.map((v) =>
|
|
745
|
+
flatSchema({
|
|
746
|
+
prefix: props.prefix,
|
|
747
|
+
components: props.components,
|
|
748
|
+
schema: v,
|
|
749
|
+
}),
|
|
750
|
+
)
|
|
751
|
+
.flat();
|
|
752
|
+
return [schema];
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
const escapeReferenceOfFlatSchema = (props: {
|
|
756
|
+
prefix: string;
|
|
757
|
+
components: OpenApi.IComponents;
|
|
758
|
+
schema: OpenApi.IJsonSchema;
|
|
759
|
+
}): Exclude<OpenApi.IJsonSchema, OpenApi.IJsonSchema.IReference> => {
|
|
760
|
+
if (isReference(props.schema) === false) return props.schema;
|
|
761
|
+
const key = props.schema.$ref.replace(props.prefix, "");
|
|
762
|
+
const found: OpenApi.IJsonSchema | undefined = escapeReferenceOfFlatSchema({
|
|
763
|
+
prefix: props.prefix,
|
|
764
|
+
components: props.components,
|
|
765
|
+
schema: props.components.schemas?.[key] ?? {},
|
|
766
|
+
});
|
|
767
|
+
if (found === undefined)
|
|
768
|
+
throw new Error(
|
|
769
|
+
`Reference type not found: ${JSON.stringify(props.schema.$ref)}`,
|
|
770
|
+
);
|
|
771
|
+
return escapeReferenceOfFlatSchema({
|
|
772
|
+
prefix: props.prefix,
|
|
773
|
+
components: props.components,
|
|
774
|
+
schema: found,
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
export const coverNumericRange = (
|
|
779
|
+
x: Pick<
|
|
780
|
+
OpenApi.IJsonSchema.INumber,
|
|
781
|
+
| "minimum"
|
|
782
|
+
| "maximum"
|
|
783
|
+
| "exclusiveMinimum"
|
|
784
|
+
| "exclusiveMaximum"
|
|
785
|
+
| "multipleOf"
|
|
786
|
+
>,
|
|
787
|
+
y: Pick<
|
|
788
|
+
OpenApi.IJsonSchema.INumber,
|
|
789
|
+
| "minimum"
|
|
790
|
+
| "maximum"
|
|
791
|
+
| "exclusiveMinimum"
|
|
792
|
+
| "exclusiveMaximum"
|
|
793
|
+
| "multipleOf"
|
|
794
|
+
>,
|
|
795
|
+
): boolean =>
|
|
796
|
+
[
|
|
797
|
+
x.minimum === undefined ||
|
|
798
|
+
(y.minimum !== undefined && x.minimum <= y.minimum) ||
|
|
799
|
+
(y.exclusiveMinimum !== undefined && x.minimum < y.exclusiveMinimum),
|
|
800
|
+
x.maximum === undefined ||
|
|
801
|
+
(y.maximum !== undefined && x.maximum >= y.maximum) ||
|
|
802
|
+
(y.exclusiveMaximum !== undefined && x.maximum > y.exclusiveMaximum),
|
|
803
|
+
x.exclusiveMinimum === undefined ||
|
|
804
|
+
(y.minimum !== undefined && x.exclusiveMinimum <= y.minimum) ||
|
|
805
|
+
(y.exclusiveMinimum !== undefined &&
|
|
806
|
+
x.exclusiveMinimum <= y.exclusiveMinimum),
|
|
807
|
+
x.exclusiveMaximum === undefined ||
|
|
808
|
+
(y.maximum !== undefined && x.exclusiveMaximum >= y.maximum) ||
|
|
809
|
+
(y.exclusiveMaximum !== undefined &&
|
|
810
|
+
x.exclusiveMaximum >= y.exclusiveMaximum),
|
|
811
|
+
x.multipleOf === undefined ||
|
|
812
|
+
(y.multipleOf !== undefined &&
|
|
813
|
+
y.multipleOf / x.multipleOf ===
|
|
814
|
+
Math.floor(y.multipleOf / x.multipleOf)),
|
|
815
|
+
].every((v) => v);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const getReference = (prefix: string): string =>
|
|
819
|
+
prefix
|
|
820
|
+
.split("/")
|
|
821
|
+
.filter((str, i) => !!str.length && !(i === 0 && str === "#"))
|
|
822
|
+
.join(".");
|