@@ -502,4 +502,83 @@ Rule checks for the following conditions:
502502
503503
504504
505+ ### IPA-125
506+
507+ Rules are based on [ http://go/ipa/IPA-125 ] ( http://go/ipa/IPA-125 ) .
508+
509+ #### xgen-IPA-125-oneOf-must-have-discriminator
510+
511+ ![ error] ( https://img.shields.io/badge/error-red )
512+ Each oneOf property must include a discriminator property to define the exact type.
513+
514+ ##### Implementation details
515+ Rule checks for the following conditions:
516+ - Applies only to schemas with ` oneOf ` containing references
517+ - Ensures a ` discriminator ` property is present with a valid ` propertyName `
518+ - Validates that ` discriminator.mapping ` contains exactly the same number of entries as ` oneOf ` references
519+ - Validates that each ` discriminator.mapping ` value matches a reference in the ` oneOf ` array
520+ - Ignores ` oneOf ` definitions with inline schemas
521+
522+ ##### Matching Logic
523+ - The ` discriminator.mapping ` must have the same number of entries as there are references in the ` oneOf ` array
524+ - Each value in the ` discriminator.mapping ` must match one of the ` $ref ` values in the ` oneOf ` array
525+ - Each ` $ref ` in the ` oneOf ` array must have a corresponding entry in the ` discriminator.mapping `
526+ - Example:
527+ ``` yaml
528+ oneOf :
529+ - $ref : ' #/components/schemas/Dog'
530+ - $ref : ' #/components/schemas/Cat'
531+ discriminator :
532+ propertyName : type
533+ mapping :
534+ dog : ' #/components/schemas/Dog'
535+ cat : ' #/components/schemas/Cat'
536+ ` ` `
537+ This is valid because there are exactly 2 mappings for 2 oneOf references, and all values match.
538+
539+ #### xgen-IPA-125-oneOf-no-base-types
540+
541+ 
542+ API producers should not use oneOf with base types like integer, string, boolean, or number.
543+
544+ ##### Implementation details
545+ Rule checks for the following conditions:
546+ - Applies to schemas with ` oneOf` arrays
547+ - Ensures no element within oneOf has a type property that is a primitive/base type
548+ - Base types considered are : integer, string, boolean, number
549+
550+ # #### Rationale
551+ Using oneOf with primitive types can lead to ambiguity and validation problems. Clients may not
552+ be able to properly determine which type to use in which context. Instead, use more specific
553+ object types with clear discriminators.
554+
555+ # #### Example Violation
556+ ` ` ` yaml
557+ # Incorrect - Using oneOf with base types
558+ type: object
559+ properties:
560+ value:
561+ oneOf:
562+ - type: string
563+ - type: integer
564+ ` ` `
565+
566+ # #### Example Compliance
567+ ` ` ` yaml
568+ # Correct - Using oneOf with object types only
569+ type: object
570+ properties:
571+ value:
572+ oneOf:
573+ - $ref: '#/components/schemas/StringValue'
574+ - $ref: '#/components/schemas/IntegerValue'
575+ discriminator:
576+ propertyName: valueType
577+ mapping:
578+ string: '#/components/schemas/StringValue'
579+ integer: '#/components/schemas/IntegerValue'
580+ ` ` `
581+
582+
583+
505584
0 commit comments