diff --git a/assets/json-schema-faker.js b/assets/json-schema-faker.js index cec6d27..0e8ee4b 100644 --- a/assets/json-schema-faker.js +++ b/assets/json-schema-faker.js @@ -23469,6 +23469,9 @@ function extend() { var fn = keys[length].replace(/^x-/, ''); var gen = this.support[fn]; if (typeof gen === 'function') { + if (typeof schema[fn] === 'object' && schema[fn].hasOwnProperty('type')) { + continue; + } Object.defineProperty(schema, 'generate', { configurable: false, enumerable: false, diff --git a/test/data/valid_openapi/issue#10672.json b/test/data/valid_openapi/issue#10672.json new file mode 100644 index 0000000..72a6d11 --- /dev/null +++ b/test/data/valid_openapi/issue#10672.json @@ -0,0 +1,216 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore issue 10672", + "license": { + "name": "MIT" + } + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v1" + } + ], + "paths": { + "/pets": { + "get": { + "summary": "List all pets", + "operationId": "listPets", + "tags": [ + "pets" + ], + "parameters": [ + { + "name": "limit", + "in": "header", + "description": "How many items to return at one time (max 100)", + "required": false, + "schema": { + "type": "integer", + "format": "int32" + } + }, + { + "name": "variable", + "in": "query", + "description": "random variable", + "style": "form", + "explode": false, + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "variable2", + "in": "query", + "description": "another random variable", + "style": "spaceDelimited", + "schema": { + "type": "array", + "items": { + "type": "integer", + "format": "int64" + } + } + } + ], + "responses": { + "200": { + "description": "An paged array of pets", + "headers": { + "x-next": { + "description": "A link to the next page of responses", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pets" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "post": { + "summary": "Create a pet", + "operationId": "createPets", + "tags": [ + "pets" + ], + "responses": { + "201": { + "description": "Null response" + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "parameters": [ + { + "name": "limit_2", + "in": "headers", + "description": "How many items to return at one time (max 100)", + "required": false, + "schema": { + "type": "integer", + "format": "int32" + } + } + ] + }, + "/pets/{petId}": { + "get": { + "summary": "Info for a specific pet", + "operationId": "showPetById", + "tags": [ + "pets" + ], + "parameters": [ + { + "name": "petId", + "in": "path", + "required": true, + "description": "The id of the pet to retrieve", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Expected response to a valid request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "pattern": { + "type": "string" + } + } + }, + "Pets": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + }, + "Error": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } +} diff --git a/test/unit/base.test.js b/test/unit/base.test.js index 7317cd3..c79199b 100644 --- a/test/unit/base.test.js +++ b/test/unit/base.test.js @@ -16,6 +16,7 @@ describe('CONVERT FUNCTION TESTS ', function() { test31SpecDir = path.join(__dirname, '../data/valid_openapi31X/'), issue133 = path.join(__dirname, VALID_OPENAPI_PATH + '/issue#133.json'), issue160 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#160.json'), + issue10672 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10672.json'), unique_items_schema = path.join(__dirname, VALID_OPENAPI_PATH + '/unique_items_schema.json'), serverOverRidingSpec = path.join(__dirname, VALID_OPENAPI_PATH + '/server_overriding.json'), infoHavingContactOnlySpec = path.join(__dirname, VALID_OPENAPI_PATH + '/info_having_contact_only.json'), @@ -872,6 +873,26 @@ describe('CONVERT FUNCTION TESTS ', function() { }); }); + it('[GITHUB #10672] Should convert a collection with a key "pattern" in a schema', function() { + const fileSource = issue10672, + fileData = fs.readFileSync(fileSource, 'utf8'), + input = { + type: 'string', + data: fileData + }; + + Converter.convert(input, {}, (err, result) => { + expect(err).to.be.null; + let body = JSON.parse(result.output[0].data.item[0].item[0].response[0].body); + expect(result.result).to.be.true; + expect(body) + .to.be.an('array').with.length(2); + expect(body.filter((item) => { + return item.pattern && typeof item.pattern === 'string'; + })).to.be.an('array').with.length(2); + }); + }); + it('should not return undefined in the error message if spec is not valid JSON/YAML', function(done) { // invalid JSON Converter.convert({ type: 'string', data: '{"key": { "value" : } ' }, {}, (err, conversionResult) => {