
Company News
Socket Has Acquired Secure Annex
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.
Kommentaar generates documentation for Go APIs.
The primary focus is currently on OpenAPI output (previously known as Swagger), but it can also output directly to HTML, and the design allows easy addition of other output formats.
Goals:
Non-goals:
anyOf, don't map well to how Go works, and supporting it
would add much complexity and would benefit only a few users.Install it:
$ go get zgo.at/kommentaar
Parse one package:
$ kommentaar zgo.at/goatcounter/v2/handlers
Or several packages:
$ kommentaar zgo.at/goatcounter/v2/...
The default output is as an OpenAPI 2 JSON file. You can generate a HTML page
with -output html, or directly serve it with -output html -serve :8080. When
serving the documentation it will rescan the source tree on every page load,
making development/proofreading easier.
See kommentaar -h for the full list of options.
You can also the Go API, for example to serve documentation in an HTTP endpoint.
See doc/syntax.markdown for a full description of the
syntax; a basic example:
type bikeRequest struct {
// Frame colour {enum: black red blue, default: black}.
Color string
// Frame size in centimetres {required, range: 40-62}.
Size int
}
type bikeResponse struct {
// Price in Eurocents.
Price int
// Estimated delivery date {date}.
DeliveryTime int
}
type errorResponse struct {
Error []string `json:"errors"`
}
// POST /bike/{id} bikes
// Order a new bike.
//
// A more detailed multi-line description.
//
// Request body: bikeRequest
// Response 200: bikeResponse
// Response 400: errorResonse
Kommentaar can be configured with a configuration file; see
config.example for the documentation.
The motivation for writing Kommentaar was a lack of satisfaction with existing tools:
yvasiyarov/swagger requires extensive
comments; you will need to duplicate every parameter as @param foo query string Some description. It's flexible but also tedious and ugly.
We implemented go-swagger but found several pain points:
goa means a complete rewrite of our API, and whether the goa DSL approach is a good one is also debatable (we haven't tried it due to the prohibitive costs of the rewrite, so lack direct experience).
We tried implementing both yvasiyarov/swagger and go-swagger, and both ended in fairly dismal (and time-consuming) failure.
Kommentaar is designed to strike a reasonable balance:
You will need to duplicate some information from the code in comments, but not too much, and it shouldn't have to be updated very often; adding new request or response parameters is still easy.
Makes some assumptions about your code (e.g. that you're returning a
struct), but not many, and rewriting existing code (e.g. handlers returning
a map[string]any) should be straightforward.
Syntax is straightforward and easy to read and write.
Impossible to make Kommentaar output invalid OpenAPI files (if it does, then that's a bug); the syntax doesn't offer too much flexibility, and the tool errors out when it encounters unexpected or wrong input.
Reasonably fast and should not exceed more than 2 or 3 seconds for moderate-sized APIs (and it can probably be made faster with some effort).
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.

Research
/Security News
Socket is tracking cloned Open VSX extensions tied to GlassWorm, with several updated from benign-looking sleepers into malware delivery vehicles.

Product
Reachability analysis for PHP is now available in experimental, helping teams identify which vulnerabilities are actually exploitable.