Skip to content

Commit

Permalink
fix(Thing, CreativeWork): Allow Thing.description and CreativeWork.ti…
Browse files Browse the repository at this point in the history
…tle to be content (ie. Node[])
  • Loading branch information
nokome committed Sep 6, 2019
1 parent 6e4c324 commit ad6a002
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 73 deletions.
88 changes: 44 additions & 44 deletions py/stencila/schema/types.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions r/R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Thing <- function(
)
self$type <- as_scalar("Thing")
self[["alternateNames"]] <- check_property("Thing", "alternateNames", FALSE, missing(alternateNames), Array("character"), alternateNames)
self[["description"]] <- check_property("Thing", "description", FALSE, missing(description), "character", description)
self[["description"]] <- check_property("Thing", "description", FALSE, missing(description), Union("character", Array("Node")), description)
self[["name"]] <- check_property("Thing", "name", FALSE, missing(name), "character", name)
self[["url"]] <- check_property("Thing", "url", FALSE, missing(url), "character", url)
class(self) <- c("list", "Entity")
Expand Down Expand Up @@ -662,7 +662,7 @@ CreativeWork <- function(
self[["publisher"]] <- check_property("CreativeWork", "publisher", FALSE, missing(publisher), Union("Person", "Organization"), publisher)
self[["references"]] <- check_property("CreativeWork", "references", FALSE, missing(references), Array(Union("character", "CreativeWorkTypes")), references)
self[["text"]] <- check_property("CreativeWork", "text", FALSE, missing(text), "character", text)
self[["title"]] <- check_property("CreativeWork", "title", FALSE, missing(title), "character", title)
self[["title"]] <- check_property("CreativeWork", "title", FALSE, missing(title), Union("character", Array("Node")), title)
self[["version"]] <- check_property("CreativeWork", "version", FALSE, missing(version), Union("character", "numeric"), version)
class(self) <- c("list", "Entity")
self
Expand Down Expand Up @@ -748,7 +748,7 @@ Article <- function(
)
self$type <- as_scalar("Article")
self[["authors"]] <- check_property("Article", "authors", TRUE, missing(authors), Array(Union("Person", "Organization")), authors)
self[["title"]] <- check_property("Article", "title", TRUE, missing(title), "character", title)
self[["title"]] <- check_property("Article", "title", TRUE, missing(title), Union("character", Array("Node")), title)
self[["environment"]] <- check_property("Article", "environment", FALSE, missing(environment), "Environment", environment)
class(self) <- c("list", "Entity")
self
Expand Down
30 changes: 17 additions & 13 deletions schema/CreativeWork.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ properties:
anyOf:
- $ref: Person
- $ref: Organization
references:
'@id': schema:citation
aliases:
- citations
description: |
References to other creative works, such as another publication,
web page, scholarly article, etc.
type: array
items:
anyOf:
- type: string
- $ref: CreativeWorkTypes
content:
# We have added "content" because the existing schema.org property "text" implies
# only unstructured text content.
Expand Down Expand Up @@ -137,6 +125,18 @@ properties:
anyOf:
- $ref: Person
- $ref: Organization
references:
'@id': schema:citation
aliases:
- citations
description: |
References to other creative works, such as another publication,
web page, scholarly article, etc.
type: array
items:
anyOf:
- type: string
- $ref: CreativeWorkTypes
text:
'@id': schema:text
description: The textual content of this creative work.
Expand All @@ -148,7 +148,11 @@ properties:
description: The title of the creative work.
aliases:
- headline
type: string
anyOf:
- type: string
- type: array
items:
$ref: Node
version:
'@id': schema:version
description: The version of the creative work.
Expand Down
6 changes: 5 additions & 1 deletion schema/Thing.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ properties:
description:
'@id': schema:description
description: A description of the item.
type: string
anyOf:
- type: string
- type: array
items:
$ref: Node
name:
'@id': schema:name
description: The name of the item.
Expand Down
2 changes: 1 addition & 1 deletion ts/bindings/__file_snapshots__/Person.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
address: Optional[str] = None,
affiliations: Optional[Array["Organization"]] = None,
alternateNames: Optional[Array[str]] = None,
description: Optional[str] = None,
description: Optional[Union[str, Array["Node"]]] = None,
emails: Optional[Array[str]] = None,
familyNames: Optional[Array[str]] = None,
funders: Optional[Array[Union["Organization", "Person"]]] = None,
Expand Down
2 changes: 1 addition & 1 deletion ts/bindings/__file_snapshots__/Thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export interface Thing extends Entity {
type: 'Thing' | 'Article' | 'AudioObject' | 'Brand' | 'Collection' | 'ContactPoint' | 'CreativeWork' | 'Datatable' | 'DatatableColumn' | 'Environment' | 'Figure' | 'ImageObject' | 'MediaObject' | 'Mount' | 'Organization' | 'Periodical' | 'Person' | 'Product' | 'PublicationIssue' | 'PublicationVolume' | 'ResourceParameters' | 'SoftwareApplication' | 'SoftwareSession' | 'SoftwareSourceCode' | 'Table' | 'VideoObject'
alternateNames?: Array<string>
description?: string
description?: string | Array<Node>
name?: string
url?: string
}
Expand Down
21 changes: 13 additions & 8 deletions ts/bindings/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ export const typesInterface = (schemas: Schema[]): string => {
* Generate a `interface` and a factory function for each type.
*/
export const typeGenerator = (schema: Schema): string => {
const { title = 'Undefined', extends: parent, description } = schema
const {
title = 'Undefined',
extends: parent,
properties,
description
} = schema
const { own, required } = props(schema)

const type =
schema.properties !== undefined
? schema.properties.type !== undefined
? schema.properties.type.enum !== undefined
? schema.properties.type.enum.map(type => `'${type}'`).join(' | ')
properties !== undefined
? properties.type !== undefined
? properties.type.enum !== undefined
? properties.type.enum.map(type => `'${type}'`).join(' | ')
: ''
: ''
: ''
Expand Down Expand Up @@ -175,7 +180,7 @@ const docComment = (description?: string, tags: string[] = []): string => {
}

/**
* Convert a schema definition to a Python type
* Convert a schema definition to a Typescript type
*/
const schemaToType = (schema: Schema): string => {
const { type, anyOf, allOf, $ref } = schema
Expand All @@ -197,7 +202,7 @@ const schemaToType = (schema: Schema): string => {
}

/**
* Convert a schema with the `anyOf` property to a Python `Union` type.
* Convert a schema with the `anyOf` property to a Typescript `Union` type.
*/
const anyOfToType = (anyOf: Schema[]): string => {
const types = anyOf
Expand All @@ -212,7 +217,7 @@ const anyOfToType = (anyOf: Schema[]): string => {
}

/**
* Convert a schema with the `allOf` property to a Python type.
* Convert a schema with the `allOf` property to a Typescript type.
*
* If the `allOf` is singular then just use that (this usually arises
* because the `allOf` is used for a property with a `$ref`). Otherwise,
Expand Down
4 changes: 2 additions & 2 deletions ts/bindings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export async function read(
}

/**
* Get the 'normal' types (i.e. not union types) which are
* Get the 'type' schemas (i.e. not union schema, not property schemas) which are
* usually translated into classes or similar for the language.
*
* Types are sorted topologically so that schemas come before
* any of their descendants.
*/
export function types(schemas: Schema[]): Schema[] {
const types = schemas.filter(schema => schema.anyOf === undefined)
const types = schemas.filter(schema => schema.properties !== undefined)
const map = new Map(schemas.map(schema => [schema.title, schema]))

const edges = types.map(
Expand Down

0 comments on commit ad6a002

Please sign in to comment.