Skip to content

Commit c0880cd

Browse files
committed
fix: fixing annotations serialization
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 8d1504f commit c0880cd

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/amf-helper-mixin",
33
"description": "A mixin with common functions user by most AMF components to compute AMF values",
4-
"version": "4.5.3",
4+
"version": "4.5.4",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/AmfSerializer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
916916
const result = /** @type ApiObjectNode */ (this.dataNode(object));
917917
result.properties = {};
918918
const prefix = this.ns.aml.vocabularies.data.toString();
919-
const prefixCompact = this._getAmfKey(prefix);
919+
const prefixCompact = `${this._getAmfKey(prefix)}:`;
920920
Object.keys(object).forEach((key) => {
921921
if (key.startsWith(prefix) || key.startsWith(prefixCompact)) {
922922
let value = object[key];
@@ -955,7 +955,7 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
955955
if (Array.isArray(ids) && ids.length) {
956956
ids.forEach((id) => {
957957
const key = `amf://id${id}`;
958-
let value = /** @type DomainElement */ (object[key]);
958+
let value = /** @type DomainElement */ (object[id] || object[key]);
959959
if (!value) {
960960
return;
961961
}

test/serializer/Anotations.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { assert } from "@open-wc/testing";
2+
import { AmfLoader } from "../AmfLoader.js";
3+
import { AmfSerializer } from "../../index.js";
4+
5+
/** @typedef {import('../../src/types').ApiScalarNode} ApiScalarNode */
6+
/** @typedef {import('../../src/types').ApiObjectNode} ApiObjectNode */
7+
8+
describe("AmfSerializer", () => {
9+
describe("Annotations", () => {
10+
[true, ].forEach((compact) => {
11+
describe(compact ? "Compact model" : "Full model", () => {
12+
let api;
13+
/** @type AmfSerializer */
14+
let serializer;
15+
before(async () => {
16+
api = await AmfLoader.load(compact);
17+
serializer = new AmfSerializer();
18+
serializer.amf = api;
19+
});
20+
21+
it("ObjectNode annotations", () => {
22+
const shape = AmfLoader.lookupOperation(api, "/about", "get");
23+
const result = serializer.operation(shape);
24+
assert.typeOf(result, "object", "returns an object");
25+
const { customDomainProperties } = result;
26+
assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties');
27+
assert.lengthOf(customDomainProperties, 1, 'has a single annotation');
28+
const [annotation] = customDomainProperties;
29+
assert.equal(annotation.extensionName, 'clearanceLevel', 'has the extensionName');
30+
const { properties } = /** @type ApiObjectNode */ (/** @type unknown */ (annotation));
31+
assert.typeOf(properties, 'object', 'has properties');
32+
const { level, signature } = properties;
33+
assert.typeOf(level, 'object', 'has the level property');
34+
assert.typeOf(signature, 'object', 'has the level property');
35+
});
36+
37+
it("ScalarShape annotations", () => {
38+
const shape = AmfLoader.lookupOperation(api, "/files", "post");
39+
const result = serializer.operation(shape);
40+
assert.typeOf(result, "object", "returns an object");
41+
const { customDomainProperties } = result;
42+
assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties');
43+
assert.lengthOf(customDomainProperties, 1, 'has a single annotation');
44+
const [annotation] = customDomainProperties;
45+
assert.equal(annotation.extensionName, 'deprecated', 'has the extensionName');
46+
const { value, dataType, } = /** @type ApiScalarNode */ (/** @type unknown */ (annotation));
47+
assert.equal(dataType, 'http://www.w3.org/2001/XMLSchema#string', 'has the dataType');
48+
assert.equal(value, 'This operation is deprecated and will be removed.', 'has the value');
49+
});
50+
});
51+
});
52+
});
53+
});

0 commit comments

Comments
 (0)