Skip to content

Support conversion of cyclic types to JSON Schema #1087

Closed

Description

@ssalbdivad

This would allow types like the following to be converted to JSON schema via $ref:

import { scope } from "arktype";

const types = scope({ a: { b: "b" }, b: { a: "a" } }).export();

const jsonSchema = types.a.toJsonSchema();

See https://json-schema.org/understanding-json-schema/structuring

Activity

  1. donovandicks commented on Feb 3, 2025

    @donovandicks

    👋 This issue is relevant to some work I'm doing. I'm interested in contributing, will take a look at the guide.

  2. ssalbdivad commented on Feb 3, 2025

    @ssalbdivad
    MemberAuthor

    Awesome! As a first step, we should plan out what we want the behavior here to be. We can convert a type and all of its references to JSON schema. I guess the way to do it would be to have the Type we're directly converting as the top-level definition, then a defs key with its references mapped to corresponding JSON schema?

    The change itself will need to made in @ark/schema. Cyclic types will have an Alias node where they cycle, so this would be the toJsonSchema method you'd need to change to accommodate this. A node's references can be found under the .references property.

    Feel free to let me know if you have additional questions- dealing with cyclic types in any system can be tricky!

  3. moved this from Backlog to Implemented in arktypeioon Apr 16, 2025
  4. moved this from Implemented to Done (merged or closed) in arktypeioon Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions