Skip to content

Bean Validation for array + item constraints is incomplete when mapping array to List #480

Description

@Razvanmatis

Hello,

when I generate code from the following OpenAPI schema, I get inconsistent Bean Validation annotations depending on the array mapping.

OpenAPI schema

ValidationRequest:
  type: object
  required:
    - openApiFile
  additionalProperties: false
  properties:
    openApiFile:
      type: object
      additionalProperties: true
      description: OpenAPI file content.
      required:
        - openapi
    environment:
      type: string
      enum: [ local, dev]
      default: "dev"
      description: Target environment for the validation.
    rules:
      type: array
      description: Optional list of specific rules to validate against. If not provided, the default ruleset will be used.
      maxItems: 1000
      items:
        type: string
        maxLength: 500
        pattern: "^[a-zA-Z0-9_-]+$"

mapping.yaml

openapi-processor-mapping: v18

options:
  package-name: service_api
  model-name-suffix: Model
  model-type: record
  bean-validation: true
  generated: true
  generated-date: true
  format-code: false
  javadoc: true
  json-property-annotation: auto
  package-name-from-path: true
  model-unreferenced: true

map:
  types:
    - type: array => java.util.List
    - type: string:uuid => java.util.UUID
    - type: ValidationRequestOpenApiFile => java.util.Map<java.lang.String, java.lang.Object>
    - type: ValidationRegexRequestOpenApiFile => java.util.Map<java.lang.String, java.lang.Object>

logging:
  mapping: true
  mapping-target: stdout

Actual result (with type: array => java.util.List)

import java.util.List;
import java.util.Map;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * @param openApiFile OpenAPI file content.
 * @param environment Target environment for the validation.
 * @param rules Optional list of specific Spectral rules to validate against. If not provided, the default ruleset will be used.
 */
@Generated(value = "openapi-processor-spring", version = "2026.3", date = "2026-06-30T13:01:10.636288300+02:00")
public record ValidationRequestModel(
    @Valid
    @NotNull
    Map<String, Object> openApiFile,

    ValidationRequestEnvironmentModel environment,

    List<@Size(max = 500) @Pattern(regexp = "^[a-zA-Z0-9_-]+$") String> rules
) {}

Issue: the container constraint @SiZe(max = 1000) (from maxItems) is missing.

Actual result (without type: array => java.util.List)

import java.util.Map;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * @param openApiFile OpenAPI file content.
 * @param environment Target environment for the validation.
 * @param rules Optional list of specific Spectral rules to validate against. If not provided, the default ruleset will be used.
 */
@Generated(value = "openapi-processor-spring", version = "2026.3", date = "2026-06-30T13:10:50.099920200+02:00")
public record ValidationRequestModel(
    @Valid
    @NotNull
    Map<String, Object> openApiFile,

    ValidationRequestEnvironmentModel environment,

    @Size(max = 1000)
    String[] rules
) {}

Issue: now the item-level string constraints are missing (@SiZe(max = 500) and @pattern(...)).

Expected result

import java.util.List;
import java.util.Map;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * @param openApiFile OpenAPI file content.
 * @param environment Target environment for the validation.
 * @param rules Optional list of specific Spectral rules to validate against. If not provided, the default ruleset will be used.
 */
@Generated(value = "openapi-processor-spring", version = "2026.3", date = "2026-06-30T13:11:52.615243800+02:00")
public record ValidationRequestModel(
    @Valid
    @NotNull
    Map<String, Object> openApiFile,

    ValidationRequestEnvironmentModel environment,

    @Size(max = 1000)
    List<@Size(max = 500) @Pattern(regexp = "^[a-zA-Z0-9_-]+$") String> rules
) {}

Question

Is this currently supported (possibly via configuration), or is this a bug/limitation in annotation generation for mapped arrays (List)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions