Skip to content

Commit

Permalink
fix(*): Use allOf where needed
Browse files Browse the repository at this point in the history
This reverts 1957053
because the use of `allOf` is not redundant - one can note use a "bare" `$ref`.
  • Loading branch information
nokome committed Mar 30, 2021
1 parent f3dffef commit 31be54c
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 36 deletions.
6 changes: 4 additions & 2 deletions schema/ArrayValidator.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ properties:
itemsValidator:
'@id': stencila:itemsValidator
description: Another validator node specifying the constraints on all items in the array.
$ref: ValidatorTypes
allOf:
- $ref: ValidatorTypes
contains:
'@id': stencila:contains
description: An array node is valid if at least one of its items is valid against the `contains` schema.
$ref: ValidatorTypes
allOf:
- $ref: ValidatorTypes
minItems:
'@id': stencila:minItems
description: An array node is valid if its size is greater than, or equal to, this value.
Expand Down
3 changes: 2 additions & 1 deletion schema/CodeExpression.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ properties:
output:
'@id': stencila:output
description: The value of the expression when it was last evaluated.
$ref: Node
allOf:
- $ref: Node
errors:
'@id': stencila:errors
description: Errors when compiling or executing the chunk.
Expand Down
3 changes: 2 additions & 1 deletion schema/ConstantValidator.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ properties:
value:
'@id': schema:value
description: The value that the node must have.
$ref: Node
allOf:
- $ref: Node
15 changes: 10 additions & 5 deletions schema/CreativeWork.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,35 @@ properties:
dateCreated:
'@id': schema:dateCreated
description: Date/time of creation.
$ref: Date
allOf:
- $ref: Date
dateReceived:
'@id': schema:dateReceived
description: Date/time that work was received.
$ref: Date
allOf:
- $ref: Date
dateAccepted:
'@id': stencila:dateAccepted
description: Date/time of acceptance.
$comment: |
This is not yet a schema.org property but the term is used
[in Dublin Core](http://purl.org/dc/terms/dateAccepted).
$ref: Date
allOf:
- $ref: Date
dateModified:
'@id': schema:dateModified
description: Date/time of most recent modification.
$ref: Date
allOf:
- $ref: Date
datePublished:
'@id': schema:datePublished
aliases:
# This assumes that a user specifying `date` means the date published
# and not the date modified or created.
- date
description: Date of first publication.
$ref: Date
allOf:
- $ref: Date
editors:
'@id': schema:editor
description: People who edited the `CreativeWork`.
Expand Down
3 changes: 2 additions & 1 deletion schema/DatatableColumn.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ properties:
validator:
'@id': stencila:validator
description: The validator to use to validate data in the column.
$ref: ArrayValidator
allOf:
- $ref: ArrayValidator
values:
'@id': stencila:values
description: The data values of the column.
Expand Down
3 changes: 2 additions & 1 deletion schema/Function.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ properties:
returns:
'@id': stencila:returns
description: The return type of the function.
$ref: ValidatorTypes
allOf:
- $ref: ValidatorTypes
3 changes: 2 additions & 1 deletion schema/ImageObject.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ properties:
thumbnail:
'@id': schema:thumbnail
description: Thumbnail image of this image.
$ref: ImageObject
allOf:
- $ref: ImageObject
3 changes: 2 additions & 1 deletion schema/ListItem.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ properties:
'@id': schema:item
description: The item represented by this list item.
$comment: Use either `item` or `content`, not both.
$ref: Node
allOf:
- $ref: Node
position:
'@id': schema:position
description: The position of the item in a series or sequence of items.
Expand Down
3 changes: 2 additions & 1 deletion schema/Organization.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ properties:
'@id': schema:parentOrganization
description: |
Entity that the Organization is a part of. For example, parentOrganization to a department is a university.
$ref: Organization
allOf:
- $ref: Organization
3 changes: 2 additions & 1 deletion schema/Parameter.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ properties:
default:
'@id': schema:defaultValue
description: The default value of the parameter.
$ref: Node
allOf:
- $ref: Node
isRequired:
'@id': schema:valueRequired
description: Is this parameter required, if not it should have a default or default is assumed to be null.
Expand Down
3 changes: 2 additions & 1 deletion schema/PropertyValue.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ properties:
value:
'@id': schema:value
description: The value of the property.
$ref: Node
allOf:
- $ref: Node
required:
- value
9 changes: 6 additions & 3 deletions schema/SoftwareSession.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ properties:
environment:
'@id': stencila:environment
description: The software environment to execute this session in.
$ref: SoftwareEnvironment
allOf:
- $ref: SoftwareEnvironment
dateStart:
'@id': schema:startDate
description: The date-time that the session began.
$ref: Date
allOf:
- $ref: Date
dateEnd:
'@id': schema:endDate
description: The date-time that the session ended.
$ref: Date
allOf:
- $ref: Date
status:
'@id': stencila:sessionStatus
description: The status of the session (starting, stopped, etc).
Expand Down
6 changes: 4 additions & 2 deletions schema/Variable.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ properties:
validator:
'@id': stencila:validator
description: The validator that the value is validated against.
$ref: ValidatorTypes
allOf:
- $ref: ValidatorTypes
value:
'@id': schema:value
description: The value of the variable.
$ref: Node
allOf:
- $ref: Node
required:
- name
3 changes: 2 additions & 1 deletion schema/VideoObject.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ properties:
thumbnail:
'@id': schema:thumbnail
description: Thumbnail image of this video recording.
$ref: ImageObject
allOf:
- $ref: ImageObject
transcript:
'@id': schema:transcript
description: The transcript of this video recording.
Expand Down
15 changes: 1 addition & 14 deletions ts/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export const readSchema = async (type: string): Promise<JsonSchema> => {
* - each `@id` is associated with only one property name or type `title`
* - no duplicate `stencila:` `@ids` (case insensitive)
* - that other schemas that are referred to in `extends` or `$ref` exist
* - that `anyOf` and `allOf` for properties have at least two items
* - that no ordering is required for `array` properties
*
* @param schemas A map of all the schemas
Expand Down Expand Up @@ -222,21 +221,9 @@ const checkSchema = (
else if (property.description.length > maxDescriptionLength)
error(`${title}.${name}.description is too long`)

if (property.anyOf && property.anyOf.length < 2) {
error(
`${title}.${name}.anyOf has less than two items, is it necessary?`
)
}

if (property.allOf && property.allOf.length < 2) {
error(
`${title}.${name}.allOf has less than two items, is it necessary?`
)
}

if (property.type === 'array' && Array.isArray(property.items)) {
error(
`${title}.${name}.items is using ordered validation, use plain 'ref' or 'anyOf' instead?`
`${title}.${name}.items is using ordered validation, use plain '$ref' or 'anyOf' instead?`
)
}
}
Expand Down

0 comments on commit 31be54c

Please sign in to comment.