krakend-openapi-importer 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/lib/commands/import.rb +1 -1
- data/lib/importer/version.rb +1 -1
- data/lib/importer.rb +1 -1
- data/lib/writers/krakend_writer.rb +9 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a7b6aa237ddcad0132e8c293cd42181382f5f4e32cbf174b18c9760abb5120
|
4
|
+
data.tar.gz: 243242837fbc0ebca42f8e311eeb8da9a7a1aed32fc4b1f2d7ceddf9f70db7c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b6f24df2079fd9131a46a1cb2e19af2e17c4eba7a5b47db4b1fbccc57ed9c3d6b707663918117bf5f0d3b09bde7e8e122476eab8b8cfa2be6e8142af162ef1f
|
7
|
+
data.tar.gz: 67ec817c14e10bb62d087b7038750100fad0f3f219e32028d5531b054c2b74263df2ecdde38fb75fbdf6d35e196fa69bbb510c1f7a007b04eedc787e6471b9b4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -17,14 +17,14 @@ Execute
|
|
17
17
|
Import OpenAPI spec from SPEC file. Writes KrakenD config to output.json
|
18
18
|
|
19
19
|
```bash
|
20
|
-
krakend-openapi-importer import SPEC
|
20
|
+
krakend-openapi-importer import SPEC -c CONFIG
|
21
21
|
```
|
22
22
|
|
23
23
|
```bash
|
24
24
|
Options:
|
25
|
+
-c, --config=CONFIG # Path to importer.yaml config
|
25
26
|
-s, [--syntax=SYNTAX] # Specifies input data syntax: json or yaml. Defaults to json
|
26
27
|
# Default: json
|
27
|
-
-c, [--config=CONFIG] # Path to importer.yaml config
|
28
28
|
```
|
29
29
|
|
30
30
|
## Configuration
|
@@ -34,6 +34,7 @@ Example config
|
|
34
34
|
```yaml
|
35
35
|
---
|
36
36
|
all_roles: ['admin', 'guest'] # all available roles for JWT validator
|
37
|
+
pretty: false
|
37
38
|
defaults:
|
38
39
|
endpoint:
|
39
40
|
output_encoding: "no-op" # act like a no-op proxy
|
data/lib/commands/import.rb
CHANGED
@@ -19,7 +19,7 @@ module KrakendOpenAPI
|
|
19
19
|
def execute
|
20
20
|
paths = OA3Reader.new.read(@spec).paths
|
21
21
|
endpoints = OA3ToKrakendTransformer.new(@importer_config).transform_paths(paths)
|
22
|
-
KrakendWriter.new.write(endpoints)
|
22
|
+
KrakendWriter.new(@importer_config).write(endpoints)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/importer/version.rb
CHANGED
data/lib/importer.rb
CHANGED
@@ -7,9 +7,9 @@ module KrakendOpenAPI
|
|
7
7
|
# Importer CLI
|
8
8
|
class Importer < Thor
|
9
9
|
desc 'import SPEC', 'Import OpenAPI spec from SPEC file. Writes KrakenD config to output.json'
|
10
|
+
method_option :config, aliases: '-c', desc: 'Path to importer.yaml config', required: true
|
10
11
|
method_option :syntax, aliases: '-s', default: 'json',
|
11
12
|
desc: 'Specifies input data syntax: json or yaml. Defaults to json'
|
12
|
-
method_option :config, aliases: '-c', desc: 'Path to importer.yaml config'
|
13
13
|
def import(spec)
|
14
14
|
ImportCommand.new(spec: spec, syntax: options[:syntax], config: options[:config]).execute
|
15
15
|
end
|
@@ -5,16 +5,19 @@ require 'json'
|
|
5
5
|
module KrakendOpenAPI
|
6
6
|
# Writes KrakenD configuration to a file
|
7
7
|
class KrakendWriter
|
8
|
-
def initialize
|
8
|
+
def initialize(importer_config)
|
9
|
+
@importer_config = importer_config
|
9
10
|
@file_path = "#{Dir.pwd}/output.json"
|
10
11
|
end
|
11
12
|
|
12
13
|
def write(endpoints)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
pretty_output = !!@importer_config['pretty'] # rubocop:disable Style/DoubleNegation
|
15
|
+
json_generate = pretty_output ? ->(obj) { JSON.pretty_generate(obj) } : ->(obj) { JSON.dump(obj) }
|
16
|
+
File.write(@file_path, json_generate.call({
|
17
|
+
'$schema': 'https://www.krakend.io/schema/v3.json',
|
18
|
+
version: 3,
|
19
|
+
endpoints: endpoints
|
20
|
+
}))
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|