Skip to content

Commit

Permalink
Addressed the issues in checking response for every request and camel…
Browse files Browse the repository at this point in the history
… case ruleset
  • Loading branch information
SnehaThangavelu1603 committed Aug 16, 2023
1 parent 00af71f commit 735b83a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 12 deletions.
7 changes: 6 additions & 1 deletion functions/check-for-response-in-every-request.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module.exports = (input) => {
if (!input["responses"]) {
let keys = Object.keys(input)
let http_verbs = keys.filter((verb) => !(['parameters'].includes(verb)));
for(let index = 0; index < http_verbs.length; index++)
{
if (!input[http_verbs[index]]["responses"]) {
return [
{
message: "Response body missing for the given request.",
},
];
}
}
};
2 changes: 1 addition & 1 deletion functions/does-spec-contains-valid-http-verbs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = (input) => {

const httpVerbs = ['get', 'post', 'put', 'delete', 'patch', 'trace', 'options', 'head', 'connect'];
const httpVerbs = ['get', 'post', 'put', 'delete', 'patch', 'trace', 'options', 'head', 'connect', 'parameters'];

if (!httpVerbs.includes(input.toLowerCase())) {
return [{
Expand Down
2 changes: 1 addition & 1 deletion functions/valid-url-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = (input) => {
for (let index in input) {
let url = input[index]["url"];
var re =
/(^(https:\/\/)(eu|us)(-aws|-az)(.api.trimble.com\/)(product\/{1})([-a-z0-9]{0,}\/{1})(v[1-9]{1}[0-9]{0,14}(-dev|-qa|-stage)?)(\/){0,1}((?<=\/)([a-z]{0,})(((?<=[a-z])([-_0-9]{0,}))*((?<=[-_])([a-z0-9]{1,})))*(?<!\/)(\/){0,1})*)$/g;
/(^(https:\/\/)(((eu|us)(-aws|-az)(.api.trimble.com\/)(product\/{1}))|(cloud((.dev|.qa.|.stage){0,}.api.(trimblecloud|trimble)).com\/cloud\/{1}))([-a-z0-9]{0,}\/{1})(v[1-9]{1}[0-9]{0,14}(-dev|-qa|-stage)?)(\/[a-z0-9]{0,}){0,}((?<=\/)([a-z]{0,})(((?<=[a-z])([-_0-9]{0,}))((?<=[-_])([a-z0-9]{1,})))(?<!\/)(\/){0,1})*)$/;

var valid = re.test(url);

Expand Down
4 changes: 2 additions & 2 deletions spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ rules:
description: Ensuring that schema property names are camel case.
message: All schema property names should be camel case.
severity: error
given: "$..properties.."
given: "$..properties."
then:
field: "@key"
function: pattern
Expand Down Expand Up @@ -305,7 +305,7 @@ rules:
description: Check if every request has their respective responses.
severity: error
message: "{{error}}"
given: "$.paths.*.*."
given: "$.paths.*"
then:
function: check-for-response-in-every-request

Expand Down
110 changes: 103 additions & 7 deletions test/operation-check-for-response-in-every-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,118 @@ test("check-response-body should return null since all the response has body", (

const oasDoc = {
"paths": {
"/apis": {
"/clients/{clientId}/tariffClasses/{tariffClassId}": {
"get": {
"summary": "Retrieve a client tariff class",
"description": "Retrieves a client tariff class record for the specified client.\n\nClient tariff classes can be viewed in the Customer & Vendor Profiles application > Customer > Rating > Tariff Class tab.",
"operationId": "ClientsGetTariffClasses",
"security": [
{
"truckmateApiKeyAuth": []
}
],
"tags": ["Clients"],
"parameters": [
{
"name": "string"
}
],
"responses": {
"200": {
"description": "OK"
"description": "OK",
"content": {
"application/json": {
"schema": {
"name": "string"
}
}
}
}
}
},
"post": {
"put": {
"summary": "Update a client tariff class",
"description": "Updates one or more properties of a specific client tariff class record for the specified client.\n\nThe effectiveFrom and effectiveTo dates are auto-populated based on the following app config options:\n\n- PROFILE.EXE > Default Customer Rating Effective Date Logic\n\n- PROFILE.EXE > Default Customer Rating Expiry Date Logic\n\nThe effectiveFrom date must be prior to the effectiveTo date.\n\nThe request body may include the multi service level child resource. Keep in mind when a child resource is specified in the body, it will do a complete replace of that resource. In other words, it will DELETE ALL records of the specified resource in the vendor record, and insert the new ones from the request body.\n\nThe customSQL will be added to the WHERE clause of the following SQL statement:\n\n\tSELECT COUNT(*) FROM CMODTY C\n\tINNER JOIN RATE_CL_TARIFF_CLASS T ON C.CLASS = T.TARIFF_CLASS\n\tWHERE T.CLIENT_ID = :clientId AND C.CLASS = :tariffClass\n\tAND\nwhere :clientId is the client Id, :tariffClass is the Tariff Class (tariffClassFrom) in the request.\n\nClient tariff classes can be viewed in the Customer & Vendor Profiles application > Customer > Rating > Tariff Class tab.\n\nApp config options can be viewed in the Application Configurator application.",
"operationId": "ClientsPutTariffClasses",
"security": [
{
"truckmateApiKeyAuth": []
}
],
"tags": ["Clients"],
"requestBody": {
"description": "A single JSON object containing the properties to be updated. All fields are optional, but at least one field must be sent.",
"required": true,
"content": {
"application/json": {
"schema": {
"name": "string"
}
}
}
},
"parameters": [
{
"name": "tariffClassId",
"in": "path",
"description": "Tariff Class identifier",
"required": true,
"schema": {
"type": "integer"
}
}
],
"responses": {
"201": {
"description": "Created",
"202": {
"description": "OK",
"content": {
"application/json": {
}
}
}
}
}
}
},
"delete": {
"summary": "Delete a client tariff class",
"description": "Deletes a client tariff class record from the specified client.\n\nClient tariff classes can be viewed in the Customer & Vendor Profiles application > Customer > Rating > Tariff Class tab.",
"operationId": "ClientsDeleteTariffClasses",
"security": [
{
"truckmateApiKeyAuth": []
}
],
"responses": {
"202": {
"description": "OK",
"content": {
"application/json": {
}
}
}
},
"tags": ["Clients"]
},
"parameters": [
{
"name": "tariffClassId",
"in": "path",
"description": "Tariff Class identifier",
"required": true,
"schema": {
"type": "integer"
}
},
{
"name": "clientId",
"in": "path",
"description": "Client identifier",
"required": true,
"schema": {
"type": "string"
}
}
]
},
}
};
return linter.run(oasDoc).then((results) => {
Expand Down

0 comments on commit 735b83a

Please sign in to comment.