Skip to content

Commit

Permalink
feat(specs): add secrets authentications to ingestion (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4054

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 30, 2024
1 parent f1a8685 commit f34eebc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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;

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

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

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<AuthInput> {

private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName());
Expand Down Expand Up @@ -77,6 +107,16 @@ public AuthInput deserialize(JsonParser jp, DeserializationContext ctxt) throws
LOGGER.finest("Failed to deserialize oneOf AuthAlgoliaInsights (error: " + e.getMessage() + ") (type: AuthAlgoliaInsights)");
}
}
// 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 AuthInput.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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public enum AuthenticationType {

ALGOLIA("algolia"),

ALGOLIA_INSIGHTS("algoliaInsights");
ALGOLIA_INSIGHTS("algoliaInsights"),

SECRETS("secrets");

private final String value;

Expand Down

0 comments on commit f34eebc

Please sign in to comment.