From 137edeee9cda506f908140eec8b587d4a89d58f5 Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Thu, 6 Feb 2020 16:53:23 +0100 Subject: [PATCH] Update `dimension_types` schema/model 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. --- openapi/openapi.json | 10 +++++++++- optimade/models/structures.py | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/openapi/openapi.json b/openapi/openapi.json index be5a401697..368654678f 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -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": { diff --git a/optimade/models/structures.py b/optimade/models/structures.py index 675471270c..adfba5d56d 100644 --- a/optimade/models/structures.py +++ b/optimade/models/structures.py @@ -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 @@ -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. @@ -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`_). @@ -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(