open_api_2_json_schema 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +40 -0
- data/lib/attribute_handlers/discriminator.rb +18 -0
- data/lib/open_api_2_json_schema/version.rb +1 -1
- data/lib/open_api_2_json_schema.rb +8 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f25b393383b6694b23d0306c5a48f91762ba658afbd488c15fa16c40cbfa246
|
4
|
+
data.tar.gz: 5bc71e2ab8ff4019428686c39b17cc46f8ea5445d4d181af6fca65aa41b8cdd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3263c6c3f5372ff6e6cc93a812ce429ce1ab03d64b1d7eb5cfb23e9291f48b162accca973247dfca2fbc1da1b851089d5a4b21d663cfd0a300fe4fb368f69c1c
|
7
|
+
data.tar.gz: 828d603767e21eab7b4197d4e3c8217b0cd816464e1726916c9e42571b09c0bcfdff8e1e3622f0f07928f74b67f6d54c87c752ec890dc0902119343181518ce8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,46 @@ schema = {
|
|
34
34
|
OpenApi2JsonSchema.convert(schema)
|
35
35
|
```
|
36
36
|
|
37
|
+
### Discriminator
|
38
|
+
|
39
|
+
```yaml
|
40
|
+
# Sample YAML file
|
41
|
+
schema:
|
42
|
+
discriminator:
|
43
|
+
propertyName: key
|
44
|
+
mapping:
|
45
|
+
value1: 'path-to-file-2.yml'
|
46
|
+
value2: 'path-to-file-2.yml'
|
47
|
+
properties:
|
48
|
+
key:
|
49
|
+
type: string
|
50
|
+
enum:
|
51
|
+
- value1
|
52
|
+
- value2
|
53
|
+
```
|
54
|
+
|
55
|
+
```json
|
56
|
+
"schema": {
|
57
|
+
"properties": {
|
58
|
+
"key": {
|
59
|
+
"type": "string",
|
60
|
+
"enum": ["value1", "value2"]
|
61
|
+
}
|
62
|
+
},
|
63
|
+
"discriminator": {
|
64
|
+
"propertyName": "name",
|
65
|
+
"mapping": {
|
66
|
+
"value1": {
|
67
|
+
"type": "object"
|
68
|
+
},
|
69
|
+
"value2": {
|
70
|
+
"type": "array"
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
37
77
|
## Development
|
38
78
|
|
39
79
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../ref_schema_parser"
|
2
|
+
|
3
|
+
module OpenApi2JsonSchema
|
4
|
+
module AttributeHandlers
|
5
|
+
class Discriminator
|
6
|
+
def call(discriminator_schema)
|
7
|
+
raise "discriminator schema must be a Hash" unless discriminator_schema.is_a?(Hash)
|
8
|
+
|
9
|
+
mapping = discriminator_schema.fetch("mapping")
|
10
|
+
mapping.each do |key, file_path|
|
11
|
+
mapping[key] = OpenApi2JsonSchema::RefSchemaParser.new.call(file_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
discriminator_schema
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -4,13 +4,14 @@ require 'json'
|
|
4
4
|
require 'yaml'
|
5
5
|
require_relative "open_api_2_json_schema/version"
|
6
6
|
require_relative 'attribute_handlers/all_of'
|
7
|
+
require_relative 'attribute_handlers/discriminator'
|
7
8
|
|
8
9
|
module OpenApi2JsonSchema
|
9
10
|
module_function
|
10
11
|
|
11
|
-
STRUCTS = ['allOf', 'anyOf', 'oneOf', 'not', 'items', 'additionalProperties', 'schema']
|
12
|
+
STRUCTS = ['allOf', 'anyOf', 'oneOf', 'not', 'items', 'additionalProperties', 'schema', 'discriminator']
|
12
13
|
NOT_SUPPORTED = [
|
13
|
-
'nullable', '
|
14
|
+
'nullable', 'readOnly',
|
14
15
|
'writeOnly', 'xml', 'externalDocs',
|
15
16
|
'example', 'deprecated'
|
16
17
|
]
|
@@ -59,7 +60,11 @@ module OpenApi2JsonSchema
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
when Hash
|
62
|
-
|
63
|
+
if struct == 'discriminator'
|
64
|
+
json_schema[struct] = AttributeHandlers::Discriminator.new.call(data)
|
65
|
+
else
|
66
|
+
json_schema[struct] = convert_schema(data)
|
67
|
+
end
|
63
68
|
else
|
64
69
|
# ignore
|
65
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_api_2_json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hieuk09
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Due to the OpenAPI v3.0 and JSON Schema discrepancy, you can use this
|
14
14
|
JS library to convert OpenAPI Schema objects to proper JSON Schema. '
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- bin/console
|
29
29
|
- bin/setup
|
30
30
|
- lib/attribute_handlers/all_of.rb
|
31
|
+
- lib/attribute_handlers/discriminator.rb
|
31
32
|
- lib/open_api_2_json_schema.rb
|
32
33
|
- lib/open_api_2_json_schema/version.rb
|
33
34
|
- lib/ref_schema_parser.rb
|