diff --git a/package.json b/package.json index 844c8a0..a4b078e 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "peerDependencies": {}, "dependencies": { "@stoplight/json": "^3.12.0", - "@stoplight/json-schema-merge-allof": "^0.7.8", + "@stoplight/json-schema-merge-allof": "^0.8.0", "@stoplight/lifecycle": "^2.3.2", "@types/json-schema": "^7.0.7", "magic-error": "0.0.1" diff --git a/src/__tests__/tree.spec.ts b/src/__tests__/tree.spec.ts index 4216bad..721cf98 100644 --- a/src/__tests__/tree.spec.ts +++ b/src/__tests__/tree.spec.ts @@ -787,6 +787,61 @@ describe('SchemaTree', () => { ).toEqual('_Everyone_ ~hates~ loves caves'); }); + it('should not override description reference siblings', () => { + const schema = { + $schema: 'http://json-schema.org/draft-07/schema#', + type: 'object', + properties: { + AAAAA: { + allOf: [{ description: 'AAAAA', type: 'string' }, { examples: ['AAAAA'] }], + }, + BBBBB: { + allOf: [ + { + $ref: '#/properties/AAAAA/allOf/0', + description: 'BBBBB', + }, + { examples: ['BBBBB'] }, + ], + }, + }, + }; + + const tree = new SchemaTree(schema, {}); + tree.populate(); + + expect(tree.root).toEqual( + expect.objectContaining({ + children: [ + expect.objectContaining({ + primaryType: 'object', + types: ['object'], + children: [ + expect.objectContaining({ + primaryType: 'string', + subpath: ['properties', 'AAAAA'], + types: ['string'], + annotations: { + description: 'AAAAA', + examples: ['AAAAA'], + }, + }), + expect.objectContaining({ + primaryType: 'string', + subpath: ['properties', 'BBBBB'], + types: ['string'], + annotations: { + description: 'BBBBB', + examples: ['BBBBB'], + }, + }), + ], + }), + ], + }), + ); + }); + it('node of type array should keep its own description even when referenced node has a description', () => { const schema = { definitions: { diff --git a/yarn.lock b/yarn.lock index 0ec7f5f..0a95cbc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -936,10 +936,10 @@ dependencies: eslint-config-prettier "^7.1.0" -"@stoplight/json-schema-merge-allof@^0.7.8": - version "0.7.8" - resolved "https://registry.yarnpkg.com/@stoplight/json-schema-merge-allof/-/json-schema-merge-allof-0.7.8.tgz#7efe5e0086dff433eb011f617e82f7295c3de061" - integrity sha512-JTDt6GYpCWQSb7+UW1P91IAp/pcLWis0mmEzWVFcLsrNgtUYK7JLtYYz0ZPSR4QVL0fJ0YQejM+MPq5iNDFO4g== +"@stoplight/json-schema-merge-allof@^0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@stoplight/json-schema-merge-allof/-/json-schema-merge-allof-0.8.0.tgz#62f8116f59d9df5a910d037b1965decd2efab472" + integrity sha512-g8e0s43v96Xbzvd8d6KKUuJTO16CS2oJglJrviUi8ASIUxzFvAJqTHWLtGmpTryisQopqg1evXGJfi0+164+Qw== dependencies: compute-lcm "^1.1.0" json-schema-compare "^0.2.2"