Haskell-OpenAPI-Code-Generator / Haskell-OpenAPI-Client-Code-Generator

Generate Haskell client code from an OpenAPI 3 specification
46 stars 19 forks source link

Generate with NonEmpty if minItems: 1 #101

Closed pbrisbin closed 5 months ago

pbrisbin commented 5 months ago

When I generate a spec from a Haskell server using NonEmpty, it adds minItems: 1:

          "levels": {
            "items": {
              "$ref": "#/components/schemas/ElaArticleLevel"
            },
            "minItems": 1,
            "type": "array"
          },

Ideally the generator should generate a NonEmpty ElaArticleLevel instead of [ElaArticleLevel] when it sees this. Currently, I have a bunch of NE.fromList conversions, with comments that's it's actually safe because the spec says minItems: 1 -- but that's only true right now, and could change going forward.

Hard to say what something like minItems: 2 (for example) should do. I'd be inclined to just say NonEmpty for any minItems: x | x > 0 as a good 80/20 vs getting fancier.

pbrisbin commented 5 months ago

I'm bumping in a few of these sorts of conversions, such as using Natural when minimum: 0 or UUID when format: uuid. But I will wait for your thoughts on this one before proceeding to make more Issues.

NorfairKing commented 5 months ago

I like this idea!

joel-bach commented 5 months ago

I like this idea as well! I am not sure if I get to do an implementation of this in the near future myself, so if you want to give it a try, feel free to open a PR 🙏

pbrisbin commented 5 months ago

Great, I've got a draft PR for NonEmpty here: https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/pull/102

Happy to poke at the other stuff I mentioned after that lands.

joel-bach commented 5 months ago

Hey @pbrisbin, with #102 being merged, do we want to close this issue?

pbrisbin commented 5 months ago

Yeah, I think we should close this one. Up to you though: do you want me to open separate Issues for (e.g.) Natural or UUID?

joel-bach commented 5 months ago

I think we could also just discuss these in a respective PR, wdyt? But I am also fine with leaving this one open to keep track on them.

pbrisbin commented 5 months ago

I think we could also just discuss these in a respective PR, wdyt?

Yeah, that works. Only downside is there's nothing tracking things if I don't get to those PRs for a while (which is likely), but that's minor so sounds good.