1+ package com .databricks .sdk .core .error .details ;
2+
3+ import com .fasterxml .jackson .annotation .JsonProperty ;
4+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
5+ import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
6+ import com .google .auto .value .AutoValue ;
7+ import java .util .List ;
8+
9+ /**
10+ * BadRequest describes violations in a client request. This error type focuses
11+ * on the syntactic aspects of the request.
12+ *
13+ * <p>BadRequest errors occur when the request format, structure, or content
14+ * does not meet the service's requirements. This is different from business
15+ * logic errors or system failures - it specifically indicates that the client
16+ * sent a malformed or invalid request.
17+ *
18+ * <p>Examples of bad request violations might include:
19+ * <ul>
20+ * <li>Missing required fields</li>
21+ * <li>Invalid field values (wrong type, format, or range)</li>
22+ * <li>Malformed JSON or XML</li>
23+ * <li>Unsupported field combinations</li>
24+ * <li>Invalid enum values</li>
25+ * <li>Field length or size violations</li>
26+ * </ul>
27+ *
28+ * <p>This information helps clients:
29+ * <ul>
30+ * <li>Identify what's wrong with their request</li>
31+ * <li>Fix the request format before retrying</li>
32+ * <li>Understand the service's input requirements</li>
33+ * <li>Implement proper input validation</li>
34+ * </ul>
35+ */
36+ @ AutoValue
37+ @ JsonDeserialize (builder = AutoValue_BadRequest .Builder .class )
38+ @ JsonIgnoreProperties (ignoreUnknown = true )
39+ public abstract class BadRequest {
40+
41+ /**
42+ * Describes all field violations in the request.
43+ *
44+ * <p>This list contains details about each specific field or aspect of
45+ * the request that violated the service's requirements. Multiple violations
46+ * can occur if the request has multiple problems.
47+ *
48+ * @return the list of field violations
49+ */
50+ @ JsonProperty ("field_violations" )
51+ public abstract List <BadRequestFieldViolation > fieldViolations ();
52+
53+ /**
54+ * Creates a new builder for constructing BadRequest instances.
55+ *
56+ * @return a new builder instance
57+ */
58+ public static Builder builder () {
59+ return new AutoValue_BadRequest .Builder ();
60+ }
61+
62+ /**
63+ * Builder for constructing BadRequest instances.
64+ */
65+ @ AutoValue .Builder
66+ @ JsonIgnoreProperties (ignoreUnknown = true )
67+ public abstract static class Builder {
68+
69+ /**
70+ * Sets the field violations.
71+ *
72+ * @param fieldViolations the list of field violations
73+ * @return this builder for method chaining
74+ */
75+ @ JsonProperty ("field_violations" )
76+ public abstract Builder fieldViolations (List <BadRequestFieldViolation > fieldViolations );
77+
78+ /**
79+ * Builds the BadRequest instance.
80+ *
81+ * @return a new BadRequest instance
82+ */
83+ public abstract BadRequest build ();
84+ }
85+
86+ /**
87+ * BadRequestFieldViolation describes a specific field violation in a request.
88+ *
89+ * <p>Each violation provides details about what specific field or aspect
90+ * of the request was invalid and how the client can fix it.
91+ */
92+ @ AutoValue
93+ @ JsonDeserialize (builder = AutoValue_BadRequest_BadRequestFieldViolation .Builder .class )
94+ @ JsonIgnoreProperties (ignoreUnknown = true )
95+ public abstract static class BadRequestFieldViolation {
96+
97+ /**
98+ * A path leading to a field in the request body.
99+ *
100+ * <p>This field identifies the specific location of the violation
101+ * within the request structure. The path format depends on the request
102+ * format but typically follows a hierarchical structure.
103+ *
104+ * <p>Examples of field paths:
105+ * <ul>
106+ * <li>"name" - top-level field</li>
107+ * <li>"user.email" - nested field</li>
108+ * <li>"items[0].id" - array element field</li>
109+ * <li>"metadata.api_key" - deeply nested field</li>
110+ * <li>"settings.notifications.enabled" - multi-level nested field</li>
111+ * </ul>
112+ *
113+ * <p>This path helps clients quickly locate and fix the problematic
114+ * field in their request.
115+ *
116+ * @return the path to the violating field
117+ */
118+ @ JsonProperty ("field" )
119+ public abstract String field ();
120+
121+ /**
122+ * A description of why the request element is bad.
123+ *
124+ * <p>This field provides a human-readable explanation of what's wrong
125+ * with the field and how to fix it. The description should be clear
126+ * enough for developers to understand and resolve the issue.
127+ *
128+ * <p>Examples of field violation descriptions:
129+ * <ul>
130+ * <li>"Field is required and cannot be empty"</li>
131+ * <li>"Value must be a positive integer"</li>
132+ * <li>"Invalid email format"</li>
133+ * <li>"String length must be between 1 and 100 characters"</li>
134+ * <li>"Unsupported enum value. Must be one of: [A, B, C]"</li>
135+ * <li>"Field cannot contain special characters"</li>
136+ * <li>"Date must be in ISO 8601 format (YYYY-MM-DD)"</li>
137+ * </ul>
138+ *
139+ * @return description of why the field is invalid
140+ */
141+ @ JsonProperty ("description" )
142+ public abstract String description ();
143+
144+ /**
145+ * Creates a new builder for constructing BadRequestFieldViolation instances.
146+ *
147+ * @return a new builder instance
148+ */
149+ public static Builder builder () {
150+ return new AutoValue_BadRequest_BadRequestFieldViolation .Builder ();
151+ }
152+
153+ /**
154+ * Builder for constructing BadRequestFieldViolation instances.
155+ */
156+ @ AutoValue .Builder
157+ @ JsonIgnoreProperties (ignoreUnknown = true )
158+ public abstract static class Builder {
159+
160+ /**
161+ * Sets the field path.
162+ *
163+ * @param field the path to the violating field
164+ * @return this builder for method chaining
165+ */
166+ @ JsonProperty ("field" )
167+ public abstract Builder field (String field );
168+
169+ /**
170+ * Sets the violation description.
171+ *
172+ * @param description description of why the field is invalid
173+ * @return this builder for method chaining
174+ */
175+ @ JsonProperty ("description" )
176+ public abstract Builder description (String description );
177+
178+ /**
179+ * Builds the BadRequestFieldViolation instance.
180+ *
181+ * @return a new BadRequestFieldViolation instance
182+ */
183+ public abstract BadRequestFieldViolation build ();
184+ }
185+ }
186+ }
0 commit comments