Generate OpenAPI spec from gin project
Asked Answered
A

2

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.

Asseveration answered 23/5, 2022 at 12:46 Comment(0)
U
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.
Urea answered 23/5, 2022 at 21:22 Comment(1)
This project still generates Swagger v2 specifications. Do you know how to get v3?Huehuebner
S
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.

Sheared answered 2/6, 2022 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.