-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Primitive-based types are not reused in the generated OAS. #560
Comments
I also tried to reuse this schema via registry, but no luck router := chi.NewMux()
cfg := huma.DefaultConfig("My API", "1.0.0")
api := humachi.New(router, cfg)
customHeaderSchema := cfg.Components.Schemas.Schema(reflect.TypeOf(CustomHeader("")), true, "")
huma.Register(api, huma.Operation{
OperationID: "UserCreate",
Method: http.MethodPost,
Path: "/users",
Parameters: []*huma.Param{
{
// Omitting the header fields.
Ref: customHeaderSchema.Ref,
},
},
Tags: []string{"users"},
}, func(ctx context.Context, req *CreateUser) (*Output, error) {
resp := &Output{}
resp.Body.Message = "It works!"
return resp, nil
})
huma.Register(api, huma.Operation{
OperationID: "UserUpdate",
Method: http.MethodPatch,
Path: "/users/{id}",
Parameters: []*huma.Param{
{
// Omitting the header fields.
Ref: customHeaderSchema.Ref,
},
},
Tags: []string{"users"},
}, func(ctx context.Context, req *UpdateUser) (*Output, error) {
resp := &Output{}
resp.Body.Message = "It works!"
return resp, nil
}) |
@superstas you are correct that this is currently not supported. All primitive types will be defined inline in the schema, which is done to keep from having every type get its own |
@danielgtaylor, thank you for the clarification. Yes, it is important to us to simplify our specs as much as possible by using |
Hey there!
I've got the following types
With the following routes
I expect that
CustomHeader
would be re-used via$ref
in the generated OAS.Instead the
CustomHeader
schema is embedded into all the endpointsCan an operation be registered to force Huma to reuse shared schemas?
Thank you.
The text was updated successfully, but these errors were encountered: