Open juanpablo-santos opened 2 years ago
I can confirm that upgrading swagger-parser-v3
resolved this issue
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-v3</artifactId>
<version>2.0.30</version>
</dependency>
And here is the commit which fixed it https://github.com/swagger-api/swagger-parser/commit/16e499ce3e89aa9d401231f5ddb823d587216953
Make it works by using an upgraded version of io.swagger.parser.v3:swagger-parser (2.1.22) as suggested by https://github.com/OpenAPITools/openapi-generator/issues/10053#issuecomment-1036376625
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:7.5.0"
classpath "io.swagger.parser.v3:swagger-parser:2.1.22"
}
}
apply plugin: "org.openapi.generator"
And casting the input path to an URI make it works on Windows with absolute path.
Without casting I have the same error as @juanpablo-santos on the ref resolution
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:7.5.0"
classpath "io.swagger.parser.v3:swagger-parser:2.1.22"
}
}
apply plugin: "org.openapi.generator"
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
void createOpenApiGenerateTask(File input, File target) {
String fileNameWithoutExtension = input.name.take(input.name.lastIndexOf('.'))
String taskName = "openApiGenerate_" + fileNameWithoutExtension;
println "Generating OpenAPI client for ${input} to ${target}"
tasks.register(taskName, GenerateTask) {
generatorName = "spring"
//If path is not cast into an URI here swagger failed to resolve ref
inputSpec = input.toURI().toString()
outputDir = target.toString()
modelNameSuffix = "Dto"
configOptions = [
useSpringBoot3 : "true",
dateLibrary : "java8",
useSpringController: "true",
interfaceOnly : "true",
]
}
compileJava.dependsOn(taskName)
}
def dir = file("src/main/resources/openApi/")
def target = file("build/generated")
if (dir.exists() && dir.isDirectory()) {
fileTree(dir).each { file ->
createOpenApiGenerateTask(file,target);
}
} else {
println "Directory does not exist or is not a directory: ${dir}"
}
sourceSets {
main {
java {
srcDirs += 'build/generated/src/main/java'
}
}
}
The following code should return a correct URI with the format file://C:/my_workspace but it looks like he need some help
Bug Report Checklist
Description
StringIndexOutOfBoundsException for relative $ref
appears with a validated openapi.yaml contract, which is conformed following the description at theOpenAPI declaration file content or url
section below. It seems that openapi-generator-maven-plugin 5.2.0 is hit by https://github.com/swagger-api/swagger-parser/issues/1511. Adding swagger-parser v. 2.0.27 and jackson-core 2.12.4 seems enough to fix the problem, but then the generation fails with a much more weirderStackOverflowError
:Turning on debug to see what spec has been understood by openapi, the aforementioned
StackOverflowError
seems to be caused because all models inheriting from any other model are parsed like this:Not sure where or why all
allOf
$refs
are changed to self instead of its proper parent, hence causing this error.. Note that this only happens on Windows boxes, the same contract generates the associated files OK if it is launched on an Ubuntu box.openapi-generator version
5.2.0 (but only on Windows environments), suspect it might happen with 5.0.0 onwards.
OpenAPI declaration file content or url
openapi.yaml
and with
./model/beneficiarios/BeneficiarioContract.yaml
been something likeand
./common/Base.yaml
being something likeGeneration Details
Don't know how many languages are affected by this behaviour, I stumbled with this using JavaSpring, with no fancy configuration options..
Steps to reproduce
see
Description
sectionRelated issues/PRs
Not sure if #8495 is involved.
Suggest a fix
N/A