OpenAPITools / OpenAPITools/openapi-generator
[BUG] validation is not applied when $ref is used
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- What's the version of OpenAPI Generator used?
- What's the actual output vs expected output?
Description
when $ref is applied to model field, then validation properties is ignored
openapi-generator version
3.3.4
OpenAPI declaration file content or url
openapi: '3.0.0'
components:
schemas:
BaseUser:
type: object
properties:
description:
$ref: 'common-types.yaml#/components/schemas/ApplicableText'
maxLength: 255
common-types.yaml
ApplicableText:
type: string
pattern: '^(?:\p{Alnum}|[ +@!#$%&''*-/=?^_`.{|}~]){1,}$'
Command line used for generation
mvn clean install
Steps to reproduce
copy-n-paste this example and generate dto
Actual output vs expected output
Actual:
public class BaseUserDto {
@JsonProperty("description")
private String description;
/**
* Get description
* @return description
*/
@ApiModelProperty(value = "")
@Pattern(regexp="^(?:\\p{Alnum}|[ +@!#$%&'*-/=?^_`.{|}~]){1,}$")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
..
}
Expected:
javax.validation.constraints.Size(max=255) to be present over getDescription()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal OpenAPI YAML declaration and the generated Java BaseUserDto shown in the report, then inspect how Java generation handles validation properties on fields using $ref. Run the reported mvn clean install workflow and confirm that the generated getter includes javax.validation.constraints.Size(max=255) alongside the existing pattern validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100