Skip to content

Commit

Permalink
fix(versioning): revert all commits from 3.2.0 onwards to create new …
Browse files Browse the repository at this point in the history
…minor release for 3.x
  • Loading branch information
jonluca committed Mar 30, 2023
1 parent a7069d6 commit d076cf0
Show file tree
Hide file tree
Showing 69 changed files with 18,352 additions and 8,181 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8

[*.{ts,js,yaml,scenario,md}]
indent_style = space
indent_size = 2

[*.{ts,js}]
trim_trailing_whitespace = true
insert_final_newline = true
31 changes: 9 additions & 22 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,18 @@ module.exports = {
browser: true,
commonjs: true,
es6: true,
node: true,
node: true
},
extends: ["prettier", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended"
],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2018
},
plugins: ["prettier", "unused-imports", "@typescript-eslint"],
rules: {
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
semi: ["error", "always"],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
},
],
},
ignorePatterns: ["dist/**"],
};
}
}
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test
node-version: "12.x"
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npx semantic-release --branches main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
29 changes: 15 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ jobs:
strategy:
matrix:
node-version:
- 18
- 12
- 14
- 16
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: yarn install, build, and test
run: |
yarn --frozen-lockfile
yarn build --if-present
yarn lint
yarn test
env:
CI: true
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm ci
npm run build --if-present
npm test
env:
CI: true
37 changes: 0 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
*.swp
build.sh
.coveralls.yml
.node-version
.nyc_output
yarn.lock
resolved.yaml

# Logs
logs
*.log
npm-debug.log*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage
# (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
dist
.idea
85 changes: 22 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ If you need to do the conversion in reverse, checkout [json-schema-to-openapi-sc

## Features

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

**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.

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

```js
var toJsonSchema = require("@openapi-contrib/openapi-schema-to-json-schema");

var toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema');

var schema = {
type: "string",
format: "date-time",
nullable: true,
type: 'string',
format: 'date-time',
nullable: true
};

var convertedSchema = toJsonSchema(schema);
Expand Down Expand Up @@ -79,8 +80,8 @@ For example

```js
var schema = {
type: "string",
format: "date",
type: 'string',
format: 'date'
};

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

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

#### `definitionKeywords` (array)

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']`.

```js
var schema = {
definitions: {
sharedDefinition: {
type: "object",
properties: {
foo: {
type: "string",
nullable: true,
},
},
},
},
};
var convertedSchema = toJsonSchema(schema, {
definitionKeywords: ["definitions"],
});
console.log(convertedSchema);
```

prints

```js
{
$schema: 'http://json-schema.org/draft-04/schema#',
definitions: {
sharedDefinition: {
type: 'object',
properties: {
foo: {
type: ['string', 'null']
}
}
}
}
}
```

## Converting OpenAPI parameters

OpenAPI parameters can be converted:

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

var param = {
name: "parameter name",
in: "query",
name: 'parameter name',
in: 'query',
schema: {
type: "string",
format: "date",
},
};
type: 'string',
format: 'date'
}
}

var convertedSchema = toJsonSchema(param);

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

[stoplight]: https://stoplight.io/
[Stoplight]: https://stoplight.io/
[mikunn]: https://github.com/mikunn
[link-contributors]: https://github.com/openapi-contrib/openapi-schema-to-json-schema/graphs/contributors

## Copyright
## Copyright

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).
32 changes: 32 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
declare namespace OpenapiSchemaToJsonSchema {
interface Options {
dateToDateTime?: boolean;
cloneSchema?: boolean;
supportPatternProperties?: boolean;
keepNotSupported?: NotSupported[];
strictMode?: boolean;
}
type NotSupported =
| "nullable"
| "discriminator"
| "readOnly"
| "writeOnly"
| "xml"
| "externalDocs"
| "example"
| "deprecated";

function fromSchema<T = Record<string | number, any>>(
schema: Record<string | number, any>,
options?: Options
): T;
function fromParameter<T = Record<string | number, any>>(
parameter: Record<string | number, any>,
options?: Options
): T;
}
declare function OpenapiSchemaToJsonSchema<T = Record<string | number, any>>(
schema: Record<string | number, any>,
options?: OpenapiSchemaToJsonSchema.Options
): T;
export = OpenapiSchemaToJsonSchema;
88 changes: 88 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
var deepEqual = require('fast-deep-equal');
var convert = require('./lib/convert');

module.exports = openapiSchemaToJsonSchema;
module.exports.fromSchema = openapiSchemaToJsonSchema;
module.exports.fromParameter = openapiParameterToJsonSchema;

function openapiSchemaToJsonSchema(schema, options) {
options = resolveOptions(options);

var jsonSchema = convert.fromSchema(schema, options);
return jsonSchema;
}

function openapiParameterToJsonSchema(parameter, options) {
options = resolveOptions(options);

var jsonSchema = convert.fromParameter(parameter, options);
return jsonSchema;
}

function resolveOptions(options) {
var notSupported = [
'nullable', 'discriminator', 'readOnly',
'writeOnly', 'xml', 'externalDocs',
'example', 'deprecated'
];

options = options || {};
options.dateToDateTime = options.dateToDateTime || false;
options.cloneSchema = options.cloneSchema == false ? false : true;
options.supportPatternProperties = options.supportPatternProperties || false;
options.keepNotSupported = options.keepNotSupported || [];
options.strictMode = options.strictMode == false ? false : true;

if (typeof options.patternPropertiesHandler !== 'function') {
options.patternPropertiesHandler = patternPropertiesHandler;
}

options._removeProps = [];

if (options.removeReadOnly === true) {
options._removeProps.push('readOnly');
}

if (options.removeWriteOnly === true) {
options._removeProps.push('writeOnly');
}

options._structs = ['allOf', 'anyOf', 'oneOf', 'not', 'items', 'additionalProperties'];
options._notSupported = resolveNotSupported(notSupported, options.keepNotSupported);

return options;
}

function patternPropertiesHandler(schema) {
var pattern;
var patternsObj = schema.patternProperties;
var additProps = schema.additionalProperties;

if (typeof additProps !== 'object') {
return schema;
}

for (pattern in patternsObj) {
if (deepEqual(patternsObj[pattern], additProps)) {
schema.additionalProperties = false;
break;
}
}

return schema;
}

function resolveNotSupported(notSupported, toRetain) {
var i = 0;
var index;

for (i; i < toRetain.length; i++) {
index = notSupported.indexOf(toRetain[i]);

if (index >= 0) {
notSupported.splice(index, 1);
}
}

return notSupported;
}
Loading

0 comments on commit d076cf0

Please sign in to comment.