Skip to content

Commit

Permalink
fix: Upgrade json-ptr to 1.3.1.
Browse files Browse the repository at this point in the history
json-ptr has breaking changes between 1.2.0 and 1.3.x.  :(

fixes #146
  • Loading branch information
jwalton committed Jul 14, 2020
1 parent e79f4ad commit ef038ee
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
5 changes: 0 additions & 5 deletions @types/json-ptr/index.d.ts

This file was deleted.

26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
"typescript": "^3.3.3"
},
"dependencies": {
"ajv": "^6.9.1",
"ajv": "^6.12.2",
"body-parser": "^1.18.3",
"content-type": "^1.0.4",
"deep-freeze": "0.0.1",
"events-listener": "^1.1.0",
"glob": "^7.1.3",
"json-ptr": "^1.1.1",
"json-ptr": "^1.3.1",
"json-schema-ref-parser": "^7.0.0",
"json-schema-traverse": "^0.4.1",
"lodash": "^4.17.11",
Expand Down
13 changes: 9 additions & 4 deletions src/oas3/Oas3CompileContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ExegesisCompiledOptions } from '../options';
* A path to an object within a JSON document.
*/
export type JsonPath = string[];
export type ReadOnlyJsonPath = readonly string[];

/**
* This has common stuff that we want to pass all the way down through the OAS
Expand All @@ -29,17 +30,21 @@ export default class Oas3CompileContext {
* @param path - The path to the object represented by this context.
* @param options - Options.
*/
constructor(openApiDoc: oas3.OpenAPIObject, path: JsonPath, options: ExegesisCompiledOptions);
constructor(parent: Oas3CompileContext, relativePath: JsonPath);
constructor(a: any, path: JsonPath, options?: ExegesisCompiledOptions) {
constructor(
openApiDoc: oas3.OpenAPIObject,
path: ReadOnlyJsonPath,
options: ExegesisCompiledOptions
);
constructor(parent: Oas3CompileContext, relativePath: ReadOnlyJsonPath);
constructor(a: any, path: ReadOnlyJsonPath, options?: ExegesisCompiledOptions) {
if (a instanceof Oas3CompileContext) {
// TODO: Could make this WAY more efficient with Object.create().
const parent = a;
this.path = parent.path.concat(path);
this.openApiDoc = parent.openApiDoc;
this.options = parent.options;
} else if (options) {
this.path = path;
this.path = path.slice();
this.openApiDoc = a;
this.options = options;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/json-schema-resolve-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function resolveRefPriv(document: any, ref: string): any {
throw new Error(`Cannot resolve non-local ref ${ref}`);
}

const path = jsonPtr.decode(ref);
const path = jsonPtr.JsonPointer.decode(ref).slice();
let currentDoc = document;
while (path.length > 0) {
const pathname = path.shift() as string;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/jsonPaths.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as jsonPtr from 'json-ptr';

function normalize(path: string): string {
return jsonPtr.encodePointer(jsonPtr.decode(path));
return jsonPtr.encodePointer(jsonPtr.JsonPointer.decode(path));
}

export function toUriFragment(path: string) {
return jsonPtr.encodeUriFragmentIdentifier(jsonPtr.decode(path));
return jsonPtr.encodeUriFragmentIdentifier(jsonPtr.JsonPointer.decode(path));
}

export function jsonPointerStartsWith(path: string, prefix: string): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function extractSchemaPriv(
// all the `newRefSuffix`es we pick in `ctx.replacements`, and
// then we can make sure this doesn't happen.
const origRef = schema.$ref;
const jsonPath = jsonPtr.decode(schema.$ref);
const jsonPath = jsonPtr.JsonPointer.decode(schema.$ref);
let newRefSuffix: string | undefined =
jsonPath.length > 0 ? jsonPath[jsonPath.length - 1] : undefined;
jsonPath.length > 0 ? `${jsonPath[jsonPath.length - 1]}` : undefined;
while (
!newRefSuffix ||
ctx.result.definitions[newRefSuffix] ||
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function makeContext(
) {
return new Oas3CompileContext(
openApiDoc,
jsonPtr.decode(jsonPointer),
jsonPtr.JsonPointer.decode(jsonPointer).map(x => `${x}`),
Object.assign({}, defaultCompiledOptions, options || {})
);
}
4 changes: 2 additions & 2 deletions test/oas3/oas3ControllersTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ async function findControllerTest(
) {
const context = new FakeExegesisContext();
const openApiDoc = generateOpenApi();
ld.set(openApiDoc, jsonPtr.decode(controllerLocation), 'myController');
ld.set(openApiDoc, jsonPtr.decode(operationLocation), 'op');
ld.set(openApiDoc, jsonPtr.JsonPointer.decode(controllerLocation), 'myController');
ld.set(openApiDoc, jsonPtr.JsonPointer.decode(operationLocation), 'op');

const openApi = new OpenApi(openApiDoc, options);

Expand Down

0 comments on commit ef038ee

Please sign in to comment.