diff --git a/packages/apidom-ls/test/fixtures/deref/dereferenced.json b/packages/apidom-ls/test/fixtures/deref/dereferenced.json index 2e878f5017..1aa46a845f 100644 --- a/packages/apidom-ls/test/fixtures/deref/dereferenced.json +++ b/packages/apidom-ls/test/fixtures/deref/dereferenced.json @@ -17,8 +17,8 @@ "userId": { "name": "userId", "in": "query", - "description": "override", - "required": true + "required": true, + "description": "override" }, "indirection1": { "name": "userId", @@ -41,8 +41,8 @@ "externalRef": { "name": "externalParameter", "in": "query", - "description": "another ref", - "required": true + "required": true, + "description": "another ref" } } } diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts index ad5fb6ef0f..d6dbae72c8 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts @@ -1,17 +1,18 @@ import stampit from 'stampit'; -import { hasIn, pathSatisfies, propEq, none } from 'ramda'; -import { isUndefined, isNotUndefined } from 'ramda-adjunct'; +import { propEq, none } from 'ramda'; +import { isUndefined } from 'ramda-adjunct'; import { isElement, isPrimitiveElement, isStringElement, isMemberElement, + isObjectElement, visit, - Element, find, cloneShallow, cloneDeep, toValue, + Element, } from '@swagger-api/apidom-core'; import { evaluate as jsonPointerEvaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { @@ -193,7 +194,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ this.indirections.pop(); const mergeAndAnnotateReferencedElement = (refedElement: T): T => { - const copy = cloneDeep(refedElement); + const copy = cloneShallow(refedElement); // annotate fragment with info about original Reference element copy.setMetaProperty('ref-fields', { @@ -207,16 +208,19 @@ const OpenApi3_1DereferenceVisitor = stampit({ copy.setMetaProperty('ref-origin', reference.uri); // override description and summary (outer has higher priority then inner) - const hasDescription = pathSatisfies(isNotUndefined, ['description'], referencingElement); - const hasSummary = pathSatisfies(isNotUndefined, ['summary'], referencingElement); - - if (hasDescription && hasIn('description', refedElement)) { - // @ts-ignore - copy.description = referencingElement.description; - } - if (hasSummary && hasIn('summary', refedElement)) { - // @ts-ignore - copy.summary = referencingElement.summary; + if (isObjectElement(refedElement)) { + if (referencingElement.hasKey('description') && 'description' in refedElement) { + // @ts-ignore + copy.remove('description'); + // @ts-ignore + copy.set('description', referencingElement.get('description')); + } + if (referencingElement.hasKey('summary') && 'summary' in refedElement) { + // @ts-ignore + copy.remove('summary'); + // @ts-ignore + copy.set('summary', referencingElement.get('summary')); + } } return copy; diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/fixtures/cycle-internal/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/fixtures/cycle-internal/root.json index badb77703d..78cef3dfef 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/fixtures/cycle-internal/root.json +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/fixtures/cycle-internal/root.json @@ -1,12 +1,12 @@ { "openapi": "3.1.0", "components": { - "schemas": { - "User": { - "type": "object", - "properties": { - "parent": { - "$ref": "#/components/schemas/User" + "parameters": { + "param1": { + "examples": { + "example1": { + "$ref": "#/components/parameters/param1", + "description": "test" } } } diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts index a2d2ddde9a..3cf9167b93 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts @@ -152,9 +152,9 @@ describe('dereference', function () { const dereferenced = await dereference(rootFilePath, { parse: { mediaType: mediaTypes.latest('json') }, }); - const parent = evaluate('/0/components/schemas/User/properties/parent', dereferenced); + const parent = evaluate('/0/components/parameters/param1/examples', dereferenced); const cyclicParent = evaluate( - '/0/components/schemas/User/properties/parent/properties/parent', + '/0/components/parameters/param1/examples/example1/examples', dereferenced, );