Can I disable explicit API mode for generated sources?

I’m developing a library in Kotlin, and as it is best practise, I enabled explicit API mode in my gradle buildscript:

kotlin {
    explicitApi()
}

Now, for this library I also generate source code with the openapitools/kotlin-gradle generator (which is IMO flawed in a lot of ways anyway) and I put the generated files into build/generated/openapi/main/kotlin which I marked as a source set by doing:

sourceSets {
    main {
        kotlin.setSrcDirs(kotlin.srcDirs + "$projectDir/build/generated/openapi/main/kotlin")
    }
}

However, my project doesn’t compile because the generated sources don’t comply with explicit API mode (declarations aren’t explicitly marked public), which is fine for me. But I’d like to know if there’s any way to exclude generated sources from the explicit API checks, because it’s currently failing my build. As I see it currently, I have three options:

  1. Find some way to exclude my generated sources from the explicit API checks (which I don’t know if that’s possible, hopefully someone can answer me this)
  2. Disable explicit API mode entirely (which would be quite sad because I do believe it helps me a lot to keep my API clean)
  3. Switch to generating Java POJOs instead (which I really don’t want to do, because I quite enjoy the extra type safety that OpenAPI required → Kotlin non-nullable brings)

I’d suggest another option: put the generated code in a separate module. (However this does require some jar-file merging at the publishing end)

Could use explicitApiWarning() for warning mode.

Since you mention a third party tool that is generating the sources for you, this issue sounds like something that should be brought up with the maintainers. In principle, code generation can write anything to the generated files, so there should be no reason why they couldn’t add public etc. to their generated files.