Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a258721

Browse files
committedSep 26, 2024
Don't convert standalone enums in V1
1 parent 70fd0a2 commit a258721

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed
 

‎pydantic2ts/cli/script.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,8 @@ def generate_json_schema_v1(
254254
for e in enums:
255255
add_enum_names_v1(e)
256256

257-
all_models = models + enums
258257
master_model = create_model(
259-
"_Master_", **{m.__name__: (m, ...) for m in all_models}
258+
"_Master_", **{m.__name__: (m, ...) for m in models}
260259
)
261260
master_model.Config.extra = "forbid"
262261
master_model.Config.schema_extra = staticmethod(clean_schema)

‎tests/expected_results/enums/v1/input.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import Enum
12
from typing import List, Optional
23

34
from pydantic import BaseModel
@@ -23,3 +24,8 @@ class AnimalShelter(BaseModel):
2324
dogs: List[Dog]
2425
owner: Optional[Dog]
2526
master: Cat
27+
28+
29+
class Standalone(Enum):
30+
something = "something"
31+
anything = "anything"

‎tests/expected_results/enums/v2/input.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import Enum
12
from typing import List, Optional
23

34
from pydantic import BaseModel
@@ -23,3 +24,8 @@ class AnimalShelter(BaseModel):
2324
dogs: List[Dog]
2425
owner: Optional[Dog]
2526
master: Cat
27+
28+
29+
class Standalone(Enum):
30+
something = "something"
31+
anything = "anything"

‎tests/expected_results/extra_fields/v1/output.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@ export interface ModelAllow {
1212
export interface ModelDefault {
1313
a: string;
1414
}
15-
16-
export const enum Extra {
17-
allow = "allow",
18-
ignore = "ignore",
19-
forbid = "forbid"
20-
}

0 commit comments

Comments
 (0)
Please sign in to comment.