jsonschema2md icon indicating copy to clipboard operation
jsonschema2md copied to clipboard

if-then components get generated but are not linked to parent document

Open Dr-Irv opened this issue 4 years ago • 3 comments

What did you do

Convert the if-then example from JSON Schema doc at https://json-schema.org/understanding-json-schema/reference/conditionals.html using filename test.json. Example replicated below

What did you expect to happen

The if-then parts should be in the file "test.md" .

What happened

The files generated were:

README.md                            test-properties-country.md
test-else-properties-postal_code.md  test-properties-street_address.md
test-else-properties.md              test-properties.md
test-else.md                         test-then-properties-postal_code.md
test-if-properties-country.md        test-then-properties.md
test-if-properties.md                test-then.md
test-if.md                           test.md

So the files related to the if-then-else clause are generated, but there is no link to them, nor is the if-then-else structure documented in a way to understand the linked then and else clauses. In other words the file test-if.md has no links to the files test-then.md and test-else.md .

What's your environment

  • Operating System: Windows 10
  • node.js version: 10.13.0
  • jsonschema2md version: 4.1.1

Do you have example files:

For this schema

{
  "type": "object",
  "properties": {
    "street_address": {
      "type": "string"
    },
    "country": {
      "enum": ["United States of America", "Canada"]
    }
  },
  "if": {
    "properties": { "country": { "const": "United States of America" } }
  },
  "then": {
    "properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } }
  },
  "else": {
    "properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } }
  }
}

I'm getting following Markdown (in test.md)

# Untitled object in undefined Schema

COMMENTED OUT for Github ```txt
COMMENTED OUT for Github undefined
COMMENTED OUT for Github ```




| Abstract            | Extensible | Status         | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In                                               |
| :------------------ | ---------- | -------------- | ------------ | :---------------- | --------------------- | ------------------- | -------------------------------------------------------- |
| Can be instantiated | No         | Unknown status | No           | Forbidden         | Allowed               | none                | [test.json](../schemas/test.json "open original schema") |

## Untitled object in undefined Type

`object` ([Details](test.md))

# undefined Properties

| Property                          | Type          | Required | Nullable       | Defined by                                                                                  |
| :-------------------------------- | ------------- | -------- | -------------- | :------------------------------------------------------------------------------------------ |
| [street_address](#street_address) | `string`      | Optional | cannot be null | [Untitled schema](test-properties-street_address.md "undefined#/properties/street_address") |
| [country](#country)               | Not specified | Optional | cannot be null | [Untitled schema](test-properties-country.md "undefined#/properties/country")               |

## street_address




`street_address`

-   is optional
-   Type: `string`
-   cannot be null
-   defined in: [Untitled schema](test-properties-street_address.md "undefined#/properties/street_address")

### street_address Type

`string`

## country




`country`

-   is optional
-   Type: unknown
-   cannot be null
-   defined in: [Untitled schema](test-properties-country.md "undefined#/properties/country")

### country Type

unknown

### country Constraints

**enum**: the value of this property must be equal to one of the following values:

| Value                        | Explanation |
| :--------------------------- | ----------- |
| `"United States of America"` |             |
| `"Canada"`                   |             |

Dr-Irv avatar Apr 17 '20 21:04 Dr-Irv

That's a case of a missing feature. What would you expect the generated markdown to look for the provided schema?

I haven't built it yet because I don't have any schemas that use if-then-else and felt that I'm not informed enough to decide what a good Markdown representation would be.

trieloff avatar Apr 19 '20 16:04 trieloff

At the top level, I think you just have to state that there is an if-then-else with pointers to the 3 markdown documents containing the "if", "then" and "else" parts. Within each of those 3, they should point to each other, i.e., the "if" should point to the "then" and "else" (if present) markdowns, and the "then" should point to the binding "if" and corresponding "else" (if present) and the "else" should point to the binding "if" and corresponding "then".

Maybe label them as "Conditional" elements in the parent document.

Hope that helps.

We are using the if-then-else construct in one schema, so I think if you got it working on the published example, I could better comment as to whether that structure applies in our example. In our example, the if-then-else part looks like this (substituted out some of the names for confidentiality reasons):

  "if": {
    "properties": {
      "modelType": {
        "const": "ABC"
      }
    }
  },
  "then": {
    "maxProperties": 5,
    "required": ["DEF"]
  },
  "else": {
    "maxProperties": 4
  }

Dr-Irv avatar Apr 20 '20 15:04 Dr-Irv

Hi everyone, is there any update on the if-then-else representation?

M-casado avatar Nov 25 '21 14:11 M-casado