Skip to content

Commit

Permalink
fix: improve generation of jsonld
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Mar 26, 2019
1 parent 1ec3716 commit 6f0093a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 8 deletions.
10 changes: 8 additions & 2 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ function jsonld() {
'@id': cid
}
}
} else {
console.error(`Warning: @id is not defined at the top level in ${file.path}`)
}

// Create a [`Property`](https://meta.schema.org/Property)
// TODO: Implement schema:rangeIncludes property - requires the
// resolving `$refs`. See https://github.com/epoberezkin/ajv/issues/125#issuecomment-408960384
// for an approach to that.
if (schema.properties) {
for (let [name, property] of Object.entries(schema.properties)) {
const typeProperties = schema.properties || (schema.allOf && schema.allOf[1] && schema.allOf[1].properties)
if (typeProperties) {
for (let [name, property] of Object.entries(typeProperties)) {
const pid = property['@id']
if (!pid) continue
if (pid.startsWith('stencila:')) {
Expand All @@ -94,6 +97,9 @@ function jsonld() {
'schema:domainIncludes': [{ '@id': cid }]
}
} else {
if (properties[name]['@id'] !== pid) {
throw new Error(`Property "${name}" has more than one @id "${properties[name]['@id']}" and "${pid}"`)
}
properties[name]['schema:domainIncludes'].push({ '@id': cid })
}
} else {
Expand Down
1 change: 1 addition & 0 deletions schema/Document.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$schema: http://json-schema.org/draft-07/schema#
$id: https://stencila.github.com/schema/Document.schema.json
title: Document
'@id': stencila:Document
description: |
An executable document.
allOf:
Expand Down
1 change: 1 addition & 0 deletions schema/Environment.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$schema: https://json-schema.org/draft-07/schema
$id: https://stencila.github.com/schema/Environment.schema.json
title: Environment
'@id': stencila:Environment
description: A computational environment.
properties:
type:
Expand Down
1 change: 1 addition & 0 deletions schema/Include.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$schema: http://json-schema.org/draft-07/schema#
$id: https://stencila.github.com/schema/Include.schema.json
title: Include
'@id': stencila:Include
description: |
A directive to include content from an external source (e.g. file, URL) or content.
type: object
Expand Down
1 change: 1 addition & 0 deletions schema/Sheet.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$schema: http://json-schema.org/draft-07/schema#
$id: https://stencila.github.com/schema/Sheet.schema.json
title: Sheet
'@id': stencila:Sheet
description: |
A sheet within an executable document.
allOf:
Expand Down
8 changes: 2 additions & 6 deletions schema/Table.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
$schema: http://json-schema.org/draft-07/schema#
$id: https://stencila.github.com/schema/Table.schema.json
title: Table
'@id': stencila:Table
description: |
A table within an executable document.
type: object
properties:
type:
description: The type of node.
type: string
const: Table
value:
cells:
'@id': stencila:cells
description: |
An array of cells in the table.
type: array
items:
$ref: TableCell.schema.yaml
additionalProperties: false
1 change: 1 addition & 0 deletions schema/TableCell.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$schema: http://json-schema.org/draft-07/schema#
$id: https://stencila.github.com/schema/TableCell.schema.json
title: TableCell
'@id': stencila:TableCell
description: |
A cell within a `Table`.
type: object
Expand Down
1 change: 1 addition & 0 deletions schema/Text.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$schema: http://json-schema.org/draft-07/schema#
$id: https://stencila.github.com/schema/Text.schema.json
title: Text
'@id': stencila:Text
description: Some text
type: object
properties:
Expand Down

0 comments on commit 6f0093a

Please sign in to comment.