Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/deref.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = {
return mergeAllOf({
allOf: schemaArr.map((schema) => {
return this.resolveRefs(schema, parameterSourceOption, components, schemaResolutionCache, resolveFor,
resolveTo, stack, seenRef, stackLimit);
resolveTo, stack, seenRef, stackLimit, true);
})
}, {
resolvers: {
Expand Down Expand Up @@ -122,7 +122,7 @@ module.exports = {
*/

resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache,
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10) {
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10, isAllOf = false) {
var resolvedSchema, prop, splitRef,
ERR_TOO_MANY_LEVELS = '<Error: Too many levels of nesting to fake this schema>';
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
Expand Down Expand Up @@ -325,6 +325,9 @@ module.exports = {
value: schema.enum[0]
};
}
else if (isAllOf) {
return schema;
}
else {
return {
type: SCHEMA_TYPES.object
Expand Down
96 changes: 96 additions & 0 deletions test/data/valid_openapi/all_of_property.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"openapi": "3.0.2",
"info": {
"title": "Platform API",
"description": "[ Platform](https://server.dev) provides functionality to provide access to content stored within. It provides endpoints for basic manipulation of files and folder.",
"termsOfService": "https://server.com/s",
"contact": {
"name": "nc",
"url": "https://server.dev",
"email": "dev@server.com"
},
"license": {
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
},
"version": "2.0.0"
},
"servers": [
{
"url": "https://server.com/2.0",
"description": "Platform API server"
}
],
"paths": {
"/files": {
"get": {
"operationId": "get_Files",
"summary": "List files ",
"tags": [
"Skills"
],
"description": "List the files.",
"parameters": [
{
"name": "file_id",
"description": "The unique identifier",
"example": "12345",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Returns all the data.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/File"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"File": {
"title": "File",
"type": "object",
"description": "A mini representation of a file",
"required": [
"id"
],
"allOf": [
{
"properties": {
"id": {
"allOf": [
{
"type": "string",
"example": "3",
"nullable": false,
"description": "A numeric identifier"
},
{
"nullable": false
}
]
},
"name": {
"type": "string",
"description": "The name of the file",
"example": "Contract.pdf"
}
}
}
]
}
}
}
}
43 changes: 43 additions & 0 deletions test/unit/validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function getFoldersByVersion(folder30Path, folder31Path) {
}

describe('Validate with servers', function () {

it('Fix for GITHUB#496: Should identify url with fragment', function () {
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/explicit_server_in_path.json'),
openAPIData = fs.readFileSync(openAPI, 'utf8'),
Expand Down Expand Up @@ -1613,3 +1614,45 @@ describe('validateTransaction method. Path variables matching validation (issue
});
});
});

describe('validateTransaction convert and validate schemas with allOf', function () {
it('Should convert and validate allOf properties for string schema', function () {
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/all_of_property.json'),
openAPIData = fs.readFileSync(openAPI, 'utf8'),
expectedRequestBody = '{\n "id": "3",\n "name": "Contract.pdf"\n}',
options = {
requestParametersResolution: 'Example',
exampleParametersResolution: 'Example',
showMissingInSchemaErrors: true,
strictRequestMatching: true,
ignoreUnresolvedVariables: true,
validateMetadata: true,
suggestAvailableFixes: true,
detailedBlobValidation: false
},
schemaPack = new Converter.SchemaPack({ type: 'string', data: openAPIData }, options);
schemaPack.convert((err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);
expect(conversionResult.output[0].data.item[0].response[0].body).to.equal(expectedRequestBody);

let historyRequest = [];

getAllTransactions(conversionResult.output[0].data, historyRequest);

schemaPack.validateTransaction(historyRequest, (err, result) => {
expect(err).to.be.null;
expect(result).to.be.an('object');

let requestIds = Object.keys(result.requests);
expect(err).to.be.null;
expect(result.missingEndpoints.length).to.eq(0);
requestIds.forEach((requestId) => {
expect(result.requests[requestId].endpoints[0]).to.not.be.undefined;
expect(result.requests[requestId].endpoints[0].matched).to.be.true;
});
});
});
});
});