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

Separate naming schemes for field names and enum members #407

Closed
untereiner opened this issue Feb 12, 2021 · 8 comments · Fixed by #409
Closed

Separate naming schemes for field names and enum members #407

untereiner opened this issue Feb 12, 2021 · 8 comments · Fixed by #409
Labels
enhancement New feature or request

Comments

@untereiner
Copy link

The function  constant_name doesn't handle values with spaces or dashes between words, example

<xs:enumeration value="tested below and above"/>
<xs:enumeration value="non-intrusive"/>
@tefra
Copy link
Owner

tefra commented Feb 12, 2021

What version of xsdata are you using @untereiner ?

  <xsd:simpleType name="RootEnum">
    <xsd:restriction>
      <xsd:enumeration value="tested below and above" />
      <xsd:enumeration value="non-intrusive" />
    </xsd:restriction>
  </xsd:simpleType>

generates with xsdata v21.2

class RootEnum(Enum):
    TESTED_BELOW_AND_ABOVE = "tested below and above"
    NON_INTRUSIVE = "non-intrusive"

@untereiner
Copy link
Author

with xsdata 21.2 in a venv:

  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:simpleType name="RootEnum">
    <xsd:restriction base="xs:string">
      <xsd:enumeration value="tested below and above" />
      <xsd:enumeration value="non-intrusive" />
    </xsd:restriction>
  </xsd:simpleType>
class RootEnum(Enum):
    TESTEDBELOWANDABOVE = "tested below and above"
    NONINTRUSIVE = "non-intrusive"

@tefra
Copy link
Owner

tefra commented Feb 12, 2021

Are you using a custom generator config?

@untereiner
Copy link
Author

untereiner commented Feb 12, 2021

I have a .xdata.xml. It can be something with the aliases I did not understand

  <Conventions>
    <ClassName case="pascalCase" safePrefix="type"/>
    <FieldName case="camelCase" safePrefix="value"/>
    <ModuleName case="snakeCase" safePrefix="mod"/>
    <PackageName case="snakeCase" safePrefix="pkg"/>
  </Conventions>
  <Aliases>
    <ClassName source="fooType" target="Foo"/>
    <ClassName source="ABCSomething" target="ABCSomething"/>
    <FieldName source="ChangeofGauge" target="changeOfGauge"/>
    <PackageName source="http://www.w3.org/1999/xhtml" target="xtml"/>
    <ModuleName source="2010.1" target="2020a"/>
  </Aliases>

@tefra
Copy link
Owner

tefra commented Feb 12, 2021

Yeah that camel case on field names is messing up the constant name, which simply turns to upper the output of the field name callback.

@untereiner
Copy link
Author

ok! is it possible to have the camelCase on the field name and an upper snake case for the enums field names ?

@tefra
Copy link
Owner

tefra commented Feb 12, 2021

yeah I am thinking we need a standalone convention config for constant names

@tefra tefra added the enhancement New feature or request label Feb 12, 2021
@tefra tefra changed the title constant_name Separate naming schemes for field names and enum members Feb 12, 2021
tefra added a commit that referenced this issue Feb 14, 2021
Closes #407

Notes:
Downgrade sphinx there is some issue with 3.5.0
tefra added a commit that referenced this issue Feb 14, 2021
Notes:
- Add screaming snake case scheme
- Downgrade sphinx there is some issue with 3.5.0
- Closes #407
tefra added a commit that referenced this issue Feb 14, 2021
Notes:
- Add screaming snake case scheme
- Downgrade sphinx there is some issue with 3.5.0
- Closes #407
@tefra
Copy link
Owner

tefra commented Feb 14, 2021

Thanks for reporting @untereiner

I added a separate convention config for constant names and a new naming scheme screamingSnakeCase

https://xsdata.readthedocs.io/en/latest/api/codegen.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants