Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,19 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
errors: [
{
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
message: 'Input parameter [filter]: Create operations should not have query parameters. http://go/ipa/106',
message: 'Create operations should not have query parameters. Found [filter]. http://go/ipa/106',
path: ['paths', '/resource', 'post'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
message: 'Input parameter [query-param]: Create operations should not have query parameters. http://go/ipa/106',
message: 'Create operations should not have query parameters. Found [query-param]. http://go/ipa/106',
path: ['paths', '/resourceTwo', 'post'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
message:
'Input parameter [query-param-2]: Create operations should not have query parameters. http://go/ipa/106',
message: 'Create operations should not have query parameters. Found [query-param-2]. http://go/ipa/106',
path: ['paths', '/resourceTwo', 'post'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
import testRule from './__helpers__/testRule';
import { DiagnosticSeverity } from '@stoplight/types';

const componentSchemas = {
schemas: {
Schema: {
type: 'object',
},
},
parameters: {
QueryParam: {
name: 'query-param',
in: 'query',
schema: {
type: 'string',
},
},
QueryParam2: {
name: 'query-param-2',
in: 'query',
schema: {
type: 'string',
},
},
PathParam: {
name: 'resource-id',
in: 'path',
schema: {
type: 'string',
},
},
envelope: {
name: 'envelope',
in: 'query',
},
pretty: {
name: 'pretty',
in: 'query',
},
},
};

testRule('xgen-IPA-107-put-must-not-have-query-params', [
{
name: 'valid put',
document: {
components: componentSchemas,
paths: {
'/resource/{id}': {
put: {
parameters: [
{
name: 'header-param',
in: 'header',
schema: { type: 'string' },
},
{
name: 'resource-id',
in: 'path',
schema: {
$ref: '#/components/schemas/Schema',
},
},
{
$ref: '#/components/parameters/PathParam',
},
{
$ref: '#/components/parameters/envelope',
},
{
$ref: '#/components/parameters/pretty',
},
],
},
},
'/resource/{id}/singleton': {
put: {
parameters: [],
},
},
},
},
errors: [],
},
{
name: 'invalid put',
document: {
components: componentSchemas,
paths: {
'/resource/{id}': {
put: {
parameters: [
{
name: 'filter',
in: 'query',
schema: { type: 'string' },
},
],
},
},
'/resource/{id}/singleton': {
put: {
parameters: [
{
name: 'header-param',
in: 'header',
schema: { type: 'string' },
},
{
$ref: '#/components/parameters/QueryParam',
},
{
$ref: '#/components/parameters/QueryParam2',
},
],
},
},
},
},
errors: [
{
code: 'xgen-IPA-107-put-must-not-have-query-params',
message: 'Update operations must not have query parameters. Found [filter]. http://go/ipa-spectral#IPA-107',
path: ['paths', '/resource/{id}', 'put'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-put-must-not-have-query-params',
message:
'Update operations must not have query parameters. Found [query-param]. http://go/ipa-spectral#IPA-107',
path: ['paths', '/resource/{id}/singleton', 'put'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-put-must-not-have-query-params',
message:
'Update operations must not have query parameters. Found [query-param-2]. http://go/ipa-spectral#IPA-107',
path: ['paths', '/resource/{id}/singleton', 'put'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'invalid put with exceptions',
document: {
components: componentSchemas,
paths: {
'/resource/{id}': {
put: {
parameters: [
{
name: 'filter',
in: 'query',
schema: { type: 'string' },
},
],
'x-xgen-IPA-exception': {
'xgen-IPA-107-put-must-not-have-query-params': 'Reason',
},
},
},
'/resource/{id}/singleton': {
put: {
parameters: [
{
$ref: '#/components/parameters/QueryParam',
},
],
'x-xgen-IPA-exception': {
'xgen-IPA-107-put-must-not-have-query-params': 'Reason',
},
},
},
},
},
errors: [],
},
]);

testRule('xgen-IPA-107-patch-must-not-have-query-params', [
{
name: 'valid patch',
document: {
components: componentSchemas,
paths: {
'/resource/{id}': {
patch: {
parameters: [
{
name: 'header-param',
in: 'header',
schema: { type: 'string' },
},
{
name: 'resource-id',
in: 'path',
schema: {
$ref: '#/components/schemas/Schema',
},
},
{
$ref: '#/components/parameters/PathParam',
},
{
$ref: '#/components/parameters/envelope',
},
{
$ref: '#/components/parameters/pretty',
},
],
},
},
'/resource/{id}/singleton': {
patch: {
parameters: [],
},
},
},
},
errors: [],
},
{
name: 'invalid patch',
document: {
components: componentSchemas,
paths: {
'/resource/{id}': {
patch: {
parameters: [
{
name: 'filter',
in: 'query',
schema: { type: 'string' },
},
],
},
},
'/resource/{id}/singleton': {
patch: {
parameters: [
{
name: 'header-param',
in: 'header',
schema: { type: 'string' },
},
{
$ref: '#/components/parameters/QueryParam',
},
{
$ref: '#/components/parameters/QueryParam2',
},
],
},
},
},
},
errors: [
{
code: 'xgen-IPA-107-patch-must-not-have-query-params',
message: 'Update operations must not have query parameters. Found [filter]. http://go/ipa-spectral#IPA-107',
path: ['paths', '/resource/{id}', 'patch'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-patch-must-not-have-query-params',
message:
'Update operations must not have query parameters. Found [query-param]. http://go/ipa-spectral#IPA-107',
path: ['paths', '/resource/{id}/singleton', 'patch'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-patch-must-not-have-query-params',
message:
'Update operations must not have query parameters. Found [query-param-2]. http://go/ipa-spectral#IPA-107',
path: ['paths', '/resource/{id}/singleton', 'patch'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'invalid patch with exceptions',
document: {
components: componentSchemas,
paths: {
'/resource/{id}': {
patch: {
parameters: [
{
name: 'filter',
in: 'query',
schema: { type: 'string' },
},
],
'x-xgen-IPA-exception': {
'xgen-IPA-107-patch-must-not-have-query-params': 'Reason',
},
},
},
'/resource/{id}/singleton': {
patch: {
parameters: [
{
$ref: '#/components/parameters/QueryParam',
},
],
'x-xgen-IPA-exception': {
'xgen-IPA-107-patch-must-not-have-query-params': 'Reason',
},
},
},
},
},
errors: [],
},
]);
1 change: 1 addition & 0 deletions tools/spectral/ipa/ipa-spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends:
- ./rulesets/IPA-104.yaml
- ./rulesets/IPA-105.yaml
- ./rulesets/IPA-106.yaml
- ./rulesets/IPA-107.yaml
- ./rulesets/IPA-108.yaml
- ./rulesets/IPA-109.yaml
- ./rulesets/IPA-113.yaml
Expand Down
2 changes: 1 addition & 1 deletion tools/spectral/ipa/rulesets/IPA-005.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ functions:
rules:
xgen-IPA-005-exception-extension-format:
description: |
IPA exception extensions must follow the correct format. http://go/ipa/5
IPA exception extensions must follow the correct format.

##### Implementation details
Rule checks for the following conditions:
Expand Down
2 changes: 1 addition & 1 deletion tools/spectral/ipa/rulesets/IPA-105.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rules:
function: 'eachResourceHasListMethod'
xgen-IPA-105-list-method-response-is-get-method-response:
description: >-
The response body of the List method should consist of the same resource object returned by the Get method. http://go/ipa/105
The response body of the List method should consist of the same resource object returned by the Get method.

##### Implementation details

Expand Down
2 changes: 2 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-106.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ rules:
given: '$.paths[*].post'
then:
function: 'createMethodShouldNotHaveQueryParameters'
functionOptions:
ignoredValues: ['pretty', 'envelope']
xgen-IPA-106-create-method-request-body-is-get-method-response:
description: >-
Request body content of the Create method and response content of the Get method should refer to the same resource. http://go/ipa/106
Expand Down
Loading
Loading