Skip to content

Commit c3da56c

Browse files
committed
fix: fixing the TupleShape serialization
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 59fca6c commit c3da56c

File tree

8 files changed

+182
-10
lines changed

8 files changed

+182
-10
lines changed

apis/APIC-483/APIC-483.raml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#%RAML 1.0
2+
title: Retrieve List of Bank
3+
description: |
4+
Bank Paynet API
5+
mediaType:
6+
- application/json
7+
baseUri: api/bank/prc/{version}
8+
version: v1
9+
10+
/banks:
11+
post:
12+
displayName: Retrieve Bank Paynet
13+
body:
14+
application/json:
15+
type: !include schema/response-retrieve-list-bank.json
16+
example: !include example/list-of-bank-succ.json
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"banks": [{
3+
"id": "BANKAMYKL",
4+
"name": "Bank A",
5+
"status": "A",
6+
"urlList": [
7+
{
8+
"urlType": "RET",
9+
"urlValue": "https://www.bank-a.com.my/retail/checkout/info",
10+
"applicationId": "com.merchanta.app"
11+
},
12+
{
13+
"urlType": "CORP",
14+
"urlValue": "https://www.bank-a.com.my/corp/checkout/info",
15+
"applicationId": "com.merchanta.app"
16+
}
17+
]
18+
},
19+
{
20+
"id": "MERAMYKL",
21+
"name": "Merchant Buffet",
22+
"status": "A",
23+
"urlList": [
24+
{
25+
"urlType": "RET",
26+
"urlValue": "https://www.buffetnotarealurl.com.my/checkout/info",
27+
"applicationId": "com.buffet.app"
28+
}
29+
]
30+
31+
}]
32+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"properties": {
5+
"banks": {
6+
"type": "array",
7+
"items": [
8+
{
9+
"type": "object",
10+
"properties": {
11+
"id": {
12+
"type": "string",
13+
"description":"Bank/Merchant Id (BIC code)",
14+
"maxLength":35
15+
},
16+
"name": {
17+
"type": "string",
18+
"description":"Bank/Merchant Name",
19+
"maxLength":35
20+
},
21+
"status": {
22+
"type": "string",
23+
"description":"Bank/Merchant Active/Inactive Status. Can have one of the values 'A'=Active, or 'I'=Inactive)",
24+
"maxLength":35
25+
},
26+
"urlList": {
27+
"type": "array",
28+
"items": [
29+
{
30+
"type": "object",
31+
"properties": {
32+
"urlType": {
33+
"type": "string",
34+
"description":"URL Type. Used where participant may have more than one Redirect URL. Example Corporate and Retail redirect URL 1)RET= Retail 2)COR= Corporate",
35+
"maxLength":3
36+
},
37+
"urlValue": {
38+
"type": "string",
39+
"description":"URL Value",
40+
"maxLength":140
41+
},
42+
"applicationId": {
43+
"type": "string",
44+
"description":"Bank Application Id",
45+
"maxLength":140
46+
}
47+
},
48+
"required": [
49+
"urlType",
50+
"urlValue"
51+
]
52+
}
53+
]
54+
}
55+
},
56+
"required": [
57+
"id",
58+
"name",
59+
"urlList"
60+
]
61+
}
62+
]
63+
}
64+
},
65+
"required": [
66+
"banks"
67+
]
68+
}

apis/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"oas-3-api/oas-3-api.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1010
"secured-api/secured-api.raml": { "type": "RAML 1.0", "mime": "application/yaml" },
1111
"petstore/petstore.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
12+
"APIC-483/APIC-483.raml": { "type": "RAML 1.0" },
1213
"src": "apis",
1314
"dest": "apis"
1415
}

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

