Skip to content

Commit 1af68f3

Browse files
committed
fix(python): oneof now uses regex pattern for validation
Signed-off-by: Alexander Dahmen <[email protected]>
1 parent ed696d6 commit 1af68f3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

templates/python/model_oneof.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
import json
33
import pprint
4+
import re
45
{{#vendorExtensions.x-py-other-imports}}
56
{{{.}}}
67
{{/vendorExtensions.x-py-other-imports}}
@@ -19,7 +20,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
1920
"""
2021
{{#composedSchemas.oneOf}}
2122
# data type: {{{dataType}}}
22-
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
23+
{{vendorExtensions.x-py-name}}: Optional[Annotated[{{{dataType}}}, Field(strict=True)]] = Field(default=None, description="{{{description}}}", pattern=re.sub(r'^\/|\/$', '',"{{pattern}}"))
2324
{{/composedSchemas.oneOf}}
2425
actual_instance: Optional[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]] = None
2526
one_of_schemas: Set[str] = { {{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}} }

0 commit comments

Comments
 (0)