Skip to content

Commit 60d313c

Browse files
committed
fix: fixing mapping type
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent c3da56c commit 60d313c

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
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.7",
4+
"version": "4.5.8",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/AmfSerializer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
13631363
types: object['@type'].map(this[expandKey].bind(this)),
13641364
customDomainProperties: this.customDomainProperties(object),
13651365
sourceMaps: this.sourceMap(object),
1366+
mapping: [],
13661367
});
13671368
const { ns } = this;
13681369
const name = this._getValue(object, ns.aml.vocabularies.core.name);
@@ -1384,12 +1385,14 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
13841385
}
13851386
result.server = this.server(server);
13861387
}
1387-
let mapping = object[this._getAmfKey(ns.aml.vocabularies.apiContract.mapping)];
1388+
let mapping = /** @type IriTemplateMapping[] */ (object[this._getAmfKey(ns.aml.vocabularies.apiContract.mapping)]);
13881389
if (mapping) {
1389-
if (Array.isArray(mapping)) {
1390-
[mapping] = mapping;
1390+
if (mapping && !Array.isArray(mapping)) {
1391+
mapping = [mapping];
1392+
}
1393+
if (mapping) {
1394+
result.mapping = mapping.map(item => this.iriTemplateMapping(item));
13911395
}
1392-
result.mapping = this.iriTemplateMapping(mapping);
13931396
}
13941397
// if (!template.isNullOrEmpty) {
13951398
// result.template = template.value();

src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export interface ApiTemplatedLink extends ApiDomainProperty {
168168
template?: string;
169169
operationId?: string;
170170
requestBody?: string;
171-
mapping?: ApiIriTemplateMapping;
171+
mapping: ApiIriTemplateMapping[];
172172
server?: ApiServer;
173173
sourceMaps?: ApiDocumentSourceMaps;
174174
}

test/serializer/Operations.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ describe('AmfSerializer', () => {
123123
assert.equal(l1.operationId, 'getUserByName', 'l1 has the name');
124124
assert.typeOf(l1.description, 'string', 'l1 has the description');
125125
assert.typeOf(l2.description, 'string', 'l2 has the description');
126-
assert.typeOf(l1.mapping, 'object', 'l1 has the mapping');
127-
assert.typeOf(l2.mapping, 'object', 'l2 has the mapping');
126+
assert.typeOf(l1.mapping, 'array', 'l1 has the mapping');
127+
assert.typeOf(l2.mapping, 'array', 'l2 has the mapping');
128128
const { mapping } = l1;
129-
assert.include(mapping.types, serializer.ns.aml.vocabularies.apiContract.IriTemplateMapping, 'mapping has the type');
130-
assert.equal(mapping.templateVariable, 'username', 'mapping has the templateVariable');
131-
assert.equal(mapping.linkExpression, '$request.body#/username', 'mapping has the linkExpression');
129+
const [mappingItem] = mapping;
130+
assert.include(mappingItem.types, serializer.ns.aml.vocabularies.apiContract.IriTemplateMapping, 'mapping has the type');
131+
assert.equal(mappingItem.templateVariable, 'username', 'mapping has the templateVariable');
132+
assert.equal(mappingItem.linkExpression, '$request.body#/username', 'mapping has the linkExpression');
132133
});
133134

134135

0 commit comments

Comments
 (0)