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

[Major Refactor] Native typescript support, circular references fix, vitest #29

Merged
merged 7 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 41 additions & 38 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
node: true
},
extends: [
'eslint:recommended'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2018
},
rules: {
indent: [
'error',
'tab',
{
SwitchCase: 1
}
],
'linebreak-style': [
'error',
'unix'
],
quotes: [
'error',
'single'
],
semi: [
'error',
'always'
]
}
}
env: {
browser: true,
commonjs: true,
es6: true,
node: true,
},
extends: [
'prettier',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
plugins: ['prettier', 'unused-imports', '@typescript-eslint'],
rules: {
indent: [
'error',
'tab',
{
SwitchCase: 1,
},
],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
},
],
},
};
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "lts/*"
node-version: 'lts/*'
- run: npm ci
- run: npm run build --if-present
- run: npm test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "lts/*"
node-version: 'lts/*'
- name: npm install, build, and test
run: |
npm ci
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jspm_packages

# Optional REPL history
.node_repl_history
dist
.idea
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog

All notable changes to this project will be documented in this file.

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

### Changed

- Moved over to the `@openapi-contrib` NPM organization.

## [0.4.0] - 2019-10-04

### Added

- Take the first JSON Schema `example` and put in OpenAPI Schema Object `example`

## [0.3.0] - 2018-12-18

### Added

- Create empty items, as it must always be present for type: array
- Rewrite exclusiveMinimum/exclusiveMaximum
- Rewrite if/then/else as oneOf + allOf
- Rewrite const as single element enum

## [0.2.0] - 2018-05-10

### Fixed

- Implemented [@cloudflare/json-schema-walker] to make sure all subschemas are
processed

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

## [0.1.1] - 2018-04-09

### Added

- Convert `dependencies` to an allOf + oneOf OpenAPI-valid equivalent
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ A little NodeJS package to convert JSON Schema to a [OpenAPI Schema Object](http

## Features

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

## Installation

``` shell
```shell
npm install --save @openapi-contrib/json-schema-to-openapi-schema
```

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

const schema = {
'$schema': 'http:https://json-schema.org/draft-04/schema#',
type: ['string', 'null'],
format: 'date-time',
$schema: 'http:https://json-schema.org/draft-04/schema#',
type: ['string', 'null'],
format: 'date-time',
};

(async () => {
const convertedSchema = await convert(schema);
console.log(convertedSchema);
const convertedSchema = await convert(schema);
console.log(convertedSchema);
})();

```

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

[mikunn]: https://github.com/mikunn
[WeWork]: https://github.com/wework
[Stoplight]: https://stoplight.io/
[Phil Sturgeon]: https://github.com/philsturgeon
[wework]: https://github.com/wework
[stoplight]: https://stoplight.io/
[phil sturgeon]: https://github.com/philsturgeon
[openapi-schema-to-json-schema]: https://github.com/openapi-contrib/openapi-schema-to-json-schema
[link-contributors]: https://github.com/openapi-contrib/json-schema-to-openapi-schema/graphs/contributors
50 changes: 25 additions & 25 deletions bin/help-text.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"default": [
"Usage:",
" json-schema-to-openapi-schema <command> [options] <file>",
"",
"Commands:",
" convert Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object",
"",
"Options:",
" -h, --help Show help for any command",
" -v, --version Output the CLI version number",
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
""
],
"convert": [
"Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object.",
"Returns a non-zero exit code if conversion fails.",
"",
"Usage:",
" json-schema-to-openapi-schema convert [options] <file>",
"",
"Options:",
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
""
]
}
"default": [
"Usage:",
" json-schema-to-openapi-schema <command> [options] <file>",
"",
"Commands:",
" convert Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object",
"",
"Options:",
" -h, --help Show help for any command",
" -v, --version Output the CLI version number",
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
""
],
"convert": [
"Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object.",
"Returns a non-zero exit code if conversion fails.",
"",
"Usage:",
" json-schema-to-openapi-schema convert [options] <file>",
"",
"Options:",
" -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced",
""
]
}
Loading