@@ -30,6 +30,7 @@ function convertSchema(schema, path, parent, parentPath) {
3030 schema = stripIllegalKeywords ( schema ) ;
3131 schema = convertTypes ( schema ) ;
3232 schema = convertDependencies ( schema ) ;
33+ schema = rewriteIfThenElse ( schema ) ;
3334 schema = rewriteExclusiveMinMax ( schema ) ;
3435
3536 if ( typeof schema [ 'patternProperties' ] === 'object' ) {
@@ -145,6 +146,28 @@ function convertPatternProperties(schema) {
145146 return schema ;
146147}
147148
149+ function rewriteIfThenElse ( schema ) {
150+ /* @handrews https://github.com/OAI/OpenAPI-Specification/pull/1766#issuecomment-442652805
151+ if and the *Of keywords
152+
153+ There is a really easy solution for implementations, which is that
154+
155+ if: X, then: Y, else: Z
156+
157+ is equivalent to
158+
159+ oneOf: [allOf: [X, Y], allOf: [not: X, Z]]
160+ */
161+ if ( schema . if && schema . then ) {
162+ schema . oneOf = [ { allOf : [ schema . if , schema . then ] } ,
163+ { allOf : [ { not : schema . if } , schema . else ] } ] ;
164+ delete schema . if ;
165+ delete schema . then ;
166+ delete schema . else ;
167+ }
168+ return schema ;
169+ }
170+
148171function rewriteExclusiveMinMax ( schema ) {
149172 if ( typeof schema . exclusiveMaximum === 'number' ) {
150173 schema . maximum = schema . exclusiveMaximum ;
@@ -158,3 +181,4 @@ function rewriteExclusiveMinMax(schema) {
158181}
159182
160183module . exports = convert ;
184+
0 commit comments