Skip to content

Commit 0995afe

Browse files
committed
Merge remote-tracking branch 'origin/main' into commit-hook-golang
2 parents 0b9e96d + b493767 commit 0995afe

31 files changed

+1031
-225
lines changed

.husky/pre-commit

100644100755
File mode changed.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This project uses the following Git hooks:
4343

4444
- **pre-commit**:
4545
- Automatically formats your code using Prettier and runs tests for staged JavaScript files
46+
- If you get the message `hint: The '.husky/pre-commit' hook was ignored because it's not set as executable.` during the commit, you can run `chmod ug+x .husky/*` to make it executable.
4647
- For Go files, runs formatting, linting, and tests using the project's Makefile
4748

4849
### Available Scripts
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
testRule('xgen-IPA-102-collection-identifier-pattern', [
5+
{
6+
name: 'valid collection identifiers',
7+
document: {
8+
paths: {
9+
'/resources': {},
10+
'/users': {},
11+
'/resourceGroups': {},
12+
'/api/v2/customers/payments': {},
13+
},
14+
},
15+
errors: [],
16+
},
17+
{
18+
name: 'valid with path parameters',
19+
document: {
20+
paths: {
21+
'/resources/{id}': {},
22+
'/users/{userId}/profiles': {},
23+
},
24+
},
25+
errors: [],
26+
},
27+
{
28+
name: 'valid with custom methods',
29+
document: {
30+
paths: {
31+
'/resources:create': {},
32+
'/users/{userId}:activate': {},
33+
},
34+
},
35+
errors: [],
36+
},
37+
{
38+
name: 'invalid starts with uppercase',
39+
document: {
40+
paths: {
41+
'/Resources': {},
42+
},
43+
},
44+
errors: [
45+
{
46+
code: 'xgen-IPA-102-collection-identifier-pattern',
47+
message:
48+
"Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers (/[a-z][a-zA-Z0-9]*/). Path segment 'Resources' in path '/Resources' doesn't match the required pattern. http://go/ipa/102",
49+
path: ['paths', '/Resources'],
50+
severity: DiagnosticSeverity.Warning,
51+
},
52+
],
53+
},
54+
{
55+
name: 'invalid with special characters',
56+
document: {
57+
paths: {
58+
'/resource-groups': {},
59+
'/user_profiles': {},
60+
},
61+
},
62+
errors: [
63+
{
64+
code: 'xgen-IPA-102-collection-identifier-pattern',
65+
message:
66+
"Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers (/[a-z][a-zA-Z0-9]*/). Path segment 'resource-groups' in path '/resource-groups' doesn't match the required pattern. http://go/ipa/102",
67+
path: ['paths', '/resource-groups'],
68+
severity: DiagnosticSeverity.Warning,
69+
},
70+
{
71+
code: 'xgen-IPA-102-collection-identifier-pattern',
72+
message:
73+
"Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers (/[a-z][a-zA-Z0-9]*/). Path segment 'user_profiles' in path '/user_profiles' doesn't match the required pattern. http://go/ipa/102",
74+
path: ['paths', '/user_profiles'],
75+
severity: DiagnosticSeverity.Warning,
76+
},
77+
],
78+
},
79+
{
80+
name: 'valid with path-level exception',
81+
document: {
82+
paths: {
83+
'/resource-groups': {
84+
'x-xgen-IPA-exception': {
85+
'xgen-IPA-102-collection-identifier-pattern': 'Legacy API path that cannot be changed',
86+
},
87+
},
88+
},
89+
},
90+
errors: [],
91+
},
92+
]);

