Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use ESM #240

Merged
merged 44 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9757f14
init changes
kalinchernev Jan 16, 2021
2cc36ac
update loaders
kalinchernev Jan 21, 2021
07bd5f2
update example app
kalinchernev Jan 23, 2021
7f1bfe6
update import statements in cli spec
kalinchernev Jan 23, 2021
4c096a7
move test files to fixtures
kalinchernev Jan 24, 2021
f0e5470
move v3 test files to fixtures
kalinchernev Jan 24, 2021
36c10a8
refactor existing tests for utils
kalinchernev Jan 24, 2021
223dfcd
add named exports to utils
kalinchernev Jan 24, 2021
8f433ed
refactor examples tests
kalinchernev Jan 24, 2021
433f8ca
refactor examples tests
kalinchernev Jan 24, 2021
18d10f1
reading json files
kalinchernev Jan 25, 2021
de1a747
update existing test suites
kalinchernev Jan 25, 2021
cb07714
use createRequire()
kalinchernev Jan 26, 2021
394c335
remove airbnb-base because no babel and transpilation
kalinchernev Jan 26, 2021
470b8c9
start refactor definition loader
kalinchernev Jan 27, 2021
dd0ff8a
feat: complete loadDefinition
kalinchernev Jan 28, 2021
f6ac1fe
start deleting the cli
kalinchernev Jan 31, 2021
f226343
start moving the cli to examples
kalinchernev Feb 1, 2021
9403667
remove commander
kalinchernev Feb 3, 2021
2ce964e
retry ci
kalinchernev Feb 3, 2021
cef1937
retry ci
kalinchernev Feb 3, 2021
5c37df5
retry ci
kalinchernev Feb 3, 2021
f55bb61
still inconsistent behavior, unfortunately
kalinchernev Feb 3, 2021
c089c3e
run without caching
kalinchernev Feb 4, 2021
7c5136a
upgrade deps
kalinchernev Feb 7, 2021
bda840f
remove unused files
kalinchernev Feb 7, 2021
41b28fc
move validation in one place
kalinchernev Feb 7, 2021
c1b7613
refactor organize function
kalinchernev Feb 8, 2021
57d9b03
make spec operations transparent to library
kalinchernev Feb 9, 2021
5419f65
refactor spec.prepare() tests
kalinchernev Feb 9, 2021
7dd1a78
add spec.clean() tests
kalinchernev Feb 9, 2021
e7df61d
move encoding test at its implementation
kalinchernev Feb 9, 2021
61aa10d
add some coverage for the finalize method
kalinchernev Feb 11, 2021
8982b35
Making main function async
kalinchernev Feb 12, 2021
f29f8a2
Add some coverage
kalinchernev Feb 13, 2021
0df97c5
100% on utilities, yey
kalinchernev Feb 13, 2021
8b5b5f2
add tests for spec.extract()
kalinchernev Feb 14, 2021
b4bb70d
improve coverage
kalinchernev Feb 14, 2021
53a7731
Update to latest master
kalinchernev Feb 16, 2021
7a048d9
Update landing page readme
kalinchernev Feb 16, 2021
050facd
full coverage, on paper
kalinchernev Feb 16, 2021
08a2f71
update to latest master
kalinchernev Feb 16, 2021
e6f09d3
move loadDefinition
kalinchernev Feb 17, 2021
1da74cd
Update docs
kalinchernev Feb 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 12,
},
extends: [
'airbnb-base',
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:jest/recommended',
],
Expand Down
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
17 changes: 2 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI
on: [push, pull_request]
on: [push]

jobs:
audit:
Expand All @@ -16,24 +16,11 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [12.x, 14.x, 15.x]

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run tests
run: yarn test

# publish:
# name: publish
# needs: tests
# runs-on: ubuntu-latest
# if: github.event_name == 'push' && github.ref == 'refs/heads/master'
# steps:
# - uses: actions/checkout@v2
# - name: Publish
# uses: mikeal/merge-release@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.c9
.nvm
.eslintrc.js
external.jsdoc
examples/
docs/
jsdoc/
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/erbium
lts/fermium
5 changes: 3 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/files/v2/wrong_syntax.json
test/files/v2/wrong_syntax.yaml
test/fixtures/wrong/example.js
test/fixtures/wrong/example.json
test/fixtures/wrong/example.yaml
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.get('/', (req, res) => {
The library will take the contents of `@openapi` (or `@swagger`) with the following configuration:

```javascript
const swaggerJsdoc = require('swagger-jsdoc');
import swaggerJsdoc from 'swagger-jsdoc';

const options = {
definition: {
Expand All @@ -47,15 +47,9 @@ The resulting `openapiSpecification` will be a [swagger tools](https://swagger.i

![swagger-jsdoc example screenshot](./docs/screenshot.png)

## Node.js version requirements, CommonJS and ESM
## System requirements

`swagger-jsdoc` 6.x requires Node.js 12.x and above. When using the CLI, the library will attempt to load the definition file in several formats: `.js`, `.cjs`, `.yaml` (or `.yml`) and `.json`.

The example above follows the CommonJS format, which will work when you do not have `"type": "module"` in your `package.json`.

However, if you're using ESM and have `"type": "module"`, then please change the extension to `.cjs`.

Definition files in `.js` and ESM will be supported in `swagger-jsdoc` 7.x.
Notes on CJS and ESM.

## Installation

Expand Down
86 changes: 0 additions & 86 deletions bin/swagger-jsdoc.js

This file was deleted.

61 changes: 0 additions & 61 deletions docs/CLI.md

This file was deleted.

14 changes: 8 additions & 6 deletions docs/CONCEPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Parts of the specification can be placed in annotated JSDoc comments in non-comp

Other parts of the specification can be directly written in YAML files. These are usually parts containing static definitions which are referenced from jsDoc comments parameters, components, anchors, etc. which are not so relevant to the API implementation.

Given the following definition `swaggerDefinition.cjs`:
Given the following definition `definition.js`:

```javascript
module.exports = {
export default {
info: {
title: 'Hello World',
version: '1.0.0',
Expand All @@ -24,20 +24,22 @@ module.exports = {
};
```

The end `swaggerSpecification` will be a result of following:
The end `openapiSpecification` will be a result of following:

```javascript
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerDefinition = require('./swaggerDefinition');
import swaggerJsdoc from 'swagger-jsdoc';
import definition from './definition.js';

const options = {
swaggerDefinition,
definition,
apis: ['./src/routes*.js'],
};

const swaggerSpecification = swaggerJsdoc(options);
```

Please note that it's also possible to use CommonJS syntax with `require` and `module.exports` for the example above.

## File selection patterns

`swagger-jsdoc` uses [node glob](https://github.com/isaacs/node-glob) for discovering your input files. You can use patterns such as `*.js` to select all javascript files or `**/*.js` to select all javascript files in sub-folders recursively.
Expand Down
6 changes: 3 additions & 3 deletions docs/FIRST-STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ The default target specification is 2.0. This provides backwards compatibility f
In order to create a specification compatibile with 3.0 or higher, i.e. the so called OpenAPI, set this information in the `swaggerDefinition`:

```diff
const swaggerJsdoc = require('swagger-jsdoc');
import swaggerJsdoc from 'swagger-jsdoc';

const options = {
swaggerDefinition: {
definition: {
+ openapi: '3.0.0',
info: {
title: 'Hello World',
Expand All @@ -20,7 +20,7 @@ const options = {
apis: ['./src/routes*.js'],
};

const swaggerSpecification = swaggerJsdoc(options);
const openapiSpecification = swaggerJsdoc(options);
```

## Annotating source code
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Quick-start:

- [First steps](./FIRST-STEPS.md)
- [CLI](./CLI.md)
- [Examples](../examples)

Before you submit an issue:
Expand Down
Loading