{"id":51450526,"url":"https://github.com/tinyauthapp/gin-scalar","last_synced_at":"2026-07-05T20:00:56.794Z","repository":{"id":369303699,"uuid":"1289161696","full_name":"tinyauthapp/gin-scalar","owner":"tinyauthapp","description":"A gin middleware that helps automatically generate RESTful API documentation with Scalar.","archived":false,"fork":false,"pushed_at":"2026-07-04T15:02:03.000Z","size":13348,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-04T16:14:21.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyauthapp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-07-04T11:57:38.000Z","updated_at":"2026-07-04T15:02:07.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tinyauthapp/gin-scalar","commit_stats":null,"previous_names":["tinyauthapp/gin-scalar"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/tinyauthapp/gin-scalar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyauthapp%2Fgin-scalar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyauthapp%2Fgin-scalar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyauthapp%2Fgin-scalar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyauthapp%2Fgin-scalar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyauthapp","download_url":"https://codeload.github.com/tinyauthapp/gin-scalar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyauthapp%2Fgin-scalar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35167259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-05T02:00:06.290Z","response_time":100,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-05T20:00:55.909Z","updated_at":"2026-07-05T20:00:56.789Z","avatar_url":"https://github.com/tinyauthapp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-scalar\n\nA gin middleware that helps automatically generate RESTful API documentation with Scalar.\n\n\u003e [!NOTE]\n\u003e Unlike Swagger implementations, this middleware bundles Scalar, and it does not need a separate files package.\n\n## Usage\n\n### Start using it\n\n1. Add comments to your API source code, [See Declarative Comments Format](https://github.com/swaggo/swag/blob/master/README.md#declarative-comments-format).\n2. Download [Swag](https://github.com/swaggo/swag) for Go with:\n\n```sh\ngo install github.com/swaggo/swag/cmd/swag@latest\n```\n\n3. Run [Swag](https://github.com/swaggo/swag) at your Go project root path, [Swag](https://github.com/swaggo/swag) will parse comments and generate the required files (`docs` folder and `docs/doc.go`).\n\n```sh\nswag init\n```\n\n4. Download [gin-scalar](https://github.com/tinyauthapp/gin-scalar) with:\n\n```sh\ngo get -u github.com/tinyauthapp/gin-scalar\n```\n\nImport the middleware:\n\n```go\nimport \"github.com/tinyauthapp/gin-scalar\"\n```\n\n### Canonical example\n\nNow assume you have implemented a simple API as follows:\n\n```go\n// A get function that returns a hello world string by JSON\ntype HelloWorldResponse struct {\n    Message string `json:\"message\"`\n}\n\nfunc HelloWorld(ctx *gin.Context)  {\n   ctx.JSON(http.StatusOK, HelloWorldResponse{\n   Message: \"Hello, World!\",\n   })\n}\n```\n\nNow, add the scalar middleware to your gin router:\n\n1. Add comments in the API and in the main function:\n\n```go\ntype HelloWorldResponse struct {\n\tMessage string `json:\"message\"`\n}\n// @BasePath /api/v1\n\n// HelloWorldExample godoc\n// @Summary Hello World Example\n// @Description Just return a hello world string\n// @Tags example\n// @Produce json\n// @Success 200 {object} HelloWordResponse\n// @Router /example/helloworld [get]\nfunc HelloWorld(ctx *gin.Context)  {\n    ctx.JSON(http.StatusOK, HelloWorldResponse{\n\t\tMessage: \"Hello, World!\",\n    })\n}\n```\n\n2. Use the `swag init` command to generate the docs, the generated docs will be stored at `docs/`.\n\n3. Add the scalar middleware to your gin router:\n\n```go\npackage main\n\nimport (\n   \"github.com/gin-gonic/gin\"\n   docs \"github.com/go-project-name/docs\"\n   ginScalar \"github.com/tinyauthapp/gin-scalar\"\n   \"net/http\"\n)\ntype HelloWorldResponse struct {\n   Message string `json:\"message\"`\n}\n// @BasePath /api/v1\n\n// HelloWorldExample godoc\n// @Summary Hello World Example\n// @Description Just return a hello world string\n// @Tags example\n// @Produce json\n// @Success 200 {object} HelloWorldResponse\n// @Router /example/helloworld [get]\nfunc HelloWorld(ctx *gin.Context)  {\n   ctx.JSON(http.StatusOK, HelloWorldResponse{\n      Message: \"Hello, World!\",\n   })\n}\n\nfunc main()  {\n   r := gin.Default()\n   docs.SwaggerInfo.BasePath = \"/api/v1\"\n   v1 := r.Group(\"/api/v1\")\n   {\n      eg := v1.Group(\"/example\")\n      {\n         eg.GET(\"/helloworld\", HelloWorld)\n      }\n   }\n   r.GET(\"/scalar/*any\", ginScalar.WrapHandler(nil))\n   r.Run(\":8080\")\n}\n```\n\nDemo project tree, `swag init` is run at the root path of the project.\n\n```\n.\n├── docs\n│   ├── docs.go\n│   ├── swagger.json\n│   └── swagger.yaml\n├── go.mod\n├── go.sum\n└── main.go\n```\n\n## Configuration\n\nYou can configure Scalar using different configuration options. For example:\n\n```go\nginScalar.WrapHandler(nil, ginScalar.URL(\"http://localhost:8080/swagger/doc.json\"))\n```\n\n| Option       | Type   | Default    | Description                                                                                                                                                                                                                                                |\n| ------------ | ------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| URL          | string | \"doc.json\" | URL pointing to API definition (normally swagger.json or swagger.yaml)                                                                                                                                                                                     |\n| InstanceName | string | \"swagger\"  | The instance name of the swagger document. If multiple different swagger instances should be deployed on one gin router, ensure that each instance has a unique name (use the _--instanceName_ parameter to generate swagger documents with _swag init_).  |\n| BasePath     | string | \"/scalar\"  | The base path in which the Scalar UI will be served                                                                                                                                                                                                        |\n| ProjectName  | string | \"Scalar\"   | Project name displayed as the page title of the Scalar UI                                                                                                                                                                                                  |\n\n## License\n\nLicensed under [MIT](./LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyauthapp%2Fgin-scalar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyauthapp%2Fgin-scalar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyauthapp%2Fgin-scalar/lists"}