From f9efa3bb1d1c3a4e10eaac2c9d3d1deaed4cab7d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2020 08:06:30 +0000 Subject: [PATCH 1/3] chore(deps-dev): bump typescript from 3.9.5 to 3.9.6 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.9.5 to 3.9.6. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits) Signed-off-by: dependabot-preview[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 521d8d0..f9b67dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6095,9 +6095,9 @@ } }, "typescript": { - "version": "3.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.5.tgz", - "integrity": "sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==", + "version": "3.9.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.6.tgz", + "integrity": "sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==", "dev": true }, "uglify-js": { From c54d0d5cb3574eae54ee8805fa0e40c9f5853712 Mon Sep 17 00:00:00 2001 From: Zachary Belford Date: Mon, 6 Jul 2020 18:47:07 -0700 Subject: [PATCH 2/3] fix: items cycle with first mutation skip --- src/index.test.ts | 26 ++++++++++++++++++++------ src/index.ts | 13 +++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index b1ccdbc..a9eb832 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -479,20 +479,34 @@ describe("traverse", () => { }); it("When the 2nd schema down is a cycle to its parent, the mutation function is called regardless", () => { - const testSchema: any = { + const testSchema1: any = { title: "skipFirstCycles", type: "object", properties: { skipFirstCycle: {} } }; - testSchema.properties.skipFirstCycle = testSchema; - const mockMutation = jest.fn((mockS) => mockS); - traverse(testSchema, mockMutation, { skipFirstMutation: true }); + const testSchema2: any = { + title: "skipFirstCycles", + type: "object", + items: {} + }; - expect(mockMutation).toHaveBeenCalledWith(testSchema); - expect(mockMutation).toHaveBeenCalledTimes(1); + testSchema1.properties.skipFirstCycle = testSchema1; + testSchema2.items = testSchema2; + + const mockMutation1 = jest.fn((mockS) => mockS); + traverse(testSchema1, mockMutation1, { skipFirstMutation: true }); + + const mockMutation2 = jest.fn((mockS) => mockS); + traverse(testSchema2, mockMutation2, { skipFirstMutation: true }); + + expect(mockMutation1).toHaveBeenCalledWith(testSchema1); + expect(mockMutation1).toHaveBeenCalledTimes(1); + + expect(mockMutation2).toHaveBeenCalledWith(testSchema2); + expect(mockMutation2).toHaveBeenCalledTimes(1); }); }); diff --git a/src/index.ts b/src/index.ts index d10c57a..d682b64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -123,10 +123,15 @@ export default function traverse( } else { const foundCycle = isCycle(schema.items, recursiveStack); if (foundCycle) { - const [, cycledMutableSchema] = prePostMap.find( - ([orig]) => foundCycle === orig, - ) as [JSONMetaSchema, JSONMetaSchema]; - mutableSchema.items = cycledMutableSchema; + if (traverseOptions.skipFirstMutation === true && foundCycle === recursiveStack[0]) { + return mutation(schema.items); + } else { + const [, cycledMutableSchema] = prePostMap.find( + ([orig]) => foundCycle === orig, + ) as [JSONMetaSchema, JSONMetaSchema]; + + mutableSchema.items = cycledMutableSchema; + } } else { itemsIsSingleSchema = true; mutableSchema.items = traverse( From 16fbc05117254211e0044a4dce723ceea564619e Mon Sep 17 00:00:00 2001 From: BelfordZ Date: Tue, 7 Jul 2020 01:54:39 +0000 Subject: [PATCH 3/3] chore(release): 1.2.3 [skip ci] ## [1.2.3](https://github.com/json-schema-tools/traverse/compare/1.2.2...1.2.3) (2020-07-07) ### Bug Fixes * items cycle with first mutation skip ([c54d0d5](https://github.com/json-schema-tools/traverse/commit/c54d0d5cb3574eae54ee8805fa0e40c9f5853712)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1e26a7..94afede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.2.3](https://github.com/json-schema-tools/traverse/compare/1.2.2...1.2.3) (2020-07-07) + + +### Bug Fixes + +* items cycle with first mutation skip ([c54d0d5](https://github.com/json-schema-tools/traverse/commit/c54d0d5cb3574eae54ee8805fa0e40c9f5853712)) + ## [1.2.2](https://github.com/json-schema-tools/traverse/compare/1.2.1...1.2.2) (2020-07-01)