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

Commit ea04032

Browse files
authored
Allow circular references in allOf (#322)
Allow circular references in allOf
2 parents 09d39db + f8d2939 commit ea04032

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

packages/fury-adapter-swagger/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
result. This will fix conversion to API Blueprint with fury-cli where
1212
optional parameters have shown up as required in the generated API Blueprint.
1313

14+
- Allows generating of JSON bodies for schemas which make use of `allOf` and
15+
include circular references. Under some circumstances this would previously
16+
fail, and a warning may have been emitted "Unable to generate
17+
application/json example message body out of JSON Schema"
18+
1419
## 0.27.1 (2019-06-03)
1520

1621
### Bug Fixes

packages/fury-adapter-swagger/lib/json-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const dereference = (example, root, paths, path) => {
112112
const currentPath = (path || []).join('/');
113113

114114
if (path && pathHasCircularReference(paths, path, example.$ref)) {
115-
return null;
115+
return {};
116116
}
117117

118118
let ref;

packages/fury-adapter-swagger/test/fixtures/circular-example.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"content": "application/json"
205205
}
206206
},
207-
"content": "{\n \"id\": \"ORCL\"\n}"
207+
"content": "{\n \"id\": \"ORCL\",\n \"user\": {\n \"data\": {\n \"name\": \"doe\",\n \"company\": {\n \"data\": {\n \"is_owner\": false\n }\n }\n }\n }\n}"
208208
},
209209
{
210210
"element": "asset",
@@ -225,7 +225,7 @@
225225
"content": "application/schema+json"
226226
}
227227
},
228-
"content": "{\"allOf\":[{\"$ref\":\"#/definitions/Company\"}],\"definitions\":{\"Company\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"default\":\"ORCL\"},\"user\":{\"type\":\"object\",\"properties\":{\"data\":{\"$ref\":\"#/definitions/User\"}}}},\"default\":{\"id\":\"ORCL\"}},\"User\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\",\"default\":\"doe\"},\"company\":{\"properties\":{\"data\":{\"$ref\":\"#/definitions/Company\"}}}}}}}"
228+
"content": "{\"allOf\":[{\"$ref\":\"#/definitions/Company\"}],\"definitions\":{\"Company\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"default\":\"ORCL\"},\"user\":{\"type\":\"object\",\"properties\":{\"data\":{\"$ref\":\"#/definitions/User\"}}}}},\"User\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\",\"default\":\"doe\"},\"company\":{\"properties\":{\"data\":{\"allOf\":[{\"$ref\":\"#/definitions/Company\"},{\"type\":\"object\",\"properties\":{\"is_owner\":{\"type\":\"boolean\",\"default\":false}}}]}}}}}}}"
229229
},
230230
{
231231
"element": "dataStructure",
@@ -426,7 +426,38 @@
426426
"content": "data"
427427
},
428428
"value": {
429-
"element": "definitions/Company"
429+
"element": "definitions/Company",
430+
"content": [
431+
{
432+
"element": "member",
433+
"attributes": {
434+
"typeAttributes": {
435+
"element": "array",
436+
"content": [
437+
{
438+
"element": "string",
439+
"content": "optional"
440+
}
441+
]
442+
}
443+
},
444+
"content": {
445+
"key": {
446+
"element": "string",
447+
"content": "is_owner"
448+
},
449+
"value": {
450+
"element": "boolean",
451+
"attributes": {
452+
"default": {
453+
"element": "boolean",
454+
"content": false
455+
}
456+
}
457+
}
458+
}
459+
}
460+
]
430461
}
431462
}
432463
}

packages/fury-adapter-swagger/test/fixtures/circular-example.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ definitions:
2626
properties:
2727
data:
2828
$ref: '#/definitions/User'
29-
default:
30-
id: ORCL
3129

3230
User:
3331
type: object
@@ -38,5 +36,10 @@ definitions:
3836
company:
3937
properties:
4038
data:
41-
$ref: '#/definitions/Company'
42-
39+
allOf:
40+
- $ref: '#/definitions/Company'
41+
- type: object
42+
properties:
43+
is_owner:
44+
type: boolean
45+
default: false

packages/fury-adapter-swagger/test/json-schema-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ describe('Dereferencing', () => {
754754

755755
expect(result).to.deep.equal({
756756
name: 'Doe',
757-
parent: null,
757+
parent: {},
758758
});
759759
});
760760

@@ -778,7 +778,7 @@ describe('Dereferencing', () => {
778778
expect(result).to.deep.equal({
779779
name: 'Doe',
780780
company: {
781-
owner: null,
781+
owner: {},
782782
},
783783
});
784784
});

0 commit comments

Comments
 (0)