OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.82k stars 6.58k forks source link

[REQ] Support RFC7807 problem response type #4890

Open sagikazarmark opened 4 years ago

sagikazarmark commented 4 years ago

Is your feature request related to a problem? Please describe.

RFC7807 is an error response specification. It comes with its own Content-Types:

Unfortunately the Content-Type checks does not match these.

I use the generator for generating Go code, the affected lines are https://github.com/OpenAPITools/openapi-generator/blob/af783a8/modules/openapi-generator/src/main/resources/go/client.mustache#L33-L36

But I think other languages might also benefit from this feature.

Describe the solution you'd like

In the specific case, I'd change the regular expressions to the following:

var (
    jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:(?:vnd\.[^;]+\+)|(?:problem\+))?json)`)
    xmlCheck  = regexp.MustCompile(`(?i:(?:application|text)/(?:problem\+)?xml)`)
)

I can imagine a better optimized regex, but this one is probably more readable.

Describe alternatives you've considered

Currently I run a post-processor script on the generated code, but it would be nice if it supported the RFC OOTB.

Additional context

I'm happy to provide a PR to change the above linked code.

sagikazarmark commented 4 years ago

Would you accept a PR for the suggested change?