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
@@ -0,0 +1,242 @@
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',
},
},
},
},
ResourcePaginatedList: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
results: {
type: 'array',
items: {
$ref: '#/components/schemas/Resource',
},
},
},
},
};

testRule('xgen-IPA-110-collections-response-define-results-array', [
{
name: 'valid schemas with Paginated prefix',
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: 'valid schemas without Paginated prefix but with correct structure',
document: {
paths: {
'/resources': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/ResourcePaginatedList',
},
},
},
},
},
},
},
'/resources/{id}': {
get: {},
},
},
components: {
schemas: componentSchemas,
},
},
errors: [],
},
{
name: 'invalid schema missing results',
document: {
paths: {
'/resources': {
get: {
responses: {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/PaginatedMissingResults',
},
},
},
},
},
},
},
'/resources/{id}': {
get: {},
},
},
components: {
schemas: {
PaginatedMissingResults: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-110-collections-response-define-results-array',
message: 'The response for collections must define an array of results containing the paginated resource.',
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',
},
},
},
},
},
},
},
},
},
},
'/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/PaginatedMissingResults',
},
'x-xgen-IPA-exception': {
'xgen-IPA-110-collections-response-define-results-array': 'Reason',
},
},
},
},
},
},
},
'/resources/{id}': {
get: {},
},
},
components: {
schemas: {
PaginatedMissingResults: {
type: 'object',
properties: {
totalCount: {
type: 'integer',
},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-110-collections-response-define-results-array',
message: 'The response for collections must define an array of results containing the paginated resource.',
path: ['paths', '/resources', 'get', 'responses', '200', 'content', 'application/json'],
severity: DiagnosticSeverity.Warning,
},
],
},
]);
Loading
Loading