danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
2.07k stars 148 forks source link

[Question] Implementation of `ContentTypeFilter` doesn't affect OAS generation. #559

Open superstas opened 2 months ago

superstas commented 2 months ago

Hi there!

I've got the following types

var _ huma.ContentTypeFilter = &Response{}

type Input struct {
    Body struct {
        Name string `json:"name" doc:"The name."`
    }
}

type Response struct {
    Message string `json:"message" doc:"The message."`
}

type Output struct {
    Body Response
}

func (r *Response) ContentType(t string) string {
    return "application/ld+json"
}

What I'm trying to do is override the response Content-Type. Based on this document: https://pkg.go.dev/github.com/danielgtaylor/huma/v2#ContentTypeFilter I expect that implementation of ContentTypeFilter on Response ( in this case ) would change ContentType in the generated OAS as well.

At the moment, in the generated spec I get the following:

paths:
  /input:
    post:
      operationId: post-input
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/InputBody"
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Response"
          description: OK
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/ErrorModel"
          description: Error

Please help me to understand whether it's expected or not?

Thank you.

danielgtaylor commented 1 month ago

This looks like it could be a potential bug. I'll have to dig into it a bit further.