Skip to content

Commit 70b42f9

Browse files
Merge pull request #612 from postmanlabs/fix/allOfStringProp
Fix/all of string prop
2 parents 533e881 + 42310bd commit 70b42f9

File tree

3 files changed

+144
-2
lines changed

3 files changed

+144
-2
lines changed

lib/deref.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module.exports = {
112112
return mergeAllOf({
113113
allOf: schemaArr.map((schema) => {
114114
return this.resolveRefs(schema, parameterSourceOption, components, schemaResolutionCache, resolveFor,
115-
resolveTo, stack, seenRef, stackLimit);
115+
resolveTo, stack, seenRef, stackLimit, true);
116116
})
117117
}, {
118118
resolvers: {
@@ -148,7 +148,7 @@ module.exports = {
148148
*/
149149

150150
resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache,
151-
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10) {
151+
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10, isAllOf = false) {
152152
var resolvedSchema, prop, splitRef,
153153
ERR_TOO_MANY_LEVELS = '<Error: Too many levels of nesting to fake this schema>';
154154
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
@@ -350,6 +350,9 @@ module.exports = {
350350
value: schema.enum[0]
351351
};
352352
}
353+
else if (isAllOf) {
354+
return schema;
355+
}
353356
else {
354357
return {
355358
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function getFoldersByVersion(folder30Path, folder31Path) {
6464
}
6565

6666
describe('Validate with servers', function () {
67+
6768
it('Fix for GITHUB#496: Should identify url with fragment', function () {
6869
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/explicit_server_in_path.json'),
6970
openAPIData = fs.readFileSync(openAPI, 'utf8'),
@@ -1639,3 +1640,45 @@ describe('validateTransaction method. Path variables matching validation (issue
16391640
});
16401641
});
16411642
});
1643+
1644+
describe('validateTransaction convert and validate schemas with allOf', function () {
1645+
it('Should convert and validate allOf properties for string schema', function () {
1646+
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/all_of_property.json'),
1647+
openAPIData = fs.readFileSync(openAPI, 'utf8'),
1648+
expectedRequestBody = '{\n "id": "3",\n "name": "Contract.pdf"\n}',
1649+
options = {
1650+
requestParametersResolution: 'Example',
1651+
exampleParametersResolution: 'Example',
1652+
showMissingInSchemaErrors: true,
1653+
strictRequestMatching: true,
1654+
ignoreUnresolvedVariables: true,
1655+
validateMetadata: true,
1656+
suggestAvailableFixes: true,
1657+
detailedBlobValidation: false
1658+
},
1659+
schemaPack = new Converter.SchemaPack({ type: 'string', data: openAPIData }, options);
1660+
schemaPack.convert((err, conversionResult) => {
1661+
expect(err).to.be.null;
1662+
expect(conversionResult.result).to.equal(true);
1663+
expect(conversionResult.output[0].data.item[0].response[0].body).to.equal(expectedRequestBody);
1664+
1665+
let historyRequest = [];
1666+
1667+
getAllTransactions(conversionResult.output[0].data, historyRequest);
1668+
1669+
schemaPack.validateTransaction(historyRequest, (err, result) => {
1670+
expect(err).to.be.null;
1671+
expect(result).to.be.an('object');
1672+
1673+
let requestIds = Object.keys(result.requests);
1674+
expect(err).to.be.null;
1675+
expect(result.missingEndpoints.length).to.eq(0);
1676+
requestIds.forEach((requestId) => {
1677+
expect(result.requests[requestId].endpoints[0]).to.not.be.undefined;
1678+
expect(result.requests[requestId].endpoints[0].matched).to.be.true;
1679+
});
1680+
});
1681+
});
1682+
});
1683+
});
1684+

0 commit comments

Comments
 (0)