Skip to content

Commit

Permalink
feat(Include): Add sha256 property and add to BlockContent
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Aug 9, 2021
1 parent 664c748 commit 3e94190
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
21 changes: 12 additions & 9 deletions python/stencila/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,19 +1948,19 @@ def __init__(


class Include(Entity):
"""
A directive to include content from an external source (e.g. file, URL) or
content.
"""
"""Include content from an external source (e.g. file, URL)."""

source: String
"""The source of the content, a URL or file path, or the content itself."""
"""The external source of the content, a file path or URL."""

content: Optional[Array["BlockContent"]] = None
"""The content to be included."""
"""The structured content decoded from the source."""

mediaType: Optional[String] = None
"""Media type, typically expressed using a MIME format, of the source content."""
"""Media type of the source content."""

sha256: Optional[String] = None
"""The SHA-256 hash of the content of `source`."""


def __init__(
Expand All @@ -1969,7 +1969,8 @@ def __init__(
content: Optional[Array["BlockContent"]] = None,
id: Optional[String] = None,
mediaType: Optional[String] = None,
meta: Optional[Object] = None
meta: Optional[Object] = None,
sha256: Optional[String] = None
) -> None:
super().__init__(
id=id,
Expand All @@ -1981,6 +1982,8 @@ def __init__(
self.content = content
if mediaType is not None:
self.mediaType = mediaType
if sha256 is not None:
self.sha256 = sha256


class IntegerValidator(Validator):
Expand Down Expand Up @@ -4343,7 +4346,7 @@ class CitationIntentEnumeration(Enum):
"""
Union type for valid block content.
"""
BlockContent = Union["Claim", "CodeBlock", "CodeChunk", "Collection", "Figure", "Heading", "List", "MathBlock", "Paragraph", "QuoteBlock", "Table", "ThematicBreak"]
BlockContent = Union["Claim", "CodeBlock", "CodeChunk", "Collection", "Figure", "Heading", "Include", "List", "MathBlock", "Paragraph", "QuoteBlock", "Table", "ThematicBreak"]


"""
Expand Down
4 changes: 2 additions & 2 deletions rust/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub const SCHEMAS: &[(&str, &str)] = &[
("ArrayValidator", r#"{"title":"ArrayValidator","type":"object","additionalProperties":false,"required":["type"],"propertyAliases":{},"properties":{"id":{"type":"string"},"itemsValidator":{"allOf":[{"$ref":"ValidatorTypes.schema.json"}]},"contains":{"allOf":[{"$ref":"ValidatorTypes.schema.json"}]},"minItems":{"type":"integer","minimum":0},"maxItems":{"type":"integer","minimum":0},"uniqueItems":{"type":"boolean"}}}"#),
("Article", r#"{"title":"Article","examples":[{"type":"Article","title":"Recherches sur les substances radioactives","authors":[{"type":"Person","honorificPrefix":"Dr","givenNames":["Marie","Skłodowska"],"familyNames":["Curie"],"honorificSuffix":"PhD"}],"content":["Le présent travail a pour but d'exposer les recherches que je poursuis depuis"]}],"type":"object","additionalProperties":false,"required":["type"],"propertyAliases":{"alternateName":"alternateNames","identifier":"identifiers","image":"images","author":"authors","comment":"comments","date":"datePublished","editor":"editors","funder":"funders","keyword":"keywords","license":"licenses","maintainer":"maintainers","hasParts":"parts","part":"parts","citations":"references","reference":"references","headline":"title"},"properties":{"id":{"type":"string"},"alternateNames":{"type":"array","items":{"type":"string"},"aliases":["alternateName"]},"description":{"anyOf":[{"type":"array","items":{"$ref":"BlockContent.schema.json"}},{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"identifiers":{"type":"array","items":{"anyOf":[{"$ref":"PropertyValue.schema.json"},{"type":"string"}]},"aliases":["identifier"]},"images":{"type":"array","items":{"anyOf":[{"$ref":"ImageObject.schema.json"},{"type":"string","format":"uri"}]},"aliases":["image"]},"name":{"type":"string"},"url":{"type":"string","format":"uri"},"about":{"type":"array","items":{"$ref":"ThingTypes.schema.json"}},"authors":{"allOf":[{"parser":"scsi"},{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]}}],"aliases":["author"]},"comments":{"type":"array","items":{"$ref":"Comment.schema.json"},"aliases":["comment"]},"content":{"type":"array","items":{"$ref":"BlockContent.schema.json"},"isOverride":true},"dateCreated":{"allOf":[{"$ref":"Date.schema.json"}]},"dateReceived":{"allOf":[{"$ref":"Date.schema.json"}]},"dateAccepted":{"allOf":[{"$ref":"Date.schema.json"}]},"dateModified":{"allOf":[{"$ref":"Date.schema.json"}]},"datePublished":{"aliases":["date"],"allOf":[{"$ref":"Date.schema.json"}]},"editors":{"type":"array","items":{"$ref":"Person.schema.json"},"aliases":["editor"]},"funders":{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"aliases":["funder"]},"fundedBy":{"type":"array","items":{"anyOf":[{"$ref":"Grant.schema.json"},{"$ref":"MonetaryGrant.schema.json"}]}},"genre":{"allOf":[{"parser":"csi"},{"type":"array","items":{"type":"string"}}]},"keywords":{"allOf":[{"parser":"csi"},{"type":"array","items":{"type":"string"}}],"aliases":["keyword"]},"isPartOf":{"$ref":"CreativeWorkTypes.schema.json"},"licenses":{"type":"array","items":{"anyOf":[{"$ref":"CreativeWorkTypes.schema.json"},{"type":"string","format":"uri"}]},"aliases":["license"]},"maintainers":{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"aliases":["maintainer"]},"parts":{"aliases":["hasParts","part"],"type":"array","items":{"$ref":"CreativeWorkTypes.schema.json"}},"publisher":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"references":{"aliases":["citations","reference"],"type":"array","items":{"anyOf":[{"$ref":"CreativeWorkTypes.schema.json"},{"type":"string"}]}},"text":{"type":"string"},"title":{"aliases":["headline"],"anyOf":[{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"version":{"anyOf":[{"type":"string"},{"type":"number"}]},"pageStart":{"anyOf":[{"type":"integer"},{"type":"string"}]},"pageEnd":{"anyOf":[{"type":"integer"},{"type":"string"}]},"pagination":{"type":"string"}}}"#),
("AudioObject", r#"{"title":"AudioObject","examples":[{"type":"AudioObject","caption":"Example Audio File","contentSize":54321,"contentUrl":"http://www.example.com/file.mp3","encodingFormat":"audio/mpeg3","transcript":"This is the transcript for the audio file..."}],"type":"object","additionalProperties":false,"required":["type","contentUrl"],"propertyAliases":{"alternateName":"alternateNames","identifier":"identifiers","image":"images","author":"authors","comment":"comments","date":"datePublished","editor":"editors","funder":"funders","keyword":"keywords","license":"licenses","maintainer":"maintainers","hasParts":"parts","part":"parts","citations":"references","reference":"references","headline":"title","encodingFormat":"mediaType"},"properties":{"id":{"type":"string"},"alternateNames":{"type":"array","items":{"type":"string"},"aliases":["alternateName"]},"description":{"anyOf":[{"type":"array","items":{"$ref":"BlockContent.schema.json"}},{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"identifiers":{"type":"array","items":{"anyOf":[{"$ref":"PropertyValue.schema.json"},{"type":"string"}]},"aliases":["identifier"]},"images":{"type":"array","items":{"anyOf":[{"$ref":"ImageObject.schema.json"},{"type":"string","format":"uri"}]},"aliases":["image"]},"name":{"type":"string"},"url":{"type":"string","format":"uri"},"about":{"type":"array","items":{"$ref":"ThingTypes.schema.json"}},"authors":{"allOf":[{"parser":"scsi"},{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]}}],"aliases":["author"]},"comments":{"type":"array","items":{"$ref":"Comment.schema.json"},"aliases":["comment"]},"content":{"anyOf":[{"type":"array","items":{"$ref":"Node.schema.json"}},{"type":"string"}]},"dateCreated":{"allOf":[{"$ref":"Date.schema.json"}]},"dateReceived":{"allOf":[{"$ref":"Date.schema.json"}]},"dateAccepted":{"allOf":[{"$ref":"Date.schema.json"}]},"dateModified":{"allOf":[{"$ref":"Date.schema.json"}]},"datePublished":{"aliases":["date"],"allOf":[{"$ref":"Date.schema.json"}]},"editors":{"type":"array","items":{"$ref":"Person.schema.json"},"aliases":["editor"]},"funders":{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"aliases":["funder"]},"fundedBy":{"type":"array","items":{"anyOf":[{"$ref":"Grant.schema.json"},{"$ref":"MonetaryGrant.schema.json"}]}},"genre":{"allOf":[{"parser":"csi"},{"type":"array","items":{"type":"string"}}]},"keywords":{"allOf":[{"parser":"csi"},{"type":"array","items":{"type":"string"}}],"aliases":["keyword"]},"isPartOf":{"$ref":"CreativeWorkTypes.schema.json"},"licenses":{"type":"array","items":{"anyOf":[{"$ref":"CreativeWorkTypes.schema.json"},{"type":"string","format":"uri"}]},"aliases":["license"]},"maintainers":{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"aliases":["maintainer"]},"parts":{"aliases":["hasParts","part"],"type":"array","items":{"$ref":"CreativeWorkTypes.schema.json"}},"publisher":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"references":{"aliases":["citations","reference"],"type":"array","items":{"anyOf":[{"$ref":"CreativeWorkTypes.schema.json"},{"type":"string"}]}},"text":{"type":"string"},"title":{"aliases":["headline"],"anyOf":[{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"version":{"anyOf":[{"type":"string"},{"type":"number"}]},"bitrate":{"type":"number"},"contentSize":{"type":"number"},"contentUrl":{"type":"string"},"embedUrl":{"type":"string"},"mediaType":{"aliases":["encodingFormat"],"type":"string","pattern":"^[a-z]+(\\/[a-z\\+\\-]+)$"},"caption":{"type":"string"},"transcript":{"type":"string"}}}"#),
("BlockContent", r#"{"title":"BlockContent","anyOf":[{"$ref":"Claim.schema.json"},{"$ref":"CodeBlock.schema.json"},{"$ref":"CodeChunk.schema.json"},{"$ref":"Collection.schema.json"},{"$ref":"Figure.schema.json"},{"$ref":"Heading.schema.json"},{"$ref":"List.schema.json"},{"$ref":"MathBlock.schema.json"},{"$ref":"Paragraph.schema.json"},{"$ref":"QuoteBlock.schema.json"},{"$ref":"Table.schema.json"},{"$ref":"ThematicBreak.schema.json"}]}"#),
("BlockContent", r#"{"title":"BlockContent","anyOf":[{"$ref":"Claim.schema.json"},{"$ref":"CodeBlock.schema.json"},{"$ref":"CodeChunk.schema.json"},{"$ref":"Collection.schema.json"},{"$ref":"Figure.schema.json"},{"$ref":"Heading.schema.json"},{"$ref":"Include.schema.json"},{"$ref":"List.schema.json"},{"$ref":"MathBlock.schema.json"},{"$ref":"Paragraph.schema.json"},{"$ref":"QuoteBlock.schema.json"},{"$ref":"Table.schema.json"},{"$ref":"ThematicBreak.schema.json"}]}"#),
("Boolean", r#"{"title":"Boolean","type":"boolean"}"#),
("BooleanValidator", r#"{"title":"BooleanValidator","type":"object","additionalProperties":false,"required":["type"],"propertyAliases":{},"properties":{"id":{"type":"string"}}}"#),
("Brand", r#"{"title":"Brand","required":["type","name"],"examples":[{"type":"Brand","name":"XYZ","logo":{"type":"ImageObject","url":"https://example.com/xyz.png","caption":"Logo of Brand YXZ"},"reviews":["Rather average product","Not sure if would use again"]}],"type":"object","propertyAliases":{"alternateName":"alternateNames","identifier":"identifiers","image":"images","review":"reviews"},"additionalProperties":false,"properties":{"id":{"type":"string"},"alternateNames":{"type":"array","items":{"type":"string"},"aliases":["alternateName"]},"description":{"anyOf":[{"type":"array","items":{"$ref":"BlockContent.schema.json"}},{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"identifiers":{"type":"array","items":{"anyOf":[{"$ref":"PropertyValue.schema.json"},{"type":"string"}]},"aliases":["identifier"]},"images":{"type":"array","items":{"anyOf":[{"$ref":"ImageObject.schema.json"},{"type":"string","format":"uri"}]},"aliases":["image"]},"name":{"type":"string","isOverride":true},"url":{"type":"string","format":"uri"},"logo":{"anyOf":[{"$ref":"ImageObject.schema.json"},{"type":"string","format":"uri"}]},"reviews":{"type":"array","items":{"type":"string"},"aliases":["review"]}}}"#),
Expand Down Expand Up @@ -45,7 +45,7 @@ pub const SCHEMAS: &[(&str, &str)] = &[
("GrantTypes", r#"{"title":"GrantTypes","anyOf":[{"$ref":"Grant.schema.json"},{"$ref":"MonetaryGrant.schema.json"}]}"#),
("Heading", r#"{"title":"Heading","required":["type","content"],"examples":[{"type":"Heading","depth":2,"content":["Secondary Heading"]}],"type":"object","additionalProperties":false,"propertyAliases":{},"properties":{"id":{"type":"string"},"depth":{"type":"integer","default":1,"minimum":1,"maximum":6},"content":{"type":"array","items":{"$ref":"InlineContent.schema.json"}}}}"#),
("ImageObject", r#"{"title":"ImageObject","examples":[{"type":"ImageObject","caption":"Kiwi","contentSize":"10.4","contentUrl":"http://www.example.com/kiwi.png","encodingFormat":"image/png","thumbnail":{"type":"ImageObject","contentUrl":"http://www.example.com/kiwi_mini.png"}}],"type":"object","additionalProperties":false,"required":["type","contentUrl"],"propertyAliases":{"alternateName":"alternateNames","identifier":"identifiers","image":"images","author":"authors","comment":"comments","date":"datePublished","editor":"editors","funder":"funders","keyword":"keywords","license":"licenses","maintainer":"maintainers","hasParts":"parts","part":"parts","citations":"references","reference":"references","headline":"title","encodingFormat":"mediaType"},"properties":{"id":{"type":"string"},"alternateNames":{"type":"array","items":{"type":"string"},"aliases":["alternateName"]},"description":{"anyOf":[{"type":"array","items":{"$ref":"BlockContent.schema.json"}},{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"identifiers":{"type":"array","items":{"anyOf":[{"$ref":"PropertyValue.schema.json"},{"type":"string"}]},"aliases":["identifier"]},"images":{"type":"array","items":{"anyOf":[{"$ref":"ImageObject.schema.json"},{"type":"string","format":"uri"}]},"aliases":["image"]},"name":{"type":"string"},"url":{"type":"string","format":"uri"},"about":{"type":"array","items":{"$ref":"ThingTypes.schema.json"}},"authors":{"allOf":[{"parser":"scsi"},{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]}}],"aliases":["author"]},"comments":{"type":"array","items":{"$ref":"Comment.schema.json"},"aliases":["comment"]},"content":{"anyOf":[{"type":"array","items":{"$ref":"Node.schema.json"}},{"type":"string"}]},"dateCreated":{"allOf":[{"$ref":"Date.schema.json"}]},"dateReceived":{"allOf":[{"$ref":"Date.schema.json"}]},"dateAccepted":{"allOf":[{"$ref":"Date.schema.json"}]},"dateModified":{"allOf":[{"$ref":"Date.schema.json"}]},"datePublished":{"aliases":["date"],"allOf":[{"$ref":"Date.schema.json"}]},"editors":{"type":"array","items":{"$ref":"Person.schema.json"},"aliases":["editor"]},"funders":{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"aliases":["funder"]},"fundedBy":{"type":"array","items":{"anyOf":[{"$ref":"Grant.schema.json"},{"$ref":"MonetaryGrant.schema.json"}]}},"genre":{"allOf":[{"parser":"csi"},{"type":"array","items":{"type":"string"}}]},"keywords":{"allOf":[{"parser":"csi"},{"type":"array","items":{"type":"string"}}],"aliases":["keyword"]},"isPartOf":{"$ref":"CreativeWorkTypes.schema.json"},"licenses":{"type":"array","items":{"anyOf":[{"$ref":"CreativeWorkTypes.schema.json"},{"type":"string","format":"uri"}]},"aliases":["license"]},"maintainers":{"type":"array","items":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"aliases":["maintainer"]},"parts":{"aliases":["hasParts","part"],"type":"array","items":{"$ref":"CreativeWorkTypes.schema.json"}},"publisher":{"anyOf":[{"$ref":"Person.schema.json"},{"$ref":"Organization.schema.json"}]},"references":{"aliases":["citations","reference"],"type":"array","items":{"anyOf":[{"$ref":"CreativeWorkTypes.schema.json"},{"type":"string"}]}},"text":{"type":"string"},"title":{"aliases":["headline"],"anyOf":[{"type":"array","items":{"$ref":"InlineContent.schema.json"},"minItems":2},{"type":"string"}]},"version":{"anyOf":[{"type":"string"},{"type":"number"}]},"bitrate":{"type":"number"},"contentSize":{"type":"number"},"contentUrl":{"type":"string"},"embedUrl":{"type":"string"},"mediaType":{"aliases":["encodingFormat"],"type":"string","pattern":"^[a-z]+(\\/[a-z\\+\\-]+)$"},"caption":{"type":"string"},"thumbnail":{"allOf":[{"$ref":"ImageObject.schema.json"}]}}}"#),
("Include", r#"{"title":"Include","required":["type","source"],"type":"object","propertyAliases":{"encodingFormat":"mediaType"},"additionalProperties":false,"properties":{"id":{"type":"string"},"source":{"type":"string"},"mediaType":{"aliases":["encodingFormat"],"type":"string"},"content":{"type":"array","items":{"$ref":"BlockContent.schema.json"}}}}"#),
("Include", r#"{"title":"Include","required":["type","source"],"type":"object","propertyAliases":{"encodingFormat":"mediaType"},"additionalProperties":false,"properties":{"id":{"type":"string"},"source":{"type":"string"},"mediaType":{"aliases":["encodingFormat"],"type":"string"},"sha256":{"type":"string"},"content":{"type":"array","items":{"$ref":"BlockContent.schema.json"}}}}"#),
("InlineContent", r#"{"title":"InlineContent","anyOf":[{"$ref":"AudioObject.schema.json"},{"$ref":"Cite.schema.json"},{"$ref":"CiteGroup.schema.json"},{"$ref":"CodeExpression.schema.json"},{"$ref":"CodeFragment.schema.json"},{"$ref":"Delete.schema.json"},{"$ref":"Emphasis.schema.json"},{"$ref":"ImageObject.schema.json"},{"$ref":"Link.schema.json"},{"$ref":"MathFragment.schema.json"},{"$ref":"NontextualAnnotation.schema.json"},{"$ref":"Note.schema.json"},{"$ref":"Quote.schema.json"},{"$ref":"Strong.schema.json"},{"$ref":"Subscript.schema.json"},{"$ref":"Superscript.schema.json"},{"$ref":"VideoObject.schema.json"},{"$ref":"Null.schema.json"},{"$ref":"Boolean.schema.json"},{"$ref":"Integer.schema.json"},{"$ref":"Number.schema.json"},{"$ref":"String.schema.json"}]}"#),
("Integer", r#"{"title":"Integer","type":"integer"}"#),
("IntegerValidator", r#"{"title":"IntegerValidator","type":"object","additionalProperties":false,"required":["type"],"propertyAliases":{},"properties":{"id":{"type":"string"}}}"#),
Expand Down
12 changes: 8 additions & 4 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ pub enum ImageObjectSimple_ {

impl_struct!(ImageObjectSimple);

/// A directive to include content from an external source (e.g. file, URL) or content.
/// Include content from an external source (e.g. file, URL).
#[skip_serializing_none]
#[derive(Clone, Debug, Defaults, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
Expand All @@ -2252,17 +2252,20 @@ pub struct Include {
#[def = "Include_::Include"]
pub type_: Include_,

/// The source of the content, a URL or file path, or the content itself.
/// The external source of the content, a file path or URL.
pub source: String,

/// The content to be included.
/// The structured content decoded from the source.
pub content: Option<Vec<BlockContent>>,

/// The identifier for this item.
pub id: Option<Box<String>>,

/// Media type, typically expressed using a MIME format, of the source content.
/// Media type of the source content.
pub media_type: Option<Box<String>>,

/// The SHA-256 hash of the content of `source`.
pub sha256: Option<Box<String>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -5155,6 +5158,7 @@ pub enum BlockContent {
Collection(CollectionSimple),
Figure(FigureSimple),
Heading(Heading),
Include(Include),
List(List),
MathBlock(MathBlock),
Paragraph(Paragraph),
Expand Down
1 change: 1 addition & 0 deletions schema/BlockContent.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ anyOf:
- $ref: Collection
- $ref: Figure
- $ref: Heading
- $ref: Include
- $ref: List
- $ref: MathBlock
- $ref: Paragraph
Expand Down
Loading

0 comments on commit 3e94190

Please sign in to comment.