Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.5",
"regenerated": "2023-07-10 17:45:14.758583",
"spec_repo_commit": "9e0b471a"
"regenerated": "2023-07-11 14:36:43.463695",
"spec_repo_commit": "7ca677d6"
},
"v2": {
"apigentools_version": "1.6.5",
"regenerated": "2023-07-10 17:45:14.774389",
"spec_repo_commit": "9e0b471a"
"regenerated": "2023-07-11 14:36:43.479079",
"spec_repo_commit": "7ca677d6"
}
}
}
4 changes: 2 additions & 2 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ components:
type: array
type: object
AccessRole:
default: st
description: The access role of the user. Options are **st** (standard user),
**adm** (admin user), or **ro** (read-only user).
enum:
- st
- adm
- ro
- ERROR
example: st
example: ro
nullable: true
type: string
x-enum-varnames:
- STANDARD
Expand Down
23 changes: 13 additions & 10 deletions .generator/src/generator/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,20 @@ def format_data_with_schema(
default_name=None,
):
name, imports = get_name_and_imports(schema)
if "enum" in schema and data not in schema["enum"]:
raise ValueError(f"{data} is not valid enum value {schema['enum']}")
nullable = schema.get("nullable", False)
if "enum" in schema:
if nullable and data is None:
pass
elif data not in schema["enum"]:
raise ValueError(f"{data} is not valid enum value {schema['enum']}")

if replace_values and data in replace_values:
parameters = replace_values[data]
# date time is currently retrieved as a Long. We need to convert it to a double
if isinstance(parameters, str) and schema.get("format") == "double":
parameters = f"Long.valueOf({parameters}).doubleValue()"
else:
if schema.get("nullable") and data is None:
if nullable and data is None:
parameters = "null"
else:

Expand Down Expand Up @@ -385,13 +389,12 @@ def open_file(x):
parameters = formatter(data)

if "enum" in schema and name:
# find schema index and get name from x-enum-varnames
index = schema["enum"].index(data)
enum_varnames = schema["x-enum-varnames"][index]
parameters = f"{name}.{enum_varnames}"
imports.add(name)
# TODO handle nullable enums if necessary and replaced data
# parameters = f"{name}.fromValue({parameters})"
if data is not None:
# find schema index and get name from x-enum-varnames
index = schema["enum"].index(data)
enum_varnames = schema["x-enum-varnames"][index]
parameters = f"{name}.{enum_varnames}"
imports.add(name)

