Skip to content

Commit

Permalink
fix(specs): add secrets payload for updates (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4061

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Oct 31, 2024
1 parent 5771148 commit 9397d8c
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,44 @@
import com.algolia.exceptions.AlgoliaRuntimeException;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.*;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Logger;

/** AuthInputPartial */
@JsonDeserialize(using = AuthInputPartial.Deserializer.class)
public interface AuthInputPartial {
// AuthInputPartial as Map<String, String> wrapper.
static AuthInputPartial of(Map<String, String> value) {
return new MapOfStringStringWrapper(value);
}

// AuthInputPartial as Map<String, String> wrapper.
@JsonSerialize(using = MapOfStringStringWrapper.Serializer.class)
class MapOfStringStringWrapper implements AuthInputPartial {

private final Map<String, String> value;

MapOfStringStringWrapper(Map<String, String> value) {
this.value = value;
}

public Map<String, String> getValue() {
return value;
}

static class Serializer extends JsonSerializer<MapOfStringStringWrapper> {

@Override
public void serialize(MapOfStringStringWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeObject(value.getValue());
}
}
}

class Deserializer extends JsonDeserializer<AuthInputPartial> {

private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName());
Expand Down Expand Up @@ -81,6 +111,16 @@ public AuthInputPartial deserialize(JsonParser jp, DeserializationContext ctxt)
);
}
}
// deserialize Map<String, String>
if (tree.isObject()) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
Map<String, String> value = parser.readValueAs(new TypeReference<Map<String, String>>() {});
return new AuthInputPartial.MapOfStringStringWrapper(value);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf Map<String, String> (error: " + e.getMessage() + ") (type: Map<String, String>)");
}
}
throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree));
}

Expand Down

0 comments on commit 9397d8c

Please sign in to comment.