Skip to content

Commit df1dd54

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
Mark access_role as nullable (#1566)
* fix example generator * Regenerate client from commit 7ca677d6 of spec repo --------- Co-authored-by: Sherzod Karimov <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent eef441b commit df1dd54

16 files changed

+152
-27
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.5",
7-
"regenerated": "2023-07-10 17:45:18.922571",
8-
"spec_repo_commit": "9e0b471a"
7+
"regenerated": "2023-07-11 14:36:55.813150",
8+
"spec_repo_commit": "7ca677d6"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-07-10 17:45:18.934746",
13-
"spec_repo_commit": "9e0b471a"
12+
"regenerated": "2023-07-11 14:36:55.830224",
13+
"spec_repo_commit": "7ca677d6"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ components:
352352
type: array
353353
type: object
354354
AccessRole:
355-
default: st
356355
description: The access role of the user. Options are **st** (standard user),
357356
**adm** (admin user), or **ro** (read-only user).
358357
enum:
359358
- st
360359
- adm
361360
- ro
362361
- ERROR
363-
example: st
362+
example: ro
363+
nullable: true
364364
type: string
365365
x-enum-varnames:
366366
- STANDARD

.generator/src/generator/formatter.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,34 @@ def format_data_with_schema(
226226

227227
name = None
228228
imports = imports or defaultdict(set)
229+
nullable = schema.get("nullable", False)
230+
229231
if schema.get("type") not in {"string", "integer", "boolean"} or schema.get("enum"):
230232
name, imports = get_name_and_imports(schema, version, imports)
231233
if schema.get("oneOf"):
232234
name = None
233235
if name:
234236
imports[MODEL_IMPORT_TPL.format(version=version, name=safe_snake_case(name))].add(name)
235237

236-
if "enum" in schema and data not in schema["enum"]:
237-
raise ValueError(f"{data} is not valid enum value {schema['enum']}")
238+
if "enum" in schema:
239+
if nullable and data is None:
240+
pass
241+
elif data not in schema["enum"]:
242+
raise ValueError(f"{data} is not valid enum value {schema['enum']}")
238243

239244
if replace_values and data in replace_values:
240245
parameters = replace_values[data]
241246
if schema.get("format") in ("int32", "int64"):
242247
parameters = f"int({parameters})"
243248
elif "enum" in schema:
244-
parameters = schema["x-enum-varnames"][schema["enum"].index(data)]
245-
return f"{name}.{parameters}", imports
249+
if nullable and data is None:
250+
parameters = repr(data)
251+
return parameters, imports
252+
else:
253+
parameters = schema["x-enum-varnames"][schema["enum"].index(data)]
254+
return f"{name}.{parameters}", imports
246255
else:
247-
if schema.get("nullable") and data is None:
256+
if nullable and data is None:
248257
parameters = repr(data)
249258
return parameters, imports
250259
else:

examples/v1/organizations/UpdateOrg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
saml=OrganizationSettingsSaml(
3131
enabled=False,
3232
),
33-
saml_autocreate_access_role=AccessRole.STANDARD,
33+
saml_autocreate_access_role=AccessRole.READ_ONLY,
3434
saml_autocreate_users_domains=OrganizationSettingsSamlAutocreateUsersDomains(
3535
domains=[
3636
"example.com",

examples/v1/users/CreateUser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datadog_api_client.v1.model.user import User
99

1010
body = User(
11-
access_role=AccessRole.STANDARD,
11+
access_role=AccessRole.READ_ONLY,
1212
disabled=False,
1313
1414
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Create a user returns null access role
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v1.api.users_api import UsersApi
7+
from datadog_api_client.v1.model.user import User
8+
9+
body = User(
10+
access_role=None,
11+
disabled=False,
12+
13+
14+
name="test user",
15+
)
16+
17+
configuration = Configuration()
18+
with ApiClient(configuration) as api_client:
19+
api_instance = UsersApi(api_client)
20+
response = api_instance.create_user(body=body)
21+
22+
print(response)

examples/v1/users/UpdateUser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datadog_api_client.v1.model.user import User
99

1010
body = User(
11-
access_role=AccessRole.STANDARD,
11+
access_role=AccessRole.READ_ONLY,
1212
disabled=False,
1313
1414

src/datadog_api_client/v1/model/access_role.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AccessRole(ModelSimple):
1616
"""
1717
The access role of the user. Options are **st** (standard user), **adm** (admin user), or **ro** (read-only user).
1818
19-
:param value: If omitted defaults to "st". Must be one of ["st", "adm", "ro", "ERROR"].
19+
:param value: Must be one of ["st", "adm", "ro", "ERROR"].
2020
:type value: str
2121
"""
2222

@@ -31,6 +31,8 @@ class AccessRole(ModelSimple):
3131
READ_ONLY: ClassVar["AccessRole"]
3232
ERROR: ClassVar["AccessRole"]
3333

34+
_nullable = True
35+
3436
@cached_property
3537
def openapi_types(_):
3638
return {

src/datadog_api_client/v1/model/organization_settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datadog_api_client.model_utils import (
99
ModelNormal,
1010
cached_property,
11+
none_type,
1112
unset,
1213
UnsetType,
1314
)
@@ -70,7 +71,7 @@ def __init__(
7071
self_,
7172
private_widget_share: Union[bool, UnsetType] = unset,
7273
saml: Union[OrganizationSettingsSaml, UnsetType] = unset,
73-
saml_autocreate_access_role: Union[AccessRole, UnsetType] = unset,
74+
saml_autocreate_access_role: Union[AccessRole, none_type, UnsetType] = unset,
7475
saml_autocreate_users_domains: Union[OrganizationSettingsSamlAutocreateUsersDomains, UnsetType] = unset,
7576
saml_can_be_enabled: Union[bool, UnsetType] = unset,
7677
saml_idp_endpoint: Union[str, UnsetType] = unset,
@@ -91,7 +92,7 @@ def __init__(
9192
:type saml: OrganizationSettingsSaml, optional
9293
9394
:param saml_autocreate_access_role: The access role of the user. Options are **st** (standard user), **adm** (admin user), or **ro** (read-only user).
94-
:type saml_autocreate_access_role: AccessRole, optional
95+
:type saml_autocreate_access_role: AccessRole, none_type, optional
9596
9697
:param saml_autocreate_users_domains: Has two properties, ``enabled`` (boolean) and ``domains`` , which is a list of domains without the @ symbol.
9798
:type saml_autocreate_users_domains: OrganizationSettingsSamlAutocreateUsersDomains, optional

src/datadog_api_client/v1/model/user.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datadog_api_client.model_utils import (
99
ModelNormal,
1010
cached_property,
11+
none_type,
1112
unset,
1213
UnsetType,
1314
)
@@ -48,7 +49,7 @@ def openapi_types(_):
4849

4950
def __init__(
5051
self_,
51-
access_role: Union[AccessRole, UnsetType] = unset,
52+
access_role: Union[AccessRole, none_type, UnsetType] = unset,
5253
disabled: Union[bool, UnsetType] = unset,
5354
email: Union[str, UnsetType] = unset,
5455
handle: Union[str, UnsetType] = unset,
@@ -61,7 +62,7 @@ def __init__(
6162
Create, edit, and disable users.
6263
6364
:param access_role: The access role of the user. Options are **st** (standard user), **adm** (admin user), or **ro** (read-only user).
64-
:type access_role: AccessRole, optional
65+
:type access_role: AccessRole, none_type, optional
6566
6667
:param disabled: The new disabled status of the user.
6768
:type disabled: bool, optional

0 commit comments

Comments
 (0)