eed3si9n / scalaxb

scalaxb is an XML data binding tool for Scala.
http://scalaxb.org/
MIT License
332 stars 154 forks source link

[feature request] Better name generation for kebab case attributes #655

Closed phdoerfler closed 1 month ago

phdoerfler commented 1 month ago

Currently, XML attributes with hyphens, e.g., tester-pk:

<xs:attribute name="tester-pk" type="xs:string" use="required"/>

result in generated names containing "u45", e.g. testeru45pk:

lazy val testeru45pk = attributes("@tester-pk").as[String]

In comparison, JAXB, by default, understands this attribute name to be multiple words in kebab case and generates camel case identifiers:

@XmlAttribute(name = "tester-pk", required = true)
protected String testerPk;
…
public String getTesterPk() { return testerPk; }

I was unable to find a way to coerce scalaxb to behave like this.

I propose that:

Thoughts?

eed3si9n commented 1 month ago

There seems to be two related settings as precedence:

https://github.com/eed3si9n/scalaxb/blob/e242798464468e1eb38b78401ff49f79420a968e/sbt-scalaxb/src/main/scala/sbtscalaxb/ScalaxbKeys.scala#L51-L52

Rather than a general function, which might be difficult to configure via Maven or CLI, probably adding a specific setting to convert identifiers into camelCase kind of makes sense?

phdoerfler commented 1 month ago

Indeed, SymbolEncodingStrategy.Discard does the trick, thanks! As far as I'm concerned that's sufficient. I wouldn't mind an additional specific setting to convert to camelCase, too. But for now the existing settings seem adequate.

phdoerfler commented 1 month ago

Indeed, hat does the trick, thanks! As far as I am concerend, that solution is sufficient for now.