Skip to content

Commit

Permalink
fix: if/then/else operators
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed May 26, 2022
1 parent 018edcb commit 86fcbfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export function traverse(schema, options, spec, context) {

if (schema.if && schema.then) {
popSchemaStack(seenSchemasStack, context);
return tryInferExample(schema) || traverse(mergeDeep(schema.if, schema.then), options, spec, context);
const { if: ifSchema, then, ...rest } = schema;
return traverse(mergeDeep(rest, ifSchema, then), options, spec, context);
}

let example = inferExample(schema);
Expand Down
4 changes: 3 additions & 1 deletion test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ describe('Integration', function() {
it('should support basic if/then/else usage', () => {
schema = {
type: 'object',
properties: {top: {type: 'number'}},
if: {properties: {foo: {type: 'string', format: 'email'}}},
then: {properties: {bar: {type: 'string'}}},
else: {properties: {baz: {type: 'number'}}},
Expand All @@ -467,7 +468,8 @@ describe('Integration', function() {
result = OpenAPISampler.sample(schema);
expected = {
foo: 'user@example.com',
bar: 'string'
bar: 'string',
top: 0,
};
expect(result).to.deep.equal(expected);
})
Expand Down

0 comments on commit 86fcbfb

Please sign in to comment.