@scalar/openapi-parser 0.10.15 → 0.10.17
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/CHANGELOG.md +12 -0
- package/README.md +0 -22
- package/dist/configuration/index.js +19 -22
- package/dist/configuration/index.js.map +7 -0
- package/dist/declarations.d.js +1 -0
- package/dist/declarations.d.js.map +7 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -29
- package/dist/index.js.map +7 -0
- package/dist/lib/Validator/Validator.d.ts +2 -2
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +99 -119
- package/dist/lib/Validator/Validator.js.map +7 -0
- package/dist/lib/Validator/Validator.test.js +8 -0
- package/dist/lib/Validator/Validator.test.js.map +7 -0
- package/dist/lib/Validator/index.d.ts +2 -2
- package/dist/lib/Validator/index.d.ts.map +1 -1
- package/dist/lib/Validator/index.js +3 -0
- package/dist/lib/Validator/index.js.map +7 -0
- package/dist/plugins/fetch-urls/fetchUrls.d.ts +1 -2
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.js +36 -111
- package/dist/plugins/fetch-urls/fetchUrls.js.map +7 -0
- package/dist/plugins/fetch-urls/fetchUrls.test.js +50 -0
- package/dist/plugins/fetch-urls/fetchUrls.test.js.map +7 -0
- package/dist/plugins/fetch-urls/index.d.ts +1 -1
- package/dist/plugins/fetch-urls/index.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/index.js +2 -1
- package/dist/plugins/fetch-urls/index.js.map +7 -0
- package/dist/plugins/read-files/index.d.ts +1 -1
- package/dist/plugins/read-files/index.d.ts.map +1 -1
- package/dist/plugins/read-files/index.js +2 -1
- package/dist/plugins/read-files/index.js.map +7 -0
- package/dist/plugins/read-files/readFiles.d.ts +1 -1
- package/dist/plugins/read-files/readFiles.d.ts.map +1 -1
- package/dist/plugins/read-files/readFiles.js +50 -70
- package/dist/plugins/read-files/readFiles.js.map +7 -0
- package/dist/plugins/read-files/readFiles.test.js +20 -0
- package/dist/plugins/read-files/readFiles.test.js.map +7 -0
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +5 -0
- package/dist/polyfills/index.js.map +7 -0
- package/dist/polyfills/path.js +155 -98
- package/dist/polyfills/path.js.map +7 -0
- package/dist/schemas/v2.0/schema.d.ts +1405 -0
- package/dist/schemas/v2.0/schema.d.ts.map +1 -0
- package/dist/schemas/v2.0/schema.js +1463 -0
- package/dist/schemas/v2.0/schema.js.map +7 -0
- package/dist/schemas/v3.0/schema.d.ts +1264 -0
- package/dist/schemas/v3.0/schema.d.ts.map +1 -0
- package/dist/schemas/v3.0/schema.js +1493 -0
- package/dist/schemas/v3.0/schema.js.map +7 -0
- package/dist/schemas/v3.1/schema.d.ts +1225 -0
- package/dist/schemas/v3.1/schema.d.ts.map +1 -0
- package/dist/schemas/v3.1/schema.js +1296 -0
- package/dist/schemas/v3.1/schema.js.map +7 -0
- package/dist/types/index.d.ts +5 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/helpers.js +88 -93
- package/dist/utils/betterAjvErrors/helpers.js.map +7 -0
- package/dist/utils/betterAjvErrors/index.js +14 -13
- package/dist/utils/betterAjvErrors/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.d.ts +2 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.js +27 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.js.map +7 -0
- package/dist/utils/betterAjvErrors/json/index.d.ts +2 -0
- package/dist/utils/betterAjvErrors/json/index.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/json/index.js +5 -0
- package/dist/utils/betterAjvErrors/json/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/json/utils.d.ts +2 -0
- package/dist/utils/betterAjvErrors/json/utils.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/json/utils.js +11 -0
- package/dist/utils/betterAjvErrors/json/utils.js.map +7 -0
- package/dist/utils/betterAjvErrors/utils.js +21 -14
- package/dist/utils/betterAjvErrors/utils.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.d.ts +23 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.js +6 -10
- package/dist/utils/betterAjvErrors/validation-errors/base.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/default.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts +11 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +19 -29
- package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.d.ts +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.js +15 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/required.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +7 -0
- package/dist/utils/dereference.d.ts +2 -2
- package/dist/utils/dereference.d.ts.map +1 -1
- package/dist/utils/dereference.js +17 -19
- package/dist/utils/dereference.js.map +7 -0
- package/dist/utils/dereference.test.js +300 -0
- package/dist/utils/dereference.test.js.map +7 -0
- package/dist/utils/details.d.ts +1 -1
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js +26 -28
- package/dist/utils/details.js.map +7 -0
- package/dist/utils/errors.test.js +48 -0
- package/dist/utils/errors.test.js.map +7 -0
- package/dist/utils/escapeJsonPointer.js +5 -8
- package/dist/utils/escapeJsonPointer.js.map +7 -0
- package/dist/utils/escapeJsonPointer.test.js +11 -0
- package/dist/utils/escapeJsonPointer.test.js.map +7 -0
- package/dist/utils/filter.d.ts +1 -1
- package/dist/utils/filter.d.ts.map +1 -1
- package/dist/utils/filter.js +13 -15
- package/dist/utils/filter.js.map +7 -0
- package/dist/utils/getEntrypoint.d.ts +1 -1
- package/dist/utils/getEntrypoint.d.ts.map +1 -1
- package/dist/utils/getEntrypoint.js +5 -6
- package/dist/utils/getEntrypoint.js.map +7 -0
- package/dist/utils/getEntrypoint.test.js +18 -0
- package/dist/utils/getEntrypoint.test.js.map +7 -0
- package/dist/utils/getListOfReferences.d.ts +1 -1
- package/dist/utils/getListOfReferences.d.ts.map +1 -1
- package/dist/utils/getListOfReferences.js +15 -22
- package/dist/utils/getListOfReferences.js.map +7 -0
- package/dist/utils/getSegmentsFromPath.js +8 -15
- package/dist/utils/getSegmentsFromPath.js.map +7 -0
- package/dist/utils/getSegmentsFromPath.test.js +13 -0
- package/dist/utils/getSegmentsFromPath.test.js.map +7 -0
- package/dist/utils/index.d.ts +26 -26
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +27 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/isFilesystem.d.ts +1 -2
- package/dist/utils/isFilesystem.d.ts.map +1 -1
- package/dist/utils/isFilesystem.js +5 -9
- package/dist/utils/isFilesystem.js.map +7 -0
- package/dist/utils/isJson.js +10 -9
- package/dist/utils/isJson.js.map +7 -0
- package/dist/utils/isObject.js +5 -6
- package/dist/utils/isObject.js.map +7 -0
- package/dist/utils/isObject.test.js +23 -0
- package/dist/utils/isObject.test.js.map +7 -0
- package/dist/utils/isYaml.js +16 -17
- package/dist/utils/isYaml.js.map +7 -0
- package/dist/utils/load/index.d.ts +1 -1
- package/dist/utils/load/index.d.ts.map +1 -1
- package/dist/utils/load/index.js +2 -0
- package/dist/utils/load/index.js.map +7 -0
- package/dist/utils/load/load.d.ts +3 -12
- package/dist/utils/load/load.d.ts.map +1 -1
- package/dist/utils/load/load.js +89 -149
- package/dist/utils/load/load.js.map +7 -0
- package/dist/utils/load/load.test.js +361 -0
- package/dist/utils/load/load.test.js.map +7 -0
- package/dist/utils/makeFilesystem.d.ts +2 -19
- package/dist/utils/makeFilesystem.d.ts.map +1 -1
- package/dist/utils/makeFilesystem.js +20 -68
- package/dist/utils/makeFilesystem.js.map +7 -0
- package/dist/utils/makeFilesystem.test.js +15 -0
- package/dist/utils/makeFilesystem.test.js.map +7 -0
- package/dist/utils/normalize.d.ts +1 -1
- package/dist/utils/normalize.d.ts.map +1 -1
- package/dist/utils/normalize.js +22 -27
- package/dist/utils/normalize.js.map +7 -0
- package/dist/utils/normalize.test.js +88 -0
- package/dist/utils/normalize.test.js.map +7 -0
- package/dist/utils/openapi/actions/details.d.ts +2 -2
- package/dist/utils/openapi/actions/details.d.ts.map +1 -1
- package/dist/utils/openapi/actions/details.js +9 -11
- package/dist/utils/openapi/actions/details.js.map +7 -0
- package/dist/utils/openapi/actions/files.d.ts +1 -1
- package/dist/utils/openapi/actions/files.d.ts.map +1 -1
- package/dist/utils/openapi/actions/files.js +7 -9
- package/dist/utils/openapi/actions/files.js.map +7 -0
- package/dist/utils/openapi/actions/get.d.ts +1 -1
- package/dist/utils/openapi/actions/get.d.ts.map +1 -1
- package/dist/utils/openapi/actions/get.js +9 -11
- package/dist/utils/openapi/actions/get.js.map +7 -0
- package/dist/utils/openapi/actions/toJson.d.ts +1 -1
- package/dist/utils/openapi/actions/toJson.d.ts.map +1 -1
- package/dist/utils/openapi/actions/toJson.js +9 -11
- package/dist/utils/openapi/actions/toJson.js.map +7 -0
- package/dist/utils/openapi/actions/toYaml.d.ts +1 -1
- package/dist/utils/openapi/actions/toYaml.d.ts.map +1 -1
- package/dist/utils/openapi/actions/toYaml.js +9 -11
- package/dist/utils/openapi/actions/toYaml.js.map +7 -0
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts +5 -5
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/dereferenceCommand.js +25 -27
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +7 -0
- package/dist/utils/openapi/commands/filterCommand.d.ts +9 -9
- package/dist/utils/openapi/commands/filterCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/filterCommand.js +24 -26
- package/dist/utils/openapi/commands/filterCommand.js.map +7 -0
- package/dist/utils/openapi/commands/loadCommand.d.ts +1174 -1174
- package/dist/utils/openapi/commands/loadCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/loadCommand.js +40 -42
- package/dist/utils/openapi/commands/loadCommand.js.map +7 -0
- package/dist/utils/openapi/commands/upgradeCommand.d.ts +311 -311
- package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/upgradeCommand.js +27 -29
- package/dist/utils/openapi/commands/upgradeCommand.js.map +7 -0
- package/dist/utils/openapi/commands/validateCommand.d.ts +311 -311
- package/dist/utils/openapi/commands/validateCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/validateCommand.js +31 -33
- package/dist/utils/openapi/commands/validateCommand.js.map +7 -0
- package/dist/utils/openapi/index.d.ts +1 -1
- package/dist/utils/openapi/index.d.ts.map +1 -1
- package/dist/utils/openapi/index.js +2 -0
- package/dist/utils/openapi/index.js.map +7 -0
- package/dist/utils/openapi/openapi.d.ts +700 -700
- package/dist/utils/openapi/openapi.d.ts.map +1 -1
- package/dist/utils/openapi/openapi.js +13 -16
- package/dist/utils/openapi/openapi.js.map +7 -0
- package/dist/utils/openapi/openapi.test-d.js +14 -0
- package/dist/utils/openapi/openapi.test-d.js.map +7 -0
- package/dist/utils/openapi/openapi.test.js +309 -0
- package/dist/utils/openapi/openapi.test.js.map +7 -0
- package/dist/utils/openapi/utils/queueTask.d.ts +1 -1
- package/dist/utils/openapi/utils/queueTask.d.ts.map +1 -1
- package/dist/utils/openapi/utils/queueTask.js +8 -9
- package/dist/utils/openapi/utils/queueTask.js.map +7 -0
- package/dist/utils/openapi/utils/workThroughQueue.d.ts +1 -1
- package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -1
- package/dist/utils/openapi/utils/workThroughQueue.js +49 -64
- package/dist/utils/openapi/utils/workThroughQueue.js.map +7 -0
- package/dist/utils/openapi/utils/workThroughQueue.test.js +244 -0
- package/dist/utils/openapi/utils/workThroughQueue.test.js.map +7 -0
- package/dist/utils/resolveReferences.d.ts +1 -7
- package/dist/utils/resolveReferences.d.ts.map +1 -1
- package/dist/utils/resolveReferences.js +91 -149
- package/dist/utils/resolveReferences.js.map +7 -0
- package/dist/utils/resolveReferences.test.js +567 -0
- package/dist/utils/resolveReferences.test.js.map +7 -0
- package/dist/utils/toJson.d.ts +1 -1
- package/dist/utils/toJson.d.ts.map +1 -1
- package/dist/utils/toJson.js +4 -2
- package/dist/utils/toJson.js.map +7 -0
- package/dist/utils/toYaml.d.ts +1 -1
- package/dist/utils/toYaml.d.ts.map +1 -1
- package/dist/utils/toYaml.js +5 -4
- package/dist/utils/toYaml.js.map +7 -0
- package/dist/utils/transform/index.d.ts +1 -1
- package/dist/utils/transform/index.d.ts.map +1 -1
- package/dist/utils/transform/index.js +2 -0
- package/dist/utils/transform/index.js.map +7 -0
- package/dist/utils/transform/sanitize.d.ts +3 -3
- package/dist/utils/transform/sanitize.d.ts.map +1 -1
- package/dist/utils/transform/sanitize.js +22 -21
- package/dist/utils/transform/sanitize.js.map +7 -0
- package/dist/utils/transform/sanitize.test.js +148 -0
- package/dist/utils/transform/sanitize.test.js.map +7 -0
- package/dist/utils/transform/utils/addInfoObject.d.ts +1 -1
- package/dist/utils/transform/utils/addInfoObject.d.ts.map +1 -1
- package/dist/utils/transform/utils/addInfoObject.js +14 -10
- package/dist/utils/transform/utils/addInfoObject.js.map +7 -0
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts.map +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js +8 -5
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +7 -0
- package/dist/utils/transform/utils/addMissingTags.d.ts +1 -1
- package/dist/utils/transform/utils/addMissingTags.d.ts.map +1 -1
- package/dist/utils/transform/utils/addMissingTags.js +26 -27
- package/dist/utils/transform/utils/addMissingTags.js.map +7 -0
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts.map +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js +36 -40
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +7 -0
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts.map +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js +8 -6
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +7 -0
- package/dist/utils/transformErrors.d.ts +1 -1
- package/dist/utils/transformErrors.d.ts.map +1 -1
- package/dist/utils/transformErrors.js +18 -21
- package/dist/utils/transformErrors.js.map +7 -0
- package/dist/utils/transformErrors.test.js +17 -0
- package/dist/utils/transformErrors.test.js.map +7 -0
- package/dist/utils/traverse.d.ts +1 -1
- package/dist/utils/traverse.d.ts.map +1 -1
- package/dist/utils/traverse.js +19 -22
- package/dist/utils/traverse.js.map +7 -0
- package/dist/utils/traverse.test.js +68 -0
- package/dist/utils/traverse.test.js.map +7 -0
- package/dist/utils/unescapeJsonPointer.js +5 -9
- package/dist/utils/unescapeJsonPointer.js.map +7 -0
- package/dist/utils/unescapeJsonPointer.test.js +19 -0
- package/dist/utils/unescapeJsonPointer.test.js.map +7 -0
- package/dist/utils/upgrade.d.ts +1 -1
- package/dist/utils/upgrade.d.ts.map +1 -1
- package/dist/utils/upgrade.js +22 -22
- package/dist/utils/upgrade.js.map +7 -0
- package/dist/utils/upgrade.test-d.js +16 -0
- package/dist/utils/upgrade.test-d.js.map +7 -0
- package/dist/utils/upgrade.test.js +57 -0
- package/dist/utils/upgrade.test.js.map +7 -0
- package/dist/utils/upgradeFromThreeToThreeOne.js +114 -140
- package/dist/utils/upgradeFromThreeToThreeOne.js.map +7 -0
- package/dist/utils/upgradeFromThreeToThreeOne.test.js +462 -0
- package/dist/utils/upgradeFromThreeToThreeOne.test.js.map +7 -0
- package/dist/utils/upgradeFromTwoToThree.js +212 -219
- package/dist/utils/upgradeFromTwoToThree.js.map +7 -0
- package/dist/utils/upgradeFromTwoToThree.test.js +589 -0
- package/dist/utils/upgradeFromTwoToThree.test.js.map +7 -0
- package/dist/utils/validate.d.ts +1 -1
- package/dist/utils/validate.d.ts.map +1 -1
- package/dist/utils/validate.js +14 -16
- package/dist/utils/validate.js.map +7 -0
- package/dist/utils/validate.test.js +64 -0
- package/dist/utils/validate.test.js.map +7 -0
- package/package.json +6 -8
- package/dist/schemas/v2.0/schema.json.js +0 -1623
- package/dist/schemas/v3.0/schema.json.js +0 -1673
- package/dist/schemas/v3.1/schema.json.js +0 -1451
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @scalar/openapi-parser
|
|
2
2
|
|
|
3
|
+
## 0.10.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8c7bad8: chore: move build tooling to esbuild
|
|
8
|
+
|
|
9
|
+
## 0.10.16
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c5047ee: fix: hotfix to revert the external reference commit
|
|
14
|
+
|
|
3
15
|
## 0.10.15
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -239,33 +239,11 @@ import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
|
|
|
239
239
|
const { filesystem } = await load(
|
|
240
240
|
'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',
|
|
241
241
|
{
|
|
242
|
-
// Optional: If you directly pass an OpenAPI (not an URL), let it know where the content came from
|
|
243
|
-
// That’s the only way we can resolve external references, if they are relative.
|
|
244
|
-
source: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml'
|
|
245
242
|
plugins: [fetchUrls()],
|
|
246
243
|
},
|
|
247
244
|
)
|
|
248
245
|
```
|
|
249
246
|
|
|
250
|
-
#### Bundle external references
|
|
251
|
-
|
|
252
|
-
By default, `dereference` tries to resolve both internal and external references. You can disable resolving internal references by setting `resolveInternalRefs` to `false`:
|
|
253
|
-
|
|
254
|
-
```ts
|
|
255
|
-
import { dereference, load } from '@scalar/openapi-parser'
|
|
256
|
-
import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
|
|
257
|
-
|
|
258
|
-
// Load a file and all referenced files
|
|
259
|
-
const { filesystem } = await load('https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml', {
|
|
260
|
-
plugins: [fetchUrls()],
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
const result = await dereference(filesystem, {
|
|
264
|
-
// Skips internal references like `$ref: '#/components/schemas/foobar'`
|
|
265
|
-
resolveInternalRefs: false,
|
|
266
|
-
})
|
|
267
|
-
```
|
|
268
|
-
|
|
269
247
|
#### Intercept HTTP requests
|
|
270
248
|
|
|
271
249
|
If you’re using the package in a browser environment, you may run into CORS issues when fetching from URLs. You can intercept the requests, for example to use a proxy, though:
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import Swagger20 from
|
|
2
|
-
import OpenApi30 from
|
|
3
|
-
import OpenApi31 from
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A list of the supported OpenAPI specifications
|
|
7
|
-
*/
|
|
1
|
+
import Swagger20 from "../schemas/v2.0/schema.js";
|
|
2
|
+
import OpenApi30 from "../schemas/v3.0/schema.js";
|
|
3
|
+
import OpenApi31 from "../schemas/v3.1/schema.js";
|
|
8
4
|
const OpenApiSpecifications = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
"2.0": Swagger20,
|
|
6
|
+
"3.0": OpenApi30,
|
|
7
|
+
"3.1": OpenApi31
|
|
12
8
|
};
|
|
13
9
|
const OpenApiVersions = Object.keys(OpenApiSpecifications);
|
|
14
|
-
/**
|
|
15
|
-
* List of error messages used in the Validator
|
|
16
|
-
*/
|
|
17
10
|
const ERRORS = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
EMPTY_OR_INVALID: "Can\u2019t find JSON, YAML or filename in data",
|
|
12
|
+
// URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',
|
|
13
|
+
OPENAPI_VERSION_NOT_SUPPORTED: "Can\u2019t find supported Swagger/OpenAPI version in specification, version must be a string.",
|
|
14
|
+
INVALID_REFERENCE: "Can\u2019t resolve reference: %s",
|
|
15
|
+
EXTERNAL_REFERENCE_NOT_FOUND: "Can\u2019t resolve external reference: %s",
|
|
16
|
+
FILE_DOES_NOT_EXIST: "File does not exist: %s",
|
|
17
|
+
NO_CONTENT: "No content found"
|
|
25
18
|
};
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
export {
|
|
20
|
+
ERRORS,
|
|
21
|
+
OpenApiSpecifications,
|
|
22
|
+
OpenApiVersions
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/configuration/index.ts"],
|
|
4
|
+
"sourcesContent": ["import Swagger20 from '../schemas/v2.0/schema'\nimport OpenApi30 from '../schemas/v3.0/schema'\nimport OpenApi31 from '../schemas/v3.1/schema'\n\n/**\n * A list of the supported OpenAPI specifications\n */\nexport const OpenApiSpecifications = {\n '2.0': Swagger20,\n '3.0': OpenApi30,\n '3.1': OpenApi31,\n}\n\nexport type OpenApiVersion = keyof typeof OpenApiSpecifications\n\nexport const OpenApiVersions = Object.keys(OpenApiSpecifications) as OpenApiVersion[]\n\n/**\n * List of error messages used in the Validator\n */\nexport const ERRORS = {\n EMPTY_OR_INVALID: 'Can\u2019t find JSON, YAML or filename in data',\n // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',\n OPENAPI_VERSION_NOT_SUPPORTED:\n 'Can\u2019t find supported Swagger/OpenAPI version in specification, version must be a string.',\n INVALID_REFERENCE: 'Can\u2019t resolve reference: %s',\n EXTERNAL_REFERENCE_NOT_FOUND: 'Can\u2019t resolve external reference: %s',\n FILE_DOES_NOT_EXIST: 'File does not exist: %s',\n NO_CONTENT: 'No content found',\n} as const\n\nexport type ValidationError = keyof typeof ERRORS\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,eAAe;AAKf,MAAM,wBAAwB;AAAA,EACnC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AAIO,MAAM,kBAAkB,OAAO,KAAK,qBAAqB;AAKzD,MAAM,SAAS;AAAA,EACpB,kBAAkB;AAAA;AAAA,EAElB,+BACE;AAAA,EACF,mBAAmB;AAAA,EACnB,8BAA8B;AAAA,EAC9B,qBAAqB;AAAA,EACrB,YAAY;AACd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=declarations.d.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './configuration/index.
|
|
2
|
-
export * from './lib/Validator/index.
|
|
3
|
-
export * from './types/index.
|
|
4
|
-
export * from './utils/index.
|
|
1
|
+
export * from './configuration/index.js';
|
|
2
|
+
export * from './lib/Validator/index.js';
|
|
3
|
+
export * from './types/index.js';
|
|
4
|
+
export * from './utils/index.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
export { escapeJsonPointer } from './utils/escapeJsonPointer.js';
|
|
7
|
-
export { filter } from './utils/filter.js';
|
|
8
|
-
export { getEntrypoint } from './utils/getEntrypoint.js';
|
|
9
|
-
export { getListOfReferences } from './utils/getListOfReferences.js';
|
|
10
|
-
export { getSegmentsFromPath } from './utils/getSegmentsFromPath.js';
|
|
11
|
-
export { isFilesystem } from './utils/isFilesystem.js';
|
|
12
|
-
export { isJson } from './utils/isJson.js';
|
|
13
|
-
export { isObject } from './utils/isObject.js';
|
|
14
|
-
export { isYaml } from './utils/isYaml.js';
|
|
15
|
-
export { load } from './utils/load/load.js';
|
|
16
|
-
export { normalize } from './utils/normalize.js';
|
|
17
|
-
export { openapi } from './utils/openapi/openapi.js';
|
|
18
|
-
export { toJson } from './utils/toJson.js';
|
|
19
|
-
export { toYaml } from './utils/toYaml.js';
|
|
20
|
-
export { transformErrors } from './utils/transformErrors.js';
|
|
21
|
-
export { traverse } from './utils/traverse.js';
|
|
22
|
-
export { unescapeJsonPointer } from './utils/unescapeJsonPointer.js';
|
|
23
|
-
export { upgrade } from './utils/upgrade.js';
|
|
24
|
-
export { isSchemaPath, upgradeFromThreeToThreeOne } from './utils/upgradeFromThreeToThreeOne.js';
|
|
25
|
-
export { upgradeFromTwoToThree } from './utils/upgradeFromTwoToThree.js';
|
|
26
|
-
export { validate } from './utils/validate.js';
|
|
27
|
-
export { DEFAULT_OPENAPI_VERSION } from './utils/transform/utils/addLatestOpenApiVersion.js';
|
|
28
|
-
export { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/transform/utils/addInfoObject.js';
|
|
29
|
-
export { sanitize } from './utils/transform/sanitize.js';
|
|
1
|
+
export * from "./configuration/index.js";
|
|
2
|
+
export * from "./lib/Validator/index.js";
|
|
3
|
+
export * from "./types/index.js";
|
|
4
|
+
export * from "./utils/index.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './configuration/index'\nexport * from './lib/Validator/index'\nexport * from './types/index'\nexport * from './utils/index'\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Ajv04 from 'ajv-draft-04';
|
|
2
2
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
3
|
-
import { type OpenApiVersion } from '../../configuration/index.
|
|
4
|
-
import type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../../types/index.
|
|
3
|
+
import { type OpenApiVersion } from '../../configuration/index.js';
|
|
4
|
+
import type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../../types/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* Configure available JSON Schema versions
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,OAAO,MAAM,kBAAkB,CAAA;AAEtC,OAAO,EAAiC,KAAK,cAAc,EAAmB,MAAM,
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,OAAO,MAAM,kBAAkB,CAAA;AAEtC,OAAO,EAAiC,KAAK,cAAc,EAAmB,MAAM,2BAA2B,CAAA;AAC/G,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAKlG;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;CAG9B,CAAA;AAED,qBAAa,SAAS;IACb,OAAO,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IAErC,OAAc,iBAAiB,4BAAkB;IAGjD,SAAS,CAAC,aAAa,EAAE,MAAM,CAC7B,MAAM,EACN,CAAC,CAAC,aAAa,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG;QACxC,MAAM,EAAE,MAAM,CAAA;KACf,CACF,CAAK;IAEN,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IAExB,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAA;IAEtC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAE5B,aAAa,EAAE,SAAS,CAAA;IAE/B;;OAEG;IACG,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAoF7F;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,cAAc;CA8B9C"}
|
|
@@ -1,128 +1,108 @@
|
|
|
1
|
-
import Ajv04 from
|
|
2
|
-
import addFormats from
|
|
3
|
-
import Ajv2020 from
|
|
4
|
-
import {
|
|
5
|
-
import { details } from
|
|
6
|
-
import { resolveReferences } from
|
|
7
|
-
import { transformErrors } from
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configure available JSON Schema versions
|
|
11
|
-
*/
|
|
1
|
+
import Ajv04 from "ajv-draft-04";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
import Ajv2020 from "ajv/dist/2020.js";
|
|
4
|
+
import { ERRORS, OpenApiSpecifications, OpenApiVersions } from "../../configuration/index.js";
|
|
5
|
+
import { details as getOpenApiVersion } from "../../utils/details.js";
|
|
6
|
+
import { resolveReferences } from "../../utils/resolveReferences.js";
|
|
7
|
+
import { transformErrors } from "../../utils/transformErrors.js";
|
|
12
8
|
const jsonSchemaVersions = {
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
"http://json-schema.org/draft-04/schema#": Ajv04,
|
|
10
|
+
"https://json-schema.org/draft/2020-12/schema": Ajv2020
|
|
15
11
|
};
|
|
16
12
|
class Validator {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
13
|
+
version;
|
|
14
|
+
static supportedVersions = OpenApiVersions;
|
|
15
|
+
// Object with function *or* object { errors: string }
|
|
16
|
+
ajvValidators = {};
|
|
17
|
+
errors;
|
|
18
|
+
specificationVersion;
|
|
19
|
+
specificationType;
|
|
20
|
+
specification;
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether a specification is valid and all references can be resolved.
|
|
23
|
+
*/
|
|
24
|
+
async validate(filesystem, options) {
|
|
25
|
+
const entrypoint = filesystem.find((file) => file.isEntrypoint);
|
|
26
|
+
const specification = entrypoint?.specification;
|
|
27
|
+
this.specification = specification;
|
|
28
|
+
if (this.specification?.info && !this.specification.info.version) {
|
|
29
|
+
this.specification.info.version = "0.0.1";
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
if (specification === void 0 || specification === null) {
|
|
33
|
+
if (options?.throwOnError) {
|
|
34
|
+
throw new Error(ERRORS.EMPTY_OR_INVALID);
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const { version, specificationType, specificationVersion } = details(specification);
|
|
51
|
-
this.version = version;
|
|
52
|
-
this.specificationVersion = specificationVersion;
|
|
53
|
-
this.specificationType = specificationType;
|
|
54
|
-
// AnyObject is not supported
|
|
55
|
-
if (!version) {
|
|
56
|
-
if (options?.throwOnError) {
|
|
57
|
-
throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
valid: false,
|
|
61
|
-
errors: transformErrors(entrypoint, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
// Get the correct OpenAPI validator
|
|
65
|
-
const validateSchema = await this.getAjvValidator(version);
|
|
66
|
-
const schemaResult = validateSchema(specification);
|
|
67
|
-
// Error handling
|
|
68
|
-
if (validateSchema.errors) {
|
|
69
|
-
if (validateSchema.errors.length > 0) {
|
|
70
|
-
if (options?.throwOnError) {
|
|
71
|
-
throw new Error(validateSchema.errors[0]);
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
valid: false,
|
|
75
|
-
errors: transformErrors(entrypoint, validateSchema.errors),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Check if the references are valid
|
|
80
|
-
const resolvedReferences = resolveReferences(filesystem, options);
|
|
81
|
-
return {
|
|
82
|
-
valid: schemaResult && resolvedReferences.valid,
|
|
83
|
-
errors: [...(schemaResult.errors ?? []), ...resolvedReferences.errors],
|
|
84
|
-
schema: resolvedReferences.schema,
|
|
85
|
-
};
|
|
36
|
+
return {
|
|
37
|
+
valid: false,
|
|
38
|
+
errors: transformErrors(entrypoint, ERRORS.EMPTY_OR_INVALID)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const { version, specificationType, specificationVersion } = getOpenApiVersion(specification);
|
|
42
|
+
this.version = version;
|
|
43
|
+
this.specificationVersion = specificationVersion;
|
|
44
|
+
this.specificationType = specificationType;
|
|
45
|
+
if (!version) {
|
|
46
|
+
if (options?.throwOnError) {
|
|
47
|
+
throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED);
|
|
86
48
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
49
|
+
return {
|
|
50
|
+
valid: false,
|
|
51
|
+
errors: transformErrors(entrypoint, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const validateSchema = await this.getAjvValidator(version);
|
|
55
|
+
const schemaResult = validateSchema(specification);
|
|
56
|
+
if (validateSchema.errors) {
|
|
57
|
+
if (validateSchema.errors.length > 0) {
|
|
58
|
+
if (options?.throwOnError) {
|
|
59
|
+
throw new Error(validateSchema.errors[0]);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
valid: false,
|
|
63
|
+
errors: transformErrors(entrypoint, validateSchema.errors)
|
|
64
|
+
};
|
|
96
65
|
}
|
|
66
|
+
}
|
|
67
|
+
const resolvedReferences = resolveReferences(filesystem, options);
|
|
68
|
+
return {
|
|
69
|
+
valid: schemaResult && resolvedReferences.valid,
|
|
70
|
+
errors: [...schemaResult.errors ?? [], ...resolvedReferences.errors],
|
|
71
|
+
schema: resolvedReferences.schema
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (options?.throwOnError) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
valid: false,
|
|
79
|
+
errors: transformErrors(entrypoint, error.message ?? error)
|
|
80
|
+
};
|
|
97
81
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
// Load OpenAPI Schema
|
|
107
|
-
const schema = OpenApiSpecifications[version];
|
|
108
|
-
// Load JSON Schema
|
|
109
|
-
const AjvClass = jsonSchemaVersions[schema.$schema];
|
|
110
|
-
// Get the correct Ajv validator
|
|
111
|
-
const ajv = new AjvClass({
|
|
112
|
-
// Ajv is a bit too strict in its strict validation of OpenAPI schemas.
|
|
113
|
-
// Switch strict mode off.
|
|
114
|
-
strict: false,
|
|
115
|
-
});
|
|
116
|
-
// Register formats
|
|
117
|
-
// https://ajv.js.org/packages/ajv-formats.html#formats
|
|
118
|
-
// @ts-expect-error ajv-formats is not well typed
|
|
119
|
-
addFormats(ajv);
|
|
120
|
-
// OpenAPI 3.1 uses media-range format
|
|
121
|
-
if (version === '3.1') {
|
|
122
|
-
ajv.addFormat('media-range', true);
|
|
123
|
-
}
|
|
124
|
-
return (this.ajvValidators[version] = ajv.compile(schema));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Ajv JSON schema validator
|
|
85
|
+
*/
|
|
86
|
+
async getAjvValidator(version) {
|
|
87
|
+
if (this.ajvValidators[version]) {
|
|
88
|
+
return this.ajvValidators[version];
|
|
125
89
|
}
|
|
90
|
+
const schema = OpenApiSpecifications[version];
|
|
91
|
+
const AjvClass = jsonSchemaVersions[schema.$schema];
|
|
92
|
+
const ajv = new AjvClass({
|
|
93
|
+
// Ajv is a bit too strict in its strict validation of OpenAPI schemas.
|
|
94
|
+
// Switch strict mode off.
|
|
95
|
+
strict: false
|
|
96
|
+
});
|
|
97
|
+
addFormats(ajv);
|
|
98
|
+
if (version === "3.1") {
|
|
99
|
+
ajv.addFormat("media-range", true);
|
|
100
|
+
}
|
|
101
|
+
return this.ajvValidators[version] = ajv.compile(schema);
|
|
102
|
+
}
|
|
126
103
|
}
|
|
127
|
-
|
|
128
|
-
|
|
104
|
+
export {
|
|
105
|
+
Validator,
|
|
106
|
+
jsonSchemaVersions
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=Validator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/Validator/Validator.ts"],
|
|
4
|
+
"sourcesContent": ["import Ajv04 from 'ajv-draft-04'\nimport addFormats from 'ajv-formats'\nimport Ajv2020 from 'ajv/dist/2020.js'\n\nimport { ERRORS, OpenApiSpecifications, type OpenApiVersion, OpenApiVersions } from '../../configuration/index'\nimport type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../../types/index'\nimport { details as getOpenApiVersion } from '../../utils/details'\nimport { resolveReferences } from '../../utils/resolveReferences'\nimport { transformErrors } from '../../utils/transformErrors'\n\n/**\n * Configure available JSON Schema versions\n */\nexport const jsonSchemaVersions = {\n 'http://json-schema.org/draft-04/schema#': Ajv04,\n 'https://json-schema.org/draft/2020-12/schema': Ajv2020,\n}\n\nexport class Validator {\n public version: '2.0' | '3.0' | '3.1'\n\n public static supportedVersions = OpenApiVersions\n\n // Object with function *or* object { errors: string }\n protected ajvValidators: Record<\n string,\n ((specification: AnyObject) => boolean) & {\n errors: string\n }\n > = {}\n\n protected errors: string\n\n protected specificationVersion: string\n\n protected specificationType: string\n\n public specification: AnyObject\n\n /**\n * Checks whether a specification is valid and all references can be resolved.\n */\n async validate(filesystem: Filesystem, options?: ThrowOnErrorOption): Promise<ValidateResult> {\n const entrypoint = filesystem.find((file) => file.isEntrypoint)\n const specification = entrypoint?.specification\n\n // TODO: How does this work with a filesystem?\n this.specification = specification\n\n // TODO: defaulting info.version to keep parser compatible with the previous one\n // we should bubble this error up and not throw on it\n if (this.specification?.info && !this.specification.info.version) {\n this.specification.info.version = '0.0.1'\n }\n\n try {\n // AnyObject is empty or invalid\n if (specification === undefined || specification === null) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.EMPTY_OR_INVALID)\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, ERRORS.EMPTY_OR_INVALID),\n }\n }\n\n // Meta data about the specification\n const { version, specificationType, specificationVersion } = getOpenApiVersion(specification)\n\n this.version = version\n this.specificationVersion = specificationVersion\n this.specificationType = specificationType\n\n // AnyObject is not supported\n if (!version) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED)\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED),\n }\n }\n\n // Get the correct OpenAPI validator\n const validateSchema = await this.getAjvValidator(version)\n const schemaResult = validateSchema(specification)\n\n // Error handling\n if (validateSchema.errors) {\n if (validateSchema.errors.length > 0) {\n if (options?.throwOnError) {\n throw new Error(validateSchema.errors[0])\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, validateSchema.errors),\n }\n }\n }\n\n // Check if the references are valid\n const resolvedReferences = resolveReferences(filesystem, options)\n\n return {\n valid: schemaResult && resolvedReferences.valid,\n errors: [...(schemaResult.errors ?? []), ...resolvedReferences.errors],\n schema: resolvedReferences.schema,\n }\n } catch (error) {\n // Something went horribly wrong!\n if (options?.throwOnError) {\n throw error\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, error.message ?? error),\n }\n }\n }\n\n /**\n * Ajv JSON schema validator\n */\n async getAjvValidator(version: OpenApiVersion) {\n // Schema loaded already\n if (this.ajvValidators[version]) {\n return this.ajvValidators[version]\n }\n\n // Load OpenAPI Schema\n const schema = OpenApiSpecifications[version]\n\n // Load JSON Schema\n const AjvClass = jsonSchemaVersions[schema.$schema]\n\n // Get the correct Ajv validator\n const ajv = new AjvClass({\n // Ajv is a bit too strict in its strict validation of OpenAPI schemas.\n // Switch strict mode off.\n strict: false,\n })\n\n // Register formats\n // https://ajv.js.org/packages/ajv-formats.html#formats\n addFormats(ajv)\n\n // OpenAPI 3.1 uses media-range format\n if (version === '3.1') {\n ajv.addFormat('media-range', true)\n }\n\n return (this.ajvValidators[version] = ajv.compile(schema))\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,OAAO,gBAAgB;AACvB,OAAO,aAAa;AAEpB,SAAS,QAAQ,uBAA4C,uBAAuB;AAEpF,SAAS,WAAW,yBAAyB;AAC7C,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAKzB,MAAM,qBAAqB;AAAA,EAChC,2CAA2C;AAAA,EAC3C,gDAAgD;AAClD;AAEO,MAAM,UAAU;AAAA,EACd;AAAA,EAEP,OAAc,oBAAoB;AAAA;AAAA,EAGxB,gBAKN,CAAC;AAAA,EAEK;AAAA,EAEA;AAAA,EAEA;AAAA,EAEH;AAAA;AAAA;AAAA;AAAA,EAKP,MAAM,SAAS,YAAwB,SAAuD;AAC5F,UAAM,aAAa,WAAW,KAAK,CAAC,SAAS,KAAK,YAAY;AAC9D,UAAM,gBAAgB,YAAY;AAGlC,SAAK,gBAAgB;AAIrB,QAAI,KAAK,eAAe,QAAQ,CAAC,KAAK,cAAc,KAAK,SAAS;AAChE,WAAK,cAAc,KAAK,UAAU;AAAA,IACpC;AAEA,QAAI;AAEF,UAAI,kBAAkB,UAAa,kBAAkB,MAAM;AACzD,YAAI,SAAS,cAAc;AACzB,gBAAM,IAAI,MAAM,OAAO,gBAAgB;AAAA,QACzC;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ,gBAAgB,YAAY,OAAO,gBAAgB;AAAA,QAC7D;AAAA,MACF;AAGA,YAAM,EAAE,SAAS,mBAAmB,qBAAqB,IAAI,kBAAkB,aAAa;AAE5F,WAAK,UAAU;AACf,WAAK,uBAAuB;AAC5B,WAAK,oBAAoB;AAGzB,UAAI,CAAC,SAAS;AACZ,YAAI,SAAS,cAAc;AACzB,gBAAM,IAAI,MAAM,OAAO,6BAA6B;AAAA,QACtD;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ,gBAAgB,YAAY,OAAO,6BAA6B;AAAA,QAC1E;AAAA,MACF;AAGA,YAAM,iBAAiB,MAAM,KAAK,gBAAgB,OAAO;AACzD,YAAM,eAAe,eAAe,aAAa;AAGjD,UAAI,eAAe,QAAQ;AACzB,YAAI,eAAe,OAAO,SAAS,GAAG;AACpC,cAAI,SAAS,cAAc;AACzB,kBAAM,IAAI,MAAM,eAAe,OAAO,CAAC,CAAC;AAAA,UAC1C;AAEA,iBAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ,gBAAgB,YAAY,eAAe,MAAM;AAAA,UAC3D;AAAA,QACF;AAAA,MACF;AAGA,YAAM,qBAAqB,kBAAkB,YAAY,OAAO;AAEhE,aAAO;AAAA,QACL,OAAO,gBAAgB,mBAAmB;AAAA,QAC1C,QAAQ,CAAC,GAAI,aAAa,UAAU,CAAC,GAAI,GAAG,mBAAmB,MAAM;AAAA,QACrE,QAAQ,mBAAmB;AAAA,MAC7B;AAAA,IACF,SAAS,OAAO;AAEd,UAAI,SAAS,cAAc;AACzB,cAAM;AAAA,MACR;AAEA,aAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,gBAAgB,YAAY,MAAM,WAAW,KAAK;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,gBAAgB,SAAyB;AAE7C,QAAI,KAAK,cAAc,OAAO,GAAG;AAC/B,aAAO,KAAK,cAAc,OAAO;AAAA,IACnC;AAGA,UAAM,SAAS,sBAAsB,OAAO;AAG5C,UAAM,WAAW,mBAAmB,OAAO,OAAO;AAGlD,UAAM,MAAM,IAAI,SAAS;AAAA;AAAA;AAAA,MAGvB,QAAQ;AAAA,IACV,CAAC;AAID,eAAW,GAAG;AAGd,QAAI,YAAY,OAAO;AACrB,UAAI,UAAU,eAAe,IAAI;AAAA,IACnC;AAEA,WAAQ,KAAK,cAAc,OAAO,IAAI,IAAI,QAAQ,MAAM;AAAA,EAC1D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Validator } from "./Validator.js";
|
|
3
|
+
describe("Validator", () => {
|
|
4
|
+
it("returns all supported versions", () => {
|
|
5
|
+
expect(Validator.supportedVersions).toMatchObject(["2.0", "3.0", "3.1"]);
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=Validator.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/Validator/Validator.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { Validator } from './Validator'\n\ndescribe('Validator', () => {\n it('returns all supported versions', () => {\n expect(Validator.supportedVersions).toMatchObject(['2.0', '3.0', '3.1'])\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iBAAiB;AAE1B,SAAS,aAAa,MAAM;AAC1B,KAAG,kCAAkC,MAAM;AACzC,WAAO,UAAU,iBAAiB,EAAE,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAAA,EACzE,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './Validator.
|
|
2
|
-
export * from '../../utils/resolveReferences.
|
|
1
|
+
export * from './Validator.js';
|
|
2
|
+
export * from '../../utils/resolveReferences.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,+BAA+B,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LoadPlugin } from '../../utils/load/load.
|
|
1
|
+
import type { LoadPlugin } from '../../utils/load/load.js';
|
|
2
2
|
export declare const fetchUrlsDefaultConfiguration: {
|
|
3
3
|
limit: number;
|
|
4
4
|
};
|
|
@@ -12,5 +12,4 @@ export declare const fetchUrls: (customConfiguration?: {
|
|
|
12
12
|
*/
|
|
13
13
|
fetch?: (url: string) => Promise<Response>;
|
|
14
14
|
}) => LoadPlugin;
|
|
15
|
-
export declare function getAbsoluteUrl(value: string, source?: unknown): string;
|
|
16
15
|
//# sourceMappingURL=fetchUrls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchUrls.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch-urls/fetchUrls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"fetchUrls.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch-urls/fetchUrls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,eAAO,MAAM,6BAA6B;;CAEzC,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,CAAC,mBAAmB,CAAC,EAAE;IAC7C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,KAAK,UA2CL,CAAA"}
|