Skip to content

Commit 18393ac

Browse files
authored
BREAKING: Native typescript support, circular references fix
* Rewrote in typescript, created esm/cjs exports, brought in library, fixed circular references, added tests, changed test suite to vitest * working top level dereferencing * fix tests and filter if/then
1 parent dfd52c0 commit 18393ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3822
-9173
lines changed

.eslintrc.js

+41-38
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
module.exports = {
2-
env: {
3-
browser: true,
4-
commonjs: true,
5-
es6: true,
6-
node: true
7-
},
8-
extends: [
9-
'eslint:recommended'
10-
],
11-
globals: {
12-
Atomics: 'readonly',
13-
SharedArrayBuffer: 'readonly'
14-
},
15-
parserOptions: {
16-
ecmaVersion: 2018
17-
},
18-
rules: {
19-
indent: [
20-
'error',
21-
'tab',
22-
{
23-
SwitchCase: 1
24-
}
25-
],
26-
'linebreak-style': [
27-
'error',
28-
'unix'
29-
],
30-
quotes: [
31-
'error',
32-
'single'
33-
],
34-
semi: [
35-
'error',
36-
'always'
37-
]
38-
}
39-
}
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
node: true,
7+
},
8+
extends: [
9+
'prettier',
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
parser: '@typescript-eslint/parser',
14+
globals: {
15+
Atomics: 'readonly',
16+
SharedArrayBuffer: 'readonly',
17+
},
18+
parserOptions: {
19+
ecmaVersion: 2018,
20+
},
21+
plugins: ['prettier', 'unused-imports', '@typescript-eslint'],
22+
rules: {
23+
indent: [
24+
'error',
25+
'tab',
26+
{
27+
SwitchCase: 1,
28+
},
29+
],
30+
'linebreak-style': ['error', 'unix'],
31+
quotes: ['error', 'single'],
32+
semi: ['error', 'always'],
33+
'@typescript-eslint/ban-ts-comment': 'off',
34+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
35+
'@typescript-eslint/consistent-type-imports': [
36+
'error',
37+
{
38+
prefer: 'type-imports',
39+
},
40+
],
41+
},
42+
};

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v2
1414
- uses: actions/setup-node@v2
1515
with:
16-
node-version: "lts/*"
16+
node-version: 'lts/*'
1717
- run: npm ci
1818
- run: npm run build --if-present
1919
- run: npm test

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v2
1111
with:
12-
node-version: "lts/*"
12+
node-version: 'lts/*'
1313
- name: npm install, build, and test
1414
run: |
1515
npm ci

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
dist
39+
.idea

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
@@ -7,26 +8,35 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
78
## [1.0.0] - 2020-01-20
89

910
### Changed
11+
1012
- Moved over to the `@openapi-contrib` NPM organization.
1113

1214
## [0.4.0] - 2019-10-04
15+
1316
### Added
17+
1418
- Take the first JSON Schema `example` and put in OpenAPI Schema Object `example`
1519

1620
## [0.3.0] - 2018-12-18
21+
1722
### Added
23+
1824
- Create empty items, as it must always be present for type: array
1925
- Rewrite exclusiveMinimum/exclusiveMaximum
2026
- Rewrite if/then/else as oneOf + allOf
2127
- Rewrite const as single element enum
2228

2329
## [0.2.0] - 2018-05-10
30+
2431
### Fixed
32+
2533
- Implemented [@cloudflare/json-schema-walker] to make sure all subschemas are
2634
processed
2735

2836
[@cloudflare/json-schema-walker]: https://github.com/cloudflare/json-schema-tools#cloudflarejson-schema-walker
2937

3038
## [0.1.1] - 2018-04-09
39+
3140
### Added
41+
3242
- Convert `dependencies` to an allOf + oneOf OpenAPI-valid equivalent

README.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ A little NodeJS package to convert JSON Schema to a [OpenAPI Schema Object](http
66

77
## Features
88

9-
* converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object
10-
* switches `type: ['foo', 'null']` to `type: foo` and `nullable: true`
11-
* supports deep structures with nested `allOf`s etc.
12-
* switches `patternProperties` to `x-patternProperties`
13-
* converts `dependencies` to an allOf + oneOf OpenAPI-valid equivalent
9+
- converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object
10+
- switches `type: ['foo', 'null']` to `type: foo` and `nullable: true`
11+
- supports deep structures with nested `allOf`s etc.
12+
- switches `patternProperties` to `x-patternProperties`
13+
- converts `dependencies` to an allOf + oneOf OpenAPI-valid equivalent
1414

1515
## Installation
1616

17-
``` shell
17+
```shell
1818
npm install --save @openapi-contrib/json-schema-to-openapi-schema
1919
```
2020

@@ -28,16 +28,15 @@ Here's a small example to get the idea:
2828
const convert = require('@openapi-contrib/json-schema-to-openapi-schema');
2929

3030
const schema = {
31-
'$schema': 'http://json-schema.org/draft-04/schema#',
32-
type: ['string', 'null'],
33-
format: 'date-time',
31+
$schema: 'http://json-schema.org/draft-04/schema#',
32+
type: ['string', 'null'],
33+
format: 'date-time',
3434
};
3535

3636
(async () => {
37-
const convertedSchema = await convert(schema);
38-
console.log(convertedSchema);
37+
const convertedSchema = await convert(schema);
38+
console.log(convertedSchema);
3939
})();
40-
4140
```
4241

4342
The example prints out
@@ -117,8 +116,8 @@ This package is [Treeware](https://treeware.earth). If you use it in production,
117116
- [All Contributors][link-contributors]
118117

119118
[mikunn]: https://github.com/mikunn
120-
[WeWork]: https://github.com/wework
121-
[Stoplight]: https://stoplight.io/
122-
[Phil Sturgeon]: https://github.com/philsturgeon
119+
[wework]: https://github.com/wework
120+
[stoplight]: https://stoplight.io/
121+
[phil sturgeon]: https://github.com/philsturgeon
123122
[openapi-schema-to-json-schema]: https://github.com/openapi-contrib/openapi-schema-to-json-schema
124123
[link-contributors]: https://github.com/openapi-contrib/json-schema-to-openapi-schema/graphs/contributors

bin/help-text.json

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"default": [
3-
"Usage:",
4-
" json-schema-to-openapi-schema <command> [options] <file>",
5-
"",
6-
"Commands:",
7-
" convert Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object",
8-
"",
9-
"Options:",
10-
" -h, --help Show help for any command",
11-
" -v, --version Output the CLI version number",
12-
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
13-
""
14-
],
15-
"convert": [
16-
"Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object.",
17-
"Returns a non-zero exit code if conversion fails.",
18-
"",
19-
"Usage:",
20-
" json-schema-to-openapi-schema convert [options] <file>",
21-
"",
22-
"Options:",
23-
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
24-
""
25-
]
26-
}
2+
"default": [
3+
"Usage:",
4+
" json-schema-to-openapi-schema <command> [options] <file>",
5+
"",
6+
"Commands:",
7+
" convert Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object",
8+
"",
9+
"Options:",
10+
" -h, --help Show help for any command",
11+
" -v, --version Output the CLI version number",
12+
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
13+
""
14+
],
15+
"convert": [
16+
"Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object.",
17+
"Returns a non-zero exit code if conversion fails.",
18+
"",
19+
"Usage:",
20+
" json-schema-to-openapi-schema convert [options] <file>",
21+
"",
22+
"Options:",
23+
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
24+
""
25+
]
26+
}

0 commit comments

Comments
 (0)