Skip to content

Commit 4356f5f

Browse files
committed
chore: updating definition of customDomainProperty
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 60d313c commit 4356f5f

File tree

8 files changed

+39
-35
lines changed

8 files changed

+39
-35
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.8",
4+
"version": "4.5.9",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/AmfSerializer.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,16 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
992992
if (Array.isArray(value)) {
993993
[value] = value;
994994
}
995-
const cdp = /** @type ApiCustomDomainProperty */ (this.unknownDataNode(value));
996-
const extensionName = this._getValue(value, this.ns.aml.vocabularies.core.extensionName);
997-
if (extensionName && typeof extensionName === 'string') {
998-
cdp.extensionName = extensionName;
995+
const extension = this.unknownDataNode(value);
996+
const name = this._getValue(value, this.ns.aml.vocabularies.core.extensionName);
997+
if (!name || !extension) {
998+
return;
999999
}
1000+
const cdp = /** @type ApiCustomDomainProperty */ ({
1001+
id: key,
1002+
name,
1003+
extension,
1004+
});
10001005
result.push(cdp);
10011006
});
10021007
}
@@ -1762,8 +1767,8 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
17621767
[sm] = sm;
17631768
}
17641769
const result = /** @type ApiDocumentSourceMaps */ ({
1765-
id: object['@id'],
1766-
types: object['@type'].map(this[expandKey].bind(this)),
1770+
id: sm['@id'],
1771+
types: sm['@type'].map(this[expandKey].bind(this)),
17671772
});
17681773
const sf = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.synthesizedField)];
17691774
if (Array.isArray(sf) && sf.length) {

src/types.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export interface ApiDomainProperty {
5858
customDomainProperties: ApiCustomDomainProperty[];
5959
}
6060

61-
export interface ApiCustomDomainProperty extends ApiDataNode {
62-
extensionName: string;
61+
export interface ApiCustomDomainProperty {
62+
id: string;
63+
name: string;
64+
extension: ApiDataNodeUnion;
6365
}
6466

6567
export type ScalarDataTypes = 'string' | 'base64Binary' | 'boolean' | 'date' | 'dateTime' | 'double' | 'float' | 'integer' | 'long' | 'number' | 'time';

test/serializer/Anotations.test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AmfSerializer } from "../../index.js";
77

88
describe("AmfSerializer", () => {
99
describe("Annotations", () => {
10-
[true, ].forEach((compact) => {
10+
[true, false].forEach((compact) => {
1111
describe(compact ? "Compact model" : "Full model", () => {
1212
let api;
1313
/** @type AmfSerializer */
@@ -26,8 +26,9 @@ describe("AmfSerializer", () => {
2626
assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties');
2727
assert.lengthOf(customDomainProperties, 1, 'has a single annotation');
2828
const [annotation] = customDomainProperties;
29-
assert.equal(annotation.extensionName, 'clearanceLevel', 'has the extensionName');
30-
const { properties } = /** @type ApiObjectNode */ (/** @type unknown */ (annotation));
29+
assert.equal(annotation.name, 'clearanceLevel', 'has the extensionName');
30+
assert.typeOf(annotation.extension, 'object', 'has the extension');
31+
const { properties } = /** @type ApiObjectNode */ (annotation.extension);
3132
assert.typeOf(properties, 'object', 'has properties');
3233
const { level, signature } = properties;
3334
assert.typeOf(level, 'object', 'has the level property');
@@ -42,8 +43,10 @@ describe("AmfSerializer", () => {
4243
assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties');
4344
assert.lengthOf(customDomainProperties, 1, 'has a single annotation');
4445
const [annotation] = customDomainProperties;
45-
assert.equal(annotation.extensionName, 'deprecated', 'has the extensionName');
46-
const { value, dataType, } = /** @type ApiScalarNode */ (/** @type unknown */ (annotation));
46+
assert.equal(annotation.name, 'deprecated', 'has the extensionName');
47+
assert.typeOf(annotation.extension, 'object', 'has the extension');
48+
49+
const { value, dataType, } = /** @type ApiScalarNode */ (annotation.extension);
4750
assert.equal(dataType, 'http://www.w3.org/2001/XMLSchema#string', 'has the dataType');
4851
assert.equal(value, 'This operation is deprecated and will be removed.', 'has the value');
4952
});

test/serializer/Endpoints.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ describe('AmfSerializer', () => {
5959
assert.typeOf(result.customDomainProperties, 'array', 'has the array');
6060
assert.lengthOf(result.customDomainProperties, 1, 'has the annotation');
6161
const [item] = result.customDomainProperties;
62-
assert.include(item.types, serializer.ns.aml.vocabularies.data.Object, 'has the Object type');
63-
assert.equal(item.name, 'object_1', 'has the name');
64-
assert.equal(item.extensionName, 'clearanceLevel', 'has the extensionName');
65-
const typed = /** @type ApiObjectNode */ (/** @type unknown */(item));
62+
assert.equal(item.name, 'clearanceLevel', 'has the name');
63+
const typed = /** @type ApiObjectNode */ (item.extension);
6664
assert.typeOf(typed.properties, 'object', 'has the properties');
6765
assert.lengthOf(Object.keys(typed.properties), 2, 'has all properties');
6866
});

test/serializer/Operations.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,9 @@ describe('AmfSerializer', () => {
238238
assert.typeOf(customDomainProperties, 'array', 'has the security');
239239
assert.lengthOf(customDomainProperties, 1, 'has the defined security');
240240
const [cdp] = customDomainProperties;
241-
assert.include(cdp.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the type');
242-
assert.equal(cdp.name, 'scalar_1', 'has the name');
243-
assert.equal(cdp.extensionName, 'deprecated', 'has the extensionName');
244-
const typed = /** @type ApiScalarNode */ (cdp);
241+
assert.equal(cdp.name, 'deprecated', 'has the name');
242+
const typed = /** @type ApiScalarNode */ (cdp.extension);
243+
assert.include(typed.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the type');
245244
assert.equal(typed.value, 'This operation is deprecated and will be removed.', 'has the value');
246245
assert.equal(typed.dataType, serializer.ns.w3.xmlSchema.string, 'has the dataType');
247246
});
@@ -273,8 +272,8 @@ describe('AmfSerializer', () => {
273272
assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties');
274273
const [cdp] = customDomainProperties;
275274
assert.typeOf(cdp, 'object', 'has the property');
276-
assert.include(cdp.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the type');
277-
assert.equal(cdp.extensionName, 'deprecated', 'has the extensionName');
275+
assert.include(cdp.extension.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the type');
276+
assert.equal(cdp.name, 'deprecated', 'has the extensionName');
278277
});
279278

280279
it('adds query parameters from a trait', () => {

test/serializer/Shapes.test.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,10 @@ describe('AmfSerializer', () => {
171171
assert.lengthOf(cdp, 1, 'has a single property');
172172
const [item] = cdp;
173173
assert.typeOf(item.id, 'string', 'has the id');
174-
assert.include(item.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the Scalar type');
175-
assert.equal(item.name, 'scalar_1', 'has the name');
176-
assert.equal(item.extensionName, 'deprecated', 'has the extensionName');
174+
assert.include(item.extension.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the Scalar type');
175+
assert.equal(item.name, 'deprecated', 'has the extensionName');
177176
// @ts-ignore
178-
assert.typeOf(item.value, 'string', 'has the value');
179-
assert.deepEqual(item.customDomainProperties, [], 'has empty customDomainProperties');
177+
assert.typeOf(item.extension.value, 'string', 'has the value');
180178
});
181179

182180
it('processes a SchemaShape', () => {
@@ -279,11 +277,10 @@ describe('AmfSerializer', () => {
279277
const result = /** @type ApiNodeShape */ (serializer.unknownShape(shape));
280278
assert.lengthOf(result.customDomainProperties, 1, 'has the customDomainProperties');
281279
const [cdp] = result.customDomainProperties;
282-
assert.include(cdp.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the Scalar type');
283-
assert.deepEqual(cdp.customDomainProperties, [], 'has empty customDomainProperties');
284-
assert.equal(cdp.name, 'scalar_1', 'has the name');
285-
assert.equal(cdp.extensionName, 'swagger-router-model', 'has the extensionName');
286-
const typed = /** @type ApiScalarNode */ (cdp);
280+
assert.equal(cdp.name, 'swagger-router-model', 'has the name');
281+
const typed = /** @type ApiScalarNode */ (cdp.extension);
282+
assert.include(typed.types, serializer.ns.aml.vocabularies.data.Scalar, 'has the Scalar type');
283+
assert.deepEqual(typed.customDomainProperties, [], 'has empty customDomainProperties');
287284
assert.equal(typed.dataType, serializer.ns.w3.xmlSchema.string, 'has the dataType');
288285
assert.equal(typed.value, 'io.swagger.petstore.model.Pet', 'has the value');
289286
});

0 commit comments

Comments
 (0)