tools/spectral/ipa/__tests__/createMethodShouldNotHaveQueryParameters.test.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ const componentSchemas = {
1515
type: 'string',
1616
},
1717
},
18+
QueryParam2: {
19+
name: 'query-param-2',
20+
in: 'query',
21+
schema: {
22+
type: 'string',
23+
},
24+
},
1825
PathParam: {
1926
name: 'resource-id',
2027
in: 'path',
@@ -102,6 +109,9 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
102109
{
103110
$ref: '#/components/parameters/QueryParam',
104111
},
112+
{
113+
$ref: '#/components/parameters/QueryParam2',
114+
},
105115
],
106116
},
107117
},
@@ -110,13 +120,20 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
110120
errors: [
111121
{
112122
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
113-
message: 'Create operations should not have query parameters. http://go/ipa/106',
123+
message: 'Input parameter [filter]: Create operations should not have query parameters. http://go/ipa/106',
114124
path: ['paths', '/resource', 'post'],
115125
severity: DiagnosticSeverity.Warning,
116126
},
117127
{
118128
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
119-
message: 'Create operations should not have query parameters. http://go/ipa/106',
129+
message: 'Input parameter [query-param]: Create operations should not have query parameters. http://go/ipa/106',
130+
path: ['paths', '/resource2', 'post'],
131+
severity: DiagnosticSeverity.Warning,
132+
},
133+
{
134+
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
135+
message:
136+
'Input parameter [query-param-2]: Create operations should not have query parameters. http://go/ipa/106',
120137
path: ['paths', '/resource2', 'post'],
121138
severity: DiagnosticSeverity.Warning,
122139
},

tools/spectral/ipa/__tests__/getMethodReturnsResponseSuffixedObject.test.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const componentSchemas = {
99
Schema: {
1010
type: 'object',
1111
},
12+
BadRequest: {
13+
content: {
14+
'application/json': {
15+
schema: {
16+
type: 'string',
17+
},
18+
},
19+
},
20+
},
1221
},
1322
};
1423

@@ -42,6 +51,9 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
4251
},
4352
},
4453
},
54+
401: {
55+
$ref: '#/components/schemas/BadRequest',
56+
},
4557
400: {
4658
content: {
4759
'application/vnd.atlas.2023-01-01+json': {
@@ -140,7 +152,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
140152
errors: [
141153
{
142154
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
143-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
155+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
144156
path: [
145157
'paths',
146158
'/resource/{id}',
@@ -154,7 +166,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
154166
},
155167
{
156168
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
157-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
169+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
158170
path: [
159171
'paths',
160172
'/resource/{id}',
@@ -168,7 +180,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
168180
},
169181
{
170182
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
171-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
183+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
172184
path: [
173185
'paths',
174186
'/resource/{id}',
@@ -182,7 +194,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
182194
},
183195
{
184196
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
185-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
197+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
186198
path: [
187199
'paths',
188200
'/resource/{id}/singleton',
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
testRule('xgen-IPA-105-list-method-no-request-body', [
5+
{
6+
name: 'valid list without body',
7+
document: {
8+
paths: {
9+
'/resource': {
10+
get: {
11+
responses: {
12+
200: {},
13+
},
14+
},
15+
},
16+
},
17+
},
18+
errors: [],
19+
},
20+
{
21+
name: 'rule ignores singleton and Get',
22+
document: {
23+
paths: {
24+
'/resource': {
25+
get: {
26+
responses: {
27+
200: {},
28+
},
29+
},
30+
},
31+
'/resource/{id}': {
32+
get: {
33+
responses: {
34+
200: {},
35+
},
36+
requestBody: {
37+
content: {
38+
'application/vnd.atlas.2024-08-05+json': {
39+
schema: { type: 'object' },
40+
},
41+
},
42+
},
43+
},
44+
},
45+
'/resource/{id}/singleton': {
46+
get: {
47+
responses: {
48+
200: {},
49+
},
50+
requestBody: {
51+
content: {
52+
'application/vnd.atlas.2024-08-05+json': {
53+
schema: { type: 'object' },
54+
},
55+
},
56+
},
57+
},
58+
},
59+
},
60+
},
61+
errors: [],
62+
},
63+
{
64+
name: 'invalid list with body',
65+
document: {
66+
paths: {
67+
'/resource': {
68+
get: {
69+
responses: {
70+
200: {},
71+
},
72+
requestBody: {
73+
content: {
74+
'application/vnd.atlas.2024-08-05+json': {
75+
schema: { type: 'object' },
76+
},
77+
},
78+
},
79+
},
80+
},
81+
},
82+
},
83+
errors: [
84+
{
85+
code: 'xgen-IPA-105-list-method-no-request-body',
86+
message: 'The List method must not include a request body. http://go/ipa/105',
87+
path: ['paths', '/resource', 'get'],
88+
severity: DiagnosticSeverity.Warning,
89+
},
90+
],
91+
},
92+
{
93+
name: 'invalid with exception',
94+
document: {
95+
paths: {
96+
'/resource': {
97+
get: {
98+
'x-xgen-IPA-exception': {
99+
'xgen-IPA-105-list-method-no-request-body': 'reason',
100+
},
101+
responses: {
102+
200: {},
103+
},
104+
requestBody: {
105+
content: {
106+
'application/vnd.atlas.2024-08-05+json': {
107+
schema: { type: 'object' },
108+
},
109+
},
110+
},
111+
},
112+
},
113+
},
114+
},
115+
errors: [],
116+
},
117+
]);

0 commit comments

Comments
 (0)