swagger-api / swagger-api/swagger-codegen
Generating Server Stubs for Spring results in the variables names to be changed from original snake_case to camelCase (which is wrong!)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I generate a server-api from a clean YAML file, and all parameters names gets changed from snake_case to camelCase in the @RequestParam(value="") annotations that is being generated.
Swagger-codegen version
2.2.2
Swagger declaration file content or url
swagger: '2.0'
info:
title: Bug Report
description: |
version: "1.0.0"
host: localhost:8080
schemes:
- http
- https
securityDefinitions:
userSecurity:
type: apiKey
in: header
name: session_id
# will be prefixed to all paths
basePath: /rest/v1
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
paths:
/search/messages:
get:
operationId: "SearchMessages"
summary: |
Search for messages
description: |
consumes:
- "*/*"
parameters:
- name: category_id
in: query
description: |
required: true
type: integer
format: int64
tags:
- bug
responses:
200:
description: |
An array of bug
schema:
type: array
items:
$ref: '#/definitions/BugPreview'
default:
description: |
Unexpected error
schema:
$ref: '#/definitions/ApiError'
security:
- userSecurity: []
definitions:
BugPreview:
type: object
description: |
Preview message object, used for list display.
required:
- id
properties:
id:
type: integer
format: int64
ApiError:
type: object
required:
- code
properties:
code:
type: integer
format: int32
description: |
Internal server error code
Command line used for generation
config.json
{
"projectName": "BugReport",
"classPrefix": "BugReport",
"swiftUseApiNamespace": false,
"sortParamsByRequiredFlag": true,
"ensureUniqueParams": true,
"modelPropertyNaming": "camelCase",
"hideGenerationTimestamp": true,
"groupId": "bug-report",
"artifactId": "bug-report",
"artifactVersion": "999.99-SNAPSHOT",
"interfaceOnly" : true,
"java8": true,
"useAndroidMavenGradlePlugin": false,
"dateLibrary": "java8"
}
java -jar swagger-codegen-cli-2.2.2.jar generate -i ./bug.yaml --config config.json -l spring -o ./server-api --api-package server.api --model-package server.model
Steps to reproduce
- Download the archive script.zip
- Use gen.sh
- Notice that the @RequestParam(value="") are in camelCase
Related issues
Not that I could find
Suggest a Fix
In io.swagger.codegen.languages.AbstractJavaCodegen#toParamName, should stop using io.swagger.codegen.languages.AbstractJavaCodegen#toVarName which mangles the names from whatever they were, and convert them to camelCase
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 in io.swagger.codegen.languages.AbstractJavaCodegen at toParamName and toVarName, then reproduce the Spring server generation with the supplied YAML, config.json, and command. Verify the generated @RequestParam(value="") preserves the original snake_case parameter name rather than changing it to camelCase.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100