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