swagger-api / swagger-api/swagger-codegen
JAVA - Fluent setters cause name-shadowing errors
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The Spring/Java codegen causes name shadowing problems because the setters are not named as setters. they are named like id(int id) instead of setId(int id).
Swagger-codegen version
2.4.12
Swagger declaration file content or url
swagger: '2.0'
info:
description: Evan's Test Data Server
version: 1.0.0
title: Evan's Test Data Server
put the contact info for your development or API team
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
tags are used for organizing operations
tags:
- name: admins
description: Secured Admin-only calls - name: developers
description: Operations available to regular developers
paths:
Collection of Accounts
/accounts/:
get:
tags:
- developers
summary: searches accounts
operationId: getAccountCollection
description: |
By passing in the appropriate options, you can search for
accounts in the system
produces:
- application/json
parameters:
- in: query
name: enableStatus
description: pass an optional search string for looking up inventory
required: false
type: string
- in: query
name: offsetRow
description: number of records to skip for pagination
required: false
type: integer
format: int32
minimum: 0
- in: query
name: maxRows
description: maximum number of records to return
required: false
type: integer
format: int32
minimum: 0
maximum: 50
responses:
200:
description: search results matching criteria
schema:
type: array
items:
$ref: '#/definitions/Account'
400:
description: bad input parameter
post:
tags:
- admins
summary: adds an inventory item
operationId: updateAccounts
description: Adds an item to the system
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: account
description: Inventory item to add
schema:
$ref: '#/definitions/Account'
responses:
201:
description: item created
400:
description: invalid input, object invalid
409:
description: an existing item already exists
Single Account
/accounts/{id}:
get:
tags:
- developers
summary: searches accounts
operationId: searchAccount
description: |
By passing in the appropriate options, you can search for
accounts in the system
produces:
- application/json
parameters:
- in: path
name: id
type: integer
required: true
description: If present, search for ONE account. If not present return all accounts matching query parameters
responses:
200:
description: search results matching criteria
schema:
type: array
items:
$ref: '#/definitions/Account'
400:
description: bad input parameter
put:
tags:
- admins
summary: updates an existing account
operationId: updateAccount
description: Updates (or creates) an existing Account
consumes:
- application/json
produces:
- application/json
parameters:
- in: path
name: id
type: integer
required: true
description: If present, search for ONE account. If not present return all accounts matching query parameters
- in: body
name: account
description: Inventory item to add
schema:
$ref: '#/definitions/Account'
responses:
201:
description: item created
400:
description: invalid input, object invalid
409:
description: an existing item already exists
definitions:
Account
Account:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
required:
- name
Wrapper for exchanged data
DataWrapper:
type: object
required:
- protocolVersion
- entityVersion
properties:
protocolVersion:
type: integer
format: int32
entityVersion:
type: integer
format: int64
requestUrl:
type: string
errorCode:
type: string
message:
type: string
offset:
type: integer
format: int32
affectedRows:
type: integer
format: int32
totalRows:
type: integer
format: int32
data:
type: array
items: {}
Wrapper for an update field list
UpdateWrapper:
type: object
properties:
updateList:
type: object
additionalProperties:
type: string
Added by API Auto Mocking Plugin
host: virtserver.swaggerhub.com
basePath: /evanross/DataServerSim/1.0.0
schemes:
- https
Command line used for generation
SwaggerHub
Steps to reproduce
Export Server Sub for Spring
Related issues/PRs
Suggest a fix/enhancement
Stop generating both fluent and non-fluent setters, just generate fluent. Or provide an option to do it the current way vs fluent-only way
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 Spring/Java codegen templates used by the SwaggerHub “Export Server Sub for Spring” command and reproduce the issue with the supplied Swagger 2.0 definition. Compare the generated Account setters and establish whether the completed behavior should remove fluent setters or make their generation configurable, with no name-shadowing errors remaining.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100