Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -0,0 +1,188 @@
import testRule from './__helpers__/testRule';
import { DiagnosticSeverity } from '@stoplight/types';

const parameters = {
parameters: {
includeCount: {
name: 'includeCount',
in: 'query',
schema: {
type: 'boolean',
default: true,
},
},
itemsPerPage: {
name: 'itemsPerPage',
in: 'query',
schema: {
type: 'integer',
default: 100,
},
},
},
};

testRule('xgen-IPA-110-collections-request-includeCount-not-required', [
{
name: 'valid',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'includeCount',
in: 'query',
schema: {
type: 'boolean',
},
},
],
},
},
'resources/{resourceId}': {
get: {},
},
'/resourcesTwo': {
get: {
parameters: [
{
$ref: '#/components/parameters/includeCount',
},
],
},
},
'resourcesTwo/{resourceId}': {
get: {},
},
},
components: parameters,
},
errors: [],
},
{
name: 'valid - includeCount not present',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
$ref: '#/components/parameters/itemsPerPage',
},
],
},
},
'resources/{resourceId}': {
get: {},
},
},
components: parameters,
},
errors: [],
},
{
name: 'valid - no parameters at all',
document: {
paths: {
'/resources': {
get: {},
},
'resources/{resourceId}': {
get: {},
},
},
},
errors: [],
},
{
name: 'invalid - includeCount is required',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'includeCount',
in: 'query',
required: true,
schema: {
type: 'boolean',
},
},
],
},
},
},
},
errors: [
{
code: 'xgen-IPA-110-collections-request-includeCount-not-required',
message: 'includeCount query parameter of List method must not be required.',
path: ['paths', '/resources', 'get'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'invalid - referenced includeCount is required',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
$ref: '#/components/parameters/RequiredIncludeCount',
},
],
},
},
},
components: {
parameters: {
RequiredIncludeCount: {
name: 'includeCount',
in: 'query',
required: true,
schema: {
type: 'boolean',
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-110-collections-request-includeCount-not-required',
message: 'includeCount query parameter of List method must not be required.',
path: ['paths', '/resources', 'get'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'valid - handles exception',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'includeCount',
in: 'query',
required: true,
schema: {
type: 'boolean',
},
},
],
'x-xgen-IPA-exception': {
'xgen-IPA-110-collections-request-includeCount-not-required': 'Reason',
},
},
},
},
},
errors: [],
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import testRule from './__helpers__/testRule';
import { DiagnosticSeverity } from '@stoplight/types';

const componentSchemas = {
Resource: {
type: 'object',
},
PaginatedResourceList: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
results: {
type: 'array',
items: {
$ref: '#/components/schemas/Resource',
},
},
links: {
type: 'array',
},
},
},
};

testRule('xgen-IPA-110-collections-response-define-links-array', [
{
name: 'valid schema',
document: {
paths: {
'/resources': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/PaginatedResourceList',
},
},
},
},
},
},
},
'/resources/{id}': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Resource',
},
},
},
},
},
},
},
},
components: {
schemas: componentSchemas,
},
},
errors: [],
},
{
name: 'invalid schema missing links',
document: {
paths: {
'/resources': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/PaginatedMissingLinks',
},
},
},
},
},
},
},
'/resources/{id}': {
get: {},
},
},
components: {
schemas: {
PaginatedMissingLinks: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-110-collections-response-define-links-array',
message:
'The response for collections should define a links array field, providing links to next and previous pages.',
path: ['paths', '/resources', 'get', 'responses', '200', 'content', 'application/json'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'valid inline schema instead of reference',
document: {
paths: {
'/resources': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
results: {
type: 'array',
items: {
$ref: '#/components/schemas/Resource',
},
},
links: {
type: 'array',
},
},
},
},
},
},
},
},
},
'/resources/{id}': {
get: {},
},
},
components: {
schemas: componentSchemas,
},
},
errors: [],
},
{
name: 'invalid schema missing results with exceptions',
document: {
paths: {
'/resources': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/PaginatedMissingLinks',
},
'x-xgen-IPA-exception': {
'xgen-IPA-110-collections-response-define-links-array': 'Reason',
},
},
},
},
},
},
},
'/resources/{id}': {
get: {},
},
},
components: {
schemas: {
PaginatedMissingLinks: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
},
},
},
},
},
errors: [],
},
]);
Loading
Loading