Skip to content

Commit 3ee1993

Browse files
committed
chore: regenerate SDK from enhanced generator
1 parent 45a4652 commit 3ee1993

7 files changed

Lines changed: 206 additions & 251 deletions

File tree

‎AGENTS.md‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/main/java/com/zitadel/ObjectSerializer.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ or a numeric (1) for a boolean field must fail, not be
383383
field) requires google.protobuf.Duration's decimal-seconds string
384384
form ("3600s"), not JavaTimeModule's numeric/ISO-8601 form. */
385385
.addModule(durationModule())
386+
/* Reject a non-finite float/double on ENCODE. Jackson's default
387+
QUOTE_NON_NUMERIC_NUMBERS emits NaN/Infinity as the quoted
388+
strings "NaN"/"Infinity" — invalid per RFC 8259 §6 and a wire
389+
value the other SDKs reject. This module fails loudly instead,
390+
matching python (allow_nan=False), go, node, etc. */
391+
.addModule(nonFiniteNumberModule())
386392
.defaultDateFormat(new StdDateFormat().withColonInTimeZone(true))
387393
.build();
388394
}
@@ -416,6 +422,49 @@ public Duration deserialize(JsonParser parser, DeserializationContext context)
416422
return module;
417423
}
418424

425+
/**
426+
* Build a Jackson module that rejects a non-finite {@link Double}/{@link Float} (NaN, +Infinity,
427+
* -Infinity) on serialize.
428+
*
429+
* <p>RFC 8259 §6 has no NaN/Infinity token, so a spec-conformant server rejects them. Jackson's
430+
* default {@code QUOTE_NON_NUMERIC_NUMBERS} would emit the quoted strings {@code "NaN"}/{@code
431+
* "Infinity"} instead of failing; these serializers throw a {@link SerializationException} so the
432+
* caller learns the value cannot be represented, matching the 10 other SDKs that reject
433+
* non-finite floats.
434+
*
435+
* @return the non-finite-number module
436+
*/
437+
private static SimpleModule nonFiniteNumberModule() {
438+
SimpleModule module = new SimpleModule();
439+
module.addSerializer(
440+
Double.class,
441+
new JsonSerializer<Double>() {
442+
@Override
443+
public void serialize(Double value, JsonGenerator gen, SerializerProvider provider)
444+
throws IOException {
445+
if (value == null || !Double.isFinite(value)) {
446+
throw new SerializationException(
447+
"Non-finite double value '" + value + "' is not permitted by RFC 8259");
448+
}
449+
gen.writeNumber(value.doubleValue());
450+
}
451+
});
452+
module.addSerializer(
453+
Float.class,
454+
new JsonSerializer<Float>() {
455+
@Override
456+
public void serialize(Float value, JsonGenerator gen, SerializerProvider provider)
457+
throws IOException {
458+
if (value == null || !Float.isFinite(value)) {
459+
throw new SerializationException(
460+
"Non-finite float value '" + value + "' is not permitted by RFC 8259");
461+
}
462+
gen.writeNumber(value.floatValue());
463+
}
464+
});
465+
return module;
466+
}
467+
419468
/**
420469
* Resolve a oneOf schema by trying each candidate deserializer in order.
421470
*

‎src/main/java/com/zitadel/api/BaseApi.java‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,19 +519,40 @@ private String buildQueryString(Map<String, Object> queryParams) {
519519
}
520520
StringJoiner joiner = new StringJoiner("&");
521521
for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
522-
if (entry.getValue() != null) {
523-
if (entry.getValue() instanceof List<?> list) {
522+
Object value = entry.getValue();
523+
/* OAS allowReserved: a wrapped value keeps RFC 3986 reserved
524+
* characters literal instead of percent-encoding them. */
525+
boolean allowReserved = false;
526+
if (value instanceof ValueSerializer.AllowReservedValue reserved) {
527+
value = reserved.value();
528+
allowReserved = true;
529+
}
530+
if (value != null) {
531+
String encodedKey = encode(entry.getKey());
532+
if (value instanceof List<?> list) {
524533
for (Object item : list) {
525-
joiner.add(encode(entry.getKey()) + "=" + encode(String.valueOf(item)));
534+
joiner.add(encodedKey + "=" + encodeQueryValue(String.valueOf(item), allowReserved));
526535
}
527536
} else {
528-
joiner.add(encode(entry.getKey()) + "=" + encode(String.valueOf(entry.getValue())));
537+
joiner.add(encodedKey + "=" + encodeQueryValue(String.valueOf(value), allowReserved));
529538
}
530539
}
531540
}
532541
return joiner.toString();
533542
}
534543

