Skip to content

Commit

Permalink
fix(*): Order primitive types consistenctly and always after entities
Browse files Browse the repository at this point in the history
This is done for more consistent coercion strategies.
  • Loading branch information
nokome committed Apr 12, 2021
1 parent de6cfd5 commit 810c5da
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 48 deletions.
38 changes: 19 additions & 19 deletions py/stencila/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ class CodeChunk(CodeBlock):
alters: Optional[Array[str]] = None
"""Names of variables that the code chunk alters."""

assigns: Optional[Array[Union[str, "Variable"]]] = None
assigns: Optional[Array[Union["Variable", str]]] = None
"""Variables that the code chunk assigns to."""

caption: Optional[Union[Array["BlockContent"], str]] = None
"""A caption for the CodeChunk."""

declares: Optional[Array[Union[str, "Variable", "Function"]]] = None
declares: Optional[Array[Union["Variable", "Function", str]]] = None
"""Variables that the code chunk declares."""

duration: Optional[float] = None
Expand All @@ -282,7 +282,7 @@ class CodeChunk(CodeBlock):
errors: Optional[Array["CodeError"]] = None
"""Errors when compiling or executing the chunk."""

imports: Optional[Array[Union[str, "SoftwareSourceCode", "SoftwareApplication"]]] = None
imports: Optional[Array[Union["SoftwareSourceCode", "SoftwareApplication", str]]] = None
"""Software packages that the code chunk imports"""

label: Optional[str] = None
Expand All @@ -294,30 +294,30 @@ class CodeChunk(CodeBlock):
reads: Optional[Array[str]] = None
"""Filesystem paths that this code chunk reads from."""

uses: Optional[Array[Union[str, "Variable"]]] = None
uses: Optional[Array[Union["Variable", str]]] = None
"""Names of variables that the code chunk uses (but does not alter)."""


