Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit f264f1f

Browse files
committed
fix(oas2): include fixedType for arrays with items
1 parent 9c9ffc9 commit f264f1f

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

packages/openapi2-parser/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
- The parser will now produce a data structure for Schema Object's which do not
88
contain a `type`.
99

10+
- Added the `fixedType` attribute to array data structures which describe
11+
arrays with fixed types in the items. For example, the following schema which
12+
describes an array where the values MUST be of type string:
13+
14+
```yaml
15+
type: array
16+
items:
17+
type: string
18+
```
19+
20+
Previously we generated a data structure for an array which didn't fix the
21+
values of the array to be a string type. Instead provided an example that the
22+
value of the array MAY be a string.
23+
1024
## 0.30.0 (2020-04-29)
1125
1226
The package has been renamed to `@apielements/openapi2-parser`.

packages/openapi2-parser/lib/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class DataStructureGenerator {
120120
const element = new ArrayElement();
121121

122122
if (schema.items) {
123+
element.attributes.set('typeAttributes', ['fixedType']);
124+
123125
if (_.isArray(schema.items)) {
124126
schema.items.forEach((item) => {
125127
const itemElement = this.generateElement(item);

packages/openapi2-parser/test/fixtures/json-body-generation-array-object.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@
208208
"element": "dataStructure",
209209
"content": {
210210
"element": "array",
211+
"attributes": {
212+
"typeAttributes": {
213+
"element": "array",
214+
"content": [
215+
{
216+
"element": "string",
217+
"content": "fixedType"
218+
}
219+
]
220+
}
221+
},
211222
"content": [
212223
{
213224
"element": "definitions/Question"
@@ -330,6 +341,17 @@
330341
},
331342
"value": {
332343
"element": "array",
344+
"attributes": {
345+
"typeAttributes": {
346+
"element": "array",
347+
"content": [
348+
{
349+
"element": "string",
350+
"content": "fixedType"
351+
}
352+
]
353+
}
354+
},
333355
"content": [
334356
{
335357
"element": "definitions/Choice"

packages/openapi2-parser/test/schema-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ describe('JSON Schema to Data Structure', () => {
702702
const dataStructure = schemaToDataStructure(schema);
703703

704704
expect(dataStructure.element).to.equal('dataStructure');
705-
expect(dataStructure.content).to.be.instanceof(ArrayElement);
705+
expect(dataStructure.content.attributes.getValue('typeAttributes')).to.deep.equal(['fixedType']);
706706
expect(dataStructure.content.get(0).element).to.equal('string');
707707
});
708708

packages/swagger-zoo/fixtures/features/api-elements/recursion.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@
282282
"content": "A list of categories"
283283
}
284284
},
285+
"attributes": {
286+
"typeAttributes": {
287+
"element": "array",
288+
"content": [
289+
{
290+
"element": "string",
291+
"content": "fixedType"
292+
}
293+
]
294+
}
295+
},
285296
"content": [
286297
{
287298
"element": "definitions/category"

packages/swagger-zoo/fixtures/features/api-elements/recursion.sourcemap.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,17 @@
653653
"content": "A list of categories"
654654
}
655655
},
656+
"attributes": {
657+
"typeAttributes": {
658+
"element": "array",
659+
"content": [
660+
{
661+
"element": "string",
662+
"content": "fixedType"
663+
}
664+
]
665+
}
666+
},
656667
"content": [
657668
{
658669
"element": "definitions/category"

0 commit comments

Comments
 (0)