Skip to content

Commit a518ed3

Browse files
committed
docs
1 parent c298527 commit a518ed3

File tree

1 file changed

+18
-43
lines changed

1 file changed

+18
-43
lines changed

tools/spectral/ipa/rulesets/README.md

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,24 @@ Rule checks for the following conditions:
527527

528528
Rules are based on [http://go/ipa/IPA-125](http://go/ipa/IPA-125).
529529

530+
#### xgen-IPA-125-oneOf-no-base-types
531+
532+
![error](https://img.shields.io/badge/error-red)
533+
API producers should not use oneOf with different base types like integer, string, boolean, or number or references at the same time.
534+
535+
##### Implementation details
536+
Rule checks for the following conditions:
537+
- Applies to schemas with `oneOf` arrays
538+
- Ensures no mixing of base types with references
539+
- Ensures no multiple different base types in the same oneOf
540+
- Base types considered are: integer, string, boolean, number
541+
- Using the same base type multiple times is allowed (e.g., multiple string enums)
542+
543+
##### Rationale
544+
Using oneOf with multiple primitive types can lead to ambiguity and validation problems. Clients may not
545+
be able to properly determine which type to use in which context. Instead, use more specific
546+
object types with clear discriminators.
547+
530548
#### xgen-IPA-125-oneOf-must-have-discriminator
531549

532550
![warn](https://img.shields.io/badge/warning-yellow)
@@ -557,49 +575,6 @@ Rule checks for the following conditions:
557575
```
558576
This is valid because there are exactly 2 mappings for 2 oneOf references, and all values match.
559577
560-
#### xgen-IPA-125-oneOf-no-base-types
561-
562-
![warn](https://img.shields.io/badge/warning-yellow)
563-
API producers should not use oneOf with base types like integer, string, boolean, or number.
564-
565-
##### Implementation details
566-
Rule checks for the following conditions:
567-
- Applies to schemas with `oneOf` arrays
568-
- Ensures no element within oneOf has a type property that is a primitive/base type
569-
- Base types considered are: integer, string, boolean, number
570-
571-
##### Rationale
572-
Using oneOf with primitive types can lead to ambiguity and validation problems. Clients may not
573-
be able to properly determine which type to use in which context. Instead, use more specific
574-
object types with clear discriminators.
575-
576-
##### Example Violation
577-
```yaml
578-
# Incorrect - Using oneOf with base types
579-
type: object
580-
properties:
581-
value:
582-
oneOf:
583-
- type: string
584-
- type: integer
585-
```
586-
587-
##### Example Compliance
588-
```yaml
589-
# Correct - Using oneOf with object types only
590-
type: object
591-
properties:
592-
value:
593-
oneOf:
594-
- $ref: '#/components/schemas/StringValue'
595-
- $ref: '#/components/schemas/IntegerValue'
596-
discriminator:
597-
propertyName: valueType
598-
mapping:
599-
string: '#/components/schemas/StringValue'
600-
integer: '#/components/schemas/IntegerValue'
601-
```
602-
603578
604579
605580

0 commit comments

Comments
 (0)