-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON schema for extended prefix map (#109)
- Loading branch information
Showing
7 changed files
with
184 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Generate a JSON schema for extended prefix maps.""" | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
from curies import Records | ||
from curies._pydantic_compat import PYDANTIC_V1 | ||
|
||
HERE = Path(__file__).parent.resolve() | ||
PATH = HERE.joinpath("schema.json") | ||
TITLE = "Extended Prefix Map" | ||
DESCRIPTION = ( | ||
"""\ | ||
An extended prefix map is a generalization of a prefix map that | ||
includes synonyms for URI prefixes and CURIE prefixes. | ||
""".strip() | ||
.replace("\n", " ") | ||
.replace(" ", " ") | ||
) | ||
URL = "https://w3id.org/biopragmatics/schema/epm.json" | ||
|
||
|
||
def main() -> None: | ||
"""Generate a JSON schema for extended prefix maps.""" | ||
rv = { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": URL, | ||
} | ||
|
||
if PYDANTIC_V1: | ||
import pydantic.schema | ||
|
||
# see https://docs.pydantic.dev/latest/usage/json_schema/#general-notes-on-json-schema-generation | ||
|
||
schema_dict = pydantic.schema.schema( | ||
[Records], | ||
title=TITLE, | ||
description=DESCRIPTION, | ||
) | ||
else: | ||
from pydantic.json_schema import models_json_schema | ||
|
||
_, schema_dict = models_json_schema( | ||
[(Records, "validation")], | ||
title=TITLE, | ||
description=DESCRIPTION, | ||
) | ||
|
||
rv.update(schema_dict) | ||
PATH.write_text(json.dumps(rv, indent=2) + "\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://w3id.org/biopragmatics/schema/epm.json", | ||
"$defs": { | ||
"Record": { | ||
"description": "A record of some prefixes and their associated URI prefixes.\n\n.. seealso:: https://github.com/cthoyt/curies/issues/70", | ||
"properties": { | ||
"prefix": { | ||
"description": "The canonical CURIE prefix, used in the reverse prefix map", | ||
"title": "CURIE prefix", | ||
"type": "string" | ||
}, | ||
"uri_prefix": { | ||
"description": "The canonical URI prefix, used in the forward prefix map", | ||
"title": "URI prefix", | ||
"type": "string" | ||
}, | ||
"prefix_synonyms": { | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "CURIE prefix synonyms", | ||
"type": "array" | ||
}, | ||
"uri_prefix_synonyms": { | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "URI prefix synonyms", | ||
"type": "array" | ||
}, | ||
"pattern": { | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
], | ||
"default": null, | ||
"description": "The regular expression pattern for entries in this semantic space. Warning: this is an experimental feature.", | ||
"title": "Pattern" | ||
} | ||
}, | ||
"required": [ | ||
"prefix", | ||
"uri_prefix" | ||
], | ||
"title": "Record", | ||
"type": "object" | ||
}, | ||
"Records": { | ||
"description": "A list of records.", | ||
"items": { | ||
"$ref": "#/$defs/Record" | ||
}, | ||
"title": "Records", | ||
"type": "array" | ||
} | ||
}, | ||
"title": "Extended Prefix Map", | ||
"description": "An extended prefix map is a generalization of a prefix map that includes synonyms for URI prefixes and CURIE prefixes." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters