You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a large API, having many operations on a single Handler interface can make it difficult to reasonably split up your implementation code. Many API frameworks are based on "controllers" which allow you to group related operations, and each controller can have dependencies necessary for just those operations.
Description
I propose allowing the user to group operations and generate a separate handler interface for each group. The main Handler interface would embed all of these operation group interfaces.
The operation group would be specified using an x-ogen-operation-group extension field on the Path Item Object or Operation Object. If set on the Path Item, the group would apply to all child Operations unless overridden on an Operation. This would allow creating arbitrary groups based on version, resource, etc. The group name would be treated as case-insensitive.
The name of the generated group handler interface would be the group name converted to PascalCase with a "Handler" suffix. Any operations without a group would remain on the main Handler interface. The NewError function for the Convenient errors feature would also remain on the Handler interface.
As proposed, this feature would be opt-in and backwards-compatible. Users with existing implementations could create operation groups incrementally.
I'd be happy to create PR for this if the proposal sounds good.
Example
Taking the OpenAI API example, you could split up the operations by resource. The generated code would look something like this:
If you have a large API, having many operations on a single
Handler
interface can make it difficult to reasonably split up your implementation code. Many API frameworks are based on "controllers" which allow you to group related operations, and each controller can have dependencies necessary for just those operations.Description
I propose allowing the user to group operations and generate a separate handler interface for each group. The main
Handler
interface would embed all of these operation group interfaces.The operation group would be specified using an
x-ogen-operation-group
extension field on the Path Item Object or Operation Object. If set on the Path Item, the group would apply to all child Operations unless overridden on an Operation. This would allow creating arbitrary groups based on version, resource, etc. The group name would be treated as case-insensitive.The name of the generated group handler interface would be the group name converted to PascalCase with a "Handler" suffix. Any operations without a group would remain on the main
Handler
interface. TheNewError
function for the Convenient errors feature would also remain on theHandler
interface.As proposed, this feature would be opt-in and backwards-compatible. Users with existing implementations could create operation groups incrementally.
I'd be happy to create PR for this if the proposal sounds good.
Example
Taking the OpenAI API example, you could split up the operations by resource. The generated code would look something like this:
The
Handler
implementation could be composed from the handler implementations.Open Questions
References
The contiamo/openapi-generator-go project uses a similar extension field for grouping operations.
The text was updated successfully, but these errors were encountered: