Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Add Color Palette Management Classes and Update Serialization Features #12

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#nullable enable

namespace Ideogram
{
/// <summary>
/// A member of a color palette.
/// </summary>
public sealed partial class ColorPaletteMember
{
/// <summary>
/// The hexadecimal representation of the color with an optional chosen weight<br/>
/// Example: #FFFFFF
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("color_hex")]
[global::System.Text.Json.Serialization.JsonRequired]
public required string ColorHex { get; set; }

/// <summary>
/// The weight of the color in the color palette.<br/>
/// Example: 0.25
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("color_weight")]
[global::System.Text.Json.Serialization.JsonRequired]
public required double ColorWeight { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::System.Text.Json.Serialization.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

#nullable enable

namespace Ideogram
{
/// <summary>
/// A color palette preset value<br/>
/// Example: PASTEL
/// </summary>
public enum ColorPalettePresetName
{
/// <summary>
///
/// </summary>
EMBER,
/// <summary>
///
/// </summary>
FRESH,
/// <summary>
///
/// </summary>
JUNGLE,
/// <summary>
///
/// </summary>
MAGIC,
/// <summary>
///
/// </summary>
MELON,
/// <summary>
///
/// </summary>
MOSAIC,
/// <summary>
///
/// </summary>
PASTEL,
/// <summary>
///
/// </summary>
ULTRAMARINE,
}

/// <summary>
/// Enum extensions to do fast conversions without the reflection.
/// </summary>
public static class ColorPalettePresetNameExtensions
{
/// <summary>
/// Converts an enum to a string.
/// </summary>
public static string ToValueString(this ColorPalettePresetName value)
{
return value switch
{
ColorPalettePresetName.EMBER => "EMBER",
ColorPalettePresetName.FRESH => "FRESH",
ColorPalettePresetName.JUNGLE => "JUNGLE",
ColorPalettePresetName.MAGIC => "MAGIC",
ColorPalettePresetName.MELON => "MELON",
ColorPalettePresetName.MOSAIC => "MOSAIC",
ColorPalettePresetName.PASTEL => "PASTEL",
ColorPalettePresetName.ULTRAMARINE => "ULTRAMARINE",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
};
}
/// <summary>
/// Converts an string to a enum.
/// </summary>
public static ColorPalettePresetName? ToEnum(string value)
{
return value switch
{
"EMBER" => ColorPalettePresetName.EMBER,
"FRESH" => ColorPalettePresetName.FRESH,
"JUNGLE" => ColorPalettePresetName.JUNGLE,
"MAGIC" => ColorPalettePresetName.MAGIC,
"MELON" => ColorPalettePresetName.MELON,
"MOSAIC" => ColorPalettePresetName.MOSAIC,
"PASTEL" => ColorPalettePresetName.PASTEL,
"ULTRAMARINE" => ColorPalettePresetName.ULTRAMARINE,
_ => null,
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#nullable enable

namespace Ideogram
{
/// <summary>
/// A color palette represented only via its members
/// </summary>
public sealed partial class ColorPaletteWithMembers
{
/// <summary>
/// A list of ColorPaletteMembers that define the color palette.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("members")]
[global::System.Text.Json.Serialization.JsonRequired]
public required global::System.Collections.Generic.IList<global::Ideogram.ColorPaletteMember> Members { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::System.Text.Json.Serialization.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#nullable enable

namespace Ideogram
{
/// <summary>
///
/// </summary>
public sealed partial class ColorPaletteWithPresetName
{
/// <summary>
/// A color palette preset value<br/>
/// Example: PASTEL
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("name")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::Ideogram.JsonConverters.ColorPalettePresetNameJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required global::Ideogram.ColorPalettePresetName Name { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::System.Text.Json.Serialization.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.Linq;
#pragma warning disable CS0618 // Type or member is obsolete

#nullable enable

namespace Ideogram
{
/// <summary>
/// A color palette for generation, must EITHER be specified via one of the presets (name) or explicitly via hexadecimal representations of the color with optional weights (members).
/// </summary>
public readonly partial struct ColorPaletteWithPresetNameOrMembers : global::System.IEquatable<ColorPaletteWithPresetNameOrMembers>
{
/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
public global::Ideogram.ColorPaletteWithPresetName? { get; init; }
#else
public global::Ideogram.ColorPaletteWithPresetName? { get; }

Check failure on line 19 in src/libs/Ideogram/Generated/Ideogram.Models.ColorPaletteWithPresetNameOrMembers.g.cs

View workflow job for this annotation

GitHub Actions / Test / Build, test and publish

Invalid token '{' in class, record, struct, or interface member declaration

Check failure on line 19 in src/libs/Ideogram/Generated/Ideogram.Models.ColorPaletteWithPresetNameOrMembers.g.cs

View workflow job for this annotation

GitHub Actions / Test / Build, test and publish

Invalid token ';' in class, record, struct, or interface member declaration
#endif
Comment on lines +17 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix missing property names in property declarations.

Several property declarations are missing their names, which leads to syntax errors and compilation failures. For example, at lines 17-20:

-#if NET6_0_OR_GREATER
-public global::Ideogram.ColorPaletteWithPresetName?  { get; init; }
+#if NET6_0_OR_GREATER
+public global::Ideogram.ColorPaletteWithPresetName? ColorPaletteWithPresetName { get; init; }

Ensure that all properties have valid identifiers:

  • At lines 17-20, add ColorPaletteWithPresetName.
  • At lines 52-55, add ColorPaletteWithMembers.
  • In the constructor at lines 88-93, use the appropriate property names for assignments.

Also applies to: 52-55, 88-93

Tools
GitHub Check: Test / Build, test and publish

[failure] 19-19:
Invalid token '{' in class, record, struct, or interface member declaration


[failure] 19-19:
Invalid token ';' in class, record, struct, or interface member declaration


/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof())]
#endif
public bool Is => != null;

Check failure on line 28 in src/libs/Ideogram/Generated/Ideogram.Models.ColorPaletteWithPresetNameOrMembers.g.cs

View workflow job for this annotation

GitHub Actions / Test / Build, test and publish

Invalid expression term '!='
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct invalid expressions in property accessors.

The Is properties are missing references to the appropriate properties, resulting in invalid expressions. For example, at line 28:

-public bool Is =>  != null;
+public bool IsColorPaletteWithPresetName => ColorPaletteWithPresetName != null;

Similarly, at line 63:

-public bool Is =>  != null;
+public bool IsColorPaletteWithMembers => ColorPaletteWithMembers != null;

Update these properties to correctly reference the corresponding properties.

Also applies to: 63-63

Tools
GitHub Check: Test / Build, test and publish

[failure] 28-28:
Invalid expression term '!='


/// <summary>
///
/// </summary>
public static implicit operator ColorPaletteWithPresetNameOrMembers(global::Ideogram.ColorPaletteWithPresetName value) => new ColorPaletteWithPresetNameOrMembers(value);

/// <summary>
///
/// </summary>
public static implicit operator global::Ideogram.ColorPaletteWithPresetName?(ColorPaletteWithPresetNameOrMembers @this) => @this.;

/// <summary>
///
/// </summary>
public ColorPaletteWithPresetNameOrMembers(global::Ideogram.ColorPaletteWithPresetName? value)
{
= value;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix assignments in constructors and methods where identifiers are missing.

Assignments within constructors are missing the target property names, causing syntax errors. For example, at line 45:

-= value;
+ColorPaletteWithPresetName = value;

Make similar corrections at lines 68, 81, and within the constructor at lines 91-93 to ensure all assignments reference existing properties.

Also applies to: 68-68, 81-81, 91-93

}

/// <summary>
/// A color palette represented only via its members
/// </summary>
#if NET6_0_OR_GREATER
public global::Ideogram.ColorPaletteWithMembers? { get; init; }
#else
public global::Ideogram.ColorPaletteWithMembers? { get; }
#endif

/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof())]
#endif
public bool Is => != null;

/// <summary>
///
/// </summary>
public static implicit operator ColorPaletteWithPresetNameOrMembers(global::Ideogram.ColorPaletteWithMembers value) => new ColorPaletteWithPresetNameOrMembers(value);

/// <summary>
///
/// </summary>
public static implicit operator global::Ideogram.ColorPaletteWithMembers?(ColorPaletteWithPresetNameOrMembers @this) => @this.;

/// <summary>
///
/// </summary>
public ColorPaletteWithPresetNameOrMembers(global::Ideogram.ColorPaletteWithMembers? value)
{
= value;
}

/// <summary>
///
/// </summary>
public ColorPaletteWithPresetNameOrMembers(
global::Ideogram.ColorPaletteWithPresetName? ,
global::Ideogram.ColorPaletteWithMembers?
)
{
= ;
= ;
}

/// <summary>
///
/// </summary>
public object? Object =>
as object ??
as object
;

/// <summary>
///
/// </summary>
public bool Validate()
{
return Is && !Is || !Is && Is;
}

/// <summary>
///
/// </summary>
public override int GetHashCode()
{
var fields = new object?[]
{
,
typeof(global::Ideogram.ColorPaletteWithPresetName),
,
typeof(global::Ideogram.ColorPaletteWithMembers),
};
const int offset = unchecked((int)2166136261);
const int prime = 16777619;
static int HashCodeAggregator(int hashCode, object? value) => value == null
? (hashCode ^ 0) * prime
: (hashCode ^ value.GetHashCode()) * prime;
return fields.Aggregate(offset, HashCodeAggregator);
}

/// <summary>
///
/// </summary>
public bool Equals(ColorPaletteWithPresetNameOrMembers other)
{
return
global::System.Collections.Generic.EqualityComparer<global::Ideogram.ColorPaletteWithPresetName?>.Default.Equals(, other.) &&
global::System.Collections.Generic.EqualityComparer<global::Ideogram.ColorPaletteWithMembers?>.Default.Equals(, other.)
;
}

/// <summary>
///
/// </summary>
public static bool operator ==(ColorPaletteWithPresetNameOrMembers obj1, ColorPaletteWithPresetNameOrMembers obj2)
{
return global::System.Collections.Generic.EqualityComparer<ColorPaletteWithPresetNameOrMembers>.Default.Equals(obj1, obj2);
}

/// <summary>
///
/// </summary>
public static bool operator !=(ColorPaletteWithPresetNameOrMembers obj1, ColorPaletteWithPresetNameOrMembers obj2)
{
return !(obj1 == obj2);
}

/// <summary>
///
/// </summary>
public override bool Equals(object? obj)
{
return obj is ColorPaletteWithPresetNameOrMembers o && Equals(o);
}
}
}
7 changes: 7 additions & 0 deletions src/libs/Ideogram/Generated/Ideogram.Models.ImageRequest.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public sealed partial class ImageRequest
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::Ideogram.JsonConverters.ResolutionJsonConverter))]
public global::Ideogram.Resolution? Resolution { get; set; }

/// <summary>
/// A color palette for generation, must EITHER be specified via one of the presets (name) or explicitly via hexadecimal representations of the color with optional weights (members).
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("color_palette")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::Ideogram.JsonConverters.ColorPaletteWithPresetNameOrMembersJsonConverter))]
public global::Ideogram.ColorPaletteWithPresetNameOrMembers? ColorPalette { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
Expand Down
Loading