openapi-generators / openapi-generators/openapi-python-client

Odd behaviour of snake_case functions

未关闭
#614 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

🐞bug
主要语言
Python
星标
2k
派生
293
平均合并
34 分钟
30 天内合并 PR
1

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先定位 Python 生成器中的 utils.snake_case 和 split_words 实现。复现 issue 中的示例,然后验证混合使用 snake_case 和 camelCase 的输入是否生成预期的单词,以及 MODEL4dd 情况是否仍为一个单词;如果存在相关的实用工具测试,则添加或运行这些测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
tooling
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。