Skip to content

Commit

Permalink
fix: add name constraints to yaml classes (#358)
Browse files Browse the repository at this point in the history
Adds pattern to json-schema so users get early feedback if name contains
invalid characters
  • Loading branch information
jsolaas authored Jan 29, 2024
1 parent f6a58a2 commit f586181
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from pydantic import Field

from libecalc.dto.utils.validators import ComponentNameStr
from libecalc.expression.expression import ExpressionType
from libecalc.presentation.yaml.yaml_types import YamlBase


class YamlConsumerBase(YamlBase):
name: str = Field(
name: ComponentNameStr = Field(
...,
title="NAME",
description="Consumer name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydantic import ConfigDict, Field

from libecalc.dto.base import ConsumerUserDefinedCategoryType
from libecalc.dto.utils.validators import ComponentNameStr
from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.components.legacy.yaml_electricity_consumer import (
YamlElectricityConsumer,
Expand All @@ -24,7 +25,7 @@
class YamlGeneratorSet(YamlBase):
model_config = ConfigDict(title="GeneratorSet")

name: str = Field(
name: ComponentNameStr = Field(
...,
title="NAME",
description="Name of the generator set.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydantic import ConfigDict, Field

from libecalc.dto.base import InstallationUserDefinedCategoryType
from libecalc.dto.utils.validators import ComponentNameStr
from libecalc.expression import Expression
from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.components.legacy.yaml_fuel_consumer import (
Expand Down Expand Up @@ -31,7 +32,7 @@
class YamlInstallation(YamlBase): # TODO: conditional required, either fuelconsumers or gensets
model_config = ConfigDict(title="Installation")

name: str = Field(
name: ComponentNameStr = Field(
...,
title="NAME",
description="Name of the installation.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TimeSeriesStreamDayRate,
)
from libecalc.dto.base import ComponentType, ConsumerUserDefinedCategoryType
from libecalc.dto.utils.validators import ComponentNameStr
from libecalc.dto.variables import VariablesMap
from libecalc.expression import Expression
from libecalc.presentation.yaml.yaml_types import YamlBase
Expand All @@ -39,7 +40,7 @@ class YamlVentingEmitter(YamlBase):
def component_type(self):
return ComponentType.VENTING_EMITTER

name: str = Field(
name: ComponentNameStr = Field(
...,
title="NAME",
description="Name of venting emitter",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from pydantic import ConfigDict, Field

from libecalc.dto.utils.validators import EmissionNameStr
from libecalc.expression.expression import ExpressionType
from libecalc.presentation.yaml.yaml_types import YamlBase


class YamlEmission(YamlBase):
model_config = ConfigDict(title="Emission")

name: str = Field(
name: EmissionNameStr = Field(
...,
title="NAME",
description="Name of the emission.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
},
"NAME": {
"description": "Consumer name",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -659,6 +660,7 @@
},
"NAME": {
"description": "Consumer name",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -726,6 +728,7 @@
},
"NAME": {
"description": "Consumer name",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -793,6 +796,7 @@
},
"NAME": {
"description": "Consumer name",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -1094,6 +1098,7 @@
},
"NAME": {
"description": "Name of the emission.\n\nhttps://test.ecalc.equinor.com/docs/docs/modelling/keywords/NAME",
"pattern": "^\\w*$",
"title": "NAME",
"type": "string"
}
Expand Down Expand Up @@ -2011,6 +2016,7 @@
},
"NAME": {
"description": "Name of the generator set.\n\nhttps://test.ecalc.equinor.com/docs/docs/modelling/keywords/NAME",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
}
Expand Down Expand Up @@ -2252,6 +2258,7 @@
},
"NAME": {
"description": "Name of the installation.\n\nhttps://test.ecalc.equinor.com/docs/docs/modelling/keywords/NAME",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -2538,6 +2545,7 @@
},
"NAME": {
"description": "Consumer name",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -3376,6 +3384,7 @@
},
"NAME": {
"description": "Consumer name",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
},
Expand Down Expand Up @@ -3854,6 +3863,7 @@
},
"NAME": {
"description": "Name of venting emitter",
"pattern": "^[A-Z\u00c6\u00d8\u00c5a-z\u00e6\u00f8\u00e5\\d_/\\- ]*$",
"title": "NAME",
"type": "string"
}
Expand Down

0 comments on commit f586181

Please sign in to comment.