Home  >  Article  >  Backend Development  >  How to manage go-rest server based on OpenAPI 3.0?

How to manage go-rest server based on OpenAPI 3.0?

WBOY
WBOYforward
2024-02-05 23:54:03398browse

如何基于OpenAPI 3.0管理go-rest服务器?

Question content

My current API is written in Perl using Mojolicious and its OpenAPI plugin.

As far as I know, the advantage of this plugin is that it reads the OpenAPI specification and generates all routing and validation on server startup. Linking the endpoint to the actual method is done by defining the endpoint as the "x-mojo-to" attribute in the OpenAPI specification.

So I only need to write the method once, and when my specification is enhanced or extended, I don't lose the work I did and only need to write new methods.

How to achieve this in Go?

I can only find modules that generate boilerplate code that I have to populate with my methods.

But what happens when I have to extend or enhance the API specification? The boilerplate will be regenerated and I will have to redo the work.


Correct answer


If you use https://www.php.cn/link/9e9aa9cfa4681a0bb8c946522067e902 a>, you do not edit the generated file. So when you add a route to the openapi specification and rebuild, you "only" need to implement one new method added to the server interface.

The above is the detailed content of How to manage go-rest server based on OpenAPI 3.0?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete