-
Notifications
You must be signed in to change notification settings - Fork 3
Add linting rules for AEP-126: Enumerations #59
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
base: main
Are you sure you want to change the base?
Changes from all commits
196ba23
2f3e3ae
0ecafa4
b3b89b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| functionsDir: ../functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| functions: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - aep-126-enum-case-consistent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - aep-126-enum-null-first | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - aep-126-enum-nullable-declaration | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - aep-126-no-standard-value-enums | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| rules: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| aep-126-enum-type-string: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Enumerated fields should use type string, not integer or other types. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: Enum field "{{property}}" should have type "string", not "{{error}}". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: error | ||||||||||||||||||||||||||||||||||||||||||||||||||
| formats: ['oas2', 'oas3'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| given: $..[?(@property === 'enum')]^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| then: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| field: type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function: schema | ||||||||||||||||||||||||||||||||||||||||||||||||||
| functionOptions: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| oneOf: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - const: string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - type: array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| contains: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const: string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| maxItems: 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| aep-126-enum-case-consistent: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: All enum values in a field should use consistent case format. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: '{{error}}' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: warn | ||||||||||||||||||||||||||||||||||||||||||||||||||
| formats: ['oas2', 'oas3'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| given: $..[?(@property === 'enum')]^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| then: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function: aep-126-enum-case-consistent | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| aep-126-enum-null-first: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: If enum is nullable, null should be the first value in the enum array. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: '{{error}}' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: warn | ||||||||||||||||||||||||||||||||||||||||||||||||||
| formats: ['oas2', 'oas3'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no good way to represent "nullable" fields in oas2, so I think any rule that involves nullable types should not declare that it works on oas2.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| given: $..[?(@property === 'enum')]^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| then: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function: aep-126-enum-null-first | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| aep-126-enum-nullable-declaration: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: If enum contains null, field must declare nullable true. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: '{{error}}' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: error | ||||||||||||||||||||||||||||||||||||||||||||||||||
| formats: ['oas2', 'oas3'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| given: $..[?(@property === 'enum')]^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| then: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function: aep-126-enum-nullable-declaration | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| aep-126-no-standard-value-enums: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Fields should not enumerate standard codes (language, country, currency, media types). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: '{{error}}' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: warn | ||||||||||||||||||||||||||||||||||||||||||||||||||
| formats: ['oas2', 'oas3'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| given: $..[?(@property === 'enum')]^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| then: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function: aep-126-no-standard-value-enums | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need a custom function here. I think we can write the rule this way and avoid custom js code.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| aep-126-enum-has-description: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Enum fields should include a description explaining their purpose. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: Enum field "{{property}}" should have a description. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: info | ||||||||||||||||||||||||||||||||||||||||||||||||||
| formats: ['oas2', 'oas3'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| given: $..[?(@property === 'enum')]^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| then: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| field: description | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function: truthy | ||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Since this is used in multiple
givens, it seems like a good candidate for an alias.