544+
/**
545+
* Encode a query-parameter value, preserving RFC 3986 reserved characters when the parameter
546+
* declared {@code allowReserved: true}.
547+
*
548+
* @param value the value to encode
549+
* @param allowReserved whether reserved characters are left literal
550+
* @return the encoded value
551+
*/
552+
private String encodeQueryValue(String value, boolean allowReserved) {
553+
return allowReserved ? ValueSerializer.encodeQueryAllowingReserved(value) : encode(value);
554+
}
555+
535556
/**
536557
* URL-encode a string.
537558
*

‎src/main/java/com/zitadel/api/ValueSerializer.java‎

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,70 @@ public static String encodePathSegment(String value) {
138138
.replace("%2B", "+");
139139
}
140140

141+
/**
142+
* Wraps a query value so the query-string builder preserves RFC 3986 reserved characters (OAS
143+
* {@code allowReserved: true}).
144+
*
145+
* @param value the serialized query value (a {@link String} or a {@link List} of strings for
146+
* exploded parameters)
147+
*/
148+
record AllowReservedValue(Object value) {}
149+
150+
/**
151+
* Wraps {@code value} in an {@link AllowReservedValue} when the parameter declares {@code
152+
* allowReserved: true}; otherwise returns it unchanged.
153+
*
154+
* @param value the serialized query value
155+
* @param allowReserved whether the parameter preserves reserved characters
156+
* @return the value, wrapped iff {@code allowReserved} is true
157+
*/
158+
@Nullable
159+
public static Object maybeAllowReserved(@Nullable Object value, boolean allowReserved) {
160+
if (value == null || !allowReserved) {
161+
return value;
162+
}
163+
return new AllowReservedValue(value);
164+
}
165+
166+
/**
167+
* Percent-encodes a query value while leaving RFC 3986 reserved characters literal (OAS {@code
168+
* allowReserved: true}).
169+
*
170+
* <p>Everything that is not RFC 3986 reserved or unreserved — spaces, control characters,
171+
* non-ASCII — is still percent-encoded, so the result is always a valid URL query segment. Only
172+
* the reserved set {@code : / ? # [ ] @ ! $ & ' ( ) * + , ; =} (plus the unreserved {@code ~}) is
173+
* restored after {@link URLEncoder} over-encodes it.
174+
*
175+
* @param value the raw value to encode
176+
* @return the encoded value with reserved characters preserved
177+
*/
178+
public static String encodeQueryAllowingReserved(String value) {
179+
if (value == null || value.isEmpty()) {
180+
return value;
181+
}
182+
return URLEncoder.encode(value, StandardCharsets.UTF_8)
183+
.replace("+", "%20")
184+
.replace("%7E", "~")
185+
.replace("%3A", ":")
186+
.replace("%2F", "/")
187+
.replace("%3F", "?")
188+
.replace("%23", "#")
189+
.replace("%5B", "[")
190+
.replace("%5D", "]")
191+
.replace("%40", "@")
192+
.replace("%21", "!")
193+
.replace("%24", "$")
194+
.replace("%26", "&")
195+
.replace("%27", "'")
196+
.replace("%28", "(")
197+
.replace("%29", ")")
198+
.replace("%2A", "*")
199+
.replace("%2B", "+")
200+
.replace("%2C", ",")
201+
.replace("%3B", ";")
202+
.replace("%3D", "=");
203+
}
204+
141205
/**
142206
* Serialize a deepObject-style query parameter.
143207
*
@@ -241,8 +305,18 @@ public static Object serializeStyled(
241305
}
242306
yield ObjectSerializer.stringify(value);
243307
}
244-
case "spaceDelimited" -> String.join(" ", items);
245-
case "pipeDelimited" -> String.join("|", items);
308+
case "spaceDelimited" -> {
309+
if (explode && value instanceof Collection<?>) {
310+
yield new ArrayList<>(items);
311+
}
312+
yield String.join(" ", items);
313+
}
314+
case "pipeDelimited" -> {
315+
if (explode && value instanceof Collection<?>) {
316+
yield new ArrayList<>(items);
317+
}
318+
yield String.join("|", items);
319+
}
246320
default -> serialize(value, location, schemaType, collectionFormat);
247321
};
248322
}

0 commit comments

Comments
 (0)