Skip to content

Commit

Permalink
Merge 36a1671 into 8af7459
Browse files Browse the repository at this point in the history
  • Loading branch information
uglow committed Dec 2, 2020
2 parents 8af7459 + 36a1671 commit 712826f
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 21 deletions.
299 changes: 299 additions & 0 deletions fixtures/parameterMismatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
{
"openapi": "3.0.0",
"info": {
"description": "Fake Online REST API for Testing and Prototyping",
"version": "1.0.0",
"title": "JSON Placeholder"
},
"tags": [
{
"name": "posts"
}
],
"servers": [
{
"url": "https://jsonplaceholder.typicode.com"
}
],
"paths": {
"/posts": {
"get": {
"tags": [
"posts"
],
"summary": "Get all available posts",
"parameters": [
{
"name": "id",
"in": "query",
"description": "Filter by post ID",
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "userId",
"in": "query",
"description": "Filter by user ID",
"required": false,
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Post"
}
}
}
},
"x-mock-file": "",
"x-examples": {
"default": {
"parameters": [
{
"value": null
}
]
}
}
}
}
}
},
"/posts/{id}": {
"get": {
"tags": [
"posts"
],
"summary": "Get specific post",
"parameters": [
{
"name": "id",
"in": "path",
"description": "The ID of the post to retrieve",
"required": true,
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"x-mock-file": ""
},
"404": {
"description": "not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotFoundError"
}
}
},
"x-mock-file": ""
}
}
}
}
},
"components": {
"schemas": {
"Post": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"userId": {
"type": "integer",
"format": "int64"
},
"title": {
"type": "string"
},
"body": {
"type": "string"
}
}
},
"Comment": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"postId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"body": {
"type": "string"
}
}
},
"Album": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"userId": {
"type": "integer",
"format": "int64"
},
"title": {
"type": "string"
}
}
},
"Photo": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"albumId": {
"type": "integer",
"format": "int64"
},
"title": {
"type": "string"
},
"url": {
"type": "string",
"format": "uri"
},
"thumbnailUrl": {
"type": "string",
"format": "uri"
}
}
},
"Todo": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"userId": {
"type": "integer",
"format": "int64"
},
"title": {
"type": "string"
},
"completed": {
"type": "boolean"
}
}
},
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"username": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"phone": {
"type": "string"
},
"website": {
"type": "string"
},
"company": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"catchPhrase": {
"type": "string"
},
"bs": {
"type": "string"
}
}
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"suite": {
"type": "string"
},
"city": {
"type": "string"
},
"zipcode": {
"type": "string"
},
"geo": {
"type": "object",
"properties": {
"lat": {
"type": "string"
},
"lng": {
"type": "string"
}
}
}
}
}
}
},
"NotFoundError": {
"type": "object"
},
"Empty": {
"type": "object",
"title": "Empty response model for AWS + CORS use"
},
"StringResponse": {
"type": "string",
"title": "String-type workaround for API Gateway"
}
}
}
}
2 changes: 1 addition & 1 deletion src/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function compareToSchema({ openapi, objB, res, showDiff }) {
* We do not show diffs between the old and new response in this mode.
* @param oldRes
* @param apiRes
* @return {string}
* @return {string} exact, inexact, type, nomatch
*/
function compareResponseData(oldRes, apiRes) {
const showDiff = false;
Expand Down
11 changes: 11 additions & 0 deletions src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ describe('CLI', () => {
"
`);
});

it('should display an error when the parameters do not match, and exit with a non-zero error code', async () => {
const result = await runCommand(`record ./fixtures/parameterMismatch.json`);

expect(result).toMatchInlineSnapshot(`
"warn: Ignore (no x-examples parameters) - GET /posts/{id} 200
warn: Ignore (no x-examples parameters) - GET /posts/{id} 404
error: An x-examples parameter for \\"userId\\" is missing from /posts.responses.200.x-examples.default.parameters[1]
"
`);
});
});

describe('build should create a spec file that is OpenAPI 3.x compliant', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function writeResponses(params) {
}

/**
* Compare responses to the existing responses, and return a list of files
* Compare response to the existing response, and return the response
* the should be updated.
* @param params
*/
Expand Down

0 comments on commit 712826f

Please sign in to comment.