-
-
Notifications
You must be signed in to change notification settings - Fork 232
Description
In both the OpenAPI specification and Huma's comments, the OperationID is described to be unique:
Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.
But this behaviour isn't enforced by Huma.
In the snippet below, the list-users OperationID is shared by both operations.
huma.Register(
api,
huma.Operation{
Method: http.MethodGet,
Path: "/users",
Summary: "List users",
OperationID: "list-users",
},
func(ctx context.Context, _ *struct{}) (*struct{}, error) {
return nil, nil
},
)
huma.Register(
api,
huma.Operation{
Method: http.MethodDelete,
Path: "/users",
Summary: "Delete users",
OperationID: "list-users",
},
func(ctx context.Context, _ *struct{}) (*struct{}, error) {
return nil, nil
},
)Huma accepts this without errors and that results in a documentation page where the "List users" page cannot be selected as both are seen as the same endpoint:
To be inline with the specification and prevent mistakes, it would be good for Huma to reject duplicate operation IDs.
I think it would be better to have this behaviour as the default rather than an option as having duplicate IDs is a bug in any case, even if such a change could break some pre-existing code.