swagger-api / swagger-api/swagger-codegen

Wrong parameter and method names generated for single quoted properties containing @ sign

Open
#9,001 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

Codegen on swaggerhub generates Jersey and Resteasy code that doesn't compile when properties contain '@' sign.
Codegen generates improper Java fields. Eg. for '@baseType' swagger property definition there is @BaseType field name generated, and also getter/setter names are broken.

Swagger-codegen version

Not sure. The one from swagger.io.

Swagger declaration file content or url

I came across this issue while trying to implement TMF 655 Swagger API: https://raw.githubusercontent.com/tmforum-apis/TMF655_ChangeManagement/master/Change_Management.admin.swagger.json.

properties:
   '@baseType':
          type: string
          default: 'Attachment'
          description: The base type for use in polymorphic collections
Command line used for generation

Not applicable. I was using online codegen from swagger.io. I'll make tests on "standalone" version soon.

Steps to reproduce

Export -> Server stub -> jaxrs-jersey or jaxrs-resteasy

Related issues/PRs
Suggest a fix/enhancement

Codegen should "sanitize" such property names and exclude not allowed chars from field and getter/setter names. @JsonProperty annotation should be sufficient to reflect swagger contract for such properties.
I'll try to make a fix in codegen and post my solution soon.

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 issue with the linked TMF 655 Swagger declaration and the jaxrs-jersey or jaxrs-resteasy server-stub entry points. Trace how the '@baseType' property becomes a Java field and getter/setter names. Done means the generated Java compiles while @JsonProperty preserves the original property name.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.