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

reserved scala words within properties leads to compile errors #105

Open
arron-green opened this issue Jul 15, 2021 · 4 comments
Open

reserved scala words within properties leads to compile errors #105

arron-green opened this issue Jul 15, 2021 · 4 comments

Comments

@arron-green
Copy link

i was testing out this plugin and had a case where a field was defined as type which lead to a compile time error.

I'm open to some potential workarounds or a possible fix by wrapping fieldNames with backticks

    Example:
      description: example
      properties:
        type:
          type: string

which could generate as the following

case class(`type`: String)
@eikek
Copy link
Owner

eikek commented Jul 16, 2021

Yeah, this is not taken care of. I think we could have the list of reserved words and render backticks around them. I'm currently avoiding these field names :)

@arron-green
Copy link
Author

unfortunately i didn't have a choice with some of these names

i think i have a possible workaround with the following

    openapiScalaConfig := ScalaConfig().
      withJson(ScalaJson.circeSemiautoExtra)
      .addMapping(CustomMapping.forField({
        case Field(prop, annot, typeDef) =>
          Field(prop.copy(name = prop.name.mkString("`", "", "`")), annot, typeDef)
      }))

@arron-green
Copy link
Author

If this seems like a viable workaround i'm happy to create a PR with adding this snippet to the docs to possibly help anyone else who runs into this issue

@eikek
Copy link
Owner

eikek commented Jul 16, 2021

Ah sure, that's a good workaround, thank you! If you find time to add it to the readme somewhere, that'd be great of course!

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

No branches or pull requests

2 participants