Skip to content

Commit 5666759

Browse files
committed
Avoid validation to throw with null info
1 parent 6df66da commit 5666759

File tree

8 files changed

+485
-2
lines changed

8 files changed

+485
-2
lines changed

lib/30XUtils/inputValidation.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const _ = require('lodash');
12
module.exports = {
23

34
/**
@@ -29,6 +30,14 @@ module.exports = {
2930
reason: 'Specification must contain an Info Object for the meta-data of the API'
3031
};
3132
}
33+
34+
if (_.isEmpty(spec.info)) {
35+
return {
36+
result: false,
37+
reason: 'Specification must contain a valid not null info'
38+
};
39+
}
40+
3241
if (!spec.info.hasOwnProperty('$ref')) {
3342
if (!spec.info.hasOwnProperty('title')) {
3443
return {

lib/31XUtils/inputValidation31X.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
const _ = require('lodash');
22
module.exports = {
33

44
/**
@@ -25,6 +25,29 @@ module.exports = {
2525
};
2626
}
2727

28+
if (_.isEmpty(spec.info)) {
29+
return {
30+
result: false,
31+
reason: 'Specification must contain a valid not null info'
32+
};
33+
}
34+
35+
if (!spec.info.hasOwnProperty('$ref')) {
36+
if (!spec.info.hasOwnProperty('title')) {
37+
return {
38+
result: false,
39+
reason: 'Specification must contain a title in order to generate a collection'
40+
};
41+
}
42+
43+
if (!spec.info.hasOwnProperty('version')) {
44+
return {
45+
result: false,
46+
reason: 'Specification must contain a semantic version number of the API in the Info Object'
47+
};
48+
}
49+
}
50+
2851
if (!spec.hasOwnProperty('paths') && !includeWebhooksOption) {
2952
return {
3053
result: false,
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": null,
4+
"version": "v1.0",
5+
"title": "API",
6+
"servers": [
7+
{
8+
"url": "http://localhost:3000"
9+
}
10+
],
11+
"paths": {
12+
"/user": {
13+
"get": {
14+
"summary": "Returns details about a particular user",
15+
"operationId": "listUser",
16+
"tags": [
17+
"user"
18+
],
19+
"parameters": [
20+
{
21+
"name": "id",
22+
"in": "query",
23+
"description": "ID of the user",
24+
"required": true,
25+
"schema": {
26+
"type": "integer",
27+
"format": "int32"
28+
}
29+
}
30+
],
31+
"responses": {
32+
"200": {
33+
"description": "Details about a user by ID",
34+
"headers": {
35+
"x-next": {
36+
"description": "A link to the next page of responses",
37+
"schema": {
38+
"type": "string"
39+
}
40+
}
41+
},
42+
"content": {
43+
"application/json": {
44+
"schema": {
45+
"$ref": "\\'#/components/schemas/User\\'"
46+
}
47+
}
48+
}
49+
},
50+
"default": {
51+
"description": "Unexpected error",
52+
"content": {
53+
"application/json": {
54+
"schema": {
55+
"$ref": "\\'#/components/schemas/Error\\'"
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
},
64+
"components": {
65+
"schemas": {
66+
"User": {
67+
"type": "object",
68+
"required": [
69+
"id",
70+
"name"
71+
],
72+
"properties": {
73+
"id": {
74+
"type": "integer",
75+
"format": "int64"
76+
},
77+
"name": {
78+
"type": "string"
79+
},
80+
"tag": {
81+
"type": "string"
82+
}
83+
}
84+
},
85+
"Error": {
86+
"type": "object",
87+
"required": [
88+
"code",
89+
"message"
90+
],
91+
"properties": {
92+
"code": {
93+
"type": "integer",
94+
"format": "int32"
95+
},
96+
"message": {
97+
"type": "string"
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"version": "1.0.0"
5+
},
6+
"version": "v1.0",
7+
"title": "API",
8+
"servers": [
9+
{
10+
"url": "http://localhost:3000"
11+
}
12+
],
13+
"paths": {
14+
"/user": {
15+
"get": {
16+
"summary": "Returns details about a particular user",
17+
"operationId": "listUser",
18+
"tags": [
19+
"user"
20+
],
21+
"parameters": [
22+
{
23+
"name": "id",
24+
"in": "query",
25+
"description": "ID of the user",
26+
"required": true,
27+
"schema": {
28+
"type": "integer",
29+
"format": "int32"
30+
}
31+
}
32+
],
33+
"responses": {
34+
"200": {
35+
"description": "Details about a user by ID",
36+
"headers": {
37+
"x-next": {
38+
"description": "A link to the next page of responses",
39+
"schema": {
40+
"type": "string"
41+
}
42+
}
43+
},
44+
"content": {
45+
"application/json": {
46+
"schema": {
47+
"$ref": "\\'#/components/schemas/User\\'"
48+
}
49+
}
50+
}
51+
},
52+
"default": {
53+
"description": "Unexpected error",
54+
"content": {
55+
"application/json": {
56+
"schema": {
57+
"$ref": "\\'#/components/schemas/Error\\'"
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
},
66+
"components": {
67+
"schemas": {
68+
"User": {
69+
"type": "object",
70+
"required": [
71+
"id",
72+
"name"
73+
],
74+
"properties": {
75+
"id": {
76+
"type": "integer",
77+
"format": "int64"
78+
},
79+
"name": {
80+
"type": "string"
81+
},
82+
"tag": {
83+
"type": "string"
84+
}
85+
}
86+
},
87+
"Error": {
88+
"type": "object",
89+
"required": [
90+
"code",
91+
"message"
92+
],
93+
"properties": {
94+
"code": {
95+
"type": "integer",
96+
"format": "int32"
97+
},
98+
"message": {
99+
"type": "string"
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "Swagger Petstore"
5+
},
6+
"version": "v1.0",
7+
"title": "API",
8+
"servers": [
9+
{
10+
"url": "http://localhost:3000"
11+
}
12+
],
13+
"paths": {
14+
"/user": {
15+
"get": {
16+
"summary": "Returns details about a particular user",
17+
"operationId": "listUser",
18+
"tags": [
19+
"user"
20+
],
21+
"parameters": [
22+
{
23+
"name": "id",
24+
"in": "query",
25+
"description": "ID of the user",
26+
"required": true,
27+
"schema": {
28+
"type": "integer",
29+
"format": "int32"
30+
}
31+
}
32+
],
33+
"responses": {
34+
"200": {
35+
"description": "Details about a user by ID",
36+
"headers": {
37+
"x-next": {
38+
"description": "A link to the next page of responses",
39+
"schema": {
40+
"type": "string"
41+
}
42+
}
43+
},
44+
"content": {
45+
"application/json": {
46+
"schema": {
47+
"$ref": "\\'#/components/schemas/User\\'"
48+
}
49+
}
50+
}
51+
},
52+
"default": {
53+
"description": "Unexpected error",
54+
"content": {
55+
"application/json": {
56+
"schema": {
57+
"$ref": "\\'#/components/schemas/Error\\'"
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
},
66+
"components": {
67+
"schemas": {
68+
"User": {
69+
"type": "object",
70+
"required": [
71+
"id",
72+
"name"
73+
],
74+
"properties": {
75+
"id": {
76+
"type": "integer",
77+
"format": "int64"
78+
},
79+
"name": {
80+
"type": "string"
81+
},
82+
"tag": {
83+
"type": "string"
84+
}
85+
}
86+
},
87+
"Error": {
88+
"type": "object",
89+
"required": [
90+
"code",
91+
"message"
92+
],
93+
"properties": {
94+
"code": {
95+
"type": "integer",
96+
"format": "int32"
97+
},
98+
"message": {
99+
"type": "string"
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)