def __init__(
self,
text: str,
alters: Optional[Array[str]] = None,
assigns: Optional[Array[Union[str, "Variable"]]] = None,
assigns: Optional[Array[Union["Variable", str]]] = None,
caption: Optional[Union[Array["BlockContent"], str]] = None,
declares: Optional[Array[Union[str, "Variable", "Function"]]] = None,
declares: Optional[Array[Union["Variable", "Function", str]]] = None,
duration: Optional[float] = None,
errors: Optional[Array["CodeError"]] = None,
exportFrom: Optional[str] = None,
format: Optional[str] = None,
id: Optional[str] = None,
importTo: Optional[str] = None,
imports: Optional[Array[Union[str, "SoftwareSourceCode", "SoftwareApplication"]]] = None,
imports: Optional[Array[Union["SoftwareSourceCode", "SoftwareApplication", str]]] = None,
label: Optional[str] = None,
meta: Optional[Dict[str, Any]] = None,
outputs: Optional[Array["Node"]] = None,
programmingLanguage: Optional[str] = None,
reads: Optional[Array[str]] = None,
uses: Optional[Array[Union[str, "Variable"]]] = None
uses: Optional[Array[Union["Variable", str]]] = None
) -> None:
super().__init__(
text=text,
Expand Down Expand Up @@ -601,7 +601,7 @@ class Brand(Thing):
name: str # type: ignore
"""The name of the item."""

logo: Optional[Union[str, "ImageObject"]] = None
logo: Optional[Union["ImageObject", str]] = None
"""A logo associated with the brand."""

reviews: Optional[Array[str]] = None
Expand All @@ -616,7 +616,7 @@ def __init__(
id: Optional[str] = None,
identifiers: Optional[Array[Union["PropertyValue", str]]] = None,
images: Optional[Array[Union["ImageObject", str]]] = None,
logo: Optional[Union[str, "ImageObject"]] = None,
logo: Optional[Union["ImageObject", str]] = None,
meta: Optional[Dict[str, Any]] = None,
reviews: Optional[Array[str]] = None,
url: Optional[str] = None
Expand Down Expand Up @@ -2216,7 +2216,7 @@ def __init__(
class Organization(Thing):
"""An organization such as a school, NGO, corporation, club, etc."""

address: Optional[Union[str, "PostalAddress"]] = None
address: Optional[Union["PostalAddress", str]] = None
"""Postal address for the organization.
"""

Expand All @@ -2240,7 +2240,7 @@ class Organization(Thing):
"""Legal name for the Organization. Should only include letters and spaces.
"""

logo: Optional[Union[str, "ImageObject"]] = None
logo: Optional[Union["ImageObject", str]] = None
"""The logo of the organization."""

members: Optional[Array[Union["Organization", "Person"]]] = None
Expand All @@ -2254,7 +2254,7 @@ class Organization(Thing):

def __init__(
self,
address: Optional[Union[str, "PostalAddress"]] = None,
address: Optional[Union["PostalAddress", str]] = None,
alternateNames: Optional[Array[str]] = None,
brands: Optional[Array["Brand"]] = None,
contactPoints: Optional[Array["ContactPoint"]] = None,
Expand All @@ -2265,7 +2265,7 @@ def __init__(
identifiers: Optional[Array[Union["PropertyValue", str]]] = None,
images: Optional[Array[Union["ImageObject", str]]] = None,
legalName: Optional[str] = None,
logo: Optional[Union[str, "ImageObject"]] = None,
logo: Optional[Union["ImageObject", str]] = None,
members: Optional[Array[Union["Organization", "Person"]]] = None,
meta: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
Expand Down Expand Up @@ -2503,7 +2503,7 @@ def __init__(
class Person(Thing):
"""A person (alive, dead, undead, or fictional)."""

address: Optional[Union[str, "PostalAddress"]] = None
address: Optional[Union["PostalAddress", str]] = None
"""Postal address for the person."""

affiliations: Optional[Array["Organization"]] = None
Expand Down Expand Up @@ -2541,7 +2541,7 @@ class Person(Thing):

def __init__(
self,
address: Optional[Union[str, "PostalAddress"]] = None,
address: Optional[Union["PostalAddress", str]] = None,
affiliations: Optional[Array["Organization"]] = None,
alternateNames: Optional[Array[str]] = None,
description: Optional[Union[Array["BlockContent"], Array["InlineContent"], str]] = None,
Expand Down Expand Up @@ -2673,7 +2673,7 @@ class Product(Thing):
brands: Optional[Array["Brand"]] = None
"""Brands that the product is labelled with."""

logo: Optional[Union[str, "ImageObject"]] = None
logo: Optional[Union["ImageObject", str]] = None
"""The logo of the product."""

productID: Optional[str] = None
Expand All @@ -2688,7 +2688,7 @@ def __init__(
id: Optional[str] = None,
identifiers: Optional[Array[Union["PropertyValue", str]]] = None,
images: Optional[Array[Union["ImageObject", str]]] = None,
logo: Optional[Union[str, "ImageObject"]] = None,
logo: Optional[Union["ImageObject", str]] = None,
meta: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
productID: Optional[str] = None,
Expand Down Expand Up @@ -3997,7 +3997,7 @@ def __init__(
"""
Union type for all valid nodes.
"""
Node = Union["Entity", int, float, bool, None, str, Array[Any], Dict[str, Any]]
Node = Union["Entity", None, bool, int, float, Array[Any], Dict[str, Any], str]


"""
Expand Down
20 changes: 10 additions & 10 deletions r/R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ CodeChunk <- function(
)
self$type <- as_scalar("CodeChunk")
self[["alters"]] <- check_property("CodeChunk", "alters", FALSE, missing(alters), Array("character"), alters)
self[["assigns"]] <- check_property("CodeChunk", "assigns", FALSE, missing(assigns), Array(Union("character", Variable)), assigns)
self[["assigns"]] <- check_property("CodeChunk", "assigns", FALSE, missing(assigns), Array(Union(Variable, "character")), assigns)
self[["caption"]] <- check_property("CodeChunk", "caption", FALSE, missing(caption), Union(Array(BlockContent), "character"), caption)
self[["declares"]] <- check_property("CodeChunk", "declares", FALSE, missing(declares), Array(Union("character", Variable, Function)), declares)
self[["declares"]] <- check_property("CodeChunk", "declares", FALSE, missing(declares), Array(Union(Variable, Function, "character")), declares)
self[["duration"]] <- check_property("CodeChunk", "duration", FALSE, missing(duration), "numeric", duration)
self[["errors"]] <- check_property("CodeChunk", "errors", FALSE, missing(errors), Array(CodeError), errors)
self[["imports"]] <- check_property("CodeChunk", "imports", FALSE, missing(imports), Array(Union("character", SoftwareSourceCode, SoftwareApplication)), imports)
self[["imports"]] <- check_property("CodeChunk", "imports", FALSE, missing(imports), Array(Union(SoftwareSourceCode, SoftwareApplication, "character")), imports)
self[["label"]] <- check_property("CodeChunk", "label", FALSE, missing(label), "character", label)
self[["outputs"]] <- check_property("CodeChunk", "outputs", FALSE, missing(outputs), Array(Node), outputs)
self[["reads"]] <- check_property("CodeChunk", "reads", FALSE, missing(reads), Array("character"), reads)
self[["uses"]] <- check_property("CodeChunk", "uses", FALSE, missing(uses), Array(Union("character", Variable)), uses)
self[["uses"]] <- check_property("CodeChunk", "uses", FALSE, missing(uses), Array(Union(Variable, "character")), uses)
class(self) <- c(class(self), "CodeChunk")
self
}
Expand Down Expand Up @@ -621,7 +621,7 @@ Brand <- function(
)
self$type <- as_scalar("Brand")
self[["name"]] <- check_property("Brand", "name", TRUE, missing(name), "character", name)
self[["logo"]] <- check_property("Brand", "logo", FALSE, missing(logo), Union("character", ImageObject), logo)
self[["logo"]] <- check_property("Brand", "logo", FALSE, missing(logo), Union(ImageObject, "character"), logo)
self[["reviews"]] <- check_property("Brand", "reviews", FALSE, missing(reviews), Array("character"), reviews)
class(self) <- c(class(self), "Brand")
self
Expand Down Expand Up @@ -2443,13 +2443,13 @@ Organization <- function(
url = url
)
self$type <- as_scalar("Organization")
self[["address"]] <- check_property("Organization", "address", FALSE, missing(address), Union("character", PostalAddress), address)
self[["address"]] <- check_property("Organization", "address", FALSE, missing(address), Union(PostalAddress, "character"), address)
self[["brands"]] <- check_property("Organization", "brands", FALSE, missing(brands), Array(Brand), brands)
self[["contactPoints"]] <- check_property("Organization", "contactPoints", FALSE, missing(contactPoints), Array(ContactPoint), contactPoints)
self[["departments"]] <- check_property("Organization", "departments", FALSE, missing(departments), Array(Organization), departments)
self[["funders"]] <- check_property("Organization", "funders", FALSE, missing(funders), Array(Union(Organization, Person)), funders)
self[["legalName"]] <- check_property("Organization", "legalName", FALSE, missing(legalName), "character", legalName)
self[["logo"]] <- check_property("Organization", "logo", FALSE, missing(logo), Union("character", ImageObject), logo)
self[["logo"]] <- check_property("Organization", "logo", FALSE, missing(logo), Union(ImageObject, "character"), logo)
self[["members"]] <- check_property("Organization", "members", FALSE, missing(members), Array(Union(Organization, Person)), members)
self[["parentOrganization"]] <- check_property("Organization", "parentOrganization", FALSE, missing(parentOrganization), Organization, parentOrganization)
class(self) <- c(class(self), "Organization")
Expand Down Expand Up @@ -2743,7 +2743,7 @@ Person <- function(
url = url
)
self$type <- as_scalar("Person")
self[["address"]] <- check_property("Person", "address", FALSE, missing(address), Union("character", PostalAddress), address)
self[["address"]] <- check_property("Person", "address", FALSE, missing(address), Union(PostalAddress, "character"), address)
self[["affiliations"]] <- check_property("Person", "affiliations", FALSE, missing(affiliations), Array(Organization), affiliations)
self[["emails"]] <- check_property("Person", "emails", FALSE, missing(emails), Array("character"), emails)
self[["familyNames"]] <- check_property("Person", "familyNames", FALSE, missing(familyNames), Array("character"), familyNames)
Expand Down Expand Up @@ -2868,7 +2868,7 @@ Product <- function(
)
self$type <- as_scalar("Product")
self[["brands"]] <- check_property("Product", "brands", FALSE, missing(brands), Array(Brand), brands)
self[["logo"]] <- check_property("Product", "logo", FALSE, missing(logo), Union("character", ImageObject), logo)
self[["logo"]] <- check_property("Product", "logo", FALSE, missing(logo), Union(ImageObject, "character"), logo)
self[["productID"]] <- check_property("Product", "productID", FALSE, missing(productID), "character", productID)
class(self) <- c(class(self), "Product")
self
Expand Down Expand Up @@ -4331,7 +4331,7 @@ MediaObjectTypes <- Union(MediaObject, AudioObject, ImageObject, VideoObject)
#'
#' @return A `list` of class `Union` describing valid subtypes of this type
#' @export
Node <- Union(Entity, "numeric", "logical", "NULL", "character", Array(Any()), "list")
Node <- Union(Entity, "NULL", "logical", "numeric", Array(Any()), "list", "character")


#' All type schemas that are derived from NumberValidator
Expand Down
2 changes: 1 addition & 1 deletion schema/Brand.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ properties:
'@id': schema:logo
description: A logo associated with the brand.
anyOf:
- $ref: ImageObject
- type: string
format: uri
- $ref: ImageObject
reviews:
'@id': schema:review
description: Reviews of the brand.
Expand Down
14 changes: 7 additions & 7 deletions schema/CodeChunk.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ properties:
type: array
items:
anyOf:
- type: string
- $ref: SoftwareSourceCode
- $ref: SoftwareApplication
- type: string
declares:
'@id': stencila:declares
description: Variables that the code chunk declares.
type: array
items:
anyOf:
# String for when user want to specify manually that a cell
# declares a variable
- type: string
# For when we want to store type and possibly value of variable
- $ref: Variable
# Functions already have a name so it is redundant / confusing
# to wrap then in a variable
- $ref: Function
# String for when user want to specify manually that a cell
# declares a variable
- type: string
assigns:
'@id': stencila:assigns
description: Variables that the code chunk assigns to.
type: array
items:
anyOf:
# For when we want to store type and possibly value of variable
- $ref: Variable
# String for when user want to specify manually that a cell
# declares a variable
- type: string
# For when we want to store type and possibly value of variable
- $ref: Variable
$comment: |
In languages such as Python and R we are unable
to differentiate between an assignment that
Expand All @@ -79,8 +79,8 @@ properties:
type: array
items:
anyOf:
- type: string
- $ref: Variable
- type: string
reads:
'@id': stencila:reads
description: Filesystem paths that this code chunk reads from.
Expand Down
6 changes: 3 additions & 3 deletions schema/Node.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ $comment: |
order of attempted coercion (ie. parsing and reshaping to arrays)
anyOf:
- $ref: Entity
- type: 'null'
- type: boolean
- type: integer
- type: number
- type: boolean
- type: 'null'
- type: string
- type: array
- type: object
- type: string
4 changes: 2 additions & 2 deletions schema/Organization.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ properties:
description: |
Postal address for the organization.
anyOf:
- type: string
- $ref: PostalAddress
- type: string
brands:
'@id': schema:brand
description: |
Expand Down Expand Up @@ -56,9 +56,9 @@ properties:
This is a singleton property because, at any one time, an organization
will usually only have one logo.
anyOf:
- $ref: ImageObject
- type: string
format: uri
- $ref: ImageObject
members:
'@id': schema:member
description: |
Expand Down
2 changes: 1 addition & 1 deletion schema/Person.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ properties:
'@id': schema:address
description: Postal address for the person.
anyOf:
- type: string
- $ref: PostalAddress
- type: string
affiliations:
'@id': schema:affiliation
description: Organizations that the person is affiliated with.
Expand Down
2 changes: 1 addition & 1 deletion schema/Product.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ properties:
'@id': schema:logo
description: The logo of the product.
anyOf:
- $ref: ImageObject
- type: string
format: uri
- $ref: ImageObject
productID:
'@id': schema:productID
description: Product identification code.
Expand Down
2 changes: 1 addition & 1 deletion ts/bindings/__file_snapshots__/Person.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Person <- function(
url = url
)
self$type <- as_scalar("Person")
self[["address"]] <- check_property("Person", "address", FALSE, missing(address), Union("character", PostalAddress), address)
self[["address"]] <- check_property("Person", "address", FALSE, missing(address), Union(PostalAddress, "character"), address)
self[["affiliations"]] <- check_property("Person", "affiliations", FALSE, missing(affiliations), Array(Organization), affiliations)
self[["emails"]] <- check_property("Person", "emails", FALSE, missing(emails), Array("character"), emails)
self[["familyNames"]] <- check_property("Person", "familyNames", FALSE, missing(familyNames), Array("character"), familyNames)
Expand Down
4 changes: 2 additions & 2 deletions ts/bindings/__file_snapshots__/Person.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Person(Thing):
"""A person (alive, dead, undead, or fictional)."""

address: Optional[Union[str, "PostalAddress"]] = None
address: Optional[Union["PostalAddress", str]] = None
"""Postal address for the person."""

affiliations: Optional[Array["Organization"]] = None
Expand Down Expand Up @@ -39,7 +39,7 @@ class Person(Thing):

def __init__(
self,
address: Optional[Union[str, "PostalAddress"]] = None,
address: Optional[Union["PostalAddress", str]] = None,
affiliations: Optional[Array["Organization"]] = None,
alternateNames: Optional[Array[str]] = None,
description: Optional[Union[Array["BlockContent"], Array["InlineContent"], str]] = None,
Expand Down
2 changes: 1 addition & 1 deletion ts/bindings/__file_snapshots__/Person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export interface Person extends Thing {
type: 'Person'
address?: string | PostalAddress
address?: PostalAddress | string
affiliations?: Array<Organization>
emails?: Array<string>
familyNames?: Array<string>
Expand Down

0 comments on commit 810c5da

Please sign in to comment.