Skip to content

Commit

Permalink
fix(ns-openapi-3-1): retain meta & attributes during refracting (#3861)
Browse files Browse the repository at this point in the history
This change is specific to cases when semantic ApiDOM is refractored
from generic ApiDOM.

Refs #3842
  • Loading branch information
char0n authored Feb 24, 2024
1 parent abefa88 commit e960a76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`refractor elements InfoElement given generic ApiDOM element should refract to semantic ApiDOM tree 1`] = `(InfoElement)`;

exports[`refractor elements InfoElement should refract to semantic ApiDOM tree 1`] = `
(InfoElement
(MemberElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { sexprs } from '@swagger-api/apidom-core';
import { assert, expect } from 'chai';
import { ObjectElement, sexprs, toValue } from '@swagger-api/apidom-core';

import { InfoElement } from '../../../../src';

Expand All @@ -19,6 +19,30 @@ describe('refractor', function () {

expect(sexprs(infoElement)).toMatchSnapshot();
});

context('given generic ApiDOM element', function () {
let infoElement: InfoElement;

beforeEach(function () {
infoElement = InfoElement.refract(
new ObjectElement({}, { classes: ['example'] }, { attr: true }),
) as InfoElement;
});

specify('should refract to semantic ApiDOM tree', function () {
expect(sexprs(infoElement)).toMatchSnapshot();
});

specify('should deepmerge meta', function () {
assert.deepEqual(toValue(infoElement.meta), {
classes: ['info', 'example'],
});
});

specify('should deepmerge attributes', function () {
assert.isTrue(infoElement.attributes.get('attr').equals(true));
});
});
});
});
});

0 comments on commit e960a76

Please sign in to comment.