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
Converts a standard [JSON Schema](https://json-schema.org/understanding-json-schema/index.html) to a compatible [OpenAPI v3.0.X Schema Object](https://spec.openapis.org/oas/v3.0.3#schema-object).
8
13
9
-
As of version 0.3.0, it is now advised to run a schema through a de-referencer like: https://apitools.dev/json-schema-ref-parser/ to properly deal with `$ref`. I have removed my own poor implementation of de-referencing JSON schemas since there are libraries that can do it better than I can.
14
+
As of version 0.3.0, it is now advised to run a schema through a de-referencer like: https://apitools.dev/json-schema-ref-parser/ to properly deal with `$ref`. I have removed my own poor implementation of de-referencing JSON schemas since there are libraries that can do it better than I can.
10
15
11
-
It should be noted, that de-referencing libraries have their own issues and might not be able to properly parse your JSON/output a schema you might expect. Due to the way OpenAPI v3.0.X Schema Object's are handled, should the referencing not be 100% correct you might face issues using this library and its output to be used with OpenAPI 3.0.X.
16
+
It should be noted, that de-referencing libraries have their own issues and might not be able to properly parse your JSON/output a schema you might expect. Due to the way OpenAPI v3.0.X Schema Object's are handled, should the referencing not be 100% correct you might face issues using this library and its output to be used with OpenAPI 3.0.X.
12
17
13
18
## Conversions
14
19
15
-
This attempts to massage the standard JSON Schema to a compatible OpenAPI v3.0.X Schema Object. There are many properties that are not supported by OpenAPI v3.0.X Schema Object, though have now been supported by [OpenAPI v3.1.X](https://spec.openapis.org/oas/v3.1.0#schema-object). This library should only be used if working with OpenAPI v3.0.X.
20
+
This attempts to massage the standard JSON Schema to a compatible OpenAPI v3.0.X Schema Object. There are many properties that are not supported by OpenAPI v3.0.X Schema Object, though have now been supported by [OpenAPI v3.1.X](https://spec.openapis.org/oas/v3.1.0#schema-object). This library should only be used if working with OpenAPI v3.0.X.
16
21
17
22
### Items as an Array to Object
18
23
19
24
This will convert a schema of:
25
+
20
26
```json
21
27
{
22
-
"type": "object",
23
-
"properties": {
24
-
"example": {
25
-
"type": "array",
26
-
"items": [
27
-
{
28
-
"type": "string"
29
-
}
30
-
]
28
+
"type": "object",
29
+
"properties": {
30
+
"example": {
31
+
"type": "array",
32
+
"items": [
33
+
{
34
+
"type": "string"
31
35
}
36
+
]
32
37
}
38
+
}
33
39
}
34
40
```
35
41
36
42
To:
37
43
38
44
```json
39
45
{
40
-
"type": "object",
41
-
"properties": {
42
-
"example": {
43
-
"type": "array",
44
-
"items": {
45
-
"type": "string"
46
-
}
47
-
}
46
+
"type": "object",
47
+
"properties": {
48
+
"example": {
49
+
"type": "array",
50
+
"items": {
51
+
"type": "string"
52
+
}
48
53
}
54
+
}
49
55
}
50
56
```
51
57
@@ -57,67 +63,67 @@ This will convert a schema of:
57
63
58
64
```json
59
65
{
60
-
"type": "object",
61
-
"properties": {
62
-
"example": {
63
-
"type": ["string", "number"],
64
-
}
66
+
"type": "object",
67
+
"properties": {
68
+
"example": {
69
+
"type": ["string", "number"]
65
70
}
71
+
}
66
72
}
67
73
```
68
74
69
75
To:
70
76
71
77
```json
72
78
{
73
-
"type": "object",
74
-
"properties": {
75
-
"example": {
76
-
"oneOf": [
77
-
{
78
-
"type": "string"
79
-
},
80
-
{
81
-
"type": "number"
82
-
}
83
-
]
79
+
"type": "object",
80
+
"properties": {
81
+
"example": {
82
+
"oneOf": [
83
+
{
84
+
"type": "string"
85
+
},
86
+
{
87
+
"type": "number"
84
88
}
89
+
]
85
90
}
91
+
}
86
92
}
87
93
```
88
94
89
95
Where an array contains `null`, it will now set `nullable` against all types:
90
96
91
97
```json
92
98
{
93
-
"type": "object",
94
-
"properties": {
95
-
"example": {
96
-
"type": ["string", "number", "null"],
97
-
}
99
+
"type": "object",
100
+
"properties": {
101
+
"example": {
102
+
"type": ["string", "number", "null"]
98
103
}
104
+
}
99
105
}
100
106
```
101
107
102
108
To:
103
109
104
110
```json
105
111
{
106
-
"type": "object",
107
-
"properties": {
108
-
"example": {
109
-
"oneOf": [
110
-
{
111
-
"type": "string",
112
-
"nullable": true
113
-
},
114
-
{
115
-
"type": "number",
116
-
"nullable": true
117
-
}
118
-
]
112
+
"type": "object",
113
+
"properties": {
114
+
"example": {
115
+
"oneOf": [
116
+
{
117
+
"type": "string",
118
+
"nullable": true
119
+
},
120
+
{
121
+
"type": "number",
122
+
"nullable": true
119
123
}
124
+
]
120
125
}
126
+
}
121
127
}
122
128
```
123
129
@@ -127,27 +133,27 @@ This will convert a schema of:
127
133
128
134
```json
129
135
{
130
-
"type": "object",
131
-
"properties": {
132
-
"example": {
133
-
"type": "string",
134
-
"const": "Surburbia"
135
-
}
136
+
"type": "object",
137
+
"properties": {
138
+
"example": {
139
+
"type": "string",
140
+
"const": "Surburbia"
136
141
}
142
+
}
137
143
}
138
144
```
139
145
140
146
To:
141
147
142
148
```json
143
149
{
144
-
"type": "object",
145
-
"properties": {
146
-
"example": {
147
-
"type": "string",
148
-
"enum": ["Surburbia"]
149
-
}
150
+
"type": "object",
151
+
"properties": {
152
+
"example": {
153
+
"type": "string",
154
+
"enum": ["Surburbia"]
150
155
}
156
+
}
151
157
}
152
158
```
153
159
@@ -157,31 +163,31 @@ OpenAPI 3.0.X does not allow for null as a type, so will convert a schema of:
157
163
158
164
```json
159
165
{
160
-
"type": "object",
161
-
"properties": {
162
-
"example": {
163
-
"type": "null",
164
-
}
166
+
"type": "object",
167
+
"properties": {
168
+
"example": {
169
+
"type": "null"
165
170
}
171
+
}
166
172
}
167
173
```
168
174
169
175
To:
170
176
171
177
```json
172
178
{
173
-
"type": "object",
174
-
"properties": {
175
-
"example": {
176
-
"nullable": true,
177
-
}
179
+
"type": "object",
180
+
"properties": {
181
+
"example": {
182
+
"nullable": true
178
183
}
184
+
}
179
185
}
180
186
```
181
187
182
188
### Default to their type
183
189
184
-
This will convert the `"default":` value to the relevant type. A String to a String, a Number/Integer to a number/Integer, a Boolean to a Boolean and try to manipulate an Object or an Array to either an Object or an Array
190
+
This will convert the `"default":` value to the relevant type. A String to a String, a Number/Integer to a number/Integer, a Boolean to a Boolean and try to manipulate an Object or an Array to either an Object or an Array
0 commit comments