OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Elm] Outputs duplicate types, as well as overlapping types with same name

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

还没有人认领这个 Issue。

Issue: Bug
主要语言
Java
星标
26.8k
派生
7.7k
PR 合并指标
PR 指标待抓取

描述

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Using the full Stripe API spec.

  • Have you validated the input using an OpenAPI validator (example)?
  • I used the CLI with validate and it found no issues.

  • Have you tested with the latest master to confirm the issue still exists?
  • Yes

  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description
openapi-generator version

Latest master

OpenAPI declaration file content or url

https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json

Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate    -i https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json    -g elm    -o ./elm-stripeFix

All in the same file, there will be this Status:

type Status
    = StatusActive
    | StatusBlocked
    | StatusInactive


statusVariants : List Status
statusVariants =
    [ StatusActive
    , StatusBlocked
    , StatusInactive
    ]


stringFromStatus : Status -> String
stringFromStatus model =
    case model of
        StatusActive ->
            "active"

        StatusBlocked ->
            "blocked"

        StatusInactive ->
            "inactive"

...right along with this Status somewhere else:

type Status
    = StatusExpired
    | StatusLost
    | StatusSubmitted
    | StatusUnsubmitted
    | StatusWon


statusVariants : List Status
statusVariants =
    [ StatusExpired
    , StatusLost
    , StatusSubmitted
    , StatusUnsubmitted
    , StatusWon
    ]


stringFromStatus : Status -> String
stringFromStatus model =
    case model of
        StatusExpired ->
            "expired"

        StatusLost ->
            "lost"

        StatusSubmitted ->
            "submitted"

        StatusUnsubmitted ->
            "unsubmitted"

        StatusWon ->
            "won"


Obviously this causes a conflict, and fixing it is not trivial as all references to Status are now ambiguous.

Suggest a fix

Ideally, have types belonging to different domains go in separate type modules.

At the least, add a number or underscore to the end of one of them if need be.

Naive fix would be to merge the enums and just treat them as one.

Also, this includes totally identical types and encoder/decoders. They can have everything exactly the same, and still be repeated 5 different places in the file.

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用报告中所示的 Stripe OpenAPI 规范和 Elm 生成命令重现该问题,然后检查生成的 Elm 输出中是否存在重复和冲突的类型。当生成的类型及其编码器、解码器和引用不再发生冲突,且相同的定义不再重复时,即视为完成。

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

评估

技术栈
elm, openapi
领域
api, tooling
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

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