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][KOTLIN][SPRING] Add option to skip generation of default implementations #5987

Closed
5 of 6 tasks
kleinph opened this issue Apr 20, 2020 · 7 comments
Closed
5 of 6 tasks

Comments

@kleinph
Copy link

kleinph commented Apr 20, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

There should be an option the deactivate the generation of code which makes use of supporting files.

openapi-generator version

Version 4.3.0

OpenAPI declaration file content or url

api.yml:

openapi: 3.0.0
info:
  title: Example API
  description: Example REST API
  version: 1.0.0
servers:
  - url: http://localhost:8080
    description: Local development server
paths:
  /foo:
    get:
      summary: Get foo
      operationId: getFoo
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: string

build.gradle:

openApiGenerate {
    generatorName = "kotlin-spring"

    inputSpec = "$rootDir/src/main/resources/api.yaml".toString()
    outputDir = $buildDir/generated-sources".toString()

    configOptions = [
            dateLibrary: "java8",
            delegatePattern: "true",
    ]
    systemProperties = [
            apis: "",
            models: "",
            supportingFiles: "false"
    ]
}
Command line used for generation

The gradle plugin was used (id 'org.openapi.generator' version '4.3.0').

Steps to reproduce

Use the api.yml and the gradle config to generate the API. There will be default implementations in the *Delegate interfaces which use ApiUtil.kt.

Related issues/PRs

Issue #5476

Suggest a fix

Provide an option to disable code generation for the delegate classes. Like the Java Spring generator has with skipDefaultInterface.

Note that interfaceOnly is no solution because it will prevent generation of the REST controller classes.

Also note that supportingFiles: "ApiUtil,kt" fixes the missing class reference, but requires to deactivate stricter null checks (prevenst use of -Xjsr305=strict compiler args). See #5476.

My workaround so far is to provide my own (null-safe) implementation of ApiUtil.

@kleinph kleinph changed the title [BUG][KOTLIN][SPRING] Add option to skip generation of example code [BUG][KOTLIN][SPRING] Add option to skip generation of default implementations Apr 20, 2020
@craigberry1
Copy link

Does serviceInterface config options solve this?

@kleinph
Copy link
Author

kleinph commented Nov 22, 2020

@cberry-chwy I am not sure, I am not working anymore on this project.

@mwatel42
Copy link

mwatel42 commented Jul 5, 2021

Hello,

I agree that the behavior of having a default controller interface implementation is not really practical. I would expect the existing code to stop compiling when we add new API methods.

Looking at https://github.com/borsch/openapi-generator/blob/d6bbd51b5078dde410e811f9964bc72259dfe96d/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache and https://github.com/borsch/openapi-generator/blob/d6bbd51b5078dde410e811f9964bc72259dfe96d/modules/openapi-generator/src/main/resources/kotlin-spring/returnValue.mustache, I suggest to only add a body to the method in case there is a service interface.

WDYT?

@vladimirkoba
Copy link

Totally agree, I want to get compilation error, where I add new methods in API

@pstorch
Copy link
Contributor

pstorch commented Jul 2, 2024

Looks like the skipDefaultInterface option is implemented in the meantime: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/kotlin-spring.md

@takkiraz
Copy link
Contributor

@wing328 Can be closed, as the skipDefaultInterface is implemented in the meantime.

@wing328
Copy link
Member

wing328 commented Jan 21, 2025

another way to skip certain files from being generated is to use .openapi-generator-ignore: https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#ignore-file-format

to pre-populate this file pre-code generation, please use the option openapiGeneratorIgnoreList (e.g. --openapi-generator-ignore-list in CLI)

@wing328 wing328 closed this as completed Jan 21, 2025
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

7 participants