Skip to content

[BUG][GO] Generated client does not treat all media types with the suffix +json as JSON or +xml as XML #16811

@joshraker

Description

@joshraker

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I'm creating a spec for an application/hal+json API but the resulting Go client raises an "undefined response type" error for every operation because it only treats responses with a Content-Type that conforms to application/vnd.*+json as JSON. Hence, application/hal+json is considered an "unknown" content type.

My understanding of RFC 6838, which the OpenAPI docs say is the source of truth for supported media types, is that any media type with a +suffix should conform to the suffix type. By that logic, I expect the client to treat any media type with the suffix +json as JSON and +xml as XML. I'm not using XML but it only supports application/xml so may as well update it while touching the JSON regular expression.

Assuming my understanding isn't flawed the fix is a fairly simple change to two regular expressions that I'll open a PR for but starting with an issue per the contribution guidelines. Happy to provide additional details upon request but given the simplicity of the issue they seem unnecessary.

openapi-generator version
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

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

Would be updated to

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions