Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option.RequestContentType including application/json on responses #247

Open
DimShadoWWW opened this issue Dec 2, 2024 · 6 comments
Open
Labels
enhancement New feature or request

Comments

@DimShadoWWW
Copy link

DimShadoWWW commented Dec 2, 2024

I would like the response type to be configurable.

schema:

        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Example"
                }
              },
              "application/xml": {
                "schema": {
                  "$ref": "#/components/schemas/Example"
                }
              }
            },
            "description": "OK"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPError"
                }
              }
            },
            "description": "Bad Request _(validation or deserialization error)_"
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPError"
                }
              }
            },
            "description": "Internal Server Error _(panics)_"
          },

It inserts "application/json" and it is before "application/xml", this caused it to be selected as default Content-type on documentation.

Also, all errors use "application/json" because there is no way to specify other content-type for them.
(fuego.WithGlobalResponseTypes do not change it)

@DimShadoWWW DimShadoWWW added the bug Something isn't working label Dec 2, 2024
@dylanhitt
Copy link
Collaborator

dylanhitt commented Dec 2, 2024

option.RequestContentType("application/xml; charset=UTF-8") isn't for Bodies it's' for Requests. The code above is only showing response bodies.

The response types are hardcoded currently

responseSchema := SchemaTagFromType(s, *new(T))
	content := openapi3.NewContentWithSchemaRef(&responseSchema.SchemaRef, []string{"application/json", "application/xml"})
	response := openapi3.NewResponse().WithDescription("OK").WithContent(content)
	route.Operation.AddResponse(200, response)

This issue wouldn't be a bug. More a feature request I believe.

@dylanhitt
Copy link
Collaborator

IIRC the reasoning for why we elected to not make response types configurable is that fuego is opinionated on what is returned. I believe there is a thread somewhere about this.

@dylanhitt
Copy link
Collaborator

Ah here it is #159

@DimShadoWWW
Copy link
Author

I am unable to change the tag to "Feature-request."

Currently, I am working on updating the OpenAPI structure, but I hope that "fuego" can eventually provide a way to specify it directly.

Thank you!

@dylanhitt dylanhitt added enhancement New feature or request and removed bug Something isn't working labels Dec 2, 2024
@dylanhitt
Copy link
Collaborator

Would you mind editing your issue to better reflecting the request.

Basically stating you want response type to be configurable. At the very least we should update errors to also have an xml response.

I assume the API you're working on here doesn't support json at all?

@DimShadoWWW
Copy link
Author

Sure, I updated the the first comment.

I am working on an API that defaults to responding with XML. However, it will optionally support responding in JSON if explicitly requested via the Accept header.

But now it selects JSON by default when trying in the documentation, because "application/json" es the first option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants