Skip to content

[BUG][Java][Spring] Sanitize tag name when use the option useTags is set to true #1696

@jabby

Description

@jabby
Description

The Api name is sanitize for the class name and for the value of @Api swagger tag. I think it should only be sanitized for the class name.

openapi-generator version
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

Config 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

Hello I started to test openapi-generator this weekend. I want to use useTags option in order to generate different classes for my API. I have some tags with unicode character like é in french language.

When I generate my spring-boot application, I discovered that the generated interface has the following name CrancesApi.
Here is a partial of the generated file.

@Validated
@Api(value = "Crances", description = "the Crances API")
public interface CrancesApi {

It will be great if the generated interface name will be CreanceApi and the value of @Api remains Créances.
If I set allowUnicodeIdentifiers to true, both are generated with Créances word.

Related issues/PRs

Maybe #1695 if the problem comes from sanitize methods

Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions