swagger-api / swagger-api/swagger-codegen-generators
Validation Contraints of $ref (JSON Reference) components are not generated jaxrs-spec
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating from an openapi 3.0.0 yaml the Validation-Contraints for Java Beans are not generated correctly if $ref ((JSON Reference) is used.
Swagger-codegen version
3.0.0
generatorName: jaxrs-spec
Swagger declaration file content or url
openapi: 3.0.1
paths:
/accountReferenceIban:
get:
responses:
'200':
$ref: "#/components/schemas/accountReferenceIban"
components:
schemas:
accountReferenceIban:
type: object
required:
- iban
properties:
iban:
$ref: "#/components/schemas/iban"
currency:
$ref: "#/components/schemas/currencyCode"
currencyCode:
type: string
pattern: "[A-Z]{3}"
iban:
type: string
pattern: "[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}"
Command line used for generation
java -jar swagger-codegen-cli-3.0.0.jar generate -i test.yaml -l jaxrs-spec --api-package=api --model-package=model
Steps to reproduce
Execute command line above. Beside 2 java empty JavaBeans (Iban and CurrrencyCode) the AccountReferenceIban Bean looks like this:
public class AccountReferenceIban implements Serializable {
private @Valid String iban = null; private @Valid String currency = null;
/**
**/
public AccountReferenceIban iban(String iban) {
this.iban = iban;
return this;
}
@ApiModelProperty(required = true, value = "")
@JsonProperty("iban")
@NotNull
public String getIban() {
return iban;
}
public void setIban(String iban) {
this.iban = iban;
}
/**
**/
public AccountReferenceIban currency(String currency) {
this.currency = currency;
return this;
}
@ApiModelProperty(value = "")
@JsonProperty("currency")
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
Expected Result
iban should have: @Pattern(regexp="[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}")
currencyCode should have: @Pattern(regexp="[A-Z]{3}")
if input.yaml looks like the following the output is correct:
openapi: 3.0.1
paths:
/accountReferenceIban:
get:
responses:
'200':
$ref: "#/components/schemas/accountReferenceIban"
components:
schemas:
accountReferenceIban:
type: object
required:
- iban
properties:
iban:
type: string
pattern: "[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}"
currency:
type: string
pattern: "[A-Z]{3}"
java bean output:
public class AccountReferenceIban implements Serializable {
private @Valid String iban = null; private @Valid String currency = null;
/**
**/
public AccountReferenceIban iban(String iban) {
this.iban = iban;
return this;
}
@ApiModelProperty(required = true, value = "")
@JsonProperty("iban")
@NotNull
@Pattern(regexp="[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}") public String getIban() {
return iban;
}
public void setIban(String iban) {
this.iban = iban;
}
/**
**/
public AccountReferenceIban currency(String currency) {
this.currency = currency;
return this;
}
@ApiModelProperty(value = "")
@JsonProperty("currency")
@Pattern(regexp="[A-Z]{3}") public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
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
Reproduce the issue with the supplied test.yaml and the swagger-codegen-cli command using the jaxrs-spec generator. Compare generated AccountReferenceIban output for referenced schemas with the inline-schema output, and verify that the expected @Pattern annotations are present for iban and currency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, yaml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100