You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-29Lines changed: 48 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# OpenAPI Schema to JSON Schema
2
2
3
-
A little NodeJS package to convert OpenAPI Schema Object to JSON Schema. Currently converts from [OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md) to [JSON Schema Draft 4](http://json-schema.org/specification-links.html#draft-4).
3
+
A little NodeJS package to convert OpenAPI Schema Object to JSON Schema.
4
+
5
+
Currently converts from [OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md) to [JSON Schema Draft 4](http://json-schema.org/specification-links.html#draft-4).
4
6
5
7
## Why?
6
8
@@ -18,6 +20,7 @@ The purpose of this project is to fill the grap by doing the conversion between
18
20
* deletes `nullable` and adds `"null"` to `type` array if `nullable` is `true`
19
21
* supports deep structures with nested `allOf`s etc.
20
22
* removes [OpenAPI specific properties](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-20) such as `discriminator`, `deprecated` etc.
23
+
* optionally supports `patternProperties` with `x-patternProperties` in the Schema Object
21
24
22
25
**NOTE**: `$ref`s are not dereferenced. Use a dereferences such as [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser) prior to using this package.
23
26
@@ -59,31 +62,47 @@ Provide the function the schema object with possible options.
59
62
60
63
### Options
61
64
62
-
The function accepts `options` object as the second argument. Currently, the following options are supported:
63
-
*`cloneSchema` (boolean)
64
-
* If set to `false`, converts the provided schema in place. If `true`, clones the schema by converting it to JSON and back. The overhead of the cloning is usually negligible. Defaults to `true`.
65
-
*`dateToDateTime` (boolean)
66
-
* This is `false` by default and leaves `date` type/format as is. If set to `true`, sets `type: "string"` and `format: "date-time"` if
67
-
*`type: "string"` AND `format: "date"` OR
68
-
* `type: "date"`
69
-
* For example
70
-
71
-
```js
72
-
var schema = {
73
-
type: 'date',
74
-
};
75
-
76
-
var convertedSchema = toJsonSchema(schema, {dateToDateTime: true});
The function accepts `options` object as the second argument.
66
+
67
+
#### `cloneSchema` (boolean)
68
+
69
+
If set to `false`, converts the provided schema in place. If `true`, clones the schema by converting it to JSON and back. The overhead of the cloning is usually negligible. Defaults to `true`.
70
+
71
+
#### `dateToDateTime` (boolean)
72
+
73
+
This is `false` by default and leaves `date` type/format as is. If set to `true`, sets `type: "string"` and `format: "date-time"` if
74
+
*`type: "string"` AND `format: "date"` OR
75
+
*`type: "date"`
76
+
77
+
For example
78
+
79
+
```js
80
+
var schema = {
81
+
type:'date'
82
+
};
83
+
84
+
var convertedSchema =toJsonSchema(schema, {dateToDateTime:true});
If set to `true` and `x-patternProperties` property is present, change `x-patternProperties` to `patternProperty` and call `patternPropertiesHandler`. If `patternPropertiesHandler` is not defined, call the default handler. See `patternPropertiesHandler` for more information.
102
+
103
+
#### `patternPropertiesHandler` (function)
104
+
105
+
Provide a function to handle pattern properties. The function takes the schema where `x-patternProperties` is defined on the root level. At this point `x-patternProperties` is changed to `patternProperties`.
106
+
107
+
If the handler is not provided, the default handler is used. If `additionalProperties` is set and is an object, the default handler sets it to false if the root level `type` is the same as one of the types in `patternProperties` unless `type` is `object`. This is because we might want to define `additionalProperties` in OpenAPI spec file, but want to validate against a pattern. The pattern would turn out to be useless if `additionalProperties` of the same type were allowed.
0 commit comments