fabric8io / kubernetes-client

Java client for Kubernetes & OpenShift
http://fabric8.io
Apache License 2.0
3.41k stars 1.46k forks source link

v2 crd generator for date-time includes the JsonFormat pattern string where a regex is expected #5997

Closed matteriben closed 5 months ago

matteriben commented 5 months ago

Describe the bug

According to the openapi spec "pattern (This string SHOULD be a valid regular expression, according to the Ecma-262 Edition 5.1 regular expression dialect)"

JsonFormat pattern is described as:

    /**
     * Datatype-specific additional piece of configuration that may be used
     * to further refine formatting aspects. This may, for example, determine
     * low-level format String used for {@link java.util.Date} serialization;
     * however, exact use is determined by specific <code>JsonSerializer</code>
     */

The following was generated by the v2 crd generator for the source snippet below. Note the pattern from JsonFormat is used in the generated CRD, however the JsonFormat pattern is not appropriate in the context of openapi schema which expects a regular expression that matches the string.

              startTime:
                description: "The start time."
                format: "date-time"
                pattern: "yyyy-MM-dd'T'HH:mm:ssVV"
                type: "string"
    /**
     * The start time.
     */
    @com.fasterxml.jackson.annotation.JsonProperty("startTime")
    @com.fasterxml.jackson.annotation.JsonPropertyDescription("The start time.")
    @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
    private java.time.ZonedDateTime startTime;

    @com.fasterxml.jackson.annotation.JsonFormat(shape = com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssVV")
    public java.time.ZonedDateTime getStartTime() {
        return startTime;
    }

    @com.fasterxml.jackson.annotation.JsonFormat(shape = com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[XXX][VV]")
    public void setStartTime(java.time.ZonedDateTime startTime) {
        this.startTime = startTime;
    }

Fabric8 Kubernetes Client version

SNAPSHOT

Steps to reproduce

I'm not sure an easy way to run the v2 crd generator currently, I ran it via a test case in the check-crd-generator branch of quarkus-operator-sdk.

Expected behavior

I was not expecting to see the pattern field, but if it is present, it should be a regex that matches that date-time string.

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3@latest

Environment

Linux

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

shawkins commented 5 months ago

That's on me - I looked for places were the pattern could come from and didn't make the association that it could be a java string format pattern instead of a regex.