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

BUG: JSR 303 annotations not generated for array types when minLength and/or maxLength are present #1669

Open
sigpwned opened this issue Mar 5, 2025 · 0 comments · May be fixed by #1670
Open

Comments

@sigpwned
Copy link

sigpwned commented Mar 5, 2025

I am using the following JSON Schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "BinaryImageAttributes",
  "type": "object",
  "properties": {
    "bytes": {
      "type": "string",
      "media": {
        "binaryEncoding": "base64"
      },
      "description": "Base64-encoded binary image data.",
      "minLength": 1,
      "maxLength": 102400
    }
  },
  "required": ["bytes"]
}

This is generating the following Java Bean:

package io.humangraphics.backend.lambda.image.analyze.api.model.request;

import java.util.Arrays;
import javax.annotation.processing.Generated;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import jakarta.validation.constraints.NotNull;


/**
 * BinaryImageAttributes
 * <p>
 * 
 * 
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
    "bytes"
})
@Generated("jsonschema2pojo")
public class BinaryImageAttributes {

    /**
     * Base64-encoded binary image data.
     * (Required)
     * 
     */
    @JsonProperty("bytes")
    @JsonPropertyDescription("Base64-encoded binary image data.")
    @NotNull
    private byte[] bytes;

    /**
     * Base64-encoded binary image data.
     * (Required)
     * 
     */
    @JsonProperty("bytes")
    public byte[] getBytes() {
        return bytes;
    }

    /**
     * Base64-encoded binary image data.
     * (Required)
     * 
     */
    @JsonProperty("bytes")
    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

    public BinaryImageAttributes withBytes(byte[] bytes) {
        this.bytes = bytes;
        return this;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(BinaryImageAttributes.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
        sb.append("bytes");
        sb.append('=');
        sb.append(((this.bytes == null)?"<null>":Arrays.toString(this.bytes).replace('[', '{').replace(']', '}').replace(", ", ",")));
        sb.append(',');
        if (sb.charAt((sb.length()- 1)) == ',') {
            sb.setCharAt((sb.length()- 1), ']');
        } else {
            sb.append(']');
        }
        return sb.toString();
    }

    @Override
    public int hashCode() {
        int result = 1;
        result = ((result* 31)+ Arrays.hashCode(this.bytes));
        return result;
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }
        if ((other instanceof BinaryImageAttributes) == false) {
            return false;
        }
        BinaryImageAttributes rhs = ((BinaryImageAttributes) other);
        return Arrays.equals(this.bytes, rhs.bytes);
    }

}

I expect the private byte[] bytes field to have the following annotations:

    /**
     * Base64-encoded binary image data.
     * (Required)
     * 
     */
    @JsonProperty("bytes")
    @JsonPropertyDescription("Base64-encoded binary image data.")
    @NotNull
    @Size(minLength=1, maxLength=102400)
    private byte[] bytes;

It is currently missing the @Size annotation.

@sigpwned sigpwned changed the title BUG: Validation annotations minLength and maxLength not generated for array types BUG: JSR 303 annotations not generated for array types when minLength and/or maxLength are present Mar 5, 2025
sigpwned added a commit to sigpwned/jsonschema2pojo that referenced this issue Mar 5, 2025
…pes when minLength and/or maxLength are present
@sigpwned sigpwned linked a pull request Mar 6, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant