Skip to content

Commit

Permalink
Merge pull request #141 from mikespokefire/feature/fix-ref-on-nested-…
Browse files Browse the repository at this point in the history
…objects

fix: Fix `$ref` within nested objects not generating correct markdown
  • Loading branch information
trieloff authored Jul 19, 2019
2 parents 8c26903 + b8c9a49 commit 821a272
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/docs/complex.schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions examples/generated-schemas/complex.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 8 additions & 0 deletions examples/schemas/complex.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
16 changes: 16 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions spec/examples/complex.schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 821a272

Please sign in to comment.