Skip to content

Commit acd1b70

Browse files
committed
fix: unknown enum values
1 parent 824dece commit acd1b70

3 files changed

Lines changed: 439 additions & 1 deletion

File tree

openapitools.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
"generatorName": "python",
66
"inputSpec": "public_accessa/api/v2/docs/cb-v2-openapi-3.0.0.yaml",
77
"outputDir": ".",
8+
"templateDir": "templates",
89
"additionalProperties": {
910
"packageName": "cloudbeds_pms",
1011
"projectName": "Cloudbeds PMS",
1112
"packageVersion": "2.9.0",
1213
"packageDescription": "OpenAPI client for Cloudbeds PMS API.",
1314
"generateSourceCodeOnly": true,
14-
"packageUrl": "https://github.com/cloudbeds/cloudbeds-api-python"
15+
"packageUrl": "https://github.com/cloudbeds/cloudbeds-api-python",
16+
"enumUnknownDefaultCase": true
1517
},
1618
"files": {
1719
"README_onlypackage.mustache": {

templates/model_enum.mustache

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from __future__ import annotations
2+
import json
3+
from enum import Enum
4+
{{#vendorExtensions.x-py-other-imports}}
5+
{{{.}}}
6+
{{/vendorExtensions.x-py-other-imports}}
7+
from typing_extensions import Self
8+
9+
10+
class {{classname}}({{vendorExtensions.x-py-enum-type}}, Enum):
11+
"""
12+
{{{description}}}{{^description}}{{{classname}}}{{/description}}
13+
"""
14+
15+
"""
16+
allowed enum values
17+
"""
18+
{{#allowableValues}}
19+
{{#enumVars}}
20+
{{{name}}} = {{{value}}}
21+
{{/enumVars}}
22+
23+
@classmethod
24+
def from_json(cls, json_str: str) -> Self:
25+
"""Create an instance of {{classname}} from a JSON string"""
26+
return cls(json.loads(json_str))
27+
28+
{{#enumUnknownDefaultCase}}
29+
@classmethod
30+
def _missing_(cls, value):
31+
"""Handle unknown enum values by returning the unknown default case."""
32+
return cls.UNKNOWN_DEFAULT_OPEN_API
33+
{{/enumUnknownDefaultCase}}
34+
{{/allowableValues}}

0 commit comments

Comments
 (0)