Skip to content

Turn your golang comments into a RAML 1.0 file describing your API

Notifications You must be signed in to change notification settings

florenthobein/godoc2api

Repository files navigation

WORK IN PROGRESS

godoc2api Build Status

Easily describe your API by writing JSdoc-like golang comments that render into a RAML 1.0 file

About

What is RAML?

RESTful API Modeling Language (RAML) is a YAML-based language for describing RESTful APIs. It provides all the information necessary to describe RESTful or practically RESTful APIs. Wikipedia

Documentation-oriented design of APIs

An API is a living thing - wether it's from a designer, a builder or a consumer point of view, maintaining a coherent and up-to-date documentation of its endpoints is mandatory.

godoc2api simplifies this process by peeping into your go code to extract and generate a structured, comprehensible API documentation.

  • Overly simple to implement on existing APIs
  • Binds code documentation to API behaviour for feature integrity
  • Enforces good code documentation practices
  • Produces a standardised and consommable output
  • Code documentation + auto-generated public doc + testable API = 👍

Installation

go get github.com/florenthobein/godoc2api

Limitations

For now only RAML 1.0 specification is supported. It also mainly focuses on a full application/json API, as input and output.

Usage

Examples

Say you've defined the following route / handler

func main () {
    http.HandleFunc("/myroute", myHander)
    http.ListenAndServe(":8080", nil)
}
func myHander(rw http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(rw, "Hello world!")
}

Simply add comments to your handler like this

// An endpoint that just says hi
// @resource GET /myroute
func myHander(rw http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(rw, "Hello world!")
}

That's it! Now you can generate the documentation:

import "github.com/florenthobein/godoc2api"
func main () {
    // Define your normal route
    http.HandleFunc("/myroute", myHander)

    // Define your documentation and save it
    doc := godoc2api.Documentation{URL: "http://localhost:8080"}
    doc.AddRoute(myHander)
    doc.Save("example_basic/")

    // Run your webserver
    http.ListenAndServe(":8080", nil)
}

Detailed examples are written on the godoc page, including RAML outputs.
Code in the examples folder.

Comment parsing

todo

Tag list

todo

Configuration

Defining types

todo

Defining traits

todo

Defining security schemes

todo

Defining annotations

todo

Debugging

Change the log level of the library to display warnings:

// Possible values:
// - LOG_DEBUG
// - LOG_WARN
// - LOG_ERR
// - LOG_NOTHING (default)
godoc2api.LogLevel = godoc2api.LOG_WARN

Roadmap

  • Implementation of traits
  • Implementation of security schemes
  • Implementation of annotations
  • Exportation in multiple files & includes
  • RAML structure validation
  • Support for other standards

Credits

License

Copyright (c) 2017 Florent Hobein. Licensed under the MIT license.

About

Turn your golang comments into a RAML 1.0 file describing your API

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages