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

The generator does not handle allOf/anyOf/oneOf properly if schemas include properties, and are not references. #52

Closed
MaxSavenkov opened this issue Apr 18, 2018 · 5 comments

Comments

@MaxSavenkov
Copy link

This schema:

{
  "$id" : "id",
  "title" : "title",
  "description" : "desc", 
  "type" : "object",

  "allOf": [
    { "properties": {
        "type": { "enum": [ "one", "two" ] }
      }, "required" : ["type"]
    },
    { "properties": {
        "test": { "type": "string" }
      }, "required" : ["test"]
    }
  ]
}

Produces this MarkDown:

# title Schema

id


desc

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

# title Properties

| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [test](#test) | `string` | **Required** | title (this schema) |
| `*` | any | Additional | this schema *allows* additional properties |

## test


`test`
* is **required**
* type: `string`
* defined in this schema

### test Type


`string`

The "type" property disappears completely. However, this is a valid schema that requires both properties. Additionally, if you change one of the "allOf" elements to "$ref" with the same content, everything works just fine.

The same problem applies to anyOf and oneOf combinations.

@trieloff trieloff added the bug label Apr 27, 2018
@trieloff
Copy link
Collaborator

For the allOf case this is a clear bug.

For anyOf and oneOf, we would first have to define what the output would look like.

@MaxSavenkov
Copy link
Author

Is there any difference between the three in terms of output? "and", "or" and "xor" examples from https://github.com/adobe/jsonschema2md/blob/master/examples/docs/complex.schema.md seem to follow the same rules visually, with just a different preface and headers.

@trieloff
Copy link
Collaborator

The difference is that in complex.schema.json we have the oneOf at the level of individual properties, not at the root of the schema.

One way to express it could be a big preface with multiple property tables – and then a repetition of the property lists.

@AndyOGo
Copy link
Contributor

AndyOGo commented May 24, 2018

I face the same issue, using allOf and mixin a ref with properties.

My schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$id": "http://www.axa.ch/schemas/components/Link.json",
    "type": "object",
    "title": "Link",
    "description": "Renders a Link.",
    "additionalProperties": false,
    "required": [
        "name",
        "component"
    ],
    "properties": {
        "name": {
            "$ref": "http://www.axa.ch/schemas/types/bpmid.json#"
        },
        "component": {
            "allOf": [
                {
                    "$ref": "http://www.axa.ch/schemas/types/component.json#"
                },
                {
                    "enum": [
                        "Link"
                    ]
                }
            ]
        },
        "properties": {
            "type": "object",
            "title": "Properties",
            "description": "Properties of Link.",
            "additionalProperties": false,
            "properties": {
                "value": {
                    "type": "string",
                    "title": "Value",
                    "description": "The value of the Link."
                },
                "href": {
                    "type": "string",
                    "title": "Href",
                    "description": "URL of the Link."
                }
            }
        },
        "style": {
            "type": "object",
            "title": "Style",
            "description": "Styles of Textarea.",
            "additionalProperties": false,
            "properties": {
                "color": {
                    "type": "string",
                    "title": "Color",
                    "description": "Color of Link.",
                    "enum": [
                        "red",
                        "white",
                        "blue"
                    ],
                    "default": "blue"
                },
                "listed": {
                    "type": "boolean",
                    "title": "Listed",
                    "description": "Whether or not to us lested style.",
                    "default": "false"
                },
                "arrow": {
                    "type": "boolean",
                    "title": "Arrow",
                    "description": "Whether or not to display an arrow icon or not.",
                    "default": "false"
                },
                "motion": {
                    "type": "boolean",
                    "title": "Motion",
                    "description": "Whether or not to use animation upon hovering.",
                    "default": "false"
                }
            }
        },
        "events": {
            "type": "array",
            "title": "Events",
            "description": "Supported events of Link.",
            "uniqueItems": true,
            "additionalItems": false,
            "items": [
                {
                    "$ref": "http://www.axa.ch/schemas/types/event.json#"
                }
            ]
        }
    }
}

And the generated markdown:

# Link Schema

http://www.axa.ch/schemas/components/Link.json


Renders a Link.

| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Defined In |
|----------|------------|--------|--------------|-------------------|-----------------------|------------|
| Can be instantiated | No | Experimental | No | Forbidden | Forbidden | [components/Link.json](components/Link.json) |
## Schema Hierarchy

* Link `http://www.axa.ch/schemas/components/Link.json`
  * [BPMID](../types/bpmid.md) `http://www.axa.ch/schemas/types/bpmid.json`


# Link Properties

| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [component](#component) | complex | **Required** | Link (this schema) |
| [events](#events) | `array` | Optional | Link (this schema) |
| [name](#name) | BPMID | **Required** | Link (this schema) |
| [properties](#properties) | `object` | Optional | Link (this schema) |
| [style](#style) | `object` | Optional | Link (this schema) |

## component


`component`
* is **required**
* type: complex
* defined in this schema

### component Type


**All** of the following *requirements* need to be fulfilled.


#### Requirement 1


* []() – `http://www.axa.ch/schemas/types/component.json#`


#### Requirement 2







## events
### Events

Supported events of Link.

`events`
* is optional
* type: `array`

* defined in this schema

### events Type


Array type: `array`

All items must be of the type:
Unknown type ``.

```json
{
  "type": "array",
  "title": "Events",
  "description": "Supported events of Link.",
  "uniqueItems": true,
  "additionalItems": false,
  "items": [
    {
      "$ref": "http://www.axa.ch/schemas/types/event.json#"
    }
  ],
  "simpletype": "`array`"
}

name

name

  • is required
  • type: BPMID
  • defined in this schema

name Type

  • BPMIDhttp://www.axa.ch/schemas/types/bpmid.json#

properties

Properties

Properties of Link.

properties

  • is optional
  • type: object
  • defined in this schema

properties Type

object with following properties:

Property Type Required
href string Optional
value string Optional

href

Href

URL of the Link.

href

  • is optional
  • type: string
href Type

string

value

Value

The value of the Link.

value

  • is optional
  • type: string
value Type

string

style

Style

Styles of Textarea.

style

  • is optional
  • type: object
  • defined in this schema

style Type

object with following properties:

Property Type Required Default
arrow boolean Optional "false"
color string Optional "blue"
listed boolean Optional "false"
motion boolean Optional "false"

arrow

Arrow

Whether or not to display an arrow icon or not.

arrow

  • is optional
  • type: boolean
  • default: "false"
arrow Type

boolean

color

Color

Color of Link.

color

  • is optional
  • type: enum
  • default: "blue"

The value of this property must be equal to one of the known values below.

color Known Values
Value Description
red
white
blue

listed

Listed

Whether or not to us lested style.

listed

  • is optional
  • type: boolean
  • default: "false"
listed Type

boolean

motion

Motion

Whether or not to use animation upon hovering.

motion

  • is optional
  • type: boolean
  • default: "false"
motion Type

boolean

@trieloff trieloff mentioned this issue Dec 11, 2019
7 tasks
trieloff pushed a commit that referenced this issue Dec 16, 2019
# [4.0.0](v3.3.1...v4.0.0) (2019-12-16)

### Bug Fixes

* **i18n:** use correct file name format ([43a74f4](43a74f4))
* **markdown:** constraint values can be zero now ([2e057fd](2e057fd))
* **markdown:** handle null as a constant value ([e652e11](e652e11))
* **proxy:** remove logging statements ([616a1d9](616a1d9))
* **schemas:** remove references going nowhere ([2186142](2186142))

### Build System

* **dependencies:** remove unused dependencies ([dbc9192](dbc9192))

### Code Refactoring

* **cli:** remove bluebird, lodash, simplify arg parsing ([b6b1822](b6b1822))

### Continuous Integration

* **test:** require node 10 ([ba4a947](ba4a947))

### Documentation

* **changelog:** mention changes for v4 ([4dfe90c](4dfe90c)), closes [#126](#126) [#174](#174) [#72](#72) [#73](#73) [#94](#94) [#52](#52) [#20](#20) [#125](#125) [#177](#177) [#34](#34) [#123](#123)

### Features

* **cli:** generate JSON schema output ([dd18f3b](dd18f3b)), closes [#176](#176)
* **formats:** add support for formats: json-pointer, relative-json-pointer, regex, and uri-template ([689c158](689c158))
* **i18n:** new internationalization system ([1a664de](1a664de))
* **i18n:** provide complete en_US translation ([5eb0c89](5eb0c89))
* **markdown:** add header surpression ([6225b9f](6225b9f))
* **markdown:** add support for `default` keyword ([72a0fde](72a0fde))
* **markdown:** add support for comments ([07bb52f](07bb52f))
* **markdown:** add YAML frontmatter support ([4df92e6](4df92e6))
* **markdown:** create and write markdown ([e521541](e521541))
* **markdown:** generate additional detail ([cc07df2](cc07df2))
* **markdown:** generate header again ([011427c](011427c))
* **markdown:** generate some property details ([fa34cf1](fa34cf1))
* **markdown:** generate type details ([c9f19e1](c9f19e1))
* **markdown:** highlight keyword usage for documentation ([d35e4ed](d35e4ed)), closes [#100](#100)
* **markdown:** list nested schemas in README ([608674b](608674b))
* **markdown:** list nested schemas in README ([87e8489](87e8489))
* **markdown:** show examples ([c8e8dfa](c8e8dfa))
* **markdown:** show extensibility and abstraction in header ([90a9a8e](90a9a8e))
* **markdown:** show id and status in header ([08e1923](08e1923))
* **markdown:** show id and status in header ([b6fcf53](b6fcf53))
* **markdown:** show join types ([12af018](12af018))
* **markdown:** show some info about properties, switch i18n library ([f8a32df](f8a32df))
* **markdown:** show type, link, additional and custom properties in header ([eff129a](eff129a))
* **markdown:** show value constraints ([515969c](515969c))
* **markdown:** support item arrays and additionalItems ([c9fbcdf](c9fbcdf)), closes [#31](#31)
* **markdown:** support patternProperties and additionalProperties ([1386ee3](1386ee3)), closes [#95](#95) [#180](#180)
* **proxy:** generate meta information ([ac65ac6](ac65ac6))
* **proxy:** generate slugs ([eacbf38](eacbf38))
* **proxy:** resolve references ([4cea068](4cea068))
* **readme:** generate readme again ([d6b9e5e](d6b9e5e))
* **readme:** mention the most common schema version ([fc583d7](fc583d7))
* **schema:** add full support for "A Vocabulary for the Contents of String-Encoded Data" ([96ca3a6](96ca3a6))
* **schema:** add support for keyword `$defs` ([70b63c8](70b63c8))
* **schema:** add support for keyword `deprecated` ([934b856](934b856))
* **schema:** add support for readOnly and writeOnly schemas and properties ([7452882](7452882))

### BREAKING CHANGES

* **changelog:**
* **i18n:** The file format for the i18n files has changed

You can now specify the language to use using `-l` and `jsonschema2md` will pick up the correct language configuration.
* **test:** Node 8 is no longer supported
* **dependencies:** Removes the JSON schema validation feature entirely
* **cli:** Repaces lodash with ferrum, removed bluebird, changes the meaning of `--schema-out` or `-x` to be no longer relative to output dir

The `--schema-out` or `-x` command line option is no longer relative to the output path (specified with `-o` or `--out`)
@trieloff
Copy link
Collaborator

🎉 This issue has been resolved in version 4.0.0 🎉

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

No branches or pull requests

3 participants