OpenAPITools / OpenAPITools/openapi-generator
[REQ] generate validation rules for "embedded" patterns and preserve descriptions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I was experimenting with generating code for Maven + Spring but had limited success - the problems are related to patterns and validation to be generated/expected to be generated for them...
I've used latest stable version (4.3.1 as of today) and latest available (5.0.0-beta3) but no success... :(
Patterns are generated as expected for 'simple' schemas like this one: :
operatorId:
type: string
minLength: 1
maxLength: 30
pattern: '^[a-zA-Z0-9_]*$'
x-default: 1
description: String containing the operator ID
used as reference like this:
properties:
operatorId:
$ref: '#/components/schemas/operatorId'
generated code is like this one:
public OperatorVpnData operatorId(String operatorId) {
this.operatorId = operatorId;
return this;
}
/**
* String containing the operator ID
* @return operatorId
*/
@ApiModelProperty(required = true, value = "String containing the operator ID")
@NotNull
@Pattern(regexp="^[a-zA-Z0-9_]*$") @Size(min=1,max=30)
public String getOperatorId() {
return operatorId;
}
public void setOperatorId(String operatorId) {
this.operatorId = operatorId;
}
so, so far so good...
But for definitions like this one, no success at all:
forcePresentationNumbers:
type: array
items:
type: string
minLength: 1
maxLength: 31
pattern: '^[0-9]*$'
description: List of numbers for...
Something like this is expected:
@JsonProperty(" forcePresentationNumbers ")
@Valid private List<@Pattern(regexp="^[a-z]*$") @Size(min=1,max=30) String> forcePresentationNumbers = null;
Or whatever that results in enforcing given patterns on collection elements.
And descriptions are lost at the moment, too...
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 Maven + Spring generation and compare the working simple-schema example with the embedded array example in the issue. Check how validation annotations are produced for collection elements and how descriptions are carried into generated fields or accessors. Done means generated output enforces the item pattern and length constraints while retaining the description.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100