Skip to content

Commit 9499aa8

Browse files
authored
fix(ns-openapi-3-1): use spec compliant JSON Pointer implementation (#4880)
Refs #4870
1 parent 8313d9b commit 9499aa8

File tree

21 files changed

+132
-37
lines changed

21 files changed

+132
-37
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/apidom-json-path/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@babel/runtime-corejs3": "^7.26.10",
4141
"@swagger-api/apidom-core": "^1.0.0-beta.33",
4242
"@swagger-api/apidom-error": "^1.0.0-beta.33",
43-
"@swaggerexpert/json-pointer": "^2.9.0",
43+
"@swagger-api/apidom-json-pointer": "^1.0.0-beta.33",
4444
"jsonpath-plus": "^10.0.6"
4545
},
4646
"files": [

packages/apidom-json-path/src/evaluate-multi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JSONPath } from 'jsonpath-plus';
2-
import { evaluate as jsonPointerEvaluate } from '@swaggerexpert/json-pointer/evaluate/realms/apidom';
2+
import { evaluate as jsonPointerEvaluate } from '@swagger-api/apidom-json-pointer/modern';
33
import { Element, toValue, cloneDeep } from '@swagger-api/apidom-core';
44

55
import MultiEvaluationJsonPathError from './errors/MultiEvaluationJsonPathError.ts';

packages/apidom-json-path/src/evaluate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JSONPath } from 'jsonpath-plus';
2-
import { evaluate as jsonPointerEvaluate } from '@swaggerexpert/json-pointer/evaluate/realms/apidom';
2+
import { evaluate as jsonPointerEvaluate } from '@swagger-api/apidom-json-pointer/modern';
33
import { Element, toValue, cloneDeep } from '@swagger-api/apidom-core';
44

55
import EvaluationJsonPathError from './errors/EvaluationJsonPathError.ts';

