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

Odd behaviour of snake_case functions #614

Open
hhoeflin opened this issue May 13, 2022 · 0 comments
Open

Odd behaviour of snake_case functions #614

hhoeflin opened this issue May 13, 2022 · 0 comments
Labels
🐞bug Something isn't working

Comments

@hhoeflin
Copy link

hhoeflin commented May 13, 2022

Describe the bug
The names of apis are odd, having '_' in irregular and unpredictable places

To Reproduce
The following behavior can be observed using the snake_case function from utils:

utils.snake_case("get_v2_abc")
'get_v2_abc'
utils.snake_case("get_v2_abc_deFgHij")
'get_v_2_abc_de_fg_hij'

These would for example be created for paths: /v2/abc and /v2/abc/deFgHij

The results however inserts an additional underscore between v and 2, so v_2 instead of v2.

Expected behavior
results should be:
get_v2_abc_de_fg_hij

Desktop (please complete the following information):

  • OS: CentOS7
  • Python Version: 3.8
  • openapi-python-client version: github-master from today

Suggestion:
snake_case uses split_words function , which only splits on Aa, so a capital letter followed by a lowercase one, not on underscore. split_words should first split on underscore, then split on capital followed by lowercase. This would solve the issue of mixed snake and camelcase names.

Some additional odd outcomes:

>>> utils.snake_case("MODEL4dd")
'model4_dd'
>>> utils.snake_case("MODEl4dd")
'mod_el_4_dd'

These of course violate camelCase, but in my estimate should all be treated as one word, i.e. multiple consecutive capital letters are treated as a single block. So above model4dd would be the outcome in both cases.

@hhoeflin hhoeflin added the 🐞bug Something isn't working label May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant