Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pydantic to ~=1.8 #731

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions openapi/index_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,23 @@
"description": "JSON API links object, pointing to a homepage URL for this implementation"
},
"link_type": {
"$ref": "#/components/schemas/LinkType"
"title": "Link Type",
"allOf": [
merkys marked this conversation as resolved.
Show resolved Hide resolved
{
"$ref": "#/components/schemas/LinkType"
}
],
"description": "The type of the linked relation.\nMUST be one of these values: 'child', 'root', 'external', 'providers'."
},
"aggregate": {
"$ref": "#/components/schemas/Aggregate"
"title": "Aggregate",
"allOf": [
{
"$ref": "#/components/schemas/Aggregate"
}
],
"description": "A string indicating whether a client that is following links to aggregate results from different OPTIMADE implementations should follow this link or not.\nThis flag SHOULD NOT be indicated for links where `link_type` is not `child`.\n\nIf not specified, clients MAY assume that the value is `ok`.\nIf specified, and the value is anything different than `ok`, the client MUST assume that the server is suggesting not to follow the link during aggregation by default (also if the value is not among the known ones, in case a future specification adds new accepted values).\n\nSpecific values indicate the reason why the server is providing the suggestion.\nA client MAY follow the link anyway if it has reason to do so (e.g., if the client is looking for all test databases, it MAY follow the links marked with `aggregate`=`test`).\n\nIf specified, it MUST be one of the values listed in section Link Aggregate Options.",
"default": "ok"
merkys marked this conversation as resolved.
Show resolved Hide resolved
},
"no_aggregate_reason": {
"title": "No Aggregate Reason",
Expand Down
27 changes: 23 additions & 4 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,13 @@
"description": "Defines whether the entry property can be used for sorting with the \"sort\" parameter.\nIf the entry listing endpoint supports sorting, this key MUST be present for sortable properties with value `true`."
},
"type": {
"$ref": "#/components/schemas/DataType"
"title": "Type",
"allOf": [
{
"$ref": "#/components/schemas/DataType"
}
],
"description": "The type of the property's value.\nThis MUST be any of the types defined in the Data types section.\nFor the purpose of compatibility with future versions of this specification, a client MUST accept values that are not `string` values specifying any of the OPTIMADE Data types, but MUST then also disregard the `type` field.\nNote, if the value is a nested type, only the outermost type should be reported.\nE.g., for the entry resource `structures`, the `species` property is defined as a list of dictionaries, hence its `type` value would be `list`."
}
}
},
Expand Down Expand Up @@ -1933,10 +1939,23 @@
"description": "JSON API links object, pointing to a homepage URL for this implementation"
},
"link_type": {
"$ref": "#/components/schemas/LinkType"
"title": "Link Type",
"allOf": [
{
"$ref": "#/components/schemas/LinkType"
}
],
"description": "The type of the linked relation.\nMUST be one of these values: 'child', 'root', 'external', 'providers'."
},
"aggregate": {
"$ref": "#/components/schemas/Aggregate"
"title": "Aggregate",
"allOf": [
{
"$ref": "#/components/schemas/Aggregate"
}
],
"description": "A string indicating whether a client that is following links to aggregate results from different OPTIMADE implementations should follow this link or not.\nThis flag SHOULD NOT be indicated for links where `link_type` is not `child`.\n\nIf not specified, clients MAY assume that the value is `ok`.\nIf specified, and the value is anything different than `ok`, the client MUST assume that the server is suggesting not to follow the link during aggregation by default (also if the value is not among the known ones, in case a future specification adds new accepted values).\n\nSpecific values indicate the reason why the server is providing the suggestion.\nA client MAY follow the link anyway if it has reason to do so (e.g., if the client is looking for all test databases, it MAY follow the links marked with `aggregate`=`test`).\n\nIf specified, it MUST be one of the values listed in section Link Aggregate Options.",
"default": "ok"
},
"no_aggregate_reason": {
"title": "No Aggregate Reason",
Expand Down Expand Up @@ -2105,7 +2124,7 @@
1
],
"type": "integer",
"description": "An enumeration."
"description": "Integer enumeration of dimension_types values"
},
"Person": {
"title": "Person",
Expand Down
1 change: 1 addition & 0 deletions optimade/models/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class EntryInfoProperty(BaseModel):

type: Optional[DataType] = StrictField(
None,
title="Type",
description="""The type of the property's value.
This MUST be any of the types defined in the Data types section.
For the purpose of compatibility with future versions of this specification, a client MUST accept values that are not `string` values specifying any of the OPTIMADE Data types, but MUST then also disregard the `type` field.
Expand Down
1 change: 1 addition & 0 deletions optimade/models/index_metadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class IndexInfoResource(BaseInfoResource):
None, Dict[DefaultRelationship, IndexRelationship]
] = StrictField(
...,
title="Relationships",
description="""Reference to the Links identifier object under the `links` endpoint that the provider has chosen as their 'default' OPTIMADE API database.
A client SHOULD present this database as the first choice when an end-user chooses this provider.""",
)
2 changes: 2 additions & 0 deletions optimade/models/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ class LinksResourceAttributes(Attributes):

link_type: LinkType = StrictField(
...,
title="Link Type",
description="""The type of the linked relation.
MUST be one of these values: 'child', 'root', 'external', 'providers'.""",
)

aggregate: Optional[Aggregate] = StrictField(
Aggregate.OK,
title="Aggregate",
description="""A string indicating whether a client that is following links to aggregate results from different OPTIMADE implementations should follow this link or not.
This flag SHOULD NOT be indicated for links where `link_type` is not `child`.

Expand Down
4 changes: 4 additions & 0 deletions optimade/models/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@


class Periodicity(IntEnum):
"""Integer enumeration of dimension_types values"""

APERIODIC = 0
PERIODIC = 1

Expand Down Expand Up @@ -442,6 +444,7 @@ class StructureResourceAttributes(EntryResourceAttributes):
conlist(Periodicity, min_items=3, max_items=3)
] = OptimadeField(
None,
title="Dimension Types",
description="""List of three integers.
For each of the three directions indicated by the three lattice vectors (see property `lattice_vectors`), this list indicates if the direction is periodic (value `1`) or non-periodic (value `0`).
Note: the elements in this list each refer to the direction of the corresponding entry in `lattice_vectors` and *not* the Cartesian x, y, z directions.
Expand Down Expand Up @@ -757,6 +760,7 @@ class StructureResourceAttributes(EntryResourceAttributes):

structure_features: List[StructureFeatures] = OptimadeField(
...,
title="Structure Features",
description="""A list of strings that flag which special features are used by the structure.

- **Type**: list of strings
Expand Down
2 changes: 2 additions & 0 deletions optimade/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


class SupportLevel(Enum):
"""OPTIMADE property/field support levels"""

MUST = "must"
SHOULD = "should"
OPTIONAL = "optional"
Expand Down
11 changes: 9 additions & 2 deletions optimade/server/entry_collections/entry_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ def all_fields(self) -> set:
return fields

def get_attribute_fields(self) -> set:
"""Get the set of attribute fields from the schema of the
resource class, resolving references along the way.
"""Get the set of attribute fields

Return only the _first-level_ attribute fields from the schema of the resource class,
resolving references along the way if needed.

Note:
It is not needed to take care of other special OpenAPI schema keys than `allOf`,
since only `allOf` will be found in this context.
Other special keys can be found in [the Swagger documentation](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/).

Returns:
Property names.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fastapi==0.63.0
lark-parser==0.11.2
pydantic==1.6.1
pydantic==1.8.1
email_validator==1.1.2
requests==2.25.1
uvicorn==0.13.4
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
install_requires=[
"lark-parser~=0.11.2",
"fastapi~=0.63.0",
"pydantic~=1.6.1",
"pydantic~=1.8",
"email_validator~=1.1",
"requests~=2.25",
"typing-extensions~=3.7;python_version<'3.8'",
Expand Down
26 changes: 26 additions & 0 deletions tests/server/entry_collections/test_entry_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Test the EntryCollection abstract base class"""


def test_get_attribute_fields():
"""Test get_attribute_fields() method"""
from optimade.models import (
LinksResourceAttributes,
ReferenceResourceAttributes,
StructureResourceAttributes,
)
from optimade.server.routers import ENTRY_COLLECTIONS

entry_name_attributes = {
"links": LinksResourceAttributes,
"references": ReferenceResourceAttributes,
"structures": StructureResourceAttributes,
}

# Make sure we're hitting all collections
assert set(entry_name_attributes.keys()) == set(ENTRY_COLLECTIONS.keys())

for entry_name, attributes_model in entry_name_attributes.items():
assert (
set(attributes_model.__fields__.keys())
== ENTRY_COLLECTIONS[entry_name].get_attribute_fields()
)