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

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

Open
superstas opened this issue Aug 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@superstas
Copy link
Contributor

superstas commented Aug 26, 2024

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 danielgtaylor added the bug Something isn't working label Sep 13, 2024
@danielgtaylor
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants