Skip to content

Commit

Permalink
Update dimension_types schema/model
Browse files Browse the repository at this point in the history
Using `IntEnum` and pydantic's `Field` parameters to perform validation
of the property, `dimension_types` is now represented correctly in the
OpenAPI schema as well.
  • Loading branch information
CasperWA committed Feb 6, 2020
1 parent b261d7d commit 137edee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2653,8 +2653,16 @@
},
"dimension_types": {
"title": "Dimension Types",
"maxItems": 3,
"minItems": 3,
"type": "array",
"items": {},
"items": {
"enum": [
0,
1
],
"type": "integer"
},
"description": "List of three integers.\n For each of the three directions indicated by the three lattice vectors (see property `lattice_vectors`_).\n This list indicates if the direction is periodic (value :val:`1`) or non-periodic (value :val:`0`).\n Note: the elements in this list each refer to the direction of the corresponding entry in property `lattice_vectors`_ and *not* the Cartesian x, y, z directions.\n- **Type**: list of integers.\n- **Requirements/Conventions**:\n\n - **Support**: SHOULD be supported, i.e., SHOULD NOT be :val:`null`. Is REQUIRED in this implementation, i.e., MUST NOT be :val:`null`.\n - **Query**: MUST be a queryable property. Support for equality comparison is REQUIRED, support for other comparison operators are OPTIONAL.\n - MUST be a list of length 3.\n - Each integer element MUST assume only the value 0 or 1.\n\n- **Examples**:\n\n - For a molecule: :val:`[0, 0, 0]`\n - For a wire along the direction specified by the third lattice vector: :val:`[0, 0, 1]`\n - For a 2D surface/slab, periodic on the plane defined by the first and third lattice vectors: :val:`[1, 0, 1]`\n - For a bulk 3D system: :val:`[1, 1, 1]`"
},
"lattice_vectors": {
Expand Down
10 changes: 9 additions & 1 deletion optimade/models/structures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=no-self-argument,line-too-long,no-name-in-module
from enum import IntEnum
from sys import float_info
from typing import List, Optional

Expand All @@ -17,6 +18,11 @@
EPS = float_info.epsilon


class dimension_types_values(IntEnum):
ZERO = 0
ONE = 1


class Species(BaseModel):
"""A list describing the species of the sites of this structure.
Species can be pure chemical elements, or virtual-crystal atoms representing a statistical occupation of a given site by multiple chemical elements.
Expand Down Expand Up @@ -307,7 +313,7 @@ class StructureResourceAttributes(EntryResourceAttributes):
- A filter that matches an exactly given formula is :filter:`chemical_formula_anonymous="A2B"`.""",
)

dimension_types: conlist(len_eq=3) = Field(
dimension_types: List[dimension_types_values] = Field(
...,
description="""List of three integers.
For each of the three directions indicated by the three lattice vectors (see property `lattice_vectors`_).
Expand All @@ -327,6 +333,8 @@ class StructureResourceAttributes(EntryResourceAttributes):
- For a wire along the direction specified by the third lattice vector: :val:`[0, 0, 1]`
- For a 2D surface/slab, periodic on the plane defined by the first and third lattice vectors: :val:`[1, 0, 1]`
- For a bulk 3D system: :val:`[1, 1, 1]`""",
min_items=3,
max_items=3,
)

lattice_vectors: Optional[List[conlist(len_eq=3)]] = Field(
Expand Down

0 comments on commit 137edee

Please sign in to comment.