dotnet-operator-sdk icon indicating copy to clipboard operation
dotnet-operator-sdk copied to clipboard

[bug]: Length attribute with maxLength not filled generates incorrect OpenApiSpec

Open melchor629 opened this issue 1 year ago • 0 comments

Describe the bug

When creating a CRD entity, the Length attribute has -1 as default value for minimum and maximum length. These values are then converted to null when read from the property. But when serializing the constraint into a Kubernetes resource, not filled values are rendered as -1.

See below a sample of [Length(minLength: 1)] public string Name { get; set; } = string.Empty; gets rendered: image

I suspect not filling minLength will render to something similarly wrong...

To reproduce

  1. Generate a new empty operator
  2. Create a new custom kubernetes entity having its spec something like public class EntitySpec { [Length(minLength: 1)] public string Name { get; set; } = string.Empty; }
  3. Compile the project
  4. Check the generated resource yaml

Expected behavior

The generated spec for the property should look like:

name:
  minLength: 1
  nullable: false
  type: string

Screenshots

No response

Additional Context

No response

melchor629 avatar Apr 03 '24 13:04 melchor629