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

Define schema for representing data types #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions schemas/type.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
$schema: "https://json-schema.org/draft/2020-12/schema"
$id: "schema:ethdebug/format/type"

$ref: "#/$defs/Type"

$defs:
Type:
title: ethdebug/format/type
description:
Canonical representation for all types.
oneOf:
- title: Known types
oneOf:
- title: Known elementary types
oneOf:
- $ref: "#/$defs/UintType"

- title: Known complex types
oneOf:
- $ref: "#/$defs/ArrayType"

- $ref: "schema:ethdebug/format/type/base#/$defs/Type"

UintType:
title: UintType
properties:
class:
const: elementary
kind:
const: uint
bits:
type: number
multipleOf: 8
minimum: 8
maximum: 256
required:
- kind
- bits

ArrayType:
title: ArrayType
type: object
properties:
class:
type: string
const: complex
kind:
type: string
const: array
contains:
type: object
properties:
type:
$ref: "schema:ethdebug/format/type/base#/$defs/Type"
required:
- type
required:
- kind
- contains
132 changes: 132 additions & 0 deletions schemas/type/base.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
$schema: "https://json-schema.org/draft/2020-12/schema"
$id: "schema:ethdebug/format/type/base"

$ref: "#/$defs/Type"

$defs:
Type:
title: ethdebug/format/type/base
description:
Defines the minimally necessary schema for a data type.
Types belong to a particular `class` (`"elementary"` or `"complex"`),
and are further identified by a particular `kind`.
type: object
oneOf:
- $ref: "#/$defs/ElementaryType"
- $ref: "#/$defs/ComplexType"

ElementaryType:
title: ElementaryType
description:
Represents an elementary type (one that does not compose other types)
type: object
properties:
class:
type: string
const: elementary
kind:
type: string
contains:
not:
description:
"**Elementary types must not specify a `contains` field
(to make it easier to discriminate elementary vs. complex)**"
required:
- kind
examples:
- kind: uint
bits: 256

ComplexType:
title: ComplexType
description:
Represents a complex type, one that composes other types (e.g., arrays,
structs, mappings)
type: object
properties:
class:
type: string
const: complex
description: Indicates that this is a complex type
kind:
type: string
description: The specific kind of complex type, e.g., array or struct
contains:
title: ComplexType.contains
oneOf:
- $ref: "#/$defs/TypeWrapper"
- $ref: "#/$defs/TypeWrapperArray"
- $ref: "#/$defs/TypeWrapperObject"
required:
- kind
- contains
examples:
- kind: array
contains:
type:
kind: uint
bits: 256
- kind: struct
contains:
- member: x
type:
kind: uint
bits: 256
- member: y
type:
kind: uint
bits: 256
- kind: mapping
contains:
key:
type: address
payable: true
value:
type: uint
bits: 256

ComplexTypeContains:
title: ComplexType `contains` field schema

TypeReference:
title: '{ "id": ... }'
description: A reference to a known type by ID
type: object
properties:
id:
type:
- string
- number
additionalProperties: false
required:
- id

TypeWrapper:
title: '{ "type": ... }'
description:
A wrapper around a type. Defines a `"type"` field that may include a full
Type representation or a reference to a known Type by ID. Note that this
schema permits additional properties on the same object.
type: object
properties:
type:
oneOf:
- $ref: "#/$defs/Type"
- $ref: "#/$defs/TypeReference"
required:
- type

TypeWrapperArray:
title: '{ "type": ... }[]'
description: A list of wrapped types, where the wrapper may add fields
type: array
items:
$ref: "#/$defs/TypeWrapper"

TypeWrapperObject:
title: '{ "key": { "type": ... }, ... }'
description:
A key-value mapping of wrapped types, where the wrapper may add fields
type: object
additionalProperties:
$ref: "#/$defs/TypeWrapper"
Loading