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

JSON Schema generation improvements for base types #592

Closed
dselman opened this issue Jan 17, 2023 · 0 comments · Fixed by #593
Closed

JSON Schema generation improvements for base types #592

dselman opened this issue Jan 17, 2023 · 0 comments · Fixed by #593

Comments

@dselman
Copy link
Contributor

dselman commented Jan 17, 2023

Bug Report 🐛

We currently generate a JSON Schema for a concept by expanding all the properties of the concept as JSON Schemas. This works well but doesn't capture the inheritance relationships between types.

For example:

namespace [email protected]

abstract concept Animal {
   o String name
}

concept Tiger extends Animal {
   o Integer numStripes
}

concept Camel extends Animal {
   o Integer numHumps
}

concept Zoo {
   o Animal[] animals
}

Produces the following JSON Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "[email protected]": {
      "title": "Animal",
      "description": "An instance of [email protected]",
      "type": "object",
      "properties": {
        "$class": {
          "type": "string",
          "default": "[email protected]",
          "pattern": "^zoo@1\\.0\\.0\\.Animal$",
          "description": "The class identifier for [email protected]"
        },
        "name": {
          "type": "string"
        }
      },
      "required": [
        "$class",
        "name"
      ]
    },
    "[email protected]": {
      "title": "Tiger",
      "description": "An instance of [email protected]",
      "type": "object",
      "properties": {
        "$class": {
          "type": "string",
          "default": "[email protected]",
          "pattern": "^zoo@1\\.0\\.0\\.Tiger$",
          "description": "The class identifier for [email protected]"
        },
        "numStripes": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        }
      },
      "required": [
        "$class",
        "numStripes",
        "name"
      ]
    },
    "[email protected]": {
      "title": "Camel",
      "description": "An instance of [email protected]",
      "type": "object",
      "properties": {
        "$class": {
          "type": "string",
          "default": "[email protected]",
          "pattern": "^zoo@1\\.0\\.0\\.Camel$",
          "description": "The class identifier for [email protected]"
        },
        "numHumps": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        }
      },
      "required": [
        "$class",
        "numHumps",
        "name"
      ]
    },
    "[email protected]": {
      "title": "Zoo",
      "description": "An instance of [email protected]",
      "type": "object",
      "properties": {
        "$class": {
          "type": "string",
          "default": "[email protected]",
          "pattern": "^zoo@1\\.0\\.0\\.Zoo$",
          "description": "The class identifier for [email protected]"
        },
        "animals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/[email protected]"
          }
        }
      },
      "required": [
        "$class",
        "animals"
      ]
    }
  }
}

Expected Behavior

The animals array for Zoo should indicate that this can be oneOf Camel or Tiger (not Animal because it is abstract.

 "animals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/[email protected]"
          }
        }

Current Behavior

Possible Solution

Steps to Reproduce

Context (Environment)

Desktop

  • OS: [e.g. macOS]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 0.22.15]

Detailed Description

Possible Implementation

dselman added a commit that referenced this issue Jan 17, 2023
dselman added a commit that referenced this issue Jan 17, 2023
* fix: JSON Schema generation improvements for base types #592

Signed-off-by: Dan Selman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant