Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Working with OpenAPI (Swagg | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 53 of 60

·Go

Working with OpenAPI (Swagger) – Auto‑generate Docs

20 minutes

Course progress88%

OpenAPI with swaggo

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

Install the generator:

$ go install github.com/swaggo/swag/cmd/swag@latest
$ go get -u github.com/swaggo/http-swagger

Add annotations to handlers:

// @Summary Create a Todo
// @Description Add a new todo item





 {  }
// @Accept json
// @Produce json
// @Param todo body Todo true "Todo item"
// @Success 201 {object} Todo
// @Router /todos [post]
func createTodo(w http.ResponseWriter, r *http.Request)
/* … */

Generate docs:

$ swag init -g main.go

The command creates docs/swagger.json and docs/swagger.yaml.

Serve the UI:

http.Handle("/swagger/", httpSwagger.Handler())

Visit http://localhost:8080/swagger/index.html.

Info

OpenAPI is language‑agnostic – you can auto‑generate client SDKs for TypeScript, Java, etc.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonBuilding a Microservice with gRPCContinue to lesson 54Building a Serverless Function with AWS Lambda (Go Runtime)Back to Go Programming Bootcamp curriculum