@@ -94,7 +94,74 @@ testRule('xgen-IPA-125-oneOf-must-have-discriminator', [
9494 errors : [
9595 {
9696 code : 'xgen-IPA-125-oneOf-must-have-discriminator' ,
97- message : 'Each oneOf property must include a discriminator property to define the exact type.' ,
97+ message : 'The schema has oneOf but no discriminator property.' ,
98+ path : [ 'schemas' , 'Animal' ] ,
99+ severity : DiagnosticSeverity . Error ,
100+ } ,
101+ ] ,
102+ } ,
103+ {
104+ name : 'invalid oneOf with non-object discriminator' ,
105+ document : {
106+ components : componentSchemas ,
107+ schemas : {
108+ Animal : {
109+ oneOf : [ { $ref : '#/components/schemas/Dog' } , { $ref : '#/components/schemas/Cat' } ] ,
110+ discriminator : "I'm a string, not an object!" ,
111+ } ,
112+ } ,
113+ } ,
114+ errors : [
115+ {
116+ code : 'xgen-IPA-125-oneOf-must-have-discriminator' ,
117+ message : 'Discriminator property is not an object.' ,
118+ path : [ 'schemas' , 'Animal' ] ,
119+ severity : DiagnosticSeverity . Error ,
120+ } ,
121+ ] ,
122+ } ,
123+ {
124+ name : 'invalid oneOf with discriminator but no propertyName' ,
125+ document : {
126+ components : componentSchemas ,
127+ schemas : {
128+ Animal : {
129+ oneOf : [ { $ref : '#/components/schemas/Dog' } , { $ref : '#/components/schemas/Cat' } ] ,
130+ discriminator : {
131+ mapping : {
132+ dog : '#/components/schemas/Dog' ,
133+ cat : '#/components/schemas/Cat' ,
134+ } ,
135+ } ,
136+ } ,
137+ } ,
138+ } ,
139+ errors : [
140+ {
141+ code : 'xgen-IPA-125-oneOf-must-have-discriminator' ,
142+ message : 'Discriminator has no propertyName defined.' ,
143+ path : [ 'schemas' , 'Animal' ] ,
144+ severity : DiagnosticSeverity . Error ,
145+ } ,
146+ ] ,
147+ } ,
148+ {
149+ name : 'invalid oneOf with discriminator but no mapping' ,
150+ document : {
151+ components : componentSchemas ,
152+ schemas : {
153+ Animal : {
154+ oneOf : [ { $ref : '#/components/schemas/Dog' } , { $ref : '#/components/schemas/Cat' } ] ,
155+ discriminator : {
156+ propertyName : 'type' ,
157+ } ,
158+ } ,
159+ } ,
160+ } ,
161+ errors : [
162+ {
163+ code : 'xgen-IPA-125-oneOf-must-have-discriminator' ,
164+ message : 'Discriminator must have a mapping object.' ,
98165 path : [ 'schemas' , 'Animal' ] ,
99166 severity : DiagnosticSeverity . Error ,
100167 } ,
0 commit comments