Git Product home page Git Product logo

Comments (2)

steeling avatar steeling commented on May 28, 2024 1

I wonder if it's possible to catch the issue, and not render the schema link for specific objects that suffer from this issue? Or is there an alterantive mechanism to construct the schema links?

from huma.

danielgtaylor avatar danielgtaylor commented on May 28, 2024

@steeling here's a basic repro. This panics:

type Foo struct {
	Field string `json:"field"`
}

func (f Foo) Method() string {
	return "bar"
}

// GreetingOutput represents the greeting operation response.
type GreetingOutput struct {
	Body struct {
		Foo
		Message string `json:"message" example:"Hello, world!" doc:"Greeting message"`
	}
}

This works (note the pointer method receiver):

type Foo struct {
	Field string `json:"field"`
}

func (f *Foo) Method() string {
	return "bar"
}

// GreetingOutput represents the greeting operation response.
type GreetingOutput struct {
	Body struct {
		Foo
		Message string `json:"message" example:"Hello, world!" doc:"Greeting message"`
	}
}

Apparently this is a long-standing known issue in Go: golang/go#15924. It's unclear right now if it can be worked around since it's a problem with the underlying language support for reflection.

In the meantime, you can use pointer method receivers or disable the transformer:

config := huma.DefaultConfig("My API", "1.0.0")
config.CreateHooks = []func(Config) Config{}

// api := ... use config ...

from huma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.