Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix $ref within nested objects not generating correct markdown #141

Merged
merged 1 commit into from
Jul 19, 2019
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
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