Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reference): use parent in ancestors lineage #2675

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/apidom-parser-adapter-json/test/adapter-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample-data.json'
describe('adapter-node', function () {
context('given valid JSON', function () {
specify('should detect proper media type', async function () {
assert.isFalse(await adapter.detect('spec'));
assert.isTrue(await adapter.detect('"string"'));
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import stampit from 'stampit';
import { propEq } from 'ramda';
import { isPrimitiveElement, isStringElement, visit, Element } from '@swagger-api/apidom-core';
import {
isPrimitiveElement,
isStringElement,
visit,
Element,
isElement,
} from '@swagger-api/apidom-core';
import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer';
import {
getNodeType,
Expand Down Expand Up @@ -43,7 +49,7 @@ const AsyncApi2DereferenceVisitor = stampit({
* Compute full ancestors lineage.
* Ancestors are flatten to unwrap all Element instances.
*/
const directAncestors = new WeakSet(ancestors.flat());
const directAncestors = new WeakSet(ancestors.filter(isElement));
const ancestorsLineage = [...this.ancestors, directAncestors];

return [ancestorsLineage, directAncestors];
Expand Down Expand Up @@ -90,7 +96,7 @@ const AsyncApi2DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// detect possible cycle in traversal and avoid it
if (ancestorsLineage.some((ancs: WeakSet<Element>) => ancs.has(referencingElement))) {
Expand Down Expand Up @@ -189,7 +195,7 @@ const AsyncApi2DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// ignore ChannelItemElement without $ref field
if (!isStringElement(referencingElement.$ref)) {
Expand Down Expand Up @@ -288,7 +294,7 @@ const AsyncApi2DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage] = this.toAncestorLineage(ancestors);
const [ancestorsLineage] = this.toAncestorLineage([...ancestors, parent]);

// detect possible cycle in traversal and avoid it
if (ancestorsLineage.some((ancs: WeakSet<Element>) => ancs.has(referencingElement))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isStringElement,
visit,
find,
isElement,
} from '@swagger-api/apidom-core';
import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer';
import {
Expand Down Expand Up @@ -90,7 +91,7 @@ const OpenApi3_0DereferenceVisitor = stampit({
* Compute full ancestors lineage.
* Ancestors are flatten to unwrap all Element instances.
*/
const directAncestors = new WeakSet(ancestors.flat());
const directAncestors = new WeakSet(ancestors.filter(isElement));
const ancestorsLineage = [...this.ancestors, directAncestors];

return [ancestorsLineage, directAncestors];
Expand All @@ -103,7 +104,7 @@ const OpenApi3_0DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// detect possible cycle in traversal and avoid it
if (ancestorsLineage.some((ancs: WeakSet<Element>) => ancs.has(referencingElement))) {
Expand Down Expand Up @@ -202,7 +203,7 @@ const OpenApi3_0DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// ignore PathItemElement without $ref field
if (!isStringElement(referencingElement.$ref)) {
Expand Down Expand Up @@ -388,7 +389,7 @@ const OpenApi3_0DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage] = this.toAncestorLineage(ancestors);
const [ancestorsLineage] = this.toAncestorLineage([...ancestors, parent]);

// detect possible cycle in traversal and avoid it
if (ancestorsLineage.some((ancs: WeakSet<Element>) => ancs.has(referencingElement))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
visit,
Element,
find,
isElement,
} from '@swagger-api/apidom-core';
import { evaluate as jsonPointerEvaluate, uriToPointer } from '@swagger-api/apidom-json-pointer';
import {
Expand Down Expand Up @@ -69,7 +70,7 @@ const OpenApi3_1DereferenceVisitor = stampit({
* Compute full ancestors lineage.
* Ancestors are flatten to unwrap all Element instances.
*/
const directAncestors = new WeakSet(ancestors.flat());
const directAncestors = new WeakSet(ancestors.filter(isElement));
const ancestorsLineage = [...this.ancestors, directAncestors];

return [ancestorsLineage, directAncestors];
Expand Down Expand Up @@ -115,7 +116,7 @@ const OpenApi3_1DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// detect possible cycle in traversal and avoid it
if (ancestorsLineage.some((ancs: WeakSet<Element>) => ancs.has(referencingElement))) {
Expand Down Expand Up @@ -224,7 +225,7 @@ const OpenApi3_1DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// ignore PathItemElement without $ref field
if (!isStringElement(referencingElement.$ref)) {
Expand Down Expand Up @@ -410,7 +411,7 @@ const OpenApi3_1DereferenceVisitor = stampit({
path: any,
ancestors: any[],
) {
const [ancestorsLineage, directAncestors] = this.toAncestorLineage(ancestors);
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);

// skip current referencing schema as $ref keyword was not defined
if (!isStringElement(referencingElement.$ref)) {
Expand Down