这是indexloc提供的服务,不要输入任何密码
Skip to content

Issue with Generics #74

@mtiller

Description

@mtiller

If I have a model that is generic, then there seems to be an issue resolving the schemas. For example, if my model is of type Container[Thing] and I create my route with:

registry.Get("registry", "Get the registry",
		responses.OK().Model(Container[Thing]{})).Run(func(ctx huma.Context) {

		// The `WriteModel` convenience method handles content negotiation and
		// serializaing the response for you.
		entity := Container[Thing]{}
		entity.Properties = Thing{Name: "Test1"}

		ctx.WriteModel(http.StatusOK, entity)
	})

Then my response yields a Link header of </schemas/Container[main.Thing].json>; rel="describedby". By itself, I don't think this is an issue. But if I try to access the schema that that URL, I get 404 Not Found. Presumably this has something to do with the escaping of the characters in the URL or the pattern matching in the router. Not really sure, but it doesn't find it.

My current solution is to just alias the type in Go, e.g.,

type ContainerThing Container[Thing]

This seems to resolve the issue. But I'm not sure I'll have 100% control over such things in nested types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions