OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][Spring]`allowUnicodeIdentifiers` to false does not sanitize parameter names

Open
#1,695 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Spring
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When allowUnicodeIdentifiers is set to true, the parameters name are not sanitize in the spring generated source code.

openapi-generator version

The openapi-generator version is the current master.

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  description: Sanitize for tags
  version: 1.0.0
  title: Sanitize for tags
paths:
  '/sanitize-tags':
    get:
      summary: Check the class when generated with useTags option
      tags:
      - créances
      parameters:
        - name: créance
          in: path
          required: true
          schema:
            type: string
      responses:      
        200:
          $ref: '#/components/responses/201'
components:
  responses:
    200:
      description: Get
Command line used for generation

Command line:

java -jar ~/git/github/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g spring -i tag.openapi.yaml -c java-config.json -o ./tags

And the configuration file

{
    "library": "spring-boot", 
    "groupId": "a.group.id", 
    "artifactId": "an-artifact-id",
    "artifactVersion": "0.1.0-SNAPSHOT", 
    "sourceFolder": "src/main/java", 
    "configPackage": "my.api.config", 
    "modelPackage": "my.api.model", 
    "apiPackage": "my.api.resource",
    "dateLibrary": "java8",
    "useBeanValidation": true, 
    "interfaceOnly": true, 
    "implicitHeaders": true, 
    "swaggerDocketConfig": true, 
    "useTags": true, 
    "allowUnicodeIdentifiers": false
}
Steps to reproduce

I tried allowUnicodeIdentifiers this weekend. I set it to true with the following openapi file.
It works as expected for interface. The parameter name use é character in the name.

default ResponseEntity<Void> sanitizeTagsGet(@ApiParam(value = "",required=true) @PathVariable("créance") String créance) {

When I set allowUnicodeIdentifiers to false, the result is the same. As I understand the parameter name should be sanitize.

default ResponseEntity<Void> sanitizeTagsGet(@ApiParam(value = "",required=true) @PathVariable("créance") String créance) {

For french language, it will be great to have the following result :

default ResponseEntity<Void> sanitizeTagsGet(@ApiParam(value = "",required=true) @PathVariable("créance") String creance) {

Related issues/PRs

Don't find any

Suggest a fix

I'm not sure if the problem comes from sanitize methods or in mustache templates.

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

Use the supplied OpenAPI YAML and Spring generation command as the reproduction case. Inspect the Spring generator's parameter-name sanitization path and the Mustache templates, then compare output with allowUnicodeIdentifiers set to true and false. Done means the false setting produces the sanitized parameter identifier creance while preserving the original path-variable mapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.