Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchernev committed Sep 19, 2018
1 parent 36e2a48 commit e2e12fa
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ $ yarn add swagger-jsdoc

Before you start writing your specification and/or documentation, please keep in mind that there are two fundamental concepts you need to wrap you head around when working with `swagger-jsdoc` - definition object and input APIs.

Definition object maps to [OpenAPI object](https://swagger.io/specification/#oasObject). This is where you would add information about your API and any root-level properties. Definition object is required parameter.
Definition object maps to [OpenAPI object](https://swagger.io/specification/#oasObject). This is where you would add information about your API and any root-level properties. Definition object is a required parameter.

Input APIs are any files which you pass as arguemnts to the program in order to extract information about your API. For instance, these could be `.js` files with JSDoc comments or `.yaml` files directly. This parameter is also required.

There are 2 ways by which you can pass these 2 required arguemnts:
There are a few ways by which you can pass these 2 required arguments:

- Through `apis` property in your definition object
- Through arguments (`program.args`) when using the CLI.
When using the CLI:

- Through `apis` property in your definition object.
- Through arguments

When using the Node API:

- Through `apis` in your `options` object.

For example, given the following module export for a definition object:

Expand All @@ -71,7 +77,7 @@ module.exports = {
};
```

The only way you can make use of this definition is by using the CLI as following:
One way you can make use of this definition is by using the CLI as following:

```sh
$ swagger-jsdoc.js -d example/v2/swaggerDef.js example/v2/route*.js
Expand All @@ -84,7 +90,7 @@ If you, however, want to skip the arguments and still use the CLI, you will need

module.exports = {
...
apis: ['example/v2/route*.js']
apis: ['example/v2/route*.js'] // <-- We add this property:
basePath: '/', // Base path (optional)
};
```
Expand All @@ -95,7 +101,7 @@ And then you will be able to use the CLI as following:
$ swagger-jsdoc.js -d example/v2/swaggerDef.js
```

Keep in mind that, this holds true for the CLI usage as it's flexible. When using the Node API in the following way:
When using the Node API, input APIs come in in the following way:

```javascript
const swaggerJSDoc = require('swagger-jsdoc');
Expand All @@ -107,7 +113,7 @@ const swaggerDefinition = {

const options = {
swaggerDefinition,
apis: ['./example/v2/routes*.js'],
apis: ['./example/v2/routes*.js'], // <-- not in the definition, but in the options
};

const swaggerSpec = swaggerJSDoc(options);
Expand Down

0 comments on commit e2e12fa

Please sign in to comment.