diff --git a/examples/docs/complex.schema.md b/examples/docs/complex.schema.md index ff749c8c..3f20c860 100644 --- a/examples/docs/complex.schema.md +++ b/examples/docs/complex.schema.md @@ -30,6 +30,7 @@ This is an example schema that uses types defined in other schemas. | [refabstract](#refabstract) | `object` | **Required** | No | Complex References (this schema) | | [reflist](#reflist) | Simple | Optional | No | Complex References (this schema) | | [refnamed](#refnamed) | Simple | Optional | No | Complex References (this schema) | +| [refobj](#refobj) | `object` | Optional | No | Complex References (this schema) | | [xor](#xor) | complex | Optional | No | Complex References (this schema) | | `int.*` | `integer` | Pattern | No | Complex References (this schema) | | `str.*` | `string` | Pattern | No | Complex References (this schema) | @@ -158,6 +159,33 @@ All items must be of the type: - [Simple](simple.schema.md) – `https://example.com/schemas/simple` +## refobj + +`refobj` + +- is optional +- type: `object` +- defined in this schema + +### refobj Type + +`object` with following properties: + +| Property | Type | Required | +| -------- | ------ | -------- | +| `foo` | Simple | Optional | + +#### foo + +`foo` + +- is optional +- type: Simple + +##### foo Type + +- [Simple](simple.schema.md) – `https://example.com/schemas/simple` + ## xor Exclusive choice. diff --git a/examples/generated-schemas/complex.schema.json b/examples/generated-schemas/complex.schema.json index b1a216cc..dca32439 100644 --- a/examples/generated-schemas/complex.schema.json +++ b/examples/generated-schemas/complex.schema.json @@ -23,6 +23,14 @@ "$ref": "https://example.com/schemas/simple" } }, + "refobj": { + "type": "object", + "properties": { + "foo": { + "$ref": "https://example.com/schemas/simple" + } + } + }, "or": { "description": "String or number…", "anyOf": [ diff --git a/examples/schemas/complex.schema.json b/examples/schemas/complex.schema.json index 16de8f7d..0e3d1e35 100644 --- a/examples/schemas/complex.schema.json +++ b/examples/schemas/complex.schema.json @@ -23,6 +23,14 @@ "$ref": "https://example.com/schemas/simple" } }, + "refobj": { + "type": "object", + "properties": { + "foo": { + "$ref": "https://example.com/schemas/simple" + } + } + }, "or": { "description": "String or number…", "anyOf": [ diff --git a/lib/schema.js b/lib/schema.js index 252b17fa..4315d536 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -82,6 +82,7 @@ var resolve$ref = Promise.method(function(val, base$id){ } if (refArr.refType === 'yAbsFSchema'){ + val.type = link.$linkVal; val.$linkVal = link.$linkVal; val.$linkPath = link.$linkPath; return val; @@ -113,6 +114,21 @@ var processFurther = Promise.method(function(val, key, $id){ }); }); } + } else if (val['properties'] && val['type'] === 'object') { + _.each(_.entries(val['properties']), function(property) { + const [ propertyKey, propertyValue ] = property; + if (propertyValue['$ref']) { + resolve$ref(propertyValue).then(s => { + _.forOwn(s, (v, k) => { + if (k !== '$ref'){ + val['properties'][propertyKey][k] = v; + } + }); + }); + } + }); + + return val; } //TODO if any other keyword return val; diff --git a/spec/examples/complex.schema.md b/spec/examples/complex.schema.md index ff749c8c..3f20c860 100644 --- a/spec/examples/complex.schema.md +++ b/spec/examples/complex.schema.md @@ -30,6 +30,7 @@ This is an example schema that uses types defined in other schemas. | [refabstract](#refabstract) | `object` | **Required** | No | Complex References (this schema) | | [reflist](#reflist) | Simple | Optional | No | Complex References (this schema) | | [refnamed](#refnamed) | Simple | Optional | No | Complex References (this schema) | +| [refobj](#refobj) | `object` | Optional | No | Complex References (this schema) | | [xor](#xor) | complex | Optional | No | Complex References (this schema) | | `int.*` | `integer` | Pattern | No | Complex References (this schema) | | `str.*` | `string` | Pattern | No | Complex References (this schema) | @@ -158,6 +159,33 @@ All items must be of the type: - [Simple](simple.schema.md) – `https://example.com/schemas/simple` +## refobj + +`refobj` + +- is optional +- type: `object` +- defined in this schema + +### refobj Type + +`object` with following properties: + +| Property | Type | Required | +| -------- | ------ | -------- | +| `foo` | Simple | Optional | + +#### foo + +`foo` + +- is optional +- type: Simple + +##### foo Type + +- [Simple](simple.schema.md) – `https://example.com/schemas/simple` + ## xor Exclusive choice.