if schema.get("nullable") and schema.get("type") is not None:
return name, parameters, imports
Expand Down
2 changes: 1 addition & 1 deletion examples/v1/organizations/UpdateOrg.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void main(String[] args) {
new OrganizationSettings()
.privateWidgetShare(false)
.saml(new OrganizationSettingsSaml().enabled(false))
.samlAutocreateAccessRole(AccessRole.STANDARD)
.samlAutocreateAccessRole(AccessRole.READ_ONLY)
.samlAutocreateUsersDomains(
new OrganizationSettingsSamlAutocreateUsersDomains()
.domains(Collections.singletonList("example.com"))
Expand Down
2 changes: 1 addition & 1 deletion examples/v1/users/CreateUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) {

User body =
new User()
.accessRole(AccessRole.STANDARD)
.accessRole(AccessRole.READ_ONLY)
.disabled(false)
.email("test@datadoghq.com")
.handle("test@datadoghq.com")
Expand Down
33 changes: 33 additions & 0 deletions examples/v1/users/CreateUser_266604071.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Create a user returns null access role

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.UsersApi;
import com.datadog.api.client.v1.model.User;
import com.datadog.api.client.v1.model.UserResponse;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
UsersApi apiInstance = new UsersApi(defaultClient);

User body =
new User()
.accessRole(null)
.disabled(false)
.email("test@datadoghq.com")
.handle("test@datadoghq.com")
.name("test user");

try {
UserResponse result = apiInstance.createUser(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling UsersApi#createUser");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
2 changes: 1 addition & 1 deletion examples/v1/users/UpdateUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) {

User body =
new User()
.accessRole(AccessRole.STANDARD)
.accessRole(AccessRole.READ_ONLY)
.disabled(false)
.email("test@datadoghq.com")
.handle("test@datadoghq.com")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.openapitools.jackson.nullable.JsonNullable;

/** A JSON array of settings. */
@JsonPropertyOrder({
Expand All @@ -41,7 +42,7 @@ public class OrganizationSettings {

public static final String JSON_PROPERTY_SAML_AUTOCREATE_ACCESS_ROLE =
"saml_autocreate_access_role";
private AccessRole samlAutocreateAccessRole = AccessRole.STANDARD;
private JsonNullable<AccessRole> samlAutocreateAccessRole = JsonNullable.<AccessRole>undefined();

public static final String JSON_PROPERTY_SAML_AUTOCREATE_USERS_DOMAINS =
"saml_autocreate_users_domains";
Expand Down Expand Up @@ -111,8 +112,7 @@ public void setSaml(OrganizationSettingsSaml saml) {
}

public OrganizationSettings samlAutocreateAccessRole(AccessRole samlAutocreateAccessRole) {
this.samlAutocreateAccessRole = samlAutocreateAccessRole;
this.unparsed |= !samlAutocreateAccessRole.isValid();
this.samlAutocreateAccessRole = JsonNullable.<AccessRole>of(samlAutocreateAccessRole);
return this;
}

Expand All @@ -123,17 +123,28 @@ public OrganizationSettings samlAutocreateAccessRole(AccessRole samlAutocreateAc
* @return samlAutocreateAccessRole
*/
@jakarta.annotation.Nullable
@JsonIgnore
public AccessRole getSamlAutocreateAccessRole() {
return samlAutocreateAccessRole.orElse(null);
}

@JsonProperty(JSON_PROPERTY_SAML_AUTOCREATE_ACCESS_ROLE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public AccessRole getSamlAutocreateAccessRole() {
public JsonNullable<AccessRole> getSamlAutocreateAccessRole_JsonNullable() {
return samlAutocreateAccessRole;
}

@JsonProperty(JSON_PROPERTY_SAML_AUTOCREATE_ACCESS_ROLE)
public void setSamlAutocreateAccessRole_JsonNullable(
JsonNullable<AccessRole> samlAutocreateAccessRole) {
this.samlAutocreateAccessRole = samlAutocreateAccessRole;
}

public void setSamlAutocreateAccessRole(AccessRole samlAutocreateAccessRole) {
if (!samlAutocreateAccessRole.isValid()) {
this.unparsed = true;
}
this.samlAutocreateAccessRole = samlAutocreateAccessRole;
this.samlAutocreateAccessRole = JsonNullable.<AccessRole>of(samlAutocreateAccessRole);
}

public OrganizationSettings samlAutocreateUsersDomains(
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/com/datadog/api/client/v1/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.openapitools.jackson.nullable.JsonNullable;

/** Create, edit, and disable users. */
@JsonPropertyOrder({
Expand All @@ -31,7 +32,7 @@
public class User {
@JsonIgnore public boolean unparsed = false;
public static final String JSON_PROPERTY_ACCESS_ROLE = "access_role";
private AccessRole accessRole = AccessRole.STANDARD;
private JsonNullable<AccessRole> accessRole = JsonNullable.<AccessRole>undefined();

public static final String JSON_PROPERTY_DISABLED = "disabled";
private Boolean disabled;
Expand All @@ -52,8 +53,7 @@ public class User {
private Boolean verified;

public User accessRole(AccessRole accessRole) {
this.accessRole = accessRole;
this.unparsed |= !accessRole.isValid();
this.accessRole = JsonNullable.<AccessRole>of(accessRole);
return this;
}

Expand All @@ -64,17 +64,27 @@ public User accessRole(AccessRole accessRole) {
* @return accessRole
*/
@jakarta.annotation.Nullable
@JsonIgnore
public AccessRole getAccessRole() {
return accessRole.orElse(null);
}

@JsonProperty(JSON_PROPERTY_ACCESS_ROLE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public AccessRole getAccessRole() {
public JsonNullable<AccessRole> getAccessRole_JsonNullable() {
return accessRole;
}

@JsonProperty(JSON_PROPERTY_ACCESS_ROLE)
public void setAccessRole_JsonNullable(JsonNullable<AccessRole> accessRole) {
this.accessRole = accessRole;
}

public void setAccessRole(AccessRole accessRole) {
if (!accessRole.isValid()) {
this.unparsed = true;
}
this.accessRole = accessRole;
this.accessRole = JsonNullable.<AccessRole>of(accessRole);
}

public User disabled(Boolean disabled) {
Expand Down
29 changes: 14 additions & 15 deletions src/test/java/com/datadog/api/client/v1/api/UsersApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class UsersApiTest extends V1ApiTest {
private final String apiUri = "/api/v1/user";
private final String fixturePrefix = "client/v1/api/user_fixtures";

private final AccessRole testingUserAR = AccessRole.STANDARD;
private ArrayList<String> disableUsers = null;

@Override
Expand Down Expand Up @@ -77,7 +76,6 @@ public void userCreateModifyDisableTest() throws ApiException {
String testingUserName = getUniqueEntityName(47);
String testingUserHandle = testingUserName.toLowerCase() + "@datadoghq.com";
User user = new User();
user.setAccessRole(testingUserAR);
user.setHandle(testingUserHandle);
user.setName(testingUserName);
UserResponse response = api.createUser(user);
Expand All @@ -87,20 +85,21 @@ public void userCreateModifyDisableTest() throws ApiException {
user = response.getUser();
assertEquals(testingUserHandle, user.getHandle());
assertEquals(testingUserName, user.getName());
assertEquals(testingUserAR.toString(), user.getAccessRole().toString());

// Now test updating user
user.setName(testingUserName + "-updated");
user.setDisabled(false);
response = api.updateUser(user.getHandle(), user);
User updatedUser = new User();
updatedUser.setHandle(testingUserHandle);
updatedUser.setName(testingUserName + "-updated");
updatedUser.setDisabled(false);

response = api.updateUser(user.getHandle(), updatedUser);

assertEquals(testingUserName + "-updated", response.getUser().getName());

// Now test getting user
response = api.getUser(user.getHandle());
assertEquals(testingUserHandle, response.getUser().getHandle());
assertEquals(testingUserName + "-updated", response.getUser().getName());
assertEquals(testingUserAR.toString(), response.getUser().getAccessRole().toString());
assertEquals(false, response.getUser().getDisabled());

// Now test disabling user
Expand All @@ -120,7 +119,6 @@ public void listUsersTest() throws ApiException {
String testingUserName = getUniqueEntityName(53);
for (String suffix : suffixes) {
User user = new User();
user.setAccessRole(testingUserAR);
user.setHandle(String.format("%s-%s@datadoghq.com", testingUserName, suffix));
user.setName(String.format("%s-%s", testingUserName, suffix));
UserResponse response = api.createUser(user);
Expand Down Expand Up @@ -158,7 +156,6 @@ public void listUsersTestAsync() throws ApiException, InterruptedException, Exec
String testingUserName = getUniqueEntityName(53);
for (String suffix : suffixes) {
User user = new User();
user.setAccessRole(testingUserAR);
user.setHandle(String.format("%s-%s@datadoghq.com", testingUserName, suffix));
user.setName(String.format("%s-%s", testingUserName, suffix));
UserResponse response = api.createUserAsync(user).get();
Expand Down Expand Up @@ -255,7 +252,6 @@ public void userUpdateErrorsTest() throws ApiException, IOException {
String testingUserName = getUniqueEntityName(55);
String testingUserHandle = testingUserName + "@datadoghq.com";
User user = new User();
user.setAccessRole(testingUserAR);
user.setHandle(testingUserHandle);
user.setName(testingUserName);
UserResponse response = api.createUser(user);
Expand Down Expand Up @@ -299,18 +295,21 @@ public void userDisableErrorsTest() throws ApiException, IOException {
String testingUserName = getUniqueEntityName(55);
String testingUserHandle = testingUserName + "@datadoghq.com";
User user = new User();
user.setAccessRole(testingUserAR);
user.setHandle(testingUserHandle);
user.setName(testingUserName);
UserResponse response = api.createUser(user);
// If something fails, make sure we disable the user
disableUsers.add(testingUserHandle);
user = response.getUser();
user.setDisabled(true);
api.updateUser(user.getHandle(), user);

User updatedUser = new User();
updatedUser.setHandle(response.getUser().getHandle());
updatedUser.setName(response.getUser().getName());
updatedUser.setDisabled(true);

api.updateUser(updatedUser.getHandle(), updatedUser);

try {
api.disableUser(user.getHandle());
api.disableUser(updatedUser.getHandle());
fail("Expected ApiException not thrown");
} catch (ApiException e) {
assertEquals(400, e.getCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-07-10T18:57:28.744Z
Loading