OpenAPITools / OpenAPITools/openapi-generator

Missing @Size annotation on request body attribute

Open
#22,379 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi all

I defined schema in yaml file following. it is standard primitive:

CardId:
  type: string
  minLength: 1
  maxLength: 64

and use its reference for path variable and as body field in yaml file

I dont want to use it directly but instead this I want to replace with our custom class CustomCardId, so I defined following schemaMapping, combination if importMapping with typeMapping doesnt wotk for me, probably due to logic that is primitive schema, so:

<schemaMappings>
   CardId=com.example.CustomCardId
</schemaMappings>

Generated stub for controller's method is great and I see annotation @Size(min=1, max=64) but when looking at model for my request body field there is missed this annotation.
Is possible to configure it to generate @Size annotation also on body field?

openapi-generator-maven-plugin version is 7.0.0, tested also newwest one 7.23.0, no change there
generatorName: spring
library: spring-boot

thanks
brmetalpalo

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied CardId schema, its schemaMappings entry, and the spring/spring-boot generator configuration. Compare the generated @Size annotation on the path variable with the request body model field, then reproduce the behavior on the reported generator versions; done means the body field also receives the minLength and maxLength constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.