swagger-api / swagger-api/swagger-codegen

[codegen][JAVA] Missing @pattern in generated code for field with format date-time

Open
#11,131 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

If you try to define field with type string and with format: date-time like below the generator does not create any @pattern annotation. (target is "somehow" limit possible values of field with format date-time)

Swagger-codegen version

2.2.2

Input for codegen (YAML)
startDate:
  type: string
  format: date-time
  pattern: '^(199\d{1}|20\d{2})'
Output from codegen

@JsonProperty("startDate")
@NotNull

private DateTime startDate = null;

Suggest a fix/enhancement

Codegen adds pattern (or another) annotation as ability to limit range of values in date-time format.

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

Reproduce the issue with the provided YAML input and inspect the Java code-generation path for string fields using the date-time format. Confirm the generated output currently omits the supplied pattern, then verify that the generated Java field includes an annotation or equivalent constraint preserving that pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.