Skip to content

Commit bdac387

Browse files
BREAKING: Rewrote in TypeScript and added csm+cjs builds (#46)
* Rewrote in typescript, changed testing suite to vite, stricter types, created esm and cjs builds * remove unused deps Co-authored-by: JonLuca DeCaro <jonluca.decaro@gmail.com>
1 parent 51839c0 commit bdac387

Some content is hidden

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

66 files changed

+7459
-18343
lines changed

.editorconfig

Lines changed: 0 additions & 12 deletions
This file was deleted.

.eslintrc.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@ module.exports = {
33
browser: true,
44
commonjs: true,
55
es6: true,
6-
node: true
6+
node: true,
77
},
8-
extends: [
9-
"eslint:recommended"
10-
],
8+
extends: ["prettier", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
9+
parser: "@typescript-eslint/parser",
1110
globals: {
12-
Atomics: 'readonly',
13-
SharedArrayBuffer: 'readonly'
11+
Atomics: "readonly",
12+
SharedArrayBuffer: "readonly",
1413
},
1514
parserOptions: {
16-
ecmaVersion: 2018
15+
ecmaVersion: 2018,
1716
},
17+
plugins: ["prettier", "unused-imports", "@typescript-eslint"],
1818
rules: {
19-
}
20-
}
19+
"linebreak-style": ["error", "unix"],
20+
quotes: ["error", "double"],
21+
semi: ["error", "always"],
22+
"@typescript-eslint/no-explicit-any": "off",
23+
"@typescript-eslint/ban-ts-comment": "off",
24+
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
25+
"@typescript-eslint/consistent-type-imports": [
26+
"error",
27+
{
28+
prefer: "type-imports",
29+
},
30+
],
31+
},
32+
ignorePatterns: ["dist/**"],
33+
};

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
- uses: actions/setup-node@v3
1515
with:
1616
node-version: 18
17-
- run: npm ci
18-
- run: npm run build --if-present
19-
- run: npm test
17+
- run: yarn install --frozen-lockfile
18+
- run: yarn build
19+
- run: yarn test
2020
- run: npx semantic-release --branches main
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ jobs:
1212
- 16
1313
- 18
1414
steps:
15-
- uses: actions/checkout@v3
16-
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
- name: npm install, build, and test
21-
run: |
22-
npm ci
23-
npm run build --if-present
24-
npm test
25-
env:
26-
CI: true
15+
- uses: actions/checkout@v3
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- name: yarn install, build, and test
21+
run: |
22+
yarn --frozen-lockfile
23+
yarn build --if-present
24+
yarn lint
25+
yarn test
26+
env:
27+
CI: true

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
11
*.swp
2+
build.sh
3+
.coveralls.yml
4+
.node-version
5+
.nyc_output
6+
yarn.lock
7+
resolved.yaml
8+
9+
# Logs
10+
logs
11+
*.log
12+
npm-debug.log*
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# Grunt intermediate storage
21+
# (http://gruntjs.com/creating-plugins#storing-task-files)
22+
.grunt
23+
24+
# node-waf configuration
25+
.lock-wscript
26+
27+
# Compiled binary addons (http://nodejs.org/api/addons.html)
28+
build/Release
29+
30+
# Dependency directories
231
node_modules
32+
jspm_packages
33+
34+
# Optional npm cache directory
35+
.npm
36+
37+
# Optional REPL history
38+
.node_repl_history
39+
dist
340
.idea

README.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ If you need to do the conversion in reverse, checkout [json-schema-to-openapi-sc
1818

1919
## Features
2020

21-
* converts OpenAPI v3.0 Schema Object to JSON Schema Draft 4
22-
* converts OpenAPI v3.0 Parameter Object to JSON Schema Draft 4
23-
* deletes `nullable` and adds `"null"` to `type` array if `nullable` is `true`
24-
* supports deep structures with nested `allOf`s etc.
25-
* removes [OpenAPI specific properties](https://spec.openapis.org/oas/v3.0.3.html#fixed-fields-20) such as `discriminator`, `deprecated` etc. unless specified otherwise
26-
* optionally supports `patternProperties` with `x-patternProperties` in the Schema Object
21+
- converts OpenAPI v3.0 Schema Object to JSON Schema Draft 4
22+
- converts OpenAPI v3.0 Parameter Object to JSON Schema Draft 4
23+
- deletes `nullable` and adds `"null"` to `type` array if `nullable` is `true`
24+
- supports deep structures with nested `allOf`s etc.
25+
- removes [OpenAPI specific properties](https://spec.openapis.org/oas/v3.0.3.html#fixed-fields-20) such as `discriminator`, `deprecated` etc. unless specified otherwise
26+
- optionally supports `patternProperties` with `x-patternProperties` in the Schema Object
2727

2828
**NOTE**: `$ref`s are not handled in any way, so please use a resolver such as [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser) or [swagger-cli bundle](https://www.npmjs.com/package/swagger-cli) prior to using this package.
2929

@@ -38,13 +38,12 @@ npm install --save @openapi-contrib/openapi-schema-to-json-schema
3838
Here's a small example to get the idea:
3939

4040
```js
41-
42-
var toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema');
41+
var toJsonSchema = require("@openapi-contrib/openapi-schema-to-json-schema");
4342

4443
var schema = {
45-
type: 'string',
46-
format: 'date-time',
47-
nullable: true
44+
type: "string",
45+
format: "date-time",
46+
nullable: true,
4847
};
4948

5049
var convertedSchema = toJsonSchema(schema);
@@ -80,8 +79,8 @@ For example
8079

8180
```js
8281
var schema = {
83-
type: 'string',
84-
format: 'date'
82+
type: "string",
83+
format: "date",
8584
};
8685

8786
var convertedSchema = toJsonSchema(schema, { dateToDateTime: true });
@@ -128,16 +127,16 @@ See `test/pattern_properties.test.js` for examples how this works.
128127
OpenAPI parameters can be converted:
129128

130129
```js
131-
var toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema').fromParameter;
130+
var toJsonSchema = require("@openapi-contrib/openapi-schema-to-json-schema").fromParameter;
132131

133132
var param = {
134-
name: 'parameter name',
135-
in: 'query',
133+
name: "parameter name",
134+
in: "query",
136135
schema: {
137-
type: 'string',
138-
format: 'date'
139-
}
140-
}
136+
type: "string",
137+
format: "date",
138+
},
139+
};
141140

142141
var convertedSchema = toJsonSchema(param);
143142

@@ -200,10 +199,10 @@ This package is [Treeware](https://treeware.earth). If you use it in production,
200199
- [mikunn][] for originally creating this package.
201200
- [All Contributors][link-contributors]
202201

203-
[Stoplight]: https://stoplight.io/
202+
[stoplight]: https://stoplight.io/
204203
[mikunn]: https://github.com/mikunn
205204
[link-contributors]: https://github.com/openapi-contrib/openapi-schema-to-json-schema/graphs/contributors
206205

207-
## Copyright
206+
## Copyright
208207

209208
Copyright 2021 the [OpenAPI Contrib organization](https://github.com/openapi-contrib). Code released under the [MIT License](https://github.com/openapi-contrib/openapi-schema-to-json-schema/blob/main/LICENSE).

index.d.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

lib/convert.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/converters/parameter.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)