packages/apidom-json-pointer/README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,37 @@ You can install this package via [npm CLI](https://docs.npmjs.com/cli) by runnin
99
```sh
1010
$ npm install @swagger-api/apidom-json-pointer
1111
```
12-
## Evaluating
12+
13+
## Modern API
14+
15+
This is the recommended API for use in new projects. It is fully compliant with [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901) and supports all aspects of JSON Pointer.
16+
Uses [@swaggerexpert/json-pointer](https://www.npmjs.com/package/@swaggerexpert/json-pointer) under the hood and fully reflects its API.
17+
18+
Evaluation is contextual to [ApiDOM realm](https://github.com/swaggerexpert/json-pointer?tab=readme-ov-file#apidom-evaluation-realm) - meaning `evaluate` function
19+
expects only ApiDOM as the first argument.
20+
21+
```js
22+
import { evaluate } from '@swagger-api/apidom-json-pointer/modern';
23+
```
24+
25+
26+
27+
## Legacy API
28+
29+
This is a legacy API not recommended for use in new projects. It is provided for backward compatibility only.
30+
The legacy API implementation is not RFC 6901 compliant, nor does it support all features of JSON Pointer.
31+
32+
Importing legacy API from `@swagger-api/apidom-json-pointer` is equivalent to importing from `@swagger-api/apidom-json-pointer/legacy`.
33+
34+
```js
35+
import { evaluate } from '@swagger-api/apidom-json-pointer';
36+
```
37+
or
38+
```js
39+
import { evaluate } from '@swagger-api/apidom-json-pointer/legacy';
40+
```
41+
42+
### Evaluating
1343

1444
```js
1545
import { ObjectElement } from '@swagger-api/apidom-core';
@@ -20,7 +50,7 @@ const result = evaluate('/a/b', apidom);
2050
// => StringElement('c')
2151
```
2252

23-
## Parsing
53+
### Parsing
2454

2555
Parses JSON Pointer into list of tokens.
2656

@@ -30,7 +60,7 @@ import { parse } from '@swagger-api/apidom-json-pointer';
3060
const tokens = parse('/a/b'); // => ['a', 'b']
3161
```
3262

33-
## Compiling
63+
### Compiling
3464

3565
Compiles list of tokens into JSON Pointer.
3666

@@ -40,7 +70,7 @@ import { compile } from '@swagger-api/apidom-json-pointer';
4070
const jsonPointer = compile(['a', 'b']); // => '/a/b'
4171
```
4272

43-
## Escaping
73+
### Escaping
4474

4575
Escapes/unescapes tokens of JSON Pointer.
4676

@@ -51,7 +81,7 @@ escape('~a/'); // => '~0a~1'
5181
unescape('~0a~1'); // => '~a/'
5282
```
5383

54-
## Transforming URI to JSON Pointer
84+
### Transforming URI to JSON Pointer
5585

5686
Handles case of [URI Fragment Identifier Representation](https://datatracker.ietf.org/doc/html/rfc6901#section-6).
5787

@@ -61,7 +91,7 @@ import { uriToPointer } from '@swagger-api/apidom-json-pointer';
6191
uriToPointer('https://example.com/path/#/a/b'); // => '/a/b'
6292
```
6393

64-
## Invalid JSON Pointers
94+
### Invalid JSON Pointers
6595

6696
If invalid JSON Pointer is supplied to `parse` or `evaluate` functions, `InvalidJsonPointerError`
6797
is thrown.
@@ -76,3 +106,4 @@ ApiDOM fragment, `EvaluationJsonPointerError` is thrown.
76106
```js
77107
import { EvaluationJsonPointerError } from '@swagger-api/apidom-json-pointer';
78108
```
109+

packages/apidom-json-pointer/package.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@
99
"type": "module",
1010
"sideEffects": false,
1111
"unpkg": "./dist/apidom-json-pointer.browser.min.js",
12-
"main": "./src/index.cjs",
12+
"main": "./src/legacy/index.cjs",
1313
"exports": {
14-
"types": "./types/apidom-json-pointer.d.ts",
15-
"import": "./src/index.mjs",
16-
"require": "./src/index.cjs"
14+
".": {
15+
"types": "./types/legacy/index.d.ts",
16+
"import": "./src/legacy/index.mjs",
17+
"require": "./src/legacy/index.cjs"
18+
},
19+
"./legacy": {
20+
"types": "./types/legacy/index.d.ts",
21+
"import": "./src/legacy/index.mjs",
22+
"require": "./src/legacy/index.cjs"
23+
},
24+
"./modern": {
25+
"types": "./types/apidom-json-pointer.d.ts",
26+
"import": "./src/index.mjs",
27+
"require": "./src/index.cjs"
28+
}
1729
},
18-
"types": "./types/apidom-json-pointer.d.ts",
30+
"types": "./types/legacy/index.d.ts",
1931
"scripts": {
2032
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
2133
"build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
@@ -40,7 +52,7 @@
4052
"@babel/runtime-corejs3": "^7.26.10",
4153
"@swagger-api/apidom-core": "^1.0.0-beta.33",
4254
"@swagger-api/apidom-error": "^1.0.0-beta.33",
43-
"@swaggerexpert/json-pointer": "^2.9.0"
55+
"@swaggerexpert/json-pointer": "^2.10.1"
4456
},
4557
"files": [
4658
"src/**/*.mjs",
Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1-
export { default as JsonPointerError } from './errors/JsonPointerError.ts';
2-
export { default as InvalidJsonPointerError } from './errors/InvalidJsonPointerError.ts';
3-
export type { InvalidJsonPointerErrorOptions } from './errors/InvalidJsonPointerError.ts';
4-
export { default as CompilationJsonPointerError } from './errors/CompilationJsonPointerError.ts';
5-
export type { CompilationJsonPointerErrorOptions } from './errors/CompilationJsonPointerError.ts';
6-
export { default as EvaluationJsonPointerError } from './errors/EvaluationJsonPointerError.ts';
7-
export type { EvaluationJsonPointerErrorOptions } from './errors/EvaluationJsonPointerError.ts';
8-
export { default as parse, uriToPointer } from './parse.ts';
9-
export { default as evaluate } from './evaluate.ts';
10-
export { default as escape } from './escape.ts';
11-
export { default as unescape } from './unescape.ts';
12-
export { default as compile } from './compile.ts';
1+
export {
2+
/**
3+
* Representation
4+
*/
5+
JSONString,
6+
URIFragmentIdentifier,
7+
/**
8+
* Parsing
9+
*/
10+
parse,
11+
CSTTranslator,
12+
ASTTranslator,
13+
XMLTranslator,
14+
/**
15+
* Compiling
16+
*/
17+
compile,
18+
/**
19+
* Escaping
20+
*/
21+
escape,
22+
unescape,
23+
/**
24+
* Errors
25+
*/
26+
JSONPointerError,
27+
JSONPointerParseError,
28+
JSONPointerCompileError,
29+
JSONPointerEvaluateError,
30+
JSONPointerTypeError,
31+
JSONPointerKeyError,
32+
JSONPointerIndexError,
33+
} from '@swaggerexpert/json-pointer';
34+
/**
35+
* Evaluation
36+
*/
37+
export { evaluate } from '@swaggerexpert/json-pointer/evaluate/realms/apidom';
38+
export type * from '@swaggerexpert/json-pointer';

packages/apidom-json-pointer/src/compile.ts renamed to packages/apidom-json-pointer/src/legacy/compile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CompilationJsonPointerError from './errors/CompilationJsonPointerError.ts
88

99
/**
1010
* @public
11+
* @deprecated
1112
*/
1213
const compile = (tokens: string[]): string => {
1314
try {

packages/apidom-json-pointer/src/errors/CompilationJsonPointerError.ts renamed to packages/apidom-json-pointer/src/legacy/errors/CompilationJsonPointerError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import JsonPointerError from './JsonPointerError.ts';
44

55
/**
66
* @public
7+
* @deprecated
78
*/
89
export interface CompilationJsonPointerErrorOptions extends ApiDOMErrorOptions {
910
readonly tokens: string[];
1011
}
1112

1213
/**
1314
* @public
15+
* @deprecated
1416
*/
1517
class CompilationJsonPointerError extends JsonPointerError {
1618
public readonly tokens!: string[];

packages/apidom-json-pointer/src/errors/EvaluationJsonPointerError.ts renamed to packages/apidom-json-pointer/src/legacy/errors/EvaluationJsonPointerError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import JsonPointerError from './JsonPointerError.ts';
55

66
/**
77
* @public
8+
* @deprecated
89
*/
910
export interface EvaluationJsonPointerErrorOptions<T extends Element> extends ApiDOMErrorOptions {
1011
readonly pointer: string;
@@ -16,6 +17,7 @@ export interface EvaluationJsonPointerErrorOptions<T extends Element> extends Ap
1617

1718
/**
1819
* @public
20+
* @deprecated
1921
*/
2022
class EvaluationJsonPointerError<T extends Element> extends JsonPointerError {
2123
public readonly pointer!: string;

packages/apidom-json-pointer/src/errors/InvalidJsonPointerError.ts renamed to packages/apidom-json-pointer/src/legacy/errors/InvalidJsonPointerError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import JsonPointerError from './JsonPointerError.ts';
44

55
/**
66
* @public
7+
* @deprecated
78
*/
89
export interface InvalidJsonPointerErrorOptions extends ApiDOMErrorOptions {
910
readonly pointer: string;
1011
}
1112

1213
/**
1314
* @public
15+
* @deprecated
1416
*/
1517
class InvalidJsonPointerError extends JsonPointerError {
1618
public readonly pointer!: string;

packages/apidom-json-pointer/src/errors/JsonPointerError.ts renamed to packages/apidom-json-pointer/src/legacy/errors/JsonPointerError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ApiDOMStructuredError } from '@swagger-api/apidom-error';
22

33
/**
44
* @public
5+
* @deprecated
56
*/
67
class JsonPointerError extends ApiDOMStructuredError {}
78

packages/apidom-json-pointer/src/escape.ts renamed to packages/apidom-json-pointer/src/legacy/escape.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { escape as baseEscape, URIFragmentIdentifier } from '@swaggerexpert/json
22

33
/**
44
* @public
5+
* @deprecated
56
*/
67
const escape = (referenceToken: string): string => {
78
return URIFragmentIdentifier.to(baseEscape(referenceToken)).slice(1);

packages/apidom-json-pointer/src/evaluate.ts renamed to packages/apidom-json-pointer/src/legacy/evaluate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import EvaluationJsonPointerError from './errors/EvaluationJsonPointerError.ts';
77
/**
88
* Evaluates JSON Pointer against ApiDOM fragment.
99
* @public
10+
* @deprecated
1011
*/
1112
const evaluate = <T extends Element>(pointer: string, element: T): Element => {
1213
try {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export { default as JsonPointerError } from './errors/JsonPointerError.ts';
2+
export { default as InvalidJsonPointerError } from './errors/InvalidJsonPointerError.ts';
3+
export type { InvalidJsonPointerErrorOptions } from './errors/InvalidJsonPointerError.ts';
4+
export { default as CompilationJsonPointerError } from './errors/CompilationJsonPointerError.ts';
5+
export type { CompilationJsonPointerErrorOptions } from './errors/CompilationJsonPointerError.ts';
6+
export { default as EvaluationJsonPointerError } from './errors/EvaluationJsonPointerError.ts';
7+
export type { EvaluationJsonPointerErrorOptions } from './errors/EvaluationJsonPointerError.ts';
8+
export { default as parse, uriToPointer } from './parse.ts';
9+
export { default as evaluate } from './evaluate.ts';
10+
export { default as escape } from './escape.ts';
11+
export { default as unescape } from './unescape.ts';
12+
export { default as compile } from './compile.ts';

packages/apidom-json-pointer/src/parse.ts renamed to packages/apidom-json-pointer/src/legacy/parse.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66

77
/**
88
* @public
9+
* @deprecated
910
*/
1011
const parse = (pointer: string, options?: ParseOptions): string[] => {
1112
const { tree } = jsonPointerParse(URIFragmentIdentifier.from(pointer), options);
@@ -26,6 +27,7 @@ const getHash = (uri: string): string => {
2627

2728
/**
2829
* @public
30+
* @deprecated
2931
*/
3032
export const uriToPointer = (uri: string): string => {
3133
const hash = getHash(uri);

packages/apidom-json-pointer/src/unescape.ts renamed to packages/apidom-json-pointer/src/legacy/unescape.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { unescape as baseUnescape, URIFragmentIdentifier } from '@swaggerexpert/
22

33
/**
44
* @public
5+
* @deprecated
56
*/
67
const unescape = (referenceToken: string): string => {
78
return URIFragmentIdentifier.from(baseUnescape(referenceToken));

packages/apidom-json-pointer/test/evaluate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert } from 'chai';
22
import { ObjectElement, ArrayElement, StringElement } from '@swagger-api/apidom-core';
33

4-
import { evaluate, uriToPointer, EvaluationJsonPointerError } from '../src/index.ts';
4+
import { evaluate, uriToPointer, EvaluationJsonPointerError } from '../src/legacy/index.ts';
55

66
describe('apidom-json-pointer', function () {
77
context('RFC 6901 test', function () {

packages/apidom-ns-openapi-3-1/src/refractor/toolbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
includesClasses,
1313
hasElementSourceMap,
1414
} from '@swagger-api/apidom-core';
15-
import { compile as compileJSONPointerTokens } from '@swagger-api/apidom-json-pointer';
15+
import { compile as compileJSONPointerTokens } from '@swagger-api/apidom-json-pointer/modern';
1616
import { isServersElement } from '@swagger-api/apidom-ns-openapi-3-0';
1717

1818
import * as openApi3_1Predicates from '../predicates.ts';

packages/apidom-ns-openapi-3-1/test/refractor/plugins/normalize-parameters/callbacks/__snapshots__/index.mjs.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ exports[`refractor plugins normalize-parameters given parameters are defined in
10141014
"content": [
10151015
{
10161016
"element": "string",
1017-
"content": "/paths/~1/get/callbacks/myCallback/%7B$url%7D/get"
1017+
"content": "/paths/~1/get/callbacks/myCallback/{$url}/get"
10181018
},
10191019
{
10201020
"element": "string",

packages/apidom-ns-openapi-3-1/test/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"module": "esnext",
5-
"moduleResolution": "node"
4+
"module": "nodenext",
5+
"moduleResolution": "nodenext",
6+
"skipLibCheck": true
67
},
78
"include": [
89
"."

0 commit comments

Comments
 (0)