question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[crd-gen] Support openAPIV3Schema fields: minimum, maximum, pattern, nullable

See original GitHub issue

Is your enhancement related to a problem? Please describe

(duplicate of #2959)

At the moment there is no way to auto generate a crd (with crd-gen tool) that contains properties with validation fields like minimum, maximum, pattern, nullable.

CRD example:

...

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.example.com
spec:
  group: example.com
  names:
    kind: Tenant
    plural: tenants
    singular: tenant
  scope: Namespaced
  versions:
  - name: v1
    schema:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              kafka:
                type: object
                properties:
                  port:
                    type: integer
                    minimum: 0
                    maximum: 65535
                    nullable: false
                  hostname:
                    type: string
                    pattern: '^([A-Za-z0-9-]{1,63}\.)+[[A-Za-z0-9-]{1,63}$'
                    nullable: false
                nullable: false
...

Describe the solution you’d like

I’d like to use javax annotation (like @min @max @pattern) on a java model fields.

private String protocol;

@Pattern(regexp = "\\^\\(\\[A-Za-z0-9-]\\{1,63}\\\\\\.\\)\\+\\[\\[A-Za-z0-9-]\\{1,63}\\$")
private String hostname;

@Min(0)
@Max(65535)
private Integer port;

Currently @NotNull annotation generate the filed “required” on crd, but for “nullable” validation maybe we need of a new specific annotation.

Describe alternatives you’ve considered

No response

Additional context

version: 5.12.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andreaTPcommented, Oct 26, 2022

Closed in #4348

1reaction
andreaTPcommented, Jun 27, 2022

I’m about to go on vacation, but if no one picks it up earlier I might eventually take a look at this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[java-gen] Support Min/Max/Pattern javax.validation.constraints ...
I have a CRD with openAPIV3Schema like this: .... kafka: type: object properties: port: type: integer minimum: 0 maximum: 65535 nullable: false hostname:...
Read more >
CRD Validation - The Kubebuilder Book
specifies the minimum numeric value that this field can have. Negative numbers are supported. // +kubebuilder:validation:Minimum.
Read more >
Future of CRDs: Structural Schemas - Kubernetes
Structural Schema · it has the core as defined above out of properties , items , additionalProperties , type , nullable , title...
Read more >
openapi - How to specify a property can be null or a reference ...
In various places in my spec a property may be a reference to such an object OR be null. How do I specify...
Read more >
Unsupported ESM URL Scheme error when importing bundleMDX ...
[crd-gen] Support openAPIV3Schema fields: minimum, maximum, pattern, nullable, 6, 2022-06-22, 2022-08-02. A version for notmuch, 5, 2022-03-31, 2022-08-10.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found