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

Specifying maxLength on an array #680

Open
dankristensen opened this issue Jan 27, 2025 · 3 comments
Open

Specifying maxLength on an array #680

dankristensen opened this issue Jan 27, 2025 · 3 comments

Comments

@dankristensen
Copy link

I have the following defined in a bean:

@Schema(description = "Detailed text to customer", required = true, maxItems = 30)
private String[] customerTextList;

How can i also specify that the maxLength of each customerTextList, can maximum be 15 characters long.

Adding maxLength = 15, does not work. Are there any other way to specify this?

@MikeEdgar
Copy link
Contributor

@dankristensen, something like this could work. It introduces a CustomerText stand-in class that is used only as the item schema.

@Schema(implementation = String.class, maxLength = 15)
class CustomerText {
}

@Schema(description = "Detailed text to customer", required = true, maxItems = 30, implementation = CustomerText[].class)
private String[] customerTextList;

@dankristensen
Copy link
Author

dankristensen commented Jan 28, 2025

@MikeEdgar, that does not work as intended. This results in a section like this in my openapi.yaml file:

    ResponseModel:
      required:
      - stringArray
      type: object
      properties:
        stringArray:
          maxItems: 30
          minItems: 1
          type: array
          items:
            type: array
            items:
              maxLength: 15
              type: string

What i want is this:

    ResponseModel:
      required:
      - stringArray
      type: object
      properties:
        stringArray:
          maxItems: 30
          minItems: 1
          type: array
          items:
            type: string
            maxLength: 15

Is this not possible to do with annotations?

@MikeEdgar
Copy link
Contributor

@dankristensen , try changing implementation = CustomerText[].class to implementation = CustomerText.class (remove the array square braces).

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

No branches or pull requests

2 participants