One of our current OKRs is to implement Beacon API endpoints using an HTTP server. This will remove a lot of complexity, because currently we have to transform HTTP requests/responses, which conform to OpenApi specification, into gRPC-compliant structures. This results in complex middleware code that we have to maintain.
To make this task easier, it would be nice to be able to automatically generate server code from the Beacon API specification. I spent some time searching for the right tool and unfortunately couldn't find anything suitable.
go-swagger
does not support OpenApi 3.0. It provides a flatten
utility, which I hoped to use before applying another tool, but unfortunately flattening a 3.0 spec does not produce a valid format.
oapi-codegen
does not support external references, which means anything that looks like $ref: "./apis/beacon/genesis.yaml"
. I tried flattening the spec with go-swagger
first, but it did not work because the resulting file was invalid.
swagger-codegen
has the same external references issue as oapi-codegen
. It provides a feature called 'Import mappings' as a workaround, but this requires generating all references beforehand recursively, which is too much work. We could potentially write a reusable script, but it would be one more thing to maintain. We would have to update it every time the spec's file structure changes.
ogen
was the most promising because it supports external references. After fixing some small enum issues I ran into this blocker:
I am puzzled by this error and I can't find a solution online. I can raise this issue on the project's Github.
Update: I opened an issue on Github and resolved this problem only to run into several others. It turns out the tool does not fully support OpenApi.