@api-client/core 0.6.13 → 0.6.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/build/browser.d.ts +9 -2
  2. package/build/browser.js +12 -2
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +9 -2
  5. package/build/index.js +12 -2
  6. package/build/index.js.map +1 -1
  7. package/build/src/amf/AmfMixin.d.ts +395 -0
  8. package/build/src/amf/AmfMixin.js +1146 -0
  9. package/build/src/amf/AmfMixin.js.map +1 -0
  10. package/build/src/amf/AmfSerializer.d.ts +136 -0
  11. package/build/src/amf/AmfSerializer.js +1913 -0
  12. package/build/src/amf/AmfSerializer.js.map +1 -0
  13. package/build/src/amf/AmfShapeGenerator.d.ts +85 -0
  14. package/build/src/amf/AmfShapeGenerator.js +385 -0
  15. package/build/src/amf/AmfShapeGenerator.js.map +1 -0
  16. package/build/src/amf/AmfTypes.d.ts +24 -0
  17. package/build/src/amf/AmfTypes.js +122 -0
  18. package/build/src/amf/AmfTypes.js.map +1 -0
  19. package/build/src/amf/ApiExampleGenerator.d.ts +36 -0
  20. package/build/src/amf/ApiExampleGenerator.js +109 -0
  21. package/build/src/amf/ApiExampleGenerator.js.map +1 -0
  22. package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +67 -0
  23. package/build/src/amf/ApiMonacoSchemaGenerator.js +243 -0
  24. package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -0
  25. package/build/src/amf/ApiSchemaGenerator.d.ts +55 -0
  26. package/build/src/amf/ApiSchemaGenerator.js +94 -0
  27. package/build/src/amf/ApiSchemaGenerator.js.map +1 -0
  28. package/build/src/amf/ApiSchemaValues.d.ts +98 -0
  29. package/build/src/amf/ApiSchemaValues.js +382 -0
  30. package/build/src/amf/ApiSchemaValues.js.map +1 -0
  31. package/build/src/amf/Utils.d.ts +41 -0
  32. package/build/src/amf/Utils.js +176 -0
  33. package/build/src/amf/Utils.js.map +1 -0
  34. package/build/src/amf/data-node/DataNodeBase.d.ts +31 -0
  35. package/build/src/amf/data-node/DataNodeBase.js +77 -0
  36. package/build/src/amf/data-node/DataNodeBase.js.map +1 -0
  37. package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +15 -0
  38. package/build/src/amf/data-node/JsonDataNodeGenerator.js +24 -0
  39. package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -0
  40. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +13 -0
  41. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +42 -0
  42. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -0
  43. package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +21 -0
  44. package/build/src/amf/data-node/XmlDataNodeGenerator.js +30 -0
  45. package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -0
  46. package/build/src/amf/definitions/Amf.d.ts +362 -0
  47. package/build/src/amf/definitions/Amf.js +2 -0
  48. package/build/src/amf/definitions/Amf.js.map +1 -0
  49. package/build/src/amf/definitions/Api.d.ts +381 -0
  50. package/build/src/amf/definitions/Api.js +2 -0
  51. package/build/src/amf/definitions/Api.js.map +1 -0
  52. package/build/src/amf/definitions/Base.d.ts +11 -0
  53. package/build/src/amf/definitions/Base.js +2 -0
  54. package/build/src/amf/definitions/Base.js.map +1 -0
  55. package/build/src/amf/definitions/Namespace.d.ts +311 -0
  56. package/build/src/amf/definitions/Namespace.js +330 -0
  57. package/build/src/amf/definitions/Namespace.js.map +1 -0
  58. package/build/src/amf/definitions/Shapes.d.ts +309 -0
  59. package/build/src/amf/definitions/Shapes.js +87 -0
  60. package/build/src/amf/definitions/Shapes.js.map +1 -0
  61. package/build/src/amf/models/AmfDataNode.d.ts +68 -0
  62. package/build/src/amf/models/AmfDataNode.js +188 -0
  63. package/build/src/amf/models/AmfDataNode.js.map +1 -0
  64. package/build/src/amf/shape/ShapeBase.d.ts +75 -0
  65. package/build/src/amf/shape/ShapeBase.js +90 -0
  66. package/build/src/amf/shape/ShapeBase.js.map +1 -0
  67. package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +46 -0
  68. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +406 -0
  69. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -0
  70. package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +84 -0
  71. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +820 -0
  72. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -0
  73. package/build/src/models/Thing.d.ts +17 -0
  74. package/build/src/models/Thing.js +19 -1
  75. package/build/src/models/Thing.js.map +1 -1
  76. package/build/src/models/data/Bindings.d.ts +161 -0
  77. package/build/src/models/data/Bindings.js +2 -0
  78. package/build/src/models/data/Bindings.js.map +1 -0
  79. package/build/src/models/data/DataAssociation.d.ts +135 -14
  80. package/build/src/models/data/DataAssociation.js +154 -21
  81. package/build/src/models/data/DataAssociation.js.map +1 -1
  82. package/build/src/models/data/DataAssociationSchema.d.ts +36 -0
  83. package/build/src/models/data/DataEntity.d.ts +76 -4
  84. package/build/src/models/data/DataEntity.js +136 -9
  85. package/build/src/models/data/DataEntity.js.map +1 -1
  86. package/build/src/models/data/DataFile.d.ts +3 -0
  87. package/build/src/models/data/DataFile.js +3 -0
  88. package/build/src/models/data/DataFile.js.map +1 -1
  89. package/build/src/models/data/DataModel.d.ts +1 -1
  90. package/build/src/models/data/DataModel.js.map +1 -1
  91. package/build/src/models/data/DataNamespace.d.ts +6 -0
  92. package/build/src/models/data/DataNamespace.js +11 -1
  93. package/build/src/models/data/DataNamespace.js.map +1 -1
  94. package/build/src/models/data/DataProperty.d.ts +131 -36
  95. package/build/src/models/data/DataProperty.js +200 -17
  96. package/build/src/models/data/DataProperty.js.map +1 -1
  97. package/data/apis/oas-date/oas-date.yaml +28 -0
  98. package/data/apis/oas-types/oas-types.yaml +159 -0
  99. package/data/apis/oas-unions/oas-unions.yaml +75 -0
  100. package/data/apis/raml-date/raml-date.raml +28 -0
  101. package/data/apis/recursive/recursive.raml +14 -0
  102. package/data/apis/schema-api/examples/person.json +14 -0
  103. package/data/apis/schema-api/examples/person.raml +14 -0
  104. package/data/apis/schema-api/examples/person.url.encoded +1 -0
  105. package/data/apis/schema-api/examples/person.xml +14 -0
  106. package/data/apis/schema-api/library/demo-types.raml +43 -0
  107. package/data/apis/schema-api/schema-api.raml +644 -0
  108. package/data/apis/schema-api/schemas/person.json +104 -0
  109. package/data/apis/schema-api/schemas/person.xsd +26 -0
  110. package/data/apis/schema-api/types/DemoPerson.raml +67 -0
  111. package/data/model.js +106 -0
  112. package/data/models/oas-date.json +637 -0
  113. package/data/models/oas-types.json +5352 -0
  114. package/data/models/oas-unions.json +1881 -0
  115. package/data/models/raml-date.json +1096 -0
  116. package/data/models/recursive.json +610 -0
  117. package/data/models/schema-api.json +37319 -0
  118. package/package.json +9 -6
  119. package/src/amf/AmfMixin.ts +1623 -0
  120. package/src/amf/AmfSerializer.ts +2028 -0
  121. package/src/amf/AmfShapeGenerator.ts +400 -0
  122. package/src/amf/AmfTypes.ts +126 -0
  123. package/src/amf/ApiExampleGenerator.ts +112 -0
  124. package/src/amf/ApiMonacoSchemaGenerator.ts +296 -0
  125. package/src/amf/ApiSchemaGenerator.ts +108 -0
  126. package/src/amf/ApiSchemaValues.ts +411 -0
  127. package/src/amf/Utils.ts +182 -0
  128. package/src/amf/data-node/DataNodeBase.ts +81 -0
  129. package/src/amf/data-node/JsonDataNodeGenerator.ts +26 -0
  130. package/src/amf/data-node/README.md +3 -0
  131. package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +43 -0
  132. package/src/amf/data-node/XmlDataNodeGenerator.ts +38 -0
  133. package/src/amf/definitions/Amf.ts +443 -0
  134. package/src/amf/definitions/Api.ts +427 -0
  135. package/src/amf/definitions/Base.ts +13 -0
  136. package/src/amf/definitions/Namespace.ts +341 -0
  137. package/src/amf/definitions/Shapes.ts +414 -0
  138. package/src/amf/models/AmfDataNode.ts +200 -0
  139. package/src/amf/shape/README.md +4 -0
  140. package/src/amf/shape/ShapeBase.ts +160 -0
  141. package/src/amf/shape/ShapeJsonSchemaGenerator.ts +422 -0
  142. package/src/amf/shape/ShapeXmlSchemaGenerator.ts +876 -0
  143. package/src/models/Thing.ts +25 -1
  144. package/src/models/data/Bindings.ts +186 -0
  145. package/src/models/data/DataAssociation.ts +226 -29
  146. package/src/models/data/DataAssociationSchema.ts +38 -0
  147. package/src/models/data/DataEntity.ts +170 -13
  148. package/src/models/data/DataFile.ts +3 -0
  149. package/src/models/data/DataModel.ts +1 -1
  150. package/src/models/data/DataNamespace.ts +16 -1
  151. package/src/models/data/DataProperty.ts +250 -47
  152. package/build/src/models/data/DataPropertySchema.d.ts +0 -125
  153. package/build/src/models/data/DataPropertySchema.js +0 -33
  154. package/build/src/models/data/DataPropertySchema.js.map +0 -1
  155. package/src/models/data/DataPropertySchema.ts +0 -156