src/AmfSerializer.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
243243
if (types.includes(ns.aml.vocabularies.shapes.SchemaShape)) {
244244
return this.schemaShape(/** @type SchemaShape */ (object));
245245
}
246-
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
247-
return this.arrayShape(/** @type ArrayShape */ (object));
248-
}
246+
// this must be before the ArrayShape
249247
if (types.includes(ns.aml.vocabularies.shapes.TupleShape)) {
250248
return this.tupleShape(/** @type TupleShape */ (object));
251249
}
250+
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
251+
return this.arrayShape(/** @type ArrayShape */ (object));
252+
}
252253
if (types.includes(ns.aml.vocabularies.shapes.RecursiveShape)) {
253254
return this.recursiveShape(/** @type RecursiveShape */ (object));
254255
}
@@ -746,15 +747,26 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
746747
}
747748
}
748749
const items = target[this._getAmfKey(this.ns.aml.vocabularies.shapes.items)];
750+
const prefix = this._getAmfKey(this.ns.w3.rdfSchema.key);
749751
if (Array.isArray(items) && items.length) {
750-
result.items = items.map((shape) => this.unknownShape(shape));
752+
result.items = [];
753+
items.forEach((item) => {
754+
if (Array.isArray(item)) {
755+
// eslint-disable-next-line no-param-reassign
756+
[item] = item;
757+
}
758+
Object.keys(item).filter(k => k.startsWith(prefix)).forEach((key) => {
759+
let shape = item[key];
760+
if (Array.isArray(shape)) {
761+
[shape] = shape;
762+
}
763+
const value = this.unknownShape(shape);
764+
result.items.push(value);
765+
});
766+
});
751767
} else {
752768
result.items = [];
753769
}
754-
// const { items, additionalItems } = target;
755-
// if (!additionalItems.isNull) {
756-
// result.additionalItems = additionalItems.value();
757-
// }
758770
return result;
759771
}
760772

test/serializer/APIC-483.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { assert } from '@open-wc/testing';
2+
import { AmfLoader } from '../AmfLoader.js';
3+
import { AmfSerializer, ns } from '../../index.js';
4+
5+
/** @typedef {import('../../src/amf').Server} Server */
6+
/** @typedef {import('../../src/types').ApiArrayShape} ApiArrayShape */
7+
/** @typedef {import('../../src/types').ApiNodeShape} ApiNodeShape */
8+
/** @typedef {import('../../src/types').ApiUnionShape} ApiUnionShape */
9+
/** @typedef {import('../../src/types').ApiScalarShape} ApiScalarShape */
10+
/** @typedef {import('../../src/types').ApiScalarNode} ApiScalarNode */
11+
/** @typedef {import('../../src/types').ApiFileShape} ApiFileShape */
12+
/** @typedef {import('../../src/types').ApiRecursiveShape} ApiRecursiveShape */
13+
/** @typedef {import('../../src/types').ApiCustomDomainProperty} ApiCustomDomainProperty */
14+
/** @typedef {import('../../src/types').ApiSchemaShape} ApiSchemaShape */
15+
/** @typedef {import('../../src/types').ApiTupleShape} ApiTupleShape */
16+
17+
describe('AmfSerializer', () => {
18+
describe('APIC-483', () => {
19+
const fileName = 'APIC-483';
20+
let api;
21+
/** @type AmfSerializer */
22+
let serializer;
23+
before(async () => {
24+
api = await AmfLoader.load(true, fileName);
25+
serializer = new AmfSerializer();
26+
serializer.amf = api;
27+
});
28+
29+
it('serializes a TupleShape', () => {
30+
const expects = AmfLoader.lookupExpects(api, '/banks', 'post');
31+
const payload = AmfLoader._computePayload(expects)[0];
32+
const shape = payload[serializer._getAmfKey(serializer.ns.aml.vocabularies.shapes.schema)][0];
33+
const result = /** @type ApiNodeShape */ (serializer.unknownShape(shape));
34+
const { examples, properties } = result;
35+
assert.lengthOf(examples, 1, 'has the examples');
36+
assert.lengthOf(properties, 1, 'has the properties');
37+
const array = /** @type ApiTupleShape */ (properties[0].range);
38+
const { types, items } = array;
39+
assert.include(types, ns.aml.vocabularies.shapes.TupleShape, 'range has the TupleShape');
40+
assert.lengthOf(items, 1, 'range has the items');
41+
});
42+
});
43+
});

0 commit comments

Comments
 (0)