Netflix / dgs-codegen

Apache License 2.0
183 stars 99 forks source link

Do not add redundant "public" word while kotlin code generation from schema #370

Open stingion opened 2 years ago

stingion commented 2 years ago

Subj. Example:

import com.fasterxml.jackson.`annotation`.JsonProperty

/**
 * Payload type for contactRequestAdd
 */
public data class ContactRequestAddPayload(
  /**
   * Request status (i.e. successful or not)
   */
  @JsonProperty("status")
  public val status: ContactRequestAddStatus
) {
  public companion object
}

Recommend:

import com.fasterxml.jackson.`annotation`.JsonProperty

data class ContactRequestAddPayload(
  /**
   * Request status (i.e. successful or not)
   */
  @JsonProperty("status")
  val status: ContactRequestAddStatus
) 
kilink commented 2 years ago

The public modifiers are added by KotlinPoet, and are not configurable. They are added for good reason though, for compatibility with people using Explict API mode; see the docs here:

Note: In order to maximize portability, KotlinPoet generates code with explicit visibility modifiers. This ensures compatibility with both standard Kotlin projects as well as projects using explicit API mode.

Is there an actual issue with having the explicit public modifiers?

stingion commented 2 years ago

No serious issue, but "public" is default in Kotlin. So Idea IDE, Sonar, etc. highlighting it as unnecessary. It is proposed to make the presence of this work at least configurable while DGS Kotlin code generation.