Skip to content

Commit

Permalink
Merge pull request #55 from apiaryio/pksunkara/fix
Browse files Browse the repository at this point in the history
Don't error when there is empty OneOf
  • Loading branch information
honzajavorek committed Apr 30, 2015
2 parents 8499bf0 + 4b3708c commit d881db4
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
lib
node_modules
.idea
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "boutique",
"version": "0.1.6",
"version": "0.1.7",
"author": "Apiary.io <support@apiary.io>",
"description": "The finest representations to emphasize natural beauty of your MSON AST",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/formats/json.coffee
Expand Up @@ -47,6 +47,8 @@ resolveProperties = (props, inherited, cb) ->
results = []
async.eachSeries props, (prop, next) ->
if prop.class is 'oneOf'
return next() if !prop.content.length

# oneOf can result in multiple properties
resolveOneOf prop, inherited, (err, resolvedProps) ->
results = results.concat resolvedProps
Expand Down
2 changes: 2 additions & 0 deletions src/formats/jsonschema-v4.coffee
Expand Up @@ -35,6 +35,8 @@ addDefault = (element, resolvedType, repr, cb) ->
# object with both representation in JSON Schema and optionally also
# some additional info.
resolveProperty = (prop, inherited, cb) ->
return cb(null, {}) if prop.class is 'oneOf'

handleElement prop, inherited, (err, repr) ->
return cb err if err

Expand Down
2 changes: 1 addition & 1 deletion src/inspect.coffee
Expand Up @@ -27,7 +27,7 @@ findTypeName = (typeSpec) ->
# Finds type name within *Element* node of *property* class.
findPropertyName = (propNode, variable = true) ->
nameNode = propNode.content.name
nameNode.literal or (nameNode.variable?.values?[0].literal if variable)
nameNode.literal or (nameNode.variable?.values?[0]?.literal if variable)


# Finds inline description for given *Element* node.
Expand Down
3 changes: 3 additions & 0 deletions test/formats/formats-test.coffee
Expand Up @@ -88,6 +88,7 @@ testFormat
# 'one-of'
# 'one-of-complex'
# 'one-of-properties'
# 'one-of-empty'
'optional'
'required'
'required-array'
Expand Down Expand Up @@ -150,6 +151,7 @@ testFormat
'one-of'
'one-of-complex'
'one-of-properties'
'one-of-empty'
'optional'
'required'
'required-array'
Expand All @@ -161,4 +163,5 @@ testFormat
'string'
'string-literal'
'variable-property'
'deep-nested'
]
139 changes: 139 additions & 0 deletions test/formats/samples-ast/deep-nested.json
@@ -0,0 +1,139 @@
{
"element": "resolvedDataStructure",
"name": null,
"typeDefinition": {
"typeSpecification": {
"name": "object",
"nestedTypes": []
},
"attributes": []
},
"sections": [
{
"class": "memberType",
"content": [
{
"content": {
"name": {
"literal": "a"
},
"description": "",
"valueDefinition": {
"values": [
{
"literal": "b",
"variable": false
}
],
"typeDefinition": {
"typeSpecification": {
"name": null,
"nestedTypes": []
},
"attributes": []
}
},
"sections": []
},
"class": "property"
},
{
"content": {
"name": {
"literal": "c"
},
"description": "",
"valueDefinition": {
"values": [],
"typeDefinition": {
"typeSpecification": {
"name": "array",
"nestedTypes": []
},
"attributes": []
}
},
"sections": [
{
"class": "memberType",
"content": [
{
"content": {
"description": "",
"valueDefinition": {
"values": [],
"typeDefinition": {
"typeSpecification": {
"name": "object",
"nestedTypes": []
},
"attributes": []
}
},
"sections": [
{
"class": "memberType",
"content": [
{
"content": {
"name": {
"literal": "id"
},
"description": "",
"valueDefinition": {
"values": [
{
"literal": "pavan",
"variable": false
}
],
"typeDefinition": {
"typeSpecification": {
"name": null,
"nestedTypes": []
},
"attributes": []
}
},
"sections": []
},
"class": "property"
}
]
}
]
},
"class": "value"
},
{
"content": {
"description": "",
"valueDefinition": {
"values": [
{
"literal": "pkumar",
"variable": false
}
],
"typeDefinition": {
"typeSpecification": {
"name": null,
"nestedTypes": []
},
"attributes": []
}
},
"sections": []
},
"class": "value"
}
]
}
]
},
"class": "property"
}
]
}
]
}
47 changes: 47 additions & 0 deletions test/formats/samples-ast/one-of-empty.json
@@ -0,0 +1,47 @@
{
"element": "resolvedDataStructure",
"name": null,
"typeDefinition": {
"typeSpecification": {
"name": "object",
"nestedTypes": []
},
"attributes": []
},
"sections": [
{
"class": "memberType",
"content": [
{
"class": "property",
"content": {
"name": {
"literal": "city"
},
"description": "",
"valueDefinition": {
"values": [
{
"literal": "prague",
"variable": false
}
],
"typeDefinition": {
"typeSpecification": {
"name": null,
"nestedTypes": []
},
"attributes": []
}
},
"sections": []
}
},
{
"class": "oneOf",
"content": []
}
]
}
]
}
9 changes: 9 additions & 0 deletions test/formats/samples-json/deep-nested.json
@@ -0,0 +1,9 @@
{
"a": "b",
"c": [
{
"id": "pavan"
},
"pkumar"
]
}
3 changes: 3 additions & 0 deletions test/formats/samples-json/one-of-empty.json
@@ -0,0 +1,3 @@
{
"city": "prague"
}

0 comments on commit d881db4

Please sign in to comment.