@scalar/openapi-validator 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @scalar/openapi-validator
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10202](https://github.com/scalar/scalar/pull/10202): Explain invalid URI references and OpenAPI component names, and return parser errors for malformed reference escapes.
8
+ - [#10158](https://github.com/scalar/scalar/pull/10158): Add regression coverage for duplicate required property names.
9
+ - [#10136](https://github.com/scalar/scalar/pull/10136): Restore modal and single-file reference tests, update layout selectors, and remove stale comments. Named-resource resolution remains unsupported and is tested explicitly.
10
+
11
+ ## 0.1.1
12
+
3
13
  ## 0.1.0
4
14
 
5
15
  ### Minor Changes
@@ -0,0 +1,8 @@
1
+ import type { AnyObject } from '@scalar/types/utils';
2
+ import type { ErrorObject } from './types.js';
3
+ /**
4
+ * Encoding a URI does not make an invalid OpenAPI component name valid. Keep
5
+ * this guidance in the OpenAPI layer so other JSON Schema users do not see it.
6
+ */
7
+ export declare const explainComponentReferences: (errors: ErrorObject[], specification: AnyObject) => ErrorObject[];
8
+ //# sourceMappingURL=explain-component-references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explain-component-references.d.ts","sourceRoot":"","sources":["../src/explain-component-references.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,WAAW,EAAE,EAAE,eAAe,SAAS,KAAG,WAAW,EAmCpG,CAAA"}
@@ -0,0 +1,34 @@
1
+ import { getValueAtPath } from '@scalar/helpers/object/get-value-at-path';
2
+ /**
3
+ * Encoding a URI does not make an invalid OpenAPI component name valid. Keep
4
+ * this guidance in the OpenAPI layer so other JSON Schema users do not see it.
5
+ */
6
+ export const explainComponentReferences = (errors, specification) => errors.map((error) => {
7
+ if (typeof error.path !== 'string' || !error.path.endsWith('/$ref') || typeof specification.openapi !== 'string') {
8
+ return error;
9
+ }
10
+ // Ajv paths are JSON Pointers, not URI fragments: preserve percent signs.
11
+ const segments = error.path
12
+ .split('/')
13
+ .slice(1)
14
+ .map((segment) => segment.replace(/~1/g, '/').replace(/~0/g, '~'));
15
+ const reference = getValueAtPath(specification, segments);
16
+ if (typeof reference !== 'string' || !reference.startsWith('#')) {
17
+ return error;
18
+ }
19
+ // A malformed escape already has URI guidance; do not guess its target name.
20
+ try {
21
+ // Decode the fragment before splitting: an encoded slash is a separator.
22
+ const component = decodeURIComponent(reference.slice(1)).match(/^\/components\/(?:schemas|responses|parameters|examples|requestBodies|headers|securitySchemes|links|callbacks|pathItems|mediaTypes)\/([^/]*)/)?.[1];
23
+ if (component === undefined || /^[a-zA-Z0-9._-]+$/.test(component)) {
24
+ return error;
25
+ }
26
+ }
27
+ catch {
28
+ return error;
29
+ }
30
+ return {
31
+ ...error,
32
+ message: `${error.message} OpenAPI component names must match "^[a-zA-Z0-9._-]+$". Rename the component and update its references; percent-encoding alone does not fix the component name.`,
33
+ };
34
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAKpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGpE,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG;IACjD;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAeD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,iBAAiB,CAEnG"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAMpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGpE,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG;IACjD;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAgBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,iBAAiB,CAEnG"}
package/dist/validate.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createSpecificationValidator } from '@scalar/json-schema-validator';
2
2
  import { detectVersion } from './detect-version.js';
3
3
  import { ERRORS } from './errors.js';
4
+ import { explainComponentReferences } from './explain-component-references.js';
4
5
  import { OpenApiSpecifications } from './specifications.js';
5
6
  import { validatePathParameters } from './validate-path-parameters.js';
6
7
  const validateDocument = createSpecificationValidator({
@@ -9,6 +10,7 @@ const validateDocument = createSpecificationValidator({
9
10
  // OpenAPI 3.1 and 3.2 use the media-range format.
10
11
  formats: (version) => (version === '3.1' || version === '3.2' ? { 'media-range': true } : undefined),
11
12
  errors: { emptyOrInvalid: ERRORS.EMPTY_OR_INVALID, versionNotSupported: ERRORS.OPENAPI_VERSION_NOT_SUPPORTED },
13
+ transformErrors: explainComponentReferences,
12
14
  // Path-template semantics that the JSON schema cannot express. These need a
13
15
  // fully resolved document (a path parameter can be declared via `$ref`), so
14
16
  // they are opt-in: callers that resolve references first can enable them.
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "validator",
18
18
  "typescript"
19
19
  ],
20
- "version": "0.1.0",
20
+ "version": "0.1.2",
21
21
  "engines": {
22
22
  "node": ">=22"
23
23
  },
@@ -39,9 +39,9 @@
39
39
  "sideEffects": false,
40
40
  "dependencies": {
41
41
  "yaml": "^2.9.0",
42
- "@scalar/types": "0.18.3",
43
- "@scalar/json-schema-validator": "0.1.0",
44
- "@scalar/helpers": "0.11.2"
42
+ "@scalar/json-schema-validator": "0.1.2",
43
+ "@scalar/helpers": "0.12.0",
44
+ "@scalar/types": "0.20.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@tailwindcss/vite": "^4.3.3",
@@ -50,7 +50,7 @@
50
50
  "tailwindcss": "^4.3.3",
51
51
  "vite": "8.1.5",
52
52
  "vue": "^3.5.40",
53
- "@scalar/themes": "0.17.4",
53
+ "@scalar/themes": "0.18.0",
54
54
  "@scalar/use-codemirror": "0.14.15"
55
55
  },
56
56
  "scripts": {