OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

[REQ] Just can't make this work #10227

Open falk-stefan opened 3 years ago

falk-stefan commented 3 years ago

I am so sorry to open up an issue because of this but idk why I am simply not getting how I am supposed to use the generator.

Note: Just found https://github.com/OpenAPITools/openapi-generator/pull/9059, https://github.com/OpenAPITools/openapi-generator/issues/8591 (might be related)

What I intend to do is have different tasks in order to generate clients in different languages.

So for example, I'd like to specify one task for Angular and another for Java, something like this:

openApiGenerate {
    inputSpec swaggerFilePath
}

task buildTypeScriptAngular(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "typescript-angular"
    outputDir = "$apiClientOutputDir/angular"
    configOptions = [
            npmName   : "$name-rest-client",
            npmVersion: '0.0.0',
            ngVersion : '11.0.6'
    ]
}

task buildJava(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "java"
    outputDir = "$apiClientOutputDir/java"
}

However, I'm struggling with openApiGenrate from the start. If I am writing:

openApiGenerate {
    inputSpec swaggerFilePath
}

I'd get

A problem occurred evaluating root project 'server-client-template'.
> No signature of method: build_8cj7fyrw9t67hxobm8609uql7.openApiGenerate() is applicable for argument types: (build_8cj7fyrw9t67hxobm8609uql7$_run_closure7) values: [build_8cj7fyrw9t67hxobm8609uql7$_run_closure7@5c2cd655]

If I am using the assignment operator

openApiGenerate {
    inputSpec = swaggerFilePath
}

I'd get the following error

A problem was found with the configuration of task ':openApiGenerate' (type 'GenerateTask').
  - In plugin 'org.openapi.generator' type 'org.openapitools.generator.gradle.plugin.tasks.GenerateTask' property 'input' annotated with @Internal should not be also annotated with @Input.

I cannot find a simple example on how to do this properly. Can somebody please tell me how this works - it really gets frustrating.

wing328 commented 3 years ago

Would https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin/samples/local-spec help ?

falk-stefan commented 3 years ago

@wing328 Ah, yes. Thanks! I've figured it out myself by now but an example like this would have been useful :sweat_smile: .

I have another issue (stackoverflow). I need to set specific values in the generated configuration file (package.json). Any chance you can help me there too?

wing328 commented 3 years ago

One way is to use customized templates. Please refer to the readme for more info on that.

kamilmodest commented 7 months ago

@falk-stefan

I've figured it out myself by now

Can you please share what was the solution for you?

I have kind of a similar issue. I set the inputSpec.set("$rootDir/$specFile"), but the Gradle is still complaining that the value isn't set. Tries on both versions: 7.2.0 and 6.2.0