Skip to content

Relations: Show as ID Array for JSON Schema #375

@rawkode

Description

@rawkode

This might be a slightly niche request, but please allow me to explain.

I store my data in Git, as YAML files. I'm modelling it as Prisma and syncing the YAML to PostgreSQL to make it available via REST and GraphQL.

The Many to One and Many to Many Models for JSON Schema assume that the sub-types are embedded, when actually for this use-case we want an array of IDs.

Example: I'm modelling my YouTube channel which has a concept of an "Episode" which features one or more technologies.

model Episode {
  id String @id

  technologies Technology[]
}

model Technology {
  id       String    @id
  episodes Episode[]
}

Which generates this embedded JSON schema on each side:

    "Episode": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "technologies": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Technology"
          }
        }
      }
    },
    "Technology": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "episodes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Episode"
          }
        }
      }
    },

Would it be possible to get something merged that allows me to annotate these types as disjunctions so that the following was generated?

    "Episode": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "technologies": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "Technology": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "episodes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions