3.0.0 • Published 7 years ago

swagger-md v3.0.0

Weekly downloads
277
License
MIT
Repository
github
Last release
7 years ago

swagger-md

Greenkeeper badge

Converts Swagger API spec to Markdown format.

Usage

Install NPM module:

npm install swagger-md

Convert Swagger API spec to Markdown format:

import swagger_md from 'swagger-md';
import swagger_spec from './swagger-api-spec.json';

function responseExampleProvider(path, method) {
  return [
    '```json',
    '{ "foo": 1 }',
    '```',
  ].join('\n');
} 

swagger_md.convertToMarkdown(swagger_spec, { response_example_provider: responseExampleProvider }).then(markdown_str => {
  // Use markdown_str, e.g. write to "api.md"
});
// It is also possible to pass a path to the root file of the API spec (can be json or yaml) and supports local file refs.
const path_to_spec = 'path/to/api-spec.json';

swagger_md.convertToMarkdown(path_to_spec).then(markdown_str => {
  // refs to other local files are resolved and the markdown contains the entire API
});

resolveApiSpec resolves the API spec in the same way as convertToMarkdown but returns the resolved object without converting it to markdown

const path_to_spec = 'path/to/api-spec.json';
const options = {
  // optionally specify that external refs should be fetched and resolved
  external: true
};

swagger_md.resolveApiSpec(path_to_spec, options).then(spec => {
  // spec == the resolved API spec
});

To use the swagger-md in a CommonJS module environment the usage statement should look like:

var swagger_md = require('swagger-md').default;
...

What can it do?

See ./test-fixtures/swagger for examples of a swagger.json converted to Markdown.

Want it do handle more? Feel free to contribute!

Contributing

  1. Write a new test with new fixtures or extend the existing ones
  2. Make a PR
  3. :pray: :clap:
3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.7.1

7 years ago

1.7.0

8 years ago

1.6.0

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago