Skip to content

Commit

Permalink
fix(ListItem): Narrow allowed content to arrays of inline or block co…
Browse files Browse the repository at this point in the history
…ntent
  • Loading branch information
nokome committed Jun 2, 2021
1 parent a207782 commit 5c80b17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions python/stencila/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ def __init__(
class ListItem(Thing):
"""A single item in a list."""

content: Optional[Array["Node"]] = None
content: Optional[Union[Array["BlockContent"], Array["InlineContent"]]] = None
"""The content of the list item."""

isChecked: Optional[bool] = None
Expand All @@ -2095,7 +2095,7 @@ class ListItem(Thing):
def __init__(
self,
alternateNames: Optional[Array[str]] = None,
content: Optional[Array["Node"]] = None,
content: Optional[Union[Array["BlockContent"], Array["InlineContent"]]] = None,
description: Optional[Union[Array["BlockContent"], Array["InlineContent"], str]] = None,
id: Optional[str] = None,
identifiers: Optional[Array[Union["PropertyValue", str]]] = None,
Expand Down
8 changes: 4 additions & 4 deletions r/R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ ListItem <- function(
url = url
)
self$type <- as_scalar("ListItem")
self[["content"]] <- check_property("ListItem", "content", FALSE, missing(content), Array(Node), content)
self[["content"]] <- check_property("ListItem", "content", FALSE, missing(content), Union(Array(BlockContent), Array(InlineContent)), content)
self[["isChecked"]] <- check_property("ListItem", "isChecked", FALSE, missing(isChecked), "logical", isChecked)
self[["item"]] <- check_property("ListItem", "item", FALSE, missing(item), Node, item)
self[["position"]] <- check_property("ListItem", "position", FALSE, missing(position), "numeric", position)
Expand Down Expand Up @@ -4114,9 +4114,9 @@ Table <- function(
#' A cell within a `Table`.
#'
#' @name TableCell
#' @param content Contents of the table cell. \bold{Required}.
#' @param cellType Indicates whether the cell is a header or data.
#' @param colspan How many columns the cell extends.
#' @param content Contents of the table cell.
#' @param id The identifier for this item.
#' @param meta Metadata associated with this item.
#' @param name The name of the cell.
Expand All @@ -4125,9 +4125,9 @@ Table <- function(
#' @seealso \code{\link{Entity}}
#' @export
TableCell <- function(
content,
cellType,
colspan,
content,
id,
meta,
name,
Expand All @@ -4138,9 +4138,9 @@ TableCell <- function(
meta = meta
)
self$type <- as_scalar("TableCell")
self[["content"]] <- check_property("TableCell", "content", TRUE, missing(content), Union(Array(BlockContent), Array(InlineContent)), content)
self[["cellType"]] <- check_property("TableCell", "cellType", FALSE, missing(cellType), Enum("Data", "Header"), cellType)
self[["colspan"]] <- check_property("TableCell", "colspan", FALSE, missing(colspan), "numeric", colspan)
self[["content"]] <- check_property("TableCell", "content", FALSE, missing(content), Union(Array(BlockContent), Array(InlineContent)), content)
self[["name"]] <- check_property("TableCell", "name", FALSE, missing(name), "character", name)
self[["rowspan"]] <- check_property("TableCell", "rowspan", FALSE, missing(rowspan), "numeric", rowspan)
class(self) <- c(class(self), "TableCell")
Expand Down
10 changes: 9 additions & 1 deletion rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ pub struct ListItem {
pub alternate_names: Option<Vec<String>>,

/// The content of the list item.
pub content: Option<Vec<Node>>,
pub content: Option<ListItemContent>,

/// A description of the item.
pub description: Option<ThingDescription>,
Expand Down Expand Up @@ -4330,6 +4330,14 @@ pub enum ListOrder {
Unordered,
}

/// Types permitted for the `content` property of a `ListItem` node.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListItemContent {
VecBlockContent(Vec<BlockContent>),
VecInlineContent(Vec<InlineContent>),
}

/// Types permitted for the `funders` property of a `MonetaryGrant` node.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down
10 changes: 7 additions & 3 deletions schema/ListItem.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ properties:
'@id': stencila:content
description: The content of the list item.
$comment: Use either `content` or `item`, not both.
type: array
items:
$ref: Node
anyOf:
- type: array
items:
$ref: BlockContent
- type: array
items:
$ref: InlineContent
isChecked:
'@id': stencila:isChecked
description: A flag to indicate if this list item is checked.
Expand Down

0 comments on commit 5c80b17

Please sign in to comment.