-
Notifications
You must be signed in to change notification settings - Fork 15
CLOUDP-306578: IPA-123: Enums #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
59b7aaf
CLOUDP-306578: IPA-123: Enums
yelizhenden-mdb e062ddc
fix on tests
yelizhenden-mdb f3f7087
prettier fix
yelizhenden-mdb ab837aa
reusable enum schemas
yelizhenden-mdb 6bff9a4
reusable enum schemas
yelizhenden-mdb 0b1f8fa
reusable enum schemas
yelizhenden-mdb 4d9bf07
maxEnumValues parameter
yelizhenden-mdb 2c5c2cc
prettier fix
yelizhenden-mdb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
367 changes: 367 additions & 0 deletions
367
tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| 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: [], | ||
| }, | ||
| ]); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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