discord-gophers / goapi-gen

This package contains a set of utilities for generating Go boilerplate code for services based on OpenAPI 3.0 API definitions
Apache License 2.0
132 stars 12 forks source link

make handler return type interfaces #97

Closed Karitham closed 11 months ago

Karitham commented 1 year ago

This PR adds a Reponser interface, which enables us to construct any form of custom type and turn them into responses accepted by goapi-gen.

The goal of this proposal is to shorten the error handling code, and clean up ugly multi-line errors made when constructing a non-standard/specified response body.

The example provided with the petstore may not be the best because of it's short nature, but we can easily save dozens of lines of code, and standardize better with such an API.

Karitham commented 1 year ago

After some more reading and code reviewing, I figured I could just reuse render's Renderer interface for it, thus changing very little, yet achieving the desired functionality.