guardrail-dev / guardrail

Principled code generation from OpenAPI specifications
https://guardrail.dev
MIT License
522 stars 132 forks source link

Produces/Consumes media type does not support parameters (rfc6838) #796

Open kmudrick opened 3 years ago

kmudrick commented 3 years ago

In a spec, specifying produces and consumes with media type parameters generates broken code (does not compile).

Example:

consumes:
  - application/json;foo=bar

produces:
  - application/json;baz=bat

I am guessing that the ApplicationJson check could maybe be changed to use exists with a predicate that matches against the start of the string? I can open a PR if need be to illustrate/fix.

kelnos commented 3 years ago

I don't think we considered that people might put parameters in their media types, which I guess is valid according to the spec.

The right way to fix this would be to augment ContentType to match against whatever is before the ;. We should also store the parameters so we can make use of them in the generators, but as a first step I'm fine with just fixing the matching to not account for parameters at all.