huma icon indicating copy to clipboard operation
huma copied to clipboard

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

Open superstas opened this issue 1 year ago • 1 comments

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.

superstas avatar Aug 26 '24 11:08 superstas

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

danielgtaylor avatar Sep 13 '24 01:09 danielgtaylor