Skip to content

Commit d076cf0

Browse files
committed
fix(versioning): revert all commits from 3.2.0 onwards to create new minor release for 3.x
1 parent a7069d6 commit d076cf0

Some content is hidden

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

69 files changed

+18352
-8181
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
6+
[*.{ts,js,yaml,scenario,md}]
7+
indent_style = space
8+
indent_size = 2
9+
10+
[*.{ts,js}]
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.eslintrc.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,18 @@ module.exports = {
33
browser: true,
44
commonjs: true,
55
es6: true,
6-
node: true,
6+
node: true
77
},
8-
extends: ["prettier", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
9-
parser: "@typescript-eslint/parser",
8+
extends: [
9+
"eslint:recommended"
10+
],
1011
globals: {
11-
Atomics: "readonly",
12-
SharedArrayBuffer: "readonly",
12+
Atomics: 'readonly',
13+
SharedArrayBuffer: 'readonly'
1314
},
1415
parserOptions: {
15-
ecmaVersion: 2018,
16+
ecmaVersion: 2018
1617
},
17-
plugins: ["prettier", "unused-imports", "@typescript-eslint"],
1818
rules: {
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-
};
19+
}
20+
}

.github/workflows/release.yml

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

.github/workflows/test.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ jobs:
88
strategy:
99
matrix:
1010
node-version:
11-
- 18
11+
- 12
12+
- 14
13+
- 16
1214
steps:
13-
- uses: actions/checkout@v3
14-
- name: Use Node.js ${{ matrix.node-version }}
15-
uses: actions/setup-node@v3
16-
with:
17-
node-version: ${{ matrix.node-version }}
18-
- name: yarn install, build, and test
19-
run: |
20-
yarn --frozen-lockfile
21-
yarn build --if-present
22-
yarn lint
23-
yarn test
24-
env:
25-
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: npm install, build, and test
21+
run: |
22+
npm ci
23+
npm run build --if-present
24+
npm test
25+
env:
26+
CI: true

.gitignore

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
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
312
node_modules
32-
jspm_packages
33-
34-
# Optional npm cache directory
35-
.npm
36-
37-
# Optional REPL history
38-
.node_repl_history
39-
dist
403
.idea

README.md

Lines changed: 22 additions & 63 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,12 +38,13 @@ npm install --save @openapi-contrib/openapi-schema-to-json-schema
3838
Here's a small example to get the idea:
3939

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

4344
var schema = {
44-
type: "string",
45-
format: "date-time",
46-
nullable: true,
45+
type: 'string',
46+
format: 'date-time',
47+
nullable: true
4748
};
4849

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

8081
```js
8182
var schema = {
82-
type: "string",
83-
format: "date",
83+
type: 'string',
84+
format: 'date'
8485
};
8586

8687
var convertedSchema = toJsonSchema(schema, { dateToDateTime: true });
@@ -122,63 +123,21 @@ If the handler is not provided, the default handler is used. If `additionalPrope
122123

123124
See `test/pattern_properties.test.js` for examples how this works.
124125

125-
#### `definitionKeywords` (array)
126-
127-
By default, definitions are not converted. If your documents follow the convention of having a definitions object at the root of a (sub)schema, you can set definitionKeywords to `['definitions']`.
128-
129-
```js
130-
var schema = {
131-
definitions: {
132-
sharedDefinition: {
133-
type: "object",
134-
properties: {
135-
foo: {
136-
type: "string",
137-
nullable: true,
138-
},
139-
},
140-
},
141-
},
142-
};
143-
var convertedSchema = toJsonSchema(schema, {
144-
definitionKeywords: ["definitions"],
145-
});
146-
console.log(convertedSchema);
147-
```
148-
149-
prints
150-
151-
```js
152-
{
153-
$schema: 'http://json-schema.org/draft-04/schema#',
154-
definitions: {
155-
sharedDefinition: {
156-
type: 'object',
157-
properties: {
158-
foo: {
159-
type: ['string', 'null']
160-
}
161-
}
162-
}
163-
}
164-
}
165-
```
166-
167126
## Converting OpenAPI parameters
168127

169128
OpenAPI parameters can be converted:
170129

171130
```js
172-
var toJsonSchema = require("@openapi-contrib/openapi-schema-to-json-schema").fromParameter;
131+
var toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema').fromParameter;
173132

174133
var param = {
175-
name: "parameter name",
176-
in: "query",
134+
name: 'parameter name',
135+
in: 'query',
177136
schema: {
178-
type: "string",
179-
format: "date",
180-
},
181-
};
137+
type: 'string',
138+
format: 'date'
139+
}
140+
}
182141

183142
var convertedSchema = toJsonSchema(param);
184143

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

244-
[stoplight]: https://stoplight.io/
203+
[Stoplight]: https://stoplight.io/
245204
[mikunn]: https://github.com/mikunn
246205
[link-contributors]: https://github.com/openapi-contrib/openapi-schema-to-json-schema/graphs/contributors
247206

248-
## Copyright
207+
## Copyright
249208

250209
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
declare namespace OpenapiSchemaToJsonSchema {
2+
interface Options {
3+
dateToDateTime?: boolean;
4+
cloneSchema?: boolean;
5+
supportPatternProperties?: boolean;
6+
keepNotSupported?: NotSupported[];
7+
strictMode?: boolean;
8+
}
9+
type NotSupported =
10+
| "nullable"
11+
| "discriminator"
12+
| "readOnly"
13+
| "writeOnly"
14+
| "xml"
15+
| "externalDocs"
16+
| "example"
17+
| "deprecated";
18+
19+
function fromSchema<T = Record<string | number, any>>(
20+
schema: Record<string | number, any>,
21+
options?: Options
22+
): T;
23+
function fromParameter<T = Record<string | number, any>>(
24+
parameter: Record<string | number, any>,
25+
options?: Options
26+
): T;
27+
}
28+
declare function OpenapiSchemaToJsonSchema<T = Record<string | number, any>>(
29+
schema: Record<string | number, any>,
30+
options?: OpenapiSchemaToJsonSchema.Options
31+
): T;
32+
export = OpenapiSchemaToJsonSchema;

index.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var deepEqual = require('fast-deep-equal');
2+
var convert = require('./lib/convert');
3+
4+
module.exports = openapiSchemaToJsonSchema;
5+
module.exports.fromSchema = openapiSchemaToJsonSchema;
6+
module.exports.fromParameter = openapiParameterToJsonSchema;
7+
8+
function openapiSchemaToJsonSchema(schema, options) {
9+
options = resolveOptions(options);
10+
11+
var jsonSchema = convert.fromSchema(schema, options);
12+
return jsonSchema;
13+
}
14+
15+
function openapiParameterToJsonSchema(parameter, options) {
16+
options = resolveOptions(options);
17+
18+
var jsonSchema = convert.fromParameter(parameter, options);
19+
return jsonSchema;
20+
}
21+
22+
function resolveOptions(options) {
23+
var notSupported = [
24+
'nullable', 'discriminator', 'readOnly',
25+
'writeOnly', 'xml', 'externalDocs',
26+
'example', 'deprecated'
27+
];
28+
29+
options = options || {};
30+
options.dateToDateTime = options.dateToDateTime || false;
31+
options.cloneSchema = options.cloneSchema == false ? false : true;
32+
options.supportPatternProperties = options.supportPatternProperties || false;
33+
options.keepNotSupported = options.keepNotSupported || [];
34+
options.strictMode = options.strictMode == false ? false : true;
35+
36+
if (typeof options.patternPropertiesHandler !== 'function') {
37+
options.patternPropertiesHandler = patternPropertiesHandler;
38+
}
39+
40+
options._removeProps = [];
41+
42+
if (options.removeReadOnly === true) {
43+
options._removeProps.push('readOnly');
44+
}
45+
46+
if (options.removeWriteOnly === true) {
47+
options._removeProps.push('writeOnly');
48+
}
49+
50+
options._structs = ['allOf', 'anyOf', 'oneOf', 'not', 'items', 'additionalProperties'];
51+
options._notSupported = resolveNotSupported(notSupported, options.keepNotSupported);
52+
53+
return options;
54+
}
55+
56+
function patternPropertiesHandler(schema) {
57+
var pattern;
58+
var patternsObj = schema.patternProperties;
59+
var additProps = schema.additionalProperties;
60+
61+
if (typeof additProps !== 'object') {
62+
return schema;
63+
}
64+
65+
for (pattern in patternsObj) {
66+
if (deepEqual(patternsObj[pattern], additProps)) {
67+
schema.additionalProperties = false;
68+
break;
69+
}
70+
}
71+
72+
return schema;
73+
}
74+
75+
function resolveNotSupported(notSupported, toRetain) {
76+
var i = 0;
77+
var index;
78+
79+
for (i; i < toRetain.length; i++) {
80+
index = notSupported.indexOf(toRetain[i]);
81+
82+
if (index >= 0) {
83+
notSupported.splice(index, 1);
84+
}
85+
}
86+
87+
return notSupported;
88+
}

0 commit comments

Comments
 (0)