swagger-api / swagger-api/swagger-codegen

[jaxrs-cxf-cdi] validations not working for the nested referneces in generated code

Open
#10,494 1 comment 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

I am generating code using swagger-codegen dependency version 2.3.1. The swagger file is having nested reference as shown below:

Pet:
   title: Pet object
   properties:
      id: 
         type: string
         example: 01234567-0123-0123-0123-01234567892453
      info:
         $ref: '#/definitions/info'
info:
    title: Type object.
    properties:
      owner:
        type: string
        example: John
        maxLength: 40

Generated code snipper for Pet model:

  @ApiModelProperty(value = "")
  @JsonProperty("info")
  public InfoDTO getInfo() {
    return info;
  }
  public void setInfo(InfoDTO info) {
    this.info = info;
  }

Generated code snippet for info model:

  @ApiModelProperty(example = "owner", value = "")
  @JsonProperty("owner")
  @Size(max=40)  public String getOwner() {
    return owner;
  }

Even though the generated code is having the @Size annotation, when invoking the API, the request parameter is not getting validated.

Am I missing anything here? Appreciate any help to validate the conditions mentioned in the references.

Swagger-codegen version

2.3.1

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

Start by reproducing the request validation behavior with the generated Pet and InfoDTO models in the JAX-RS-CXF-CDI setup, focusing on the nested info.owner constraint. Trace the generated validation path and confirm whether a request whose owner exceeds the shown maxLength is rejected; done means nested-reference constraints are enforced during API invocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.