@@ -0,0 +1,104 @@
1
+ {
2
+ "$id": "http://example.com/example.json",
3
+ "type": "object",
4
+ "definitions": {},
5
+ "$schema": "http://json-schema.org/draft-07/schema#",
6
+ "properties": {
7
+ "id": {
8
+ "$id": "/properties/id",
9
+ "type": "string",
10
+ "title": "The Id Schema ",
11
+ "default": "",
12
+ "examples": [
13
+ "R34fg663H9KW9MMSKISI"
14
+ ]
15
+ },
16
+ "name": {
17
+ "$id": "/properties/name",
18
+ "type": "string",
19
+ "title": "The Name Schema ",
20
+ "default": "",
21
+ "examples": [
22
+ "Pawel Psztyc"
23
+ ]
24
+ },
25
+ "birthday": {
26
+ "$id": "/properties/birthday",
27
+ "type": "string",
28
+ "title": "The Birthday Schema ",
29
+ "default": "",
30
+ "examples": [
31
+ "1983-10-20"
32
+ ]
33
+ },
34
+ "gender": {
35
+ "$id": "/properties/gender",
36
+ "type": "string",
37
+ "title": "The Gender Schema ",
38
+ "default": "",
39
+ "examples": [
40
+ "male"
41
+ ]
42
+ },
43
+ "url": {
44
+ "$id": "/properties/url",
45
+ "type": "string",
46
+ "title": "The Url Schema ",
47
+ "default": "",
48
+ "examples": [
49
+ "https://domain.com/profile/pawel.psztyc"
50
+ ]
51
+ },
52
+ "image": {
53
+ "$id": "/properties/image",
54
+ "type": "object",
55
+ "properties": {
56
+ "url": {
57
+ "$id": "/properties/image/properties/url",
58
+ "type": "string",
59
+ "title": "The Url Schema ",
60
+ "default": "",
61
+ "examples": [
62
+ "https://domain.com/profile/pawel.psztyc/image"
63
+ ]
64
+ },
65
+ "thumb": {
66
+ "$id": "/properties/image/properties/thumb",
67
+ "type": "string",
68
+ "title": "The Thumb Schema ",
69
+ "default": "",
70
+ "examples": [
71
+ "https://domain.com/profile/pawel.psztyc/image/thumb"
72
+ ]
73
+ }
74
+ }
75
+ },
76
+ "tagline": {
77
+ "$id": "/properties/tagline",
78
+ "type": "string",
79
+ "title": "The Tagline Schema ",
80
+ "default": "",
81
+ "examples": [
82
+ "Some text about me."
83
+ ]
84
+ },
85
+ "language": {
86
+ "$id": "/properties/language",
87
+ "type": "string",
88
+ "title": "The Language Schema ",
89
+ "default": "",
90
+ "examples": [
91
+ "en_GB"
92
+ ]
93
+ },
94
+ "etag": {
95
+ "$id": "/properties/etag",
96
+ "type": "string",
97
+ "title": "The Etag Schema ",
98
+ "default": "",
99
+ "examples": [
100
+ "W\\244m4n5kj3gbn2nj4k4n4"
101
+ ]
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
3
+ <xs:element name="resource">
4
+ <xs:complexType>
5
+ <xs:sequence>
6
+ <xs:element name="id" type="xs:string"></xs:element>
7
+ <xs:element name="name" type="xs:string"></xs:element>
8
+ <xs:element name="birthday" type="xs:date"></xs:element>
9
+ <xs:element name="gender" type="xs:string"></xs:element>
10
+ <xs:element name="url" type="xs:string"></xs:element>
11
+ <xs:element name="image">
12
+ <xs:complexType>
13
+ <xs:sequence>
14
+ <xs:element name="url" type="xs:string"></xs:element>
15
+ <xs:element name="thumb" type="xs:string"></xs:element>
16
+ </xs:sequence>
17
+ </xs:complexType>
18
+ </xs:element>
19
+ <xs:element name="tagline" type="xs:string"></xs:element>
20
+ <xs:element name="language" type="xs:string"></xs:element>
21
+ </xs:sequence>
22
+ <xs:attribute name="error" type="xs:boolean" use="required"></xs:attribute>
23
+ <xs:attribute name="type" type="xs:string" use="required"></xs:attribute>
24
+ </xs:complexType>
25
+ </xs:element>
26
+ </xs:schema>
@@ -0,0 +1,67 @@
1
+ #%RAML 1.0 DataType
2
+
3
+ displayName: Person
4
+ description: |
5
+ A person but without examples defined inline.
6
+
7
+ type: object
8
+
9
+ properties:
10
+ id:
11
+ xml:
12
+ attribute: true
13
+ description: A unique identifier for a person. It is a 32 bit string containing alphanumeric characters.
14
+ type: string
15
+ example: ad3fd6d4-af89-11eb-8529-0242ac130003
16
+ name:
17
+ required: true
18
+ example: John Smith
19
+ description: Person full name. The input will be rejected if this property is not set while creating new object.
20
+ type: string
21
+ pattern: "[0-9a-zA-Z ]+"
22
+ xml:
23
+ attribute: true
24
+ name: fullname
25
+ birthday:
26
+ type: date-only
27
+ description: The person's date of birth, represented as YYYY-MM-DD.
28
+ examples:
29
+ Example 1: 1983-10-20
30
+ Example 2: 1994-08-29
31
+ gender?:
32
+ type: string
33
+ description: |
34
+ The person's gender. Possible values includes, but are not limited to, the following values:
35
+ * "male" - Male gender.
36
+ * "female" - Female gender.
37
+ * "other" - Other.
38
+ example: male
39
+ url:
40
+ type: string
41
+ description: The URL of this person's profile.
42
+ image:
43
+ type: !include ../resourceTypes/image.raml
44
+ xml:
45
+ wrapped: true
46
+ tagline:
47
+ type: string
48
+ description: The brief description (tagline) of this person.
49
+ language:
50
+ type: string
51
+ description: The user's preferred language for rendering.
52
+ example: "Polish"
53
+ tags:
54
+ description: Tags added to the person.
55
+ type: array
56
+ items:
57
+ properties:
58
+ name:
59
+ type: string
60
+ description: The name of the tag
61
+ example: Manager
62
+ id:
63
+ type: string
64
+ description: Tag's identifier.
65
+ example: ad3fda8a-af89-11eb-8529-0242ac130003
66
+ xml:
67
+ wrapped: false
package/data/model.js ADDED
@@ -0,0 +1,106 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ import pkg from 'amf-client-js';
3
+ import path from 'path';
4
+ import { writeFile, mkdir } from 'fs/promises';
5
+
6
+ /** @typedef {import('amf-client-js').AMFConfiguration} AMFConfiguration */
7
+ /**
8
+ * @typedef ApiConfiguration
9
+ * @property {string} type
10
+ * @property {string=} mime
11
+ */
12
+
13
+ const {
14
+ RAMLConfiguration,
15
+ OASConfiguration,
16
+ AsyncAPIConfiguration,
17
+ RenderOptions,
18
+ PipelineId,
19
+ } = pkg;
20
+
21
+
22
+ /** @type {Map<string, ApiConfiguration>} */
23
+ const config = new Map();
24
+ config.set('schema-api/schema-api.raml', { type: "RAML 1.0" });
25
+ config.set('raml-date/raml-date.raml', { type: "RAML 1.0" });
26
+ config.set('recursive/recursive.raml', { type: "RAML 1.0" });
27
+ config.set('oas-types/oas-types.yaml', { type: "OAS 3.0" });
28
+ config.set('oas-date/oas-date.yaml', { type: "OAS 3.0" });
29
+ config.set('oas-unions/oas-unions.yaml', { type: "OAS 3.0" });
30
+
31
+ const srcFolder = path.join('data', 'apis');
32
+ const descFolder = path.join('data', 'models');
33
+
34
+ class ApiParser {
35
+ /**
36
+ * @param {Map<string, ApiConfiguration>} list
37
+ */
38
+ async batch(list) {
39
+ await mkdir(descFolder, { recursive: true });
40
+ for (const [file, info] of list) {
41
+ console.log('Processing API file', file);
42
+ try {
43
+ // eslint-disable-next-line no-await-in-loop
44
+ await this.run(file, info.type);
45
+ } catch (e) {
46
+ let message;
47
+ if (e.message) {
48
+ message = e.message;
49
+ } else {
50
+ message = e.toString();
51
+ }
52
+ console.error(`Unable to finish: `, message);
53
+ process.exit(1);
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ * @param {string} file
60
+ * @param {string} vendor
61
+ * @returns {Promise<void>}
62
+ */
63
+ async run(file, vendor) {
64
+ let destFile = `${file.substring(0, file.lastIndexOf('.')) }.json`;
65
+ if (destFile.indexOf('/') !== -1) {
66
+ destFile = destFile.substring(destFile.lastIndexOf('/'));
67
+ }
68
+ const location = path.join(srcFolder, file);
69
+ const content = await this.parse(vendor, location);
70
+ const destination = path.join(descFolder, destFile);
71
+ await writeFile(destination, content);
72
+ }
73
+
74
+ /**
75
+ * @param {string} vendor
76
+ * @param {string} location
77
+ * @returns {Promise<string>}
78
+ */
79
+ async parse(vendor, location) {
80
+ const ro = new RenderOptions().withSourceMaps().withCompactUris();
81
+ // const ro = new RenderOptions().withoutAmfJsonLdSerialization().withoutCompactUris().withoutCompactedEmission().withPrettyPrint();
82
+ const apiConfiguration = this.getConfiguration(vendor).withRenderOptions(ro);
83
+ const client = apiConfiguration.baseUnitClient();
84
+ const result = await client.parse(`file://${location}`);
85
+ const transformed = client.transform(result.baseUnit, PipelineId.Editing);
86
+ return client.render(transformed.baseUnit, 'application/ld+json');
87
+ }
88
+
89
+ /**
90
+ * @param {string} vendor
91
+ * @returns {AMFConfiguration}
92
+ */
93
+ getConfiguration(vendor) {
94
+ switch (vendor) {
95
+ case 'RAML 0.8': return RAMLConfiguration.RAML08();
96
+ case 'RAML 1.0': return RAMLConfiguration.RAML10();
97
+ case 'OAS 2.0': return OASConfiguration.OAS20();
98
+ case 'OAS 3.0': return OASConfiguration.OAS30();
99
+ case 'ASYNC 2.0': return AsyncAPIConfiguration.Async20();
100
+ default: throw new Error(`Unknown vendor: ${vendor}`);
101
+ }
102
+ }
103
+ }
104
+
105
+ const parser = new ApiParser();
106
+ parser.batch(config);