Skip to content

Commit 3d01408

Browse files
committed
fix: fixing examples serialization
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 6123e71 commit 3d01408

12 files changed

+491
-64
lines changed

apis/demo-api/demo-api.raml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,12 @@ types:
945945
application/xml:
946946
type: !include schemas/person.xsd
947947
example: !include examples/person.xml
948+
/json:
949+
post:
950+
body:
951+
application/json:
952+
type: !include schemas/person.json
953+
example: !include examples/person.json
948954
/examples:
949955
get:
950956
displayName: Included example
@@ -954,3 +960,65 @@ types:
954960
application/json:
955961
type: object
956962
example: !include examples/person.raml
963+
/body-tracking:
964+
get:
965+
displayName: Common RAML example
966+
description: |
967+
The payload has the same example for both mime types coming from RAML
968+
declaration.
969+
body:
970+
application/json:
971+
type: AppPerson
972+
example: !include examples/person.raml
973+
application/xml:
974+
type: AppPerson
975+
example: !include examples/person.raml
976+
put:
977+
displayName: Different examples
978+
description: |
979+
The payload has different examples for both mime types. Both comming for the corresponding
980+
schema.
981+
body:
982+
application/json:
983+
type: AppPerson
984+
example: !include examples/person.json
985+
application/xml:
986+
type: AppPerson
987+
example: !include examples/person.xml
988+
post:
989+
displayName: Reused examples
990+
description: |
991+
This payload is exactly the same as `put` payload.
992+
This should render how the examples behave when reused.
993+
body:
994+
application/json:
995+
type: AppPerson
996+
example: !include examples/person.json
997+
application/xml:
998+
type: AppPerson
999+
example: !include examples/person.xml
1000+
delete:
1001+
description: |
1002+
This payload has only one mime.
1003+
body:
1004+
application/json:
1005+
type: AppPerson
1006+
example: !include examples/person.json
1007+
patch:
1008+
displayName: No example
1009+
description: |
1010+
This payload has no example at all.
1011+
body:
1012+
application/json:
1013+
type: AppPerson
1014+
/not-shared:
1015+
post:
1016+
body:
1017+
application/json:
1018+
type: object
1019+
properties:
1020+
id: number
1021+
name: string
1022+
example:
1023+
id: 1234567890
1024+
name: Pawel Uchida-Psztyc

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: 2 additions & 2 deletions
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.10",
4+
"version": "4.5.11",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",
@@ -52,7 +52,7 @@
5252
"lint": "npm run lint:eslint",
5353
"format": "npm run format:eslint",
5454
"test": "web-test-runner test/**/*.test.js --coverage --node-resolve --playwright --browsers chromium firefox webkit",
55-
"test:watch": "web-test-runner test/**/*.test.js --node-resolve --watch",
55+
"test:watch": "web-test-runner --node-resolve --watch",
5656
"prepare": "node apis/model.js"
5757
},
5858
"eslintConfig": {

src/AmfSerializer.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ export declare class AmfSerializer extends AmfHelperMixin(Object) {
2626
isLink(object: DomainElement): boolean;
2727
shape(object: Shape): ApiShape;
2828
anyShape(object: AnyShape): ApiAnyShape;
29+
/**
30+
* Filters examples that should be rendered for a payload identified by `payloadId`.
31+
*
32+
* This function is copied from old `api-example-generator/ExampleGenerator`.
33+
*/
34+
filterTrackedExamples(examples: Example[], payloadId: string): Example[];
35+
/**
36+
* Kind of the opposite of the `filterTrackedExamples`. It gathers examples that only have been
37+
* defined for the parent Shape (ed in the type declaration). It filters out all examples
38+
* defined in a payload.
39+
*/
40+
filterNonTrackedExamples(examples: Example[]): Example[];
2941
scalarShape(object: ScalarShape): ApiScalarShape;
3042
/**
3143
* @param object The NodeShape to serialize

0 commit comments

Comments
 (0)