Skip to content

Conversation

@cnaples79
Copy link

@cnaples79 cnaples79 commented Sep 30, 2025

Summary

  • sanitize Kotlin identifier generation so schema fields like _ map to legal Kotlin members
  • propagate the sanitized names through Kotlin and Kotlin2 generators
  • add regression tests that compile underscore fields and check JsonProperty metadata

Rationale

  • fixes Kotlin compilation failures when GraphQL schemas expose members named _

Changes

  • add a shared Kotlin identifier sanitizer and update reserved keyword filtering to keep _
  • apply sanitized identifiers across Kotlin/Kotlin2 data, interface, constants, entity, and client generation
  • add regression tests for both generator paths covering underscore fields

Fixes #848

@cnaples79 cnaples79 force-pushed the fix-kotlin-underscore branch from 4be2a1a to f02de02 Compare September 30, 2025 05:31
Copy link
Contributor

@sjohnr sjohnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks @cnaples79! One minor comment below.

@cnaples79
Copy link
Author

cnaples79 commented Oct 14, 2025

Thanks for spotting that @sjohnr I wired the helper into sanitizeKotlinIdentifier so it now delegates to KotlinReservedKeywordSanitizer (while keeping the special-case for _).


object ReservedKeywordFilter {
val filterInvalidNames: (NamedNode<*>) -> Boolean = { it.name != "_" }
val filterInvalidNames: (NamedNode<*>) -> Boolean = { true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should just remove this completely now that it's basically a no-op.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiholee17 do you want to take a look at removing this filter after we merge this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I can take a look

@paulbakker
Copy link
Collaborator

@cnaples79 There are test failures, can you look into those?

@sjohnr
Copy link
Contributor

sjohnr commented Oct 24, 2025

@cnaples79 just checking in if you were able to look at the test failures? It looks as though fields are now generating with a _ prefix, so the latest changes might not be correct yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kotlin generator fails when '_' is used as a member

4 participants