Skip to content

Commit 877e750

Browse files
committed
Add support for allOf as properties
Add support for allOf as properties, not a full schema
1 parent 3f82eda commit 877e750

File tree

3 files changed

+141
-2
lines changed

3 files changed

+141
-2
lines changed

lib/deref.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = {
8686
return mergeAllOf({
8787
allOf: schemaArr.map((schema) => {
8888
return this.resolveRefs(schema, parameterSourceOption, components, schemaResolutionCache, resolveFor,
89-
resolveTo, stack, seenRef, stackLimit);
89+
resolveTo, stack, seenRef, stackLimit, true);
9090
})
9191
}, {
9292
resolvers: {
@@ -122,7 +122,7 @@ module.exports = {
122122
*/
123123

124124
resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache,
125-
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10) {
125+
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10, isAllOf = false) {
126126
var resolvedSchema, prop, splitRef,
127127
ERR_TOO_MANY_LEVELS = '<Error: Too many levels of nesting to fake this schema>';
128128
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
@@ -325,6 +325,9 @@ module.exports = {
325325
value: schema.enum[0]
326326
};
327327
}
328+
else if (isAllOf) {
329+
return schema;
330+
}
328331
else {
329332
return {
330333
type: SCHEMA_TYPES.object
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"openapi": "3.0.2",
3+
"info": {
4+
"title": "Platform API",
5+
"description": "[ Platform](https://server.dev) provides functionality to provide access to content stored within. It provides endpoints for basic manipulation of files and folder.",
6+
"termsOfService": "https://server.com/s",
7+
"contact": {
8+
"name": "nc",
9+
"url": "https://server.dev",
10+
"email": "dev@server.com"
11+
},
12+
"license": {
13+
"name": "Apache-2.0",
14+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
15+
},
16+
"version": "2.0.0"
17+
},
18+
"servers": [
19+
{
20+
"url": "https://server.com/2.0",
21+
"description": "Platform API server"
22+
}
23+
],
24+
"paths": {
25+
"/files": {
26+
"get": {
27+
"operationId": "get_Files",
28+
"summary": "List files ",
29+
"tags": [
30+
"Skills"
31+
],
32+
"description": "List the files.",
33+
"parameters": [
34+
{
35+
"name": "file_id",
36+
"description": "The unique identifier",
37+
"example": "12345",
38+
"in": "path",
39+
"required": true,
40+
"schema": {
41+
"type": "string"
42+
}
43+
}
44+
],
45+
"responses": {
46+
"200": {
47+
"description": "Returns all the data.",
48+
"content": {
49+
"application/json": {
50+
"schema": {
51+
"$ref": "#/components/schemas/File"
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
},
60+
"components": {
61+
"schemas": {
62+
"File": {
63+
"title": "File",
64+
"type": "object",
65+
"description": "A mini representation of a file",
66+
"required": [
67+
"id"
68+
],
69+
"allOf": [
70+
{
71+
"properties": {
72+
"id": {
73+
"allOf": [
74+
{
75+
"type": "string",
76+
"example": "3",
77+
"nullable": false,
78+
"description": "A numeric identifier"
79+
},
80+
{
81+
"nullable": false
82+
}
83+
]
84+
},
85+
"name": {
86+
"type": "string",
87+
"description": "The name of the file",
88+
"example": "Contract.pdf"
89+
}
90+
}
91+
}
92+
]
93+
}
94+
}
95+
}
96+
}

test/unit/validator.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,46 @@ function getFoldersByVersion(folder30Path, folder31Path) {
6464
}
6565

6666
describe('Validate with servers', function () {
67+
68+
it('Should convert and validate allOf properties for string schema', function () {
69+
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/all_of_property.json'),
70+
openAPIData = fs.readFileSync(openAPI, 'utf8'),
71+
expectedRequestBody = '{\n "id": "3",\n "name": "Contract.pdf"\n}',
72+
options = {
73+
requestParametersResolution: 'Example',
74+
exampleParametersResolution: 'Example',
75+
showMissingInSchemaErrors: true,
76+
strictRequestMatching: true,
77+
ignoreUnresolvedVariables: true,
78+
validateMetadata: true,
79+
suggestAvailableFixes: true,
80+
detailedBlobValidation: false
81+
},
82+
schemaPack = new Converter.SchemaPack({ type: 'string', data: openAPIData }, options);
83+
schemaPack.convert((err, conversionResult) => {
84+
expect(err).to.be.null;
85+
expect(conversionResult.result).to.equal(true);
86+
expect(conversionResult.output[0].data.item[0].response[0].body).to.equal(expectedRequestBody);
87+
88+
let historyRequest = [];
89+
90+
getAllTransactions(conversionResult.output[0].data, historyRequest);
91+
92+
schemaPack.validateTransaction(historyRequest, (err, result) => {
93+
expect(err).to.be.null;
94+
expect(result).to.be.an('object');
95+
96+
let requestIds = Object.keys(result.requests);
97+
expect(err).to.be.null;
98+
expect(result.missingEndpoints.length).to.eq(0);
99+
requestIds.forEach((requestId) => {
100+
expect(result.requests[requestId].endpoints[0]).to.not.be.undefined;
101+
expect(result.requests[requestId].endpoints[0].matched).to.be.true;
102+
});
103+
});
104+
});
105+
});
106+
67107
it('Fix for GITHUB#496: Should identify url with fragment', function () {
68108
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/explicit_server_in_path.json'),
69109
openAPIData = fs.readFileSync(openAPI, 'utf8'),

0 commit comments

Comments
 (0)