Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function build (schema, options) {
`
}

var hasShemaSomeIf = hasIf(schema)
var hasSchemaSomeIf = hasIf(schema)

var main

Expand Down Expand Up @@ -94,7 +94,7 @@ function build (schema, options) {

var dependencies = []
var dependenciesName = []
if (hasAnyOf(schema) || hasShemaSomeIf) {
if (hasAnyOf(schema) || hasSchemaSomeIf) {
dependencies.push(new Ajv())
dependenciesName.push('ajv')
}
Expand Down Expand Up @@ -514,7 +514,7 @@ function addIfThenElse (schema, name, externalSchema, fullSchema) {

r = buildInnerObject(merged, name, externalSchema, fullSchema)
code += r.code
laterCode = r.laterCode
laterCode += r.laterCode

code += `
}
Expand All @@ -529,12 +529,12 @@ function addIfThenElse (schema, name, externalSchema, fullSchema) {
if (merged.if && merged.then) {
innerR = addIfThenElse(merged, name, externalSchema, fullSchema)
code += innerR.code
laterCode = innerR.laterCode
laterCode += innerR.laterCode
}

r = buildInnerObject(merged, name, externalSchema, fullSchema)
code += r.code
laterCode = r.laterCode
laterCode += r.laterCode

code += `
}
Expand Down
46 changes: 42 additions & 4 deletions test/if-then-else.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ const schema = {
'properties': {
'kind': { 'type': 'string', 'enum': ['foobar'] },
'foo': { 'type': 'string' },
'bar': { 'type': 'number' }
'bar': { 'type': 'number' },
'list': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'value': {'type': 'string'}
}
}
}
}
},
'else': {
Expand Down Expand Up @@ -46,7 +56,17 @@ const nestedIfSchema = {
'properties': {
'kind': { 'type': 'string', 'enum': ['foobar'] },
'foo': { 'type': 'string' },
'bar': { 'type': 'number' }
'bar': { 'type': 'number' },
'list': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'value': {'type': 'string'}
}
}
}
}
},
'else': {
Expand Down Expand Up @@ -78,7 +98,17 @@ const nestedElseSchema = {
'properties': {
'kind': { 'type': 'string', 'enum': ['foobar'] },
'foo': { 'type': 'string' },
'bar': { 'type': 'number' }
'bar': { 'type': 'number' },
'list': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'value': {'type': 'string'}
}
}
}
}
},
'else': {
Expand Down Expand Up @@ -107,6 +137,10 @@ const nestedElseSchema = {
const fooBarInput = {
kind: 'foobar',
foo: 'FOO',
list: [{
name: 'name',
value: 'foo'
}],
bar: 42,
hi: 'HI',
hello: 45,
Expand Down Expand Up @@ -134,7 +168,11 @@ const alphabetInput = {
const foobarOutput = JSON.stringify({
kind: 'foobar',
foo: 'FOO',
bar: 42
bar: 42,
list: [{
name: 'name',
value: 'foo'
}]
})
const greetingOutput = JSON.stringify({
kind: 'greeting',
Expand Down