diff --git a/openapi.json b/openapi.json index 29e4d5ea5..30bb7cd63 100644 --- a/openapi.json +++ b/openapi.json @@ -298,97 +298,6 @@ } } }, - "OptimadeProvider": { - "title": "OptimadeProvider", - "required": [ - "name", - "description", - "prefix" - ], - "type": "object", - "properties": { - "name": { - "title": "Name", - "type": "string", - "description": "a short name for the database provider" - }, - "description": { - "title": "Description", - "type": "string", - "description": "a longer description of the database provider" - }, - "prefix": { - "title": "Prefix", - "type": "string", - "description": "database-provider-specific prefix as found in Appendix 1." - }, - "homepage": { - "title": "Homepage", - "anyOf": [ - { - "minLength": 1, - "maxLength": 65536, - "type": "string", - "format": "uri" - }, - { - "title": "Link", - "type": "object", - "properties": { - "href": { - "title": "Href", - "minLength": 1, - "maxLength": 65536, - "type": "string", - "format": "uri" - }, - "meta": { - "title": "Meta", - "type": "object" - } - }, - "required": [ - "href" - ] - } - ], - "description": "a [JSON API links object](http://jsonapi.org/format/1.0#document-links) pointing to homepage of the database provider, either directly as a string, or as a link object." - }, - "index_base_url": { - "title": "Index_Base_Url", - "anyOf": [ - { - "minLength": 1, - "maxLength": 65536, - "type": "string", - "format": "uri" - }, - { - "title": "Link", - "type": "object", - "properties": { - "href": { - "title": "Href", - "minLength": 1, - "maxLength": 65536, - "type": "string", - "format": "uri" - }, - "meta": { - "title": "Meta", - "type": "object" - } - }, - "required": [ - "href" - ] - } - ], - "description": "a [JSON API links object](http://jsonapi.org/format/1.0#document-links) pointing to the base URL for the `index` meta-database as specified in Appendix 1, either directly as a string, or as a link object." - } - }, - "description": "Stores information on the database provider of the\n implementation." - }, "Links": { "title": "Links", "type": "object", @@ -678,6 +587,112 @@ } } }, + "OptimadeProvider": { + "title": "OptimadeProvider", + "required": [ + "name", + "description", + "prefix" + ], + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string", + "description": "a short name for the database provider" + }, + "description": { + "title": "Description", + "type": "string", + "description": "a longer description of the database provider" + }, + "prefix": { + "title": "Prefix", + "type": "string", + "description": "database-provider-specific prefix as found in Appendix 1." + }, + "homepage": { + "title": "Homepage", + "anyOf": [ + { + "minLength": 1, + "maxLength": 65536, + "type": "string", + "format": "uri" + }, + { + "title": "Link", + "type": "object", + "properties": { + "href": { + "title": "Href", + "minLength": 1, + "maxLength": 65536, + "type": "string", + "format": "uri" + }, + "meta": { + "title": "Meta", + "type": "object" + } + }, + "required": [ + "href" + ] + } + ], + "description": "a [JSON API links object](http://jsonapi.org/format/1.0#document-links) pointing to homepage of the database provider, either directly as a string, or as a link object." + }, + "index_base_url": { + "title": "Index_Base_Url", + "anyOf": [ + { + "minLength": 1, + "maxLength": 65536, + "type": "string", + "format": "uri" + }, + { + "title": "Link", + "type": "object", + "properties": { + "href": { + "title": "Href", + "minLength": 1, + "maxLength": 65536, + "type": "string", + "format": "uri" + }, + "meta": { + "title": "Meta", + "type": "object" + } + }, + "required": [ + "href" + ] + } + ], + "description": "a [JSON API links object](http://jsonapi.org/format/1.0#document-links) pointing to the base URL for the `index` meta-database as specified in Appendix 1, either directly as a string, or as a link object." + } + }, + "description": "Stores information on the database provider of the\n implementation." + }, + "OptimadeResponseMetaQuery": { + "title": "OptimadeResponseMetaQuery", + "required": [ + "representation" + ], + "type": "object", + "properties": { + "representation": { + "title": "Representation", + "type": "string", + "description": "a string with the part of the URL that follows the base URL." + } + }, + "description": "Information on the query that was requested." + }, "StructureResource": { "title": "StructureResource", "required": [ @@ -724,21 +739,6 @@ } } }, - "OptimadeResponseMetaQuery": { - "title": "OptimadeResponseMetaQuery", - "required": [ - "representation" - ], - "type": "object", - "properties": { - "representation": { - "title": "Representation", - "type": "string", - "description": "a string with the part of the URL that follows the base URL." - } - }, - "description": "Information on the query that was requested." - }, "ValidationError": { "title": "ValidationError", "required": [ diff --git a/optimade/server/main.py b/optimade/server/main.py index 1df65fa8b..49d9fa0f4 100644 --- a/optimade/server/main.py +++ b/optimade/server/main.py @@ -13,7 +13,6 @@ from .models.baseinfo import BaseInfoResource, BaseInfoAttributes from .models.toplevel import OptimadeResponseMeta, OptimadeResponseMetaQuery, OptimadeStructureResponseMany, OptimadeInfoResponse, OptimadeProvider - config = ConfigParser() config.read(Path(__file__).resolve().parent.joinpath('config.ini')) USE_REAL_MONGO = config['DEFAULT'].getboolean('USE_REAL_MONGO') diff --git a/optimade/server/models/errors.py b/optimade/server/models/errors.py new file mode 100644 index 000000000..457d673a7 --- /dev/null +++ b/optimade/server/models/errors.py @@ -0,0 +1,19 @@ +from typing import Dict, List, Optional, Union + +from .jsonapi import Link, Links +from pydantic import BaseModel, UrlStr, Schema + +class ErrorSource(BaseModel): + pointer: Optional[str]=Schema(..., description='a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].') + parameter: Optional[str]=Schema(..., description='a string indicating which URI query parameter caused the error.') + + +class ErrorMsg(BaseModel): + id: str=Schema(..., description="a unique identifier for this particular occurrence of the problem.") + links: Dict[str, Union[str, Link]]=Schema(..., description="a list of links objects.") + status: str=Schema(..., description="the HTTP status code applicable to this problem, expressed as a string value.") + code: str=Schema(..., description="an application-specific error code, expressed as a string value.") + title: str=Schema(..., description="a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.") + detail: str=Schema(..., description="a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.") + source: ErrorSource=Schema(..., description="an object containing references to the source of the error") + meta: dict=Schema(..., description="a meta object containing non-standard meta-information about the error.") diff --git a/optimade/server/models/toplevel.py b/optimade/server/models/toplevel.py index be0b5c0f9..9cc811342 100644 --- a/optimade/server/models/toplevel.py +++ b/optimade/server/models/toplevel.py @@ -7,6 +7,7 @@ from optimade.server.models.structures import StructureResource from .baseinfo import BaseInfoResource from optimade.server.models.util import NonnegativeInt +from .errors import ErrorMsg class OptimadeResponseMetaQuery(BaseModel): @@ -149,6 +150,12 @@ class OptimadeStructureResponseMany(OptimadeResponseMany): data: List[StructureResource] +class OptimadeErrorResponse(BaseModel): + links: Optional[Links] + meta: OptimadeResponseMeta + errors: List[ErrorMsg] + + class OptimadeInfoResponse(OptimadeResponse1): links: Optional[Links] meta: Optional[OptimadeResponseMeta]