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

$ref only works on first level, broken on nested objects #136

Closed
aeneasr opened this issue Jul 17, 2019 · 6 comments · Fixed by #141
Closed

$ref only works on first level, broken on nested objects #136

aeneasr opened this issue Jul 17, 2019 · 6 comments · Fixed by #141

Comments

@aeneasr
Copy link

aeneasr commented Jul 17, 2019

What did you do

I tried to generate markdown files for schemas:

./schemas/core.schema.json

{
  "$id": "https://example.org/core.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "foo": {
      "type": "object",
      "properties": {
        "bar": {
          "$ref": "https://example.org/extension.json#"
        }
      }
    },
    "profiling": {
      "$ref": "https://example.org/extension.json#"
    }
  },
  "required": [],
  "additionalProperties": false
}

./schemas/extension.schema.json

{
  "$id": "https://example.org/extension.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Baz",
  "type": "string",
  "enum": ["foo", "bar"]
}

using jsonschema2md -d ./schemas -o ./generated/schemas.

What did you expect to happen

I expect references to generate the appropriate links.

What happened

Apparently, only ref for profiling was resolved. For foo.bar that did not work:

# Schema

https://example.org/core.json

| Abstract            | Extensible | Status       | Identifiable | Custom Properties | Additional Properties | Defined In                           |
| ------------------- | ---------- | ------------ | ------------ | ----------------- | --------------------- | ------------------------------------ |
| Can be instantiated | No         | Experimental | No           | Forbidden         | Forbidden             | [core.schema.json](core.schema.json) |

## Schema Hierarchy

- `https://example.org/core.json`
- [Baz](extension.schema.md) `https://example.org/extension.json`

# Properties

| Property                | Type     | Required | Nullable | Defined by    |
| ----------------------- | -------- | -------- | -------- | ------------- |
| [foo](#foo)             | `object` | Optional | No       | (this schema) |
| [profiling](#profiling) | Baz      | Optional | No       | (this schema) |

## foo

`foo`

- is optional
- type: `object`
- defined in this schema

### foo Type

`object` with following properties:

| Property | Type | Required |
| -------- | ---- | -------- |
| `bar`    |      | Optional |

#### bar

`bar`

- is optional
- type: reference

##### bar Type

<!--
####
The following link is broken
####
-->
- []()`https://example.org/extension.json#`

## profiling

`profiling`

- is optional
- type: Baz
- defined in this schema

### profiling Type

<!--
####
But this one works!
####
-->
- [Baz](extension.schema.md)`https://example.org/extension.json#`

What's your environment

  • Operating System: macOS latest
  • node.js version: v12.5.0
  • jsonschema2md version: 2.1.1
@aeneasr
Copy link
Author

aeneasr commented Jul 17, 2019

Log output shows "unresolved reference" once:

07
info: output directory: /Users/foobar/workspaces/js/docs/generated/schemas
info: finished reading all *.schema.json files in /Users/foobar/workspaces/js/docs/schemas, beginning processing….
/Users/foobar/workspaces/js/docs/schemas/core.schema.json
unresolved reference: https://example.org/extension.json#
/Users/foobar/workspaces/js/docs/schemas/extension.schema.json
Output processed. Trying to make a README.md now
Writing README
info: Processing complete.

@aeneasr
Copy link
Author

aeneasr commented Jul 17, 2019

I wasn't really able to understand how the nested internals work, but what I observed is that resolve$ref apparently is only called for the first level, not nested ones. Since resolve$ref isn't hydrating the data with $linkVal / $linkPath, the view throws unresolved reference and does not render the links properly.

@mikespokefire
Copy link
Contributor

I am also experiencing this problem with nested $ref using a schema similar to @aeneasr.

@mikespokefire
Copy link
Contributor

Have just opened #141 which should fix this issue :-)

@trieloff
Copy link
Collaborator

@mikespokefire thank you for the fix, I just merged it.

trieloff pushed a commit that referenced this issue Jul 19, 2019
## [2.1.2](v2.1.1...v2.1.2) (2019-07-19)

### Bug Fixes

* Fix `$ref` within nested objects not generating correct markdown ([b8c9a49](b8c9a49)), closes [#136](#136)
@trieloff
Copy link
Collaborator

🎉 This issue has been resolved in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants