How to set type mappings for OpenAPI generator in build.gradle file?
Asked Answered
Y

1

7

I have the similar problem as this post, however whenever I try to add my type mappings to my openApiGenerate task I'm met with the following error:

build.gradle': 49: Unexpected input: '{' @ line 49, column 16.
     openApiGenerate{
                    ^

  1 error

My task config is structured thus:

openApiGenerate{
    generatorName = "jaxrs-jersey"
    inputSpec = "$project.swaggerFile"
    outputDir = "$project.buildSrcRoot"
    apiPackage = "$project.apiPackage"
    invokerPackage = "$project.rootPackage"
    modelPackage = "$project.modelPackage"
    generateModelTests = false

    globalProperties = [
            apis: "",
            models: "",
            modelDocs: "false",
    ]
    configOptions = [
            dateLibrary: "java8",
            hideGenerationTimestamp: "true",
            invokerPackage: "$project.rootPackage",
            useJakartaEe: "false",
    ]

    typeMappings.set([string+date-time: "LocalDateTime"])
    importMappings.set([LocalDateTime: "java.time.LocalDateTime"])
}

However removing the type mapping resolves the issue, but is useless as the import mapping requires a type mapping to be able to achieve the desired result.
I have also not found an example beyond my earlier link on how to add these config to the build.gradle file.
I am using version 6.6.0 of the generator.

Yellowhammer answered 19/7, 2023 at 11:25 Comment(2)
Have you tried to use typeMappings = [ like configOptions = [ not sure if set works with the Groovy Gradle synstax. I've used it within a build.gradle.kts typeMappings.set( mapOf( "integer+int16" to "kotlin.Short" ) )Semiconscious
Yes, it was the first format I tried.Yellowhammer
Y
5

It turns out that the typeMappings keys and values must be in single quotes:

typeMappings = ['string+date-time':'LocalDatTime']
Yellowhammer answered 31/8, 2023 at 12:57 Comment(1)
Thank, but need also import type with importMappings like this: [code] importMappings = [ Long: 'java.lang.Long' ] typeMappings = ['number+int64':'Long'] [/code]Stoller

© 2022 - 2024 — McMap. All rights reserved.