Closed stil4m closed 7 years ago
The reason is that definitions, due to how they're defined and that they're global, can't have naming collisions. However it's fairly easy to create an enum that has the same name as a definition. On the top of my head at work we have a definition Article
and an enum type: ["Article", "..."]
(when I think about it this will actually always happen due to how discriminator
works). Thus while thinking about how to best solve this I've opted to just prefix enums.
I'm not sure how to best solve it though. One option is to keep an index of top level value names and add a _
suffix or something to colliding names; but that will lead to rather unintuitive naming. Another would be to generate multiple modules; but I'm not sure if there's a way that would completely solve this issue.
Suggestions are welcome.
A similar issue that needs solving is that nested objects can theoretically also cause naming collisions, although it's not very likely since they're named ParentChild
.
Check. Then you can ignore my PR for now. Personally I think that the need for nice names is higher than solving the name collisions. It it that likely that you have two types with different 'meaning' and the same name in your REST API?
I think a good solution would be to create multiple modules. Could this work with sane defaults or should this become configurable?
Well, like I mentioned above, if you use Swagger's "discriminator" you always get collisions, since the enum value and definition has to be the same. And I use it in pretty much all my projects. I admit that this project is currently useless in that case anyway, since polymorphism isn't implemented yet, but I still think ugly and compiling code is better than pretty and failing code.
I'm not sure what you mean with sane defaults. I'm thinking simply giving each definition its own module. For example: Definitions.Component, Definitions.Component.Type (an enum containing type Type = Article | ...
), Definitions.Article, Definitions.Article.NestedObject, etc. Sure it would create a small forest of modules, and I have no idea how to actually implement it atm, but it think collisions can be avoided without any suffix hacks.
At least it should mean that the whole "Flatten" mess can be removed 🎉.
Currently string enums from the swagger file are translated into the following
Swagger.json
Output:
Would it make more sense to create more 'Elm-conform' output such as:
I can create a PR, but I am not sure if there is a reason why this works as it currently does and thus it would be unwise to change this.