Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Spring] generator not escaping backslashes #1691

Open
hebra opened this issue Dec 17, 2018 · 1 comment
Open

[BUG][Spring] generator not escaping backslashes #1691

hebra opened this issue Dec 17, 2018 · 1 comment

Comments

@hebra
Copy link

hebra commented Dec 17, 2018

Description

Trying to generate Java code from the Vimeo OpenAPI spec.
That spec (api.yaml) uses backslashes in some of the strings (e.g. tag definitions).
Using the openapi gradle plugin 3.3.4 the generator 'spring' with any of it libraries (spring-boot, spring-mvc, spring-cloud) generates code which does not escape backslashes properly.

openapi-generator version

3.3.4

OpenAPI declaration file content or url
{
	"generatorName": "spring",
	"library": "spring-boot",
	"groupId": "com.vimeo",
	"modelPackage": "com.vimeo.model",
	"apiPackage": "com.vimeo.api",
	"invokerPackage": "com.vimeo",
	"basePackage": "com.vimeo",
	"dateLibrary": "java8",
	"java8": true,
	"async": true,
	"responseWrapper": "ListenableFuture",
	"useBeanValidation": true
}
Command line used for generation

As this is a gradle project the command line is just

./gradlew clean openApiGenerate

but I'd assume the same code is generated when using the generator lib directly.

  • Language: Java 11
  • Gradle: 4.9
  • Libraries: Spring Boot 2.1 family
Steps to reproduce
  • create a new Spring Boot basic project (e.g. via http://start.spring.io/ in Java and Gradle flavour
  • add the Gradle OpenAPI plugin to build.gradle like this
buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath "org.openapitools:openapi-generator-gradle-plugin:3.3.4"
  }
}

apply plugin: 'org.openapi.generator'
  • add a new openapi configuration file config.json
  • download the api.yaml from above Vimeo GitHub repo
  • add a openapi statement to the build.gradle like this (the folders might differ)
openApiGenerate {
	validateSpec = true
    configFile = "$rootDir/vimeo/config.json".toString()
    inputSpec = "$rootDir/vimeo/openapi/api.yaml".toString()
    outputDir = "$buildDir/generated".toString()
}
  • run ./gradlew clean openApiGenerate
  • open one of the generated java files, e.g. LanguagesAPI
  • check the tags annotation
tags={ "Videos\Languages", })

---> the backslash is not escaoped, leading to compile errors

Suggest a fix
  • it looks like a bug with the generator templates, as it works proper for other generators (like feign for Java). Fixing the template should fix the issue.
@auto-labeler auto-labeler bot added the bug label Dec 17, 2018
@auto-labeler
Copy link

auto-labeler bot commented Dec 17, 2018

Thanks for opening this issue! I have applied any relevant labels.

@hebra hebra changed the title [BUG] Description spring generator not escaping backslashes [BUG] spring generator not escaping backslashes Dec 17, 2018
@hebra hebra changed the title [BUG] spring generator not escaping backslashes [BUG][Spring] generator not escaping backslashes Dec 17, 2018
@wing328 wing328 removed the bug label Dec 22, 2018
@hebra hebra mentioned this issue Jan 4, 2019
4 tasks
hebra added a commit to hebra/openapi-generator that referenced this issue Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants