ogen icon indicating copy to clipboard operation
ogen copied to clipboard

Feature Request: Automatically Generate Accept Headers

Open Daniel-Vetter-Coverwhale opened this issue 2 years ago • 1 comments

Description

It would be really awesome if ogen would automatically generate an Accept header parameter and enum options for it based on the content-types in the response for a given operation. That way we can avoid specifying an Accept header ourselves (which I think openapi doesn't want us to do) and we can automatically deal with new content types as they are added to the spec without having to manually keep the enum in the header parameter in sync.

          "200": {
            "description": "200 OK",
            "content": {
              "application/vnd.sambasafety.json;version=2.0.4": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrJson2_04Response"
                }
              },
              "application/vnd.sambasafety.json;version=3.0.0": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrJson3_00Response"
                }
              },
              "application/vnd.sambasafety.xml;version=2.0.0": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrXml2_00Response"
                }
              },
              "application/vnd.sambasafety.xml;version=2.0.2": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrXml2_02Response"
                }
              },
              "application/vnd.sambasafety.xml;version=2.0.3": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrXml2_03Response"
                }
              },
              "application/vnd.sambasafety.html": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrHtmlResponse"
                }
              },
              "application/vnd.sambasafety.pdf": {
                "schema": {
                  "$ref": "#/components/schemas/IntelligentMvrPdfResponse"
                }
              }
            }
          },

References

https://swagger.io/docs/specification/describing-parameters/ image

The spec seems unambiguous about this, so this should be categorized as a bug. The parameter documentation also says:

If in is "header" and the name field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored.

We're currently having to add Accept headers for responses that can return different content types.

mxk avatar Jun 04 '24 13:06 mxk