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,367 @@
import testRule from './__helpers__/testRule.js';
import { DiagnosticSeverity } from '@stoplight/types';

testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [
{
name: 'valid when enum has exactly 20 values',
document: {
components: {
schemas: {
TestSchema: {
properties: {
status: {
type: 'string',
enum: [
'VALUE_1',
'VALUE_2',
'VALUE_3',
'VALUE_4',
'VALUE_5',
'VALUE_6',
'VALUE_7',
'VALUE_8',
'VALUE_9',
'VALUE_10',
'VALUE_11',
'VALUE_12',
'VALUE_13',
'VALUE_14',
'VALUE_15',
'VALUE_16',
'VALUE_17',
'VALUE_18',
'VALUE_19',
'VALUE_20',
],
},
},
},
},
},
},
errors: [],
},
{
name: 'valid when enum has fewer than 20 values',
document: {
components: {
schemas: {
TestSchema: {
properties: {
status: {
type: 'string',
enum: ['PENDING', 'ACTIVE', 'COMPLETE', 'FAILED'],
},
},
},
},
},
},
errors: [],
},
{
name: 'invalid when enum has more than 20 values',
document: {
components: {
schemas: {
TestSchema: {
properties: {
status: {
type: 'string',
enum: [
'VALUE_1',
'VALUE_2',
'VALUE_3',
'VALUE_4',
'VALUE_5',
'VALUE_6',
'VALUE_7',
'VALUE_8',
'VALUE_9',
'VALUE_10',
'VALUE_11',
'VALUE_12',
'VALUE_13',
'VALUE_14',
'VALUE_15',
'VALUE_16',
'VALUE_17',
'VALUE_18',
'VALUE_19',
'VALUE_20',
'VALUE_21',
],
},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20',
message: 'Inline enum arrays should not exceed 20 values. Current count: 21',
path: ['components', 'schemas', 'TestSchema', 'properties', 'status', 'enum'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'exception on schema',
document: {
components: {
schemas: {
TestSchema: {
properties: {
status: {
type: 'string',
enum: [
'VALUE_1',
'VALUE_2',
'VALUE_3',
'VALUE_4',
'VALUE_5',
'VALUE_6',
'VALUE_7',
'VALUE_8',
'VALUE_9',
'VALUE_10',
'VALUE_11',
'VALUE_12',
'VALUE_13',
'VALUE_14',
'VALUE_15',
'VALUE_16',
'VALUE_17',
'VALUE_18',
'VALUE_19',
'VALUE_20',
'VALUE_21',
'VALUE_22',
'VALUE_23',
'VALUE_24',
'VALUE_25',
],
'x-xgen-IPA-exception': {
'xgen-IPA-123-allowable-enum-values-should-not-exceed-20': 'Legacy enum with more than 20 values',
},
},
},
},
},
},
},
errors: [],
},
{
name: 'invalid with integer enum values exceeding limit',
document: {
components: {
schemas: {
TestSchema: {
properties: {
priority: {
type: 'integer',
enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],
},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20',
message: 'Inline enum arrays should not exceed 20 values. Current count: 21',
path: ['components', 'schemas', 'TestSchema', 'properties', 'priority', 'enum'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'valid for parameters in path operation',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'status',
in: 'query',
schema: {
type: 'string',
enum: ['ACTIVE', 'INACTIVE', 'PENDING'],
},
},
],
},
},
},
},
errors: [],
},
{
name: 'invalid for parameters in path operation exceeding limit',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'status',
in: 'query',
schema: {
type: 'string',
enum: [
'VAL_1',
'VAL_2',
'VAL_3',
'VAL_4',
'VAL_5',
'VAL_6',
'VAL_7',
'VAL_8',
'VAL_9',
'VAL_10',
'VAL_11',
'VAL_12',
'VAL_13',
'VAL_14',
'VAL_15',
'VAL_16',
'VAL_17',
'VAL_18',
'VAL_19',
'VAL_20',
'VAL_21',
],
},
},
],
},
},
},
},
errors: [
{
code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20',
message: 'Inline enum arrays should not exceed 20 values. Current count: 21',
path: ['paths', '/resources', 'get', 'parameters', '0', 'schema', 'enum'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'exception on parameter schema',
document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'status',
in: 'query',
schema: {
type: 'string',
enum: [
'VAL_1',
'VAL_2',
'VAL_3',
'VAL_4',
'VAL_5',
'VAL_6',
'VAL_7',
'VAL_8',
'VAL_9',
'VAL_10',
'VAL_11',
'VAL_12',
'VAL_13',
'VAL_14',
'VAL_15',
'VAL_16',
'VAL_17',
'VAL_18',
'VAL_19',
'VAL_20',
'VAL_21',
'VAL_22',
'VAL_23',
'VAL_24',
'VAL_25',
],
'x-xgen-IPA-exception': {
'xgen-IPA-123-allowable-enum-values-should-not-exceed-20': 'Parameter with many possible values',
},
},
},
],
},
},
},
},
errors: [],
},
{
name: 'valid on with reusable schemas',
Copy link
Collaborator Author

@yelizhenden-mdb yelizhenden-mdb Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Reusable enum schemas are ignored now

document: {
paths: {
'/resources': {
get: {
parameters: [
{
name: 'status',
in: 'query',
schema: {
$ref: '#/components/schemas/StatusEnum',
},
},
],
},
},
},
components: {
schemas: {
StatusEnum: {
type: 'string',
enum: [
'VAL_1',
'VAL_2',
'VAL_3',
'VAL_4',
'VAL_5',
'VAL_6',
'VAL_7',
'VAL_8',
'VAL_9',
'VAL_10',
'VAL_11',
'VAL_12',
'VAL_13',
'VAL_14',
'VAL_15',
'VAL_16',
'VAL_17',
'VAL_18',
'VAL_19',
'VAL_20',
'VAL_21',
'VAL_22',
'VAL_23',
'VAL_24',
'VAL_25',
],
},
TestSchema: {
properties: {
status: {
$ref: '#/components/schemas/StatusEnum',
},
},
},
},
},
},
errors: [],
},
]);
Loading
Loading