openai / openai/openai-openapi

@Size annotation not being generated for a string field if not mentioned in required section of the yaml spec

Open
#478 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
No language data
Stars
2.5k
Forks
527
Avg merge
1h 46m
Merged PRs (30d)
2

Description

Hi I have recently migrated my spring boot app for JDK 11 -> 21 and spring 2.x.x -> 3.5.4.

I noticed that in my openspi yaml spec, all the fields mentioned in my -required section for a POJO are getting the right validations annotations when generating the target class, but the ones not mentioned in the same, dont get any. I checked the formatting and the labels for the validation.

field (type string) validation config looks something like this :
demoName:
type: string
example: 'AAA'
minLength: 3
maxLength: 3
description: >-
demo description

when I do put this field in the required label, it does what it is supposed to do.
Any work around for this? as this is not a mandatory field for my use case.

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

Use the supplied OpenAPI YAML fragment as the reproduction case, comparing generated output for demoName when it is optional versus listed under required. Trace the generator path that handles minLength and maxLength for string fields; done when the optional field receives the expected @Size annotation without becoming required, with a regression test covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, spring-boot
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.