Skip to content

Commit

Permalink
allow extras
Browse files Browse the repository at this point in the history
  • Loading branch information
calmacx committed Oct 19, 2023
1 parent 0ecf534 commit ef65e8f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
22 changes: 1 addition & 21 deletions hdr_schemata/models/SchemaOrg/GoogleRecommended/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,4 @@ class Dataset(BaseDataset):
"version",
"url",
"distribution",
]

# - There is a problem with pydantic v2 where the 'exclude' feature doesnt currently work
# see: https://github.com/pydantic/pydantic/discussions/2686
# - This hack means that I can inherit from the Schema.Org model but then exclude fields
# that are not needed for the Google Recommended Schema
all_keys = list(Dataset.model_fields.keys())
for field in all_keys:
if not field in __fields_to_keep:
Dataset.model_fields_set.deleter(field)
Dataset.model_computed_fields.deleter(field)
del Dataset.model_fields[field]

for field in __fields_to_keep:
if not field in Dataset.model_fields.keys():
raise NotImplementedError(f'Field "{field}" has not been implemented!')


Dataset.__pydantic_complete__ = False
del Dataset.__pydantic_core_schema__
Dataset.model_rebuild(force=True)
])
10 changes: 8 additions & 2 deletions hdr_schemata/models/SchemaOrg/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

from hdr_schemata.definitions.SchemaOrg import Text, Text50, Number
from hdr_schemata.definitions.SchemaOrg import SingleDate, TimePeriod, OpenEndedTimePeriod


class Extra(BaseModel):
model_config = ConfigDict(extra='allow')

class Dataset(CreativeWork):

Expand Down Expand Up @@ -229,4 +231,8 @@ class Dataset(CreativeWork):
This property can be used alongside the license property which indicates license(s) applicable to some piece of content. The usageInfo property can provide information about other licensing options, e.g. acquiring commercial usage rights for an image that is also available under non-commercial creative commons licenses.'''
)


extra: Optional[Extra] = Field(
None,
title='extra',
description='There may be fields that do not exist in schema.org that need to be included'
)
19 changes: 19 additions & 0 deletions hdr_schemata/models/SchemaOrg/default/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@
"title": "DataDownload",
"type": "object"
},
"Extra": {
"additionalProperties": true,
"properties": {},
"title": "Extra",
"type": "object"
},
"GeoCoordinates": {
"properties": {
"@type": {
Expand Down Expand Up @@ -1108,6 +1114,19 @@
"default": null,
"description": "The schema.org usageInfo property indicates further information about a CreativeWork. This property is applicable both to works that are freely available and to those that require payment or other transactions. It can reference additional information, e.g. community expectations on preferred linking and citation conventions, as well as purchasing details. For something that can be commercially licensed, usageInfo can provide detailed, resource-specific information about licensing options.\n This property can be used alongside the license property which indicates license(s) applicable to some piece of content. The usageInfo property can provide information about other licensing options, e.g. acquiring commercial usage rights for an image that is also available under non-commercial creative commons licenses.",
"title": "Usage Info"
},
"extra": {
"anyOf": [
{
"$ref": "#/$defs/Extra"
},
{
"type": "null"
}
],
"default": null,
"description": "There may be fields that do not exist in schema.org that need to be included",
"title": "extra"
}
},
"required": [
Expand Down

0 comments on commit ef65e8f

Please sign in to comment.