Code Monkey home page Code Monkey logo

raml-doc's Introduction

raml-doc Build Status

Generate an HTML documentation of a RAML file. Send test requests to the service directly from within the documentation.

Usage as standalone tool

The documentation can be generated statically using the command line interface.

maven

Download raml-doc-standalone either manually or using maven, then execute

java -jar raml-doc-standalone.jar <raml-file>
npm

Install raml-doc from npm with sudo npm install raml-doc -g

Run it with raml-doc <raml-file>

Usage as a servlet

The documentation can also be generated from within a web application. Add this to web.xml

<servlet>
    <servlet-name>raml-doc</servlet-name>
    <servlet-class>guru.nidi.raml.doc.servlet.RamlDocServlet</servlet-class>
    <init-param>
        <param-name>ramlLocations</param-name>
        <param-value>classpath://api/myRaml.raml</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>raml-doc</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

and the documentation is generated at startup and will be available directly from your application.

The available config parameters are the following:

Name Meaning Values
ramlLocations Comma separated list of RAML files. Protocols like file://, classpath://, http:// are supported.
features Comma separated list of features to enable. Features are:
online: The RAML documentation is available through the application,
download: The documentation provides a download link to the RAML file,
tryout: The API can be tried out interactively from within the documentation,
docson: Use Docson to display JSON schemas.
baseUri The URL the test requests should be sent to (overrides the baseUri setting in the RAML file).
baseUriParameters Set the parameter values of the baseUri in the RAML file. The format is parameter=value,....
Special values are $host and $path which are replaced by the actual host and path of the running servlet.
customization The location where the customized favicon.ico, custom-variables.less, custom-style.less should be loaded from. For the supported protocols, see ramlLocations parameter. If not given, the first ramlLocation is used.

Another possibility is to subclass RamlDocServlet and override the configuration methods.

Resulting HTML

The resulting HTML supports the following:

  • Select a method by using an anchor, e.g. res.html#get
  • These query parameters:
Name Meaning Value
expanded Which resources in the resource tree on the left should be expanded. Can be empty (all resources are expanded) or a comma separated list of resource names.
u_* A URI parameter value to predefine. The value for the parameter.
q_* A query parameter value to predefine. The value for the parameter.
h_* A header value to predefine. The value for the header.
f_* A form parameter value to predefine. The value for the parameter.
method Which method should be selected. (Same as anchor but without scolling.) GET, POST, PUT, DELETE
run If a request of the selected method should be sent to the server. none

Demo

Documentation of a subset of the GitHub API.

raml-doc's People

Contributors

agabrys avatar nidi3 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ljubisap

raml-doc's Issues

Support use of resources with and without trailing slash when sending a request

When using different resources such as

/user:
...
/user/:
...

then raml-doc will consider different resources when creating the html docs. However, the same call is sent to the web service for both resources when using the "send request" button.

It would be great if raml-doc respects trailing slashes indicating different web service calls when using "send request".

Weird index page

The generated index page doesn't have a version nor the top level doc of the API so it's pretty useless:

screenshot from 2015-08-18 09 09 30

After clicking on the root node, the page at /Unbounce API/index.html becomes way more useful:

screenshot from 2015-08-18 09 11 06

Could the top level index page be replaced with the API one directly? I don't really understand why having to see a pretty much useless page first then click to see a useful one.

Status codes are not in ascending order

It seems status codes are in whatever order is created by the RAML parser when assembling them from traits, resources and local definitions. Sorting them ascending would be easier on the reader.

Support docson rendering of JSON Schemas

Docson is a pure HTML+CSS+JS JSON Schema renderer that does a great job at representing complex relationships via progressive drill down.

As an alternative to inlining each schema $ref, embedding Docson's widget.js in RAML Doc pages where schemas are shown, would provide end users with a convenient way to explore an API's schemas.

This would be off be default and enabled via a feature flag.

Sanitize generated file names to avoid browsing issues

I'm facing weird errors where some versions of Safari can't access the doc. I suspect this is because of the { } in the file names for resources that have path parameters.

Could file/folder names be sanitized so such characters are removed?

I would remove spaces (coming from the service title) as well because it makes for ugly URLs.

Java error when trying to run npm version

I'm getting a java error when trying to run the npm run command. This is the error message that gets returned:

Problem generating RAML documentation.
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at guru.nidi.raml.doc.GeneratorConfig.getBaseOfFirstRaml(GeneratorConfig.java:82)
at guru.nidi.raml.doc.OptionParser.parseCustomization(OptionParser.java:49
at guru.nidi.raml.doc.OptionParser.parse(OptionParser.java:44)
at guru.nidi.raml.doc.Main.main(Main.java:27)

cant build.

grabbed repo, using jdk 8, maven 3.. did mvn clean install, fails on dependency. can you put an ANT build script in..much easier/faster.

says cant find guru.nidi.raml:raml-loader:0.0.5-SNAPSHOT

Support custom favicon

Currently the site favicon is the RAML one but it would be nice to be able to use a custom one (usually your company favicon).

Problematic Markdown rendering

Markdown doc rendering has several issues:

  • numbered lists are not properly handled (see the 1. 1. 1. below)
  • inline code samples in list are not rendered as code (see curl command at the bottom of the image below)
  • overall rendering is crammed and hard to read (contrast with output from raml2html second below).

raml-doc output

screenshot from 2015-08-19 09 18 01

raml2html output

screenshot from 2015-08-19 09 20 03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.