Skip to content

Commit

Permalink
fix(specs): add secrets payload for updates (#4061) (generated) [skip…
Browse files Browse the repository at this point in the history
… ci]

Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Oct 31, 2024
1 parent 801241e commit 5a8605e
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public AuthInputPartial(AuthAlgoliaInsightsPartial actualInstance)
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}

/// <summary>
/// Initializes a new instance of the AuthInputPartial class
/// with a Dictionary{string, string}
/// </summary>
/// <param name="actualInstance">An instance of Dictionary&lt;string, string&gt;.</param>
public AuthInputPartial(Dictionary<string, string> actualInstance)
{
ActualInstance = actualInstance;
}


/// <summary>
/// Gets or Sets ActualInstance
Expand Down Expand Up @@ -146,6 +156,16 @@ public AuthAlgoliaInsightsPartial AsAuthAlgoliaInsightsPartial()
return (AuthAlgoliaInsightsPartial)ActualInstance;
}

/// <summary>
/// Get the actual instance of `Dictionary{string, string}`. If the actual instance is not `Dictionary{string, string}`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Dictionary&lt;string, string&gt;</returns>
public Dictionary<string, string> AsDictionaryString()
{
return (Dictionary<string, string>)ActualInstance;
}


/// <summary>
/// Check if the actual instance is of `AuthGoogleServiceAccountPartial` type.
Expand Down Expand Up @@ -201,6 +221,15 @@ public bool IsAuthAlgoliaInsightsPartial()
return ActualInstance.GetType() == typeof(AuthAlgoliaInsightsPartial);
}

/// <summary>
/// Check if the actual instance is of `Dictionary{string, string}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsDictionaryString()
{
return ActualInstance.GetType() == typeof(Dictionary<string, string>);
}

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand Down Expand Up @@ -357,6 +386,18 @@ public override AuthInputPartial Read(ref Utf8JsonReader reader, Type typeToConv
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into AuthAlgoliaInsightsPartial: {exception}");
}
}
if (root.ValueKind == JsonValueKind.Object)
{
try
{
return new AuthInputPartial(jsonDocument.Deserialize<Dictionary<string, string>>(JsonConfig.Options));
}
catch (Exception exception)
{
// deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into Dictionary<string, string>: {exception}");
}
}
throw new InvalidDataException($"The JSON string cannot be deserialized into any schema defined.");
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export type AuthInputPartial =
| AuthAPIKeyPartial
| AuthOAuthPartial
| AuthAlgoliaPartial
| AuthAlgoliaInsightsPartial;
| AuthAlgoliaInsightsPartial
| { [key: string]: string };
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlin.jvm.JvmInline
* - [AuthBasicPartial]
* - [AuthGoogleServiceAccountPartial]
* - [AuthOAuthPartial]
* - [Map<kotlin.String, String>] - *[AuthInputPartial.of]*
*/
@Serializable(AuthInputPartialSerializer::class)
public sealed interface AuthInputPartial {
Expand Down Expand Up @@ -47,6 +48,10 @@ public sealed interface AuthInputPartial {
@JvmInline
public value class AuthAlgoliaInsightsPartialValue(public val value: AuthAlgoliaInsightsPartial) : AuthInputPartial

@Serializable
@JvmInline
public value class MapOfkotlinStringStringValue(public val value: Map<kotlin.String, String>) : AuthInputPartial

public companion object {

public fun of(value: AuthGoogleServiceAccountPartial): AuthInputPartial {
Expand All @@ -67,6 +72,9 @@ public sealed interface AuthInputPartial {
public fun of(value: AuthAlgoliaInsightsPartial): AuthInputPartial {
return AuthAlgoliaInsightsPartialValue(value)
}
public fun of(value: Map<kotlin.String, String>): AuthInputPartial {
return MapOfkotlinStringStringValue(value)
}
}
}

Expand All @@ -79,6 +87,7 @@ internal class AuthInputPartialSerializer : JsonContentPolymorphicSerializer<Aut
element is JsonObject && element.containsKey("url") -> AuthOAuthPartial.serializer()
element is JsonObject -> AuthAlgoliaPartial.serializer()
element is JsonObject -> AuthAlgoliaInsightsPartial.serializer()
element is JsonObject -> AuthInputPartial.MapOfkotlinStringStringValue.serializer()
else -> throw AlgoliaClientException("Failed to deserialize json element: $element")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from __future__ import annotations

from json import dumps
from json import dumps, loads
from sys import version_info
from typing import Any, Dict, Optional, Set, Union

Expand Down Expand Up @@ -49,13 +49,16 @@ class AuthInputPartial(BaseModel):

oneof_schema_6_validator: Optional[AuthAlgoliaInsightsPartial] = Field(default=None)

oneof_schema_7_validator: Optional[Dict[str, str]] = Field(default=None)
""" A key:value authentication for your transformations. """
actual_instance: Union[
AuthAPIKeyPartial,
AuthAlgoliaInsightsPartial,
AuthAlgoliaPartial,
AuthBasicPartial,
AuthGoogleServiceAccountPartial,
AuthOAuthPartial,
Dict[str, str],
None,
] = None
one_of_schemas: Set[str] = {
Expand All @@ -65,6 +68,7 @@ class AuthInputPartial(BaseModel):
"AuthBasicPartial",
"AuthGoogleServiceAccountPartial",
"AuthOAuthPartial",
"Dict[str, str]",
}

def __init__(self, *args, **kwargs) -> None:
Expand All @@ -91,6 +95,7 @@ def unwrap_actual_instance(
AuthBasicPartial,
AuthGoogleServiceAccountPartial,
AuthOAuthPartial,
Dict[str, str],
Self,
None,
]:
Expand Down Expand Up @@ -145,12 +150,19 @@ def from_json(cls, json_str: str) -> Self:
try:
instance.actual_instance = AuthAlgoliaInsightsPartial.from_json(json_str)

return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
try:
instance.oneof_schema_7_validator = loads(json_str)
instance.actual_instance = instance.oneof_schema_7_validator

return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

raise ValueError(
"No match found when deserializing the JSON string into AuthInputPartial with oneOf schemas: AuthAPIKeyPartial, AuthAlgoliaInsightsPartial, AuthAlgoliaPartial, AuthBasicPartial, AuthGoogleServiceAccountPartial, AuthOAuthPartial. Details: "
"No match found when deserializing the JSON string into AuthInputPartial with oneOf schemas: AuthAPIKeyPartial, AuthAlgoliaInsightsPartial, AuthAlgoliaPartial, AuthBasicPartial, AuthGoogleServiceAccountPartial, AuthOAuthPartial, Dict[str, str]. Details: "
+ ", ".join(error_messages)
)

Expand All @@ -177,6 +189,7 @@ def to_dict(
AuthBasicPartial,
AuthGoogleServiceAccountPartial,
AuthOAuthPartial,
Dict[str, str],
]
]:
"""Returns the dict representation of the actual instance"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def openapi_one_of
:"AuthAlgoliaPartial",
:"AuthBasicPartial",
:"AuthGoogleServiceAccountPartial",
:"AuthOAuthPartial"
:"AuthOAuthPartial",
:"Hash<String, String>"
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ sealed trait AuthInputPartial

trait AuthInputPartialTrait extends AuthInputPartial

object AuthInputPartial {}
object AuthInputPartial {

case class MapOfStringString(value: Map[String, String]) extends AuthInputPartial

def apply(value: Map[String, String]): AuthInputPartial = {
AuthInputPartial.MapOfStringString(value)
}

}

object AuthInputPartialSerializer extends Serializer[AuthInputPartial] {
override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), AuthInputPartial] = {
Expand All @@ -41,6 +49,7 @@ object AuthInputPartialSerializer extends Serializer[AuthInputPartial] {
case value: JObject if value.obj.exists(_._1 == "url") => Extraction.extract[AuthOAuthPartial](value)
case value: JObject => Extraction.extract[AuthAlgoliaPartial](value)
case value: JObject => Extraction.extract[AuthAlgoliaInsightsPartial](value)
case value: JObject => AuthInputPartial.apply(Extraction.extract[Map[String, String]](value))
case _ => throw new MappingException("Can't convert " + json + " to AuthInputPartial")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum AuthInputPartial: Codable, JSONEncodable, AbstractEncodable {
case authOAuthPartial(AuthOAuthPartial)
case authAlgoliaPartial(AuthAlgoliaPartial)
case authAlgoliaInsightsPartial(AuthAlgoliaInsightsPartial)
case dictionaryOfStringToString([String: String])

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
Expand All @@ -29,6 +30,8 @@ public enum AuthInputPartial: Codable, JSONEncodable, AbstractEncodable {
try container.encode(value)
case let .authAlgoliaInsightsPartial(value):
try container.encode(value)
case let .dictionaryOfStringToString(value):
try container.encode(value)
}
}

Expand All @@ -46,6 +49,8 @@ public enum AuthInputPartial: Codable, JSONEncodable, AbstractEncodable {
self = .authAlgoliaPartial(value)
} else if let value = try? container.decode(AuthAlgoliaInsightsPartial.self) {
self = .authAlgoliaInsightsPartial(value)
} else if let value = try? container.decode([String: String].self) {
self = .dictionaryOfStringToString(value)
} else {
throw DecodingError.typeMismatch(
Self.Type.self,
Expand All @@ -68,6 +73,8 @@ public enum AuthInputPartial: Codable, JSONEncodable, AbstractEncodable {
value as AuthAlgoliaPartial
case let .authAlgoliaInsightsPartial(value):
value as AuthAlgoliaInsightsPartial
case let .dictionaryOfStringToString(value):
value as [String: String]
}
}
}
Expand Down
Loading

0 comments on commit 5a8605e

Please sign in to comment.