Skip to content

Commit

Permalink
fix regex fields
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Aug 28, 2023
1 parent 2b80540 commit fe856d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
20 changes: 6 additions & 14 deletions gen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
"""schema.json generator."""
# import re
from typing import Any, NewType
from typing import Annotated, Any, NewType

from pydantic import BaseModel, ConfigDict, Field, RootModel

Expand Down Expand Up @@ -275,12 +274,7 @@ class Stage(BaseModel):
Parametrized stage definition that'll be substituted over for each of the \
value from the foreach data."""


# class ParametrizedString(ConstrainedStr):
# regex = re.compile(r"^\${.*?}$")

# FIXME: how to add support for regex str?
ParametrizedString = str
ParametrizedString = Annotated[str, Field(pattern=r"^\$\{.*?\}$")]


class ForeachDo(BaseModel):
Expand Down Expand Up @@ -327,11 +321,9 @@ class TopLevelPlotsList(RootModel):
root: list[PlotIdOrFilePath | TopLevelPlots] = Field(default_factory=list)


# class ArtifactIdOrFilePath(ConstrainedStr):
# regex = re.compile(r"^[a-z0-9]([a-z0-9-/]*[a-z0-9])?$")

# FIXME: how to add support for regex str?
ArtifactIdOrFilePath = str
ArtifactIdOrFilePath = Annotated[
str, Field(pattern=r"^[a-z0-9]([a-z0-9-/]*[a-z0-9])?$")
]


class TopLevelArtifacts(RootModel):
Expand Down Expand Up @@ -377,9 +369,9 @@ class DvcYamlModel(BaseModel):
)

args = parser.parse_args()
json_data = DvcYamlModel.model_json_schema()
# oneOf is expected by the JSON specification but union produces anyOf
# https://github.com/pydantic/pydantic/issues/656
json_data = DvcYamlModel.model_json_schema()
out = json.dumps(json_data, indent=2).replace('"anyOf"', '"oneOf"')
args.outfile.write(out)
args.outfile.write("\n")
Expand Down
8 changes: 6 additions & 2 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"foreach": {
"oneOf": [
{
"pattern": "^\\$\\{.*?\\}$",
"type": "string"
},
{
Expand Down Expand Up @@ -225,6 +226,7 @@
"type": "array"
},
{
"pattern": "^\\$\\{.*?\\}$",
"type": "string"
}
]
Expand Down Expand Up @@ -805,8 +807,10 @@
"type": "object"
},
"TopLevelArtifacts": {
"additionalProperties": {
"$ref": "#/$defs/TopLevelArtifactFlags"
"patternProperties": {
"^[a-z0-9]([a-z0-9-/]*[a-z0-9])?$": {
"$ref": "#/$defs/TopLevelArtifactFlags"
}
},
"title": "TopLevelArtifacts",
"type": "object"
Expand Down

0 comments on commit fe856d7

Please sign in to comment.