Skip to content

Commit 9788ca4

Browse files
author
ci.datadog-api-spec
committed
Regenerate client from commit 10c6f7d of spec repo
1 parent 38a04fd commit 9788ca4

15 files changed

+478
-24
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32305,15 +32305,23 @@ components:
3230532305
properties:
3230632306
recipients:
3230732307
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
32308+
description: A list of recipients to notify. Uses the same format as the
32309+
monitor `message` field. Must not start with an '@'.
3230832310
scope:
32309-
$ref: '#/components/schemas/MonitorNotificationRuleScope'
32311+
$ref: '#/components/schemas/MonitorNotificationRuleConditionScope'
3231032312
required:
3231132313
- scope
3231232314
- recipients
3231332315
type: object
32316+
MonitorNotificationRuleConditionScope:
32317+
description: The scope to which the monitor applied.
32318+
example: transition_type:alert
32319+
maxLength: 3000
32320+
minLength: 1
32321+
type: string
3231432322
MonitorNotificationRuleConditionalRecipients:
3231532323
description: Use conditional recipients to define different recipients for different
32316-
situations.
32324+
situations. Cannot be used with `recipients`.
3231732325
properties:
3231832326
conditions:
3231932327
description: Conditions of the notification rule.
@@ -32363,12 +32371,30 @@ components:
3236332371
description: Filter used to associate the notification rule with monitors.
3236432372
oneOf:
3236532373
- $ref: '#/components/schemas/MonitorNotificationRuleFilterTags'
32374+
- $ref: '#/components/schemas/MonitorNotificationRuleFilterScope'
32375+
MonitorNotificationRuleFilterScope:
32376+
additionalProperties: false
32377+
description: Filter monitor notifications. A monitor notification must match
32378+
the scope.
32379+
properties:
32380+
scope:
32381+
description: A scope composed of one or several key:value pairs, which can
32382+
be used to filter monitor notifications on monitor and group tags.
32383+
example: service:(foo OR bar) AND team:test NOT environment:staging
32384+
maxLength: 3000
32385+
minLength: 1
32386+
type: string
32387+
required:
32388+
- scope
32389+
type: object
3236632390
MonitorNotificationRuleFilterTags:
3236732391
additionalProperties: false
32368-
description: Filter monitors by tags. Monitors must match all tags.
32392+
description: Filter monitor notifications by tags. A monitor notification must
32393+
match all tags.
3236932394
properties:
3237032395
tags:
32371-
description: A list of monitor tags.
32396+
description: A list of tags (key:value pairs), which can be used to filter
32397+
monitor notifications on monitor and group tags.
3237232398
example:
3237332399
- team:product
3237432400
- host:abc
@@ -32408,7 +32434,7 @@ components:
3240832434
type: string
3240932435
MonitorNotificationRuleRecipients:
3241032436
description: A list of recipients to notify. Uses the same format as the monitor
32411-
`message` field. Must not start with an '@'.
32437+
`message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
3241232438
example:
3241332439
- slack-test-channel
3241432440
- jira-test
@@ -32491,12 +32517,6 @@ components:
3249132517
description: An object related to a monitor notification rule.
3249232518
oneOf:
3249332519
- $ref: '#/components/schemas/User'
32494-
MonitorNotificationRuleScope:
32495-
description: The scope to which the monitor applied.
32496-
example: transition_type:alert
32497-
maxLength: 3000
32498-
minLength: 1
32499-
type: string
3250032520
MonitorNotificationRuleUpdateRequest:
3250132521
description: Request for updating a monitor notification rule.
3250232522
properties:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Create a monitor notification rule with scope returns "OK" response
2+
3+
import com.datadog.api.client.ApiClient;
4+
import com.datadog.api.client.ApiException;
5+
import com.datadog.api.client.v2.api.MonitorsApi;
6+
import com.datadog.api.client.v2.model.MonitorNotificationRuleAttributes;
7+
import com.datadog.api.client.v2.model.MonitorNotificationRuleCreateRequest;
8+
import com.datadog.api.client.v2.model.MonitorNotificationRuleCreateRequestData;
9+
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilter;
10+
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilterScope;
11+
import com.datadog.api.client.v2.model.MonitorNotificationRuleResourceType;
12+
import com.datadog.api.client.v2.model.MonitorNotificationRuleResponse;
13+
import java.util.Arrays;
14+
15+
public class Example {
16+
public static void main(String[] args) {
17+
ApiClient defaultClient = ApiClient.getDefaultApiClient();
18+
MonitorsApi apiInstance = new MonitorsApi(defaultClient);
19+
20+
MonitorNotificationRuleCreateRequest body =
21+
new MonitorNotificationRuleCreateRequest()
22+
.data(
23+
new MonitorNotificationRuleCreateRequestData()
24+
.attributes(
25+
new MonitorNotificationRuleAttributes()
26+
.filter(
27+
new MonitorNotificationRuleFilter(
28+
new MonitorNotificationRuleFilterScope()
29+
.scope("test:example-monitor")))
30+
.name("test rule")
31+
.recipients(Arrays.asList("slack-test-channel", "jira-test")))
32+
.type(MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE));
33+
34+
try {
35+
MonitorNotificationRuleResponse result = apiInstance.createMonitorNotificationRule(body);
36+
System.out.println(result);
37+
} catch (ApiException e) {
38+
System.err.println("Exception when calling MonitorsApi#createMonitorNotificationRule");
39+
System.err.println("Status code: " + e.getCode());
40+
System.err.println("Reason: " + e.getResponseBody());
41+
System.err.println("Response headers: " + e.getResponseHeaders());
42+
e.printStackTrace();
43+
}
44+
}
45+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Update a monitor notification rule with scope returns "OK" response
2+
3+
import com.datadog.api.client.ApiClient;
4+
import com.datadog.api.client.ApiException;
5+
import com.datadog.api.client.v2.api.MonitorsApi;
6+
import com.datadog.api.client.v2.model.MonitorNotificationRuleAttributes;
7+
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilter;
8+
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilterScope;
9+
import com.datadog.api.client.v2.model.MonitorNotificationRuleResourceType;
10+
import com.datadog.api.client.v2.model.MonitorNotificationRuleResponse;
11+
import com.datadog.api.client.v2.model.MonitorNotificationRuleUpdateRequest;
12+
import com.datadog.api.client.v2.model.MonitorNotificationRuleUpdateRequestData;
13+
import java.util.Collections;
14+
15+
public class Example {
16+
public static void main(String[] args) {
17+
ApiClient defaultClient = ApiClient.getDefaultApiClient();
18+
MonitorsApi apiInstance = new MonitorsApi(defaultClient);
19+
20+
// there is a valid "monitor_notification_rule" in the system
21+
String MONITOR_NOTIFICATION_RULE_DATA_ID = System.getenv("MONITOR_NOTIFICATION_RULE_DATA_ID");
22+
23+
MonitorNotificationRuleUpdateRequest body =
24+
new MonitorNotificationRuleUpdateRequest()
25+
.data(
26+
new MonitorNotificationRuleUpdateRequestData()
27+
.attributes(
28+
new MonitorNotificationRuleAttributes()
29+
.filter(
30+
new MonitorNotificationRuleFilter(
31+
new MonitorNotificationRuleFilterScope()
32+
.scope("test:example-monitor")))
33+
.name("updated rule")
34+
.recipients(Collections.singletonList("slack-test-channel")))
35+
.id(MONITOR_NOTIFICATION_RULE_DATA_ID)
36+
.type(MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE));
37+
38+
try {
39+
MonitorNotificationRuleResponse result =
40+
apiInstance.updateMonitorNotificationRule(MONITOR_NOTIFICATION_RULE_DATA_ID, body);
41+
System.out.println(result);
42+
} catch (ApiException e) {
43+
System.err.println("Exception when calling MonitorsApi#updateMonitorNotificationRule");
44+
System.err.println("Status code: " + e.getCode());
45+
System.err.println("Reason: " + e.getResponseBody());
46+
System.err.println("Response headers: " + e.getResponseHeaders());
47+
e.printStackTrace();
48+
}
49+
}
50+
}

src/main/java/com/datadog/api/client/v2/model/MonitorNotificationRuleAttributes.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public MonitorNotificationRuleAttributes conditionalRecipients(
5454
}
5555

5656
/**
57-
* Use conditional recipients to define different recipients for different situations.
57+
* Use conditional recipients to define different recipients for different situations. Cannot be
58+
* used with <code>recipients</code>.
5859
*
5960
* @return conditionalRecipients
6061
*/
@@ -127,7 +128,7 @@ public MonitorNotificationRuleAttributes addRecipientsItem(String recipientsItem
127128

128129
/**
129130
* A list of recipients to notify. Uses the same format as the monitor <code>message</code> field.
130-
* Must not start with an '@'.
131+
* Must not start with an '@'. Cannot be used with <code>conditional_recipients</code>.
131132
*
132133
* @return recipients
133134
*/

src/main/java/com/datadog/api/client/v2/model/MonitorNotificationRuleCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public MonitorNotificationRuleCondition addRecipientsItem(String recipientsItem)
5656

5757
/**
5858
* A list of recipients to notify. Uses the same format as the monitor <code>message</code> field.
59-
* Must not start with an '@'.
59+
* Must not start with an '@'. Cannot be used with <code>conditional_recipients</code>.
6060
*
6161
* @return recipients
6262
*/

src/main/java/com/datadog/api/client/v2/model/MonitorNotificationRuleConditionalRecipients.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import java.util.Map;
2020
import java.util.Objects;
2121

22-
/** Use conditional recipients to define different recipients for different situations. */
22+
/**
23+
* Use conditional recipients to define different recipients for different situations. Cannot be
24+
* used with <code>recipients</code>.
25+
*/
2326
@JsonPropertyOrder({
2427
MonitorNotificationRuleConditionalRecipients.JSON_PROPERTY_CONDITIONS,
2528
MonitorNotificationRuleConditionalRecipients.JSON_PROPERTY_FALLBACK_RECIPIENTS
@@ -91,7 +94,7 @@ public MonitorNotificationRuleConditionalRecipients addFallbackRecipientsItem(
9194

9295
/**
9396
* A list of recipients to notify. Uses the same format as the monitor <code>message</code> field.
94-
* Must not start with an '@'.
97+
* Must not start with an '@'. Cannot be used with <code>conditional_recipients</code>.
9598
*
9699
* @return fallbackRecipients
97100
*/

src/main/java/com/datadog/api/client/v2/model/MonitorNotificationRuleFilter.java

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,54 @@ public MonitorNotificationRuleFilter deserialize(JsonParser jp, DeserializationC
127127
Level.FINER, "Input data does not match schema 'MonitorNotificationRuleFilterTags'", e);
128128
}
129129

130+
// deserialize MonitorNotificationRuleFilterScope
131+
try {
132+
boolean attemptParsing = true;
133+
// ensure that we respect type coercion as set on the client ObjectMapper
134+
if (MonitorNotificationRuleFilterScope.class.equals(Integer.class)
135+
|| MonitorNotificationRuleFilterScope.class.equals(Long.class)
136+
|| MonitorNotificationRuleFilterScope.class.equals(Float.class)
137+
|| MonitorNotificationRuleFilterScope.class.equals(Double.class)
138+
|| MonitorNotificationRuleFilterScope.class.equals(Boolean.class)
139+
|| MonitorNotificationRuleFilterScope.class.equals(String.class)) {
140+
attemptParsing = typeCoercion;
141+
if (!attemptParsing) {
142+
attemptParsing |=
143+
((MonitorNotificationRuleFilterScope.class.equals(Integer.class)
144+
|| MonitorNotificationRuleFilterScope.class.equals(Long.class))
145+
&& token == JsonToken.VALUE_NUMBER_INT);
146+
attemptParsing |=
147+
((MonitorNotificationRuleFilterScope.class.equals(Float.class)
148+
|| MonitorNotificationRuleFilterScope.class.equals(Double.class))
149+
&& (token == JsonToken.VALUE_NUMBER_FLOAT
150+
|| token == JsonToken.VALUE_NUMBER_INT));
151+
attemptParsing |=
152+
(MonitorNotificationRuleFilterScope.class.equals(Boolean.class)
153+
&& (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
154+
attemptParsing |=
155+
(MonitorNotificationRuleFilterScope.class.equals(String.class)
156+
&& token == JsonToken.VALUE_STRING);
157+
}
158+
}
159+
if (attemptParsing) {
160+
tmp = tree.traverse(jp.getCodec()).readValueAs(MonitorNotificationRuleFilterScope.class);
161+
// TODO: there is no validation against JSON schema constraints
162+
// (min, max, enum, pattern...), this does not perform a strict JSON
163+
// validation, which means the 'match' count may be higher than it should be.
164+
if (!((MonitorNotificationRuleFilterScope) tmp).unparsed) {
165+
deserialized = tmp;
166+
match++;
167+
}
168+
log.log(Level.FINER, "Input data matches schema 'MonitorNotificationRuleFilterScope'");
169+
}
170+
} catch (Exception e) {
171+
// deserialization failed, continue
172+
log.log(
173+
Level.FINER,
174+
"Input data does not match schema 'MonitorNotificationRuleFilterScope'",
175+
e);
176+
}
177+
130178
MonitorNotificationRuleFilter ret = new MonitorNotificationRuleFilter();
131179
if (match == 1) {
132180
ret.setActualInstance(deserialized);
@@ -162,10 +210,18 @@ public MonitorNotificationRuleFilter(MonitorNotificationRuleFilterTags o) {
162210
setActualInstance(o);
163211
}
164212

213+
public MonitorNotificationRuleFilter(MonitorNotificationRuleFilterScope o) {
214+
super("oneOf", Boolean.FALSE);
215+
setActualInstance(o);
216+
}
217+
165218
static {
166219
schemas.put(
167220
"MonitorNotificationRuleFilterTags",
168221
new GenericType<MonitorNotificationRuleFilterTags>() {});
222+
schemas.put(
223+
"MonitorNotificationRuleFilterScope",
224+
new GenericType<MonitorNotificationRuleFilterScope>() {});
169225
JSON.registerDescendants(
170226
MonitorNotificationRuleFilter.class, Collections.unmodifiableMap(schemas));
171227
}
@@ -177,7 +233,8 @@ public Map<String, GenericType> getSchemas() {
177233

178234
/**
179235
* Set the instance that matches the oneOf child schema, check the instance parameter is valid
180-
* against the oneOf child schemas: MonitorNotificationRuleFilterTags
236+
* against the oneOf child schemas: MonitorNotificationRuleFilterTags,
237+
* MonitorNotificationRuleFilterScope
181238
*
182239
* <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
183240
* composed schema (allOf, anyOf, oneOf).
@@ -189,18 +246,27 @@ public void setActualInstance(Object instance) {
189246
super.setActualInstance(instance);
190247
return;
191248
}
249+
if (JSON.isInstanceOf(
250+
MonitorNotificationRuleFilterScope.class, instance, new HashSet<Class<?>>())) {
251+
super.setActualInstance(instance);
252+
return;
253+
}
192254

193255
if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) {
194256
super.setActualInstance(instance);
195257
return;
196258
}
197-
throw new RuntimeException("Invalid instance type. Must be MonitorNotificationRuleFilterTags");
259+
throw new RuntimeException(
260+
"Invalid instance type. Must be MonitorNotificationRuleFilterTags,"
261+
+ " MonitorNotificationRuleFilterScope");
198262
}
199263

200264
/**
201-
* Get the actual instance, which can be the following: MonitorNotificationRuleFilterTags
265+
* Get the actual instance, which can be the following: MonitorNotificationRuleFilterTags,
266+
* MonitorNotificationRuleFilterScope
202267
*
203-
* @return The actual instance (MonitorNotificationRuleFilterTags)
268+
* @return The actual instance (MonitorNotificationRuleFilterTags,
269+
* MonitorNotificationRuleFilterScope)
204270
*/
205271
@Override
206272
public Object getActualInstance() {
@@ -218,4 +284,16 @@ public MonitorNotificationRuleFilterTags getMonitorNotificationRuleFilterTags()
218284
throws ClassCastException {
219285
return (MonitorNotificationRuleFilterTags) super.getActualInstance();
220286
}
287+
288+
/**
289+
* Get the actual instance of `MonitorNotificationRuleFilterScope`. If the actual instance is not
290+
* `MonitorNotificationRuleFilterScope`, the ClassCastException will be thrown.
291+
*
292+
* @return The actual instance of `MonitorNotificationRuleFilterScope`
293+
* @throws ClassCastException if the instance is not `MonitorNotificationRuleFilterScope`
294+
*/
295+
public MonitorNotificationRuleFilterScope getMonitorNotificationRuleFilterScope()
296+
throws ClassCastException {
297+
return (MonitorNotificationRuleFilterScope) super.getActualInstance();
298+
}
221299
}

0 commit comments

Comments
 (0)