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 does not work recursively #155

Closed
MatthiasPichler opened this issue Jul 26, 2019 · 3 comments · Fixed by #156
Closed

$ref does not work recursively #155

MatthiasPichler opened this issue Jul 26, 2019 · 3 comments · Fixed by #156
Labels

Comments

@MatthiasPichler
Copy link
Contributor

What did you do

I tried to generate markdown files for the schemata below by running npx jsonschema2md -d ./schemas -o ./out

What did you expect to happen

That all references were resolved to the second schema.

What happened

Only references on the first and second level were resolved.

What's your environment

  • Operating System: Ubuntu 19.04
  • node.js version: 12.0.0

Do you have example files:

For these schemata:

./schemas/core.schema.json

{
  "$id": "https://example.org/core",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "nested": {
      "type": "object",
      "properties": {
        "reference": {
          "$ref": "https://example.org/ext#"
        }
      }
    },
    "deep": {
      "type": "object",
      "properties": {
        "deeper": {
          "type": "object",
          "properties": {
            "reference": {
              "$ref": "https://example.org/ext#"
            }
          }
        }
      }
    },
    "first": {
      "$ref": "https://example.org/ext#"
    }
  },
  "required": [],
  "additionalProperties": false
}

./schemas/ext.schema.json

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

I'm getting following Markdown

# Schema

https://example.org/core


| 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`
- [Baz](ext.schema.md) `https://example.org/ext`

# Properties

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

## deep

`deep`

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

### deep Type

`object` with following properties:

| Property | Type   | Required |
| -------- | ------ | -------- |
| `deeper` | object | Optional |

#### deeper

`deeper`

- is optional
- type: `object`

##### deeper Type

`object` with following properties:

| Property    | Type | Required |
| ----------- | ---- | -------- |
| `reference` |      | Optional |

#### reference

`reference`

- is optional
- type: reference

##### reference Type

- []() – `https://example.org/ext#`

## first

`first`

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

### first Type

- [Baz](ext.schema.md) – `https://example.org/ext#`

## nested

`nested`

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

### nested Type

`object` with following properties:

| Property    | Type | Required |
| ----------- | ---- | -------- |
| `reference` | Baz  | Optional |

#### reference

`reference`

- is optional
- type: Baz

##### reference Type

- [Baz](ext.schema.md) – `https://example.org/ext#`

@MatthiasPichler
Copy link
Contributor Author

the following log was created:

07
info: output directory: /home/username/Downloads/schema-test/out
info: finished reading all *.schema.json files in /home/username/Downloads/schema-test/schemas, beginning processing….
/home/username/Downloads/schema-test/schemas/core.schema.json
unresolved reference: https://example.org/ext#
/home/username/Downloads/schema-test/schemas/ext.schema.json
Output processed. Trying to make a README.md now
Writing README
info: Processing complete.

So only one unresolved reference was logged (which is correct)

MatthiasPichler pushed a commit to MatthiasPichler/jsonschema2md that referenced this issue Jul 26, 2019
…nce within an object

A $ref is not correctly resolved when nested within objects deeper than depth 2. Go recursively over
any object properties that are themselves objects to look for a $ref.

fix adobe#155
MatthiasPichler pushed a commit to MatthiasPichler/jsonschema2md that referenced this issue Jul 26, 2019
@MatthiasPichler
Copy link
Contributor Author

I just opened #156 to fix this

trieloff pushed a commit that referenced this issue Jul 29, 2019
## [3.0.1](v3.0.0...v3.0.1) (2019-07-29)

### Bug Fixes

* **schema.js:** fix $ref not being resolved when nested deeper than once within an object ([6eb73c3](6eb73c3)), closes [#155](#155)
@trieloff
Copy link
Collaborator

🎉 This issue has been resolved in version 3.0.1 🎉

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants