Skip to content

Commit 2a104eb

Browse files
authored
Added Int32 and Int64 and Boolean Datatypes (#49)
1 parent 8bb13fe commit 2a104eb

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/K8sOperator.NET.Generators/Builders/CustomResourceDefinitionBuilderExtensions.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,55 @@ public static TBuilder OfType<TBuilder>(this TBuilder builder, string type)
219219
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
220220
/// <param name="builder">The builder instance.</param>
221221
/// <param name="type">The type of the schema property.</param>
222+
/// <param name="nullable"></param>
222223
/// <returns>The configured builder.</returns>
223224
/// <exception cref="InvalidOperationException">Thrown when the provided type is not valid.</exception>
224-
public static TBuilder OfType<TBuilder>(this TBuilder builder, Type type)
225+
public static TBuilder OfType<TBuilder>(this TBuilder builder, Type type, bool? nullable = false)
225226
where TBuilder : IKubernetesObjectBuilder<V1JSONSchemaProps>
226227
{
227228
if (type.FullName == "System.String")
228229
{
229230
builder.Add(x =>
230231
{
231232
x.Type = "string";
232-
x.Nullable = false;
233+
x.Nullable = nullable;
234+
});
235+
return builder;
236+
}
237+
238+
if (type.FullName == "System.Int32")
239+
{
240+
builder.Add(x =>
241+
{
242+
x.Type = "integer";
243+
x.Nullable = nullable;
244+
});
245+
return builder;
246+
}
247+
248+
if (type.FullName == "System.Int64")
249+
{
250+
builder.Add(x =>
251+
{
252+
x.Type = "integer";
253+
x.Nullable = nullable;
254+
});
255+
return builder;
256+
}
257+
258+
if (type.FullName == "System.Boolean")
259+
{
260+
builder.Add(x =>
261+
{
262+
x.Type = "boolean";
263+
x.Nullable = nullable;
233264
});
234265
return builder;
235266
}
236267

237268
if (type.Name == typeof(Nullable<>).Name && type.GenericTypeArguments.Length == 1)
238269
{
239-
return builder.OfType(type.GenericTypeArguments[0]);
270+
return builder.OfType(type.GenericTypeArguments[0], true);
240271
}
241272

242273
return type.BaseType?.FullName switch

0 commit comments

Comments
 (0)