7

Is there a way to generate OpenAPI spec files from a gin project? This issue is really hard to search for, all I could find so far are on doing there reverse.

2 Answers 2

2

gin-swagger is extracting comments from your code.

Running swag init generates :

  • docs.go: To serve SwaggerUI pages
  • swagger.json: The Swagger Specification in json file format.
  • swagger.yaml: The Swagger Specification in yaml file format.
1
  • This project still generates Swagger v2 specifications. Do you know how to get v3? Commented Aug 24, 2022 at 4:59
1

You mean API docs for API user?

I saw you tag the question with swagger.

You have two chooses:

  1. go-swagger

This package contains a golang implementation of Swagger 2.0 (aka OpenAPI 2.0): it knows how to serialize and deserialize swagger specifications.

  1. swag

Swag converts Go annotations to Swagger Documentation 2.0. We've created a variety of plugins for popular Go web frameworks. This allows you to quickly integrate with an existing Go project (using Swagger UI).

What difference between them?

Here is the answer from go-swagger:

The main difference at this moment is that this one actually works...

The swagger-codegen project (like swag) only generates a workable go client and even there it will only support flat models. Further, the go server generated by swagger-codegen is mostly a stub.

Detail of this answer in How is this different from go generator in swagger-codegen? from go-swagger.

Not the answer you're looking for? Browse other questions tagged or ask your own question.