File tree Expand file tree Collapse file tree 1 file changed +81
-0
lines changed
Expand file tree Collapse file tree 1 file changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ # json-schema-to-openAPI-schema-object
2+
3+ Converts a standard JSON Schema to a compatible Open API v3 Schema Object
4+
5+ A json schema with definitions can be converted to an OpenAPI components object containing the main schema and the definitions:
6+
7+ ** simple.schema.json**
8+ ```
9+ {
10+ "$schema": "http://json-schema.org/draft-04/schema#",
11+ "title": "JSON API Schema",
12+ "description": "This is a schema for responses in the JSON API format. For more, see http://jsonapi.org",
13+ "type": "object",
14+ "required": [
15+ "errors"
16+ ],
17+ "properties": {
18+ "errors": {
19+ "type": "object",
20+ "properties": {
21+ "message": {
22+ "allOf": [
23+ {
24+ "$ref": "#/definitions/message"
25+ }
26+ ]
27+ }
28+ }
29+ }
30+ },
31+ "definitions": {
32+ "message": {
33+ "type": "string"
34+ }
35+ }
36+ }
37+ ```
38+
39+ This will return an object:
40+
41+ ```
42+ {
43+ schemas: {
44+ message: {
45+ "type": "string"
46+ }
47+ main: {
48+ "title": "JSON API Schema",
49+ "description": "This is a schema for responses in the JSON API format. For more, see http://jsonapi.org",
50+ "type": "object",
51+ "required": [
52+ "errors"
53+ ],
54+ "properties": {
55+ "errors": {
56+ "type": "object",
57+ "properties": {
58+ "message": {
59+ "allOf": [
60+ {
61+ "$ref": "#/components/schemas/message"
62+ }
63+ ]
64+ }
65+ }
66+ }
67+ }
68+ }
69+ }
70+ }
71+ ```
72+
73+ To run:
74+
75+ ```
76+ const jsonSchema = require('simple.json.schema')
77+ const Convertor = require('index')
78+
79+ const complexConvertor = new Convertor(complexOneOfSchema)
80+ const components = complexConvertor.convert()
81+ ```
You can’t perform that action at this time.
0 commit comments