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

Duplicate Operation IDs should not be allowed #910

@rhodeon

Description

@rhodeon

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:

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions