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.35k stars 6.46k forks source link

[REQ] Java, support a "no client" option #17336

Open caleb-cushing0-kr opened 9 months ago

caleb-cushing0-kr commented 9 months ago

Is your feature request related to a problem? Please describe.

I don't like the way client code is generated. I want to implement my own and let openapi-generator take care of simply generating the DTO classes. E.g. I want to just generate classes with Jackson annotations

Describe the solution you'd like

support a library none and generate code using the serializationLibrary only.

jpfinne commented 9 months ago

You can achieve this with Configuration.generateApis=false Configuration.generateSupportingFiles=false And configOptions.library=resttemplate

caleb-cushing0-kr commented 9 months ago

for some reason I get okhttp and gson errors

/Users/ccushing/IdeaProjects/cg-customer-platform-clients/groups-client/build/generated/sources/openapi/src/main/java/com/myorg/cg/clients/groups/MetadataDetail.java:38: error: package com.google.gson.stream does not exist
import com.google.gson.stream.JsonReader;

  symbol:   class JsonElement
  location: class MemberDetail
/Users/ccushing/IdeaProjects/cg-customer-platform-clients/groups-client/build/generated/sources/openapi/src/main/java/com/myorg/cg/clients/ApiClient.java:17: error: package okhttp3.internal.http does not exist
import okhttp3.internal.http.HttpMethod;
openApiGenerate {
    generatorName = "java"
    library = "resttemplate"
    inputSpec = "$projectDir/src/main/resources/openapi.json".toString()
    outputDir = layout.buildDirectory.dir("generated/sources/openapi").get().toString()
    configOptions.putAll([
        openApiNullable        : "false",
        generateApis           : "false",
        generateSupportingFiles: "false",
        serializationLibrary   : "jackson",
    ])
    ignoreFileOverride = "$projectDir/.openapi-generator-ignore"
jpfinne commented 9 months ago

generateSupportingFiles is a configuration property, not a configOptions.

this works for me using the maven plugin

 <plugin>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator-maven-plugin</artifactId>
      <version>6.6.0</version>
      <executions>
          <execution>
              <id>generate-api-spring</id>
              <goals>
                  <goal>generate</goal>
              </goals>
              <phase>generate-sources</phase>
              <configuration>
                  <inputSpec>${openapi.file}</inputSpec>
                  <generatorName>java</generatorName>
                  <modelPackage>be.jpfinne.model</modelPackage>
                  <generateSupportingFiles>true</generateSupportingFiles>
                  <modelNameSuffix/>
                  <generateApis>false</generateApis>
                  <generateModelDocumentation>false</generateModelDocumentation>
                  <generateModelTests>false</generateModelTests>
                  <generateSupportingFiles>false</generateSupportingFiles>

                  <configOptions>
                      <library>resttemplate</library>
                      <useJakartaEe>true</useJakartaEe>
                      <dateLibrary>java8</dateLibrary>
                  </configOptions>
              </configuration>
          </execution>
      </executions>
      <dependencies/>
  </plugin>
caleb-cushing0-kr commented 9 months ago
> Could not set unknown property 'generateSupportingFiles' for extension 'openApiGenerate' of type org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorGenerateExtension.

not documented https://openapi-generator.tech/docs/generators/java/

jpfinne commented 9 months ago

I see it in the maven plugin: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.md

StefanLobbenmeierObjego commented 8 months ago

Maybe this works:

    supportingFilesConstrainedTo = emptyList()

But the result seems to be the same in my project

StefanLobbenmeierObjego commented 8 months ago

This seems to fulfil your requirements:

        modelFilesConstrainedTo = listOf("")
        apiFilesConstrainedTo = listOf("")

but for my case I just wanted all sources and none of the build files, so I need to include some supporting files as well:

      supportingFilesConstrainedTo =
            listOf(
                    // base package
                    "ApiClient",
                    "JavaTimeFormatter",
                    "RFC3339DateFormat",
                    "ServerConfiguration",
                    "ServerVariable",
                    "StringUtil",

                    // auth
                    "ApiKeyAuth",
                    "Authentication",
                    "HttpBasicAuth",
                    "HttpBearerAuth",
                )
                .map { "$it.java" }
        modelFilesConstrainedTo = listOf("")
        apiFilesConstrainedTo = listOf("")