krakend-openapi-importer 0.1.0 → 0.3.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 +7 -3
- data/lib/commands/import.rb +3 -3
- data/lib/importer/version.rb +1 -1
- data/lib/importer.rb +1 -1
- data/lib/readers/oa3_reader.rb +15 -10
- data/lib/transformers/oa3_transformer.rb +7 -4
- data/lib/writers/krakend_writer.rb +13 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eccd5c3cd0254e656a85647f09b55dc6ab23a2cbe12df54f300e9f55b6232680
|
4
|
+
data.tar.gz: 1c00cf1e660f5f2d0c56eb82eea50300448b433f6396476ec2c5d0b212720703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd2c84e3b98e8953a26b730804179c3b567ec0e3b70e242e53ab4d8d9fc52123894c174a82c382e405fbd09368c460b989c68bd27c107b2d2fd432dacafd466
|
7
|
+
data.tar.gz: b10e0267cd7a62694bfe94ce853fc5f648d3a88adacc667855d6fafb012084e7ece04a399960d0cdf8e531bfd27317fbebc4c16e9ff67ada60f0f74f7433f025
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Import endpoints from OpenAPI spec to KrakenD endpoint configuration. Supports OpenAPI v3.0 and up.
|
4
4
|
|
5
|
-
[](https://github.com/denblackstache/krakend-openapi-importer/actions/workflows/main.yml)
|
5
|
+
[](https://github.com/denblackstache/krakend-openapi-importer/actions/workflows/main.yml) [](https://badge.fury.io/rb/krakend-openapi-importer)
|
6
6
|
|
7
7
|
In case you have a different version of OpenAPI you can use https://github.com/LucyBot-Inc/api-spec-converter to convert to the v3.0.
|
8
8
|
|
@@ -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,11 +34,15 @@ Example config
|
|
34
34
|
```yaml
|
35
35
|
---
|
36
36
|
all_roles: ['admin', 'guest'] # all available roles for JWT validator
|
37
|
+
pretty: true
|
38
|
+
output: 'output.json'
|
37
39
|
defaults:
|
38
40
|
endpoint:
|
39
41
|
output_encoding: "no-op" # act like a no-op proxy
|
40
42
|
input_headers: [ "*" ]
|
41
43
|
input_query_strings: [ "*" ]
|
44
|
+
backend:
|
45
|
+
- encoding: "no-op"
|
42
46
|
plugins:
|
43
47
|
auth_validator:
|
44
48
|
alg: 'RS256'
|
data/lib/commands/import.rb
CHANGED
@@ -17,9 +17,9 @@ module KrakendOpenAPI
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def execute
|
20
|
-
paths = OA3Reader.new
|
21
|
-
endpoints = OA3ToKrakendTransformer.new(@importer_config).transform_paths
|
22
|
-
KrakendWriter.new
|
20
|
+
paths = OA3Reader.new(@spec).paths
|
21
|
+
endpoints = OA3ToKrakendTransformer.new(paths, @importer_config).transform_paths
|
22
|
+
KrakendWriter.new(endpoints, @importer_config).write
|
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
|
data/lib/readers/oa3_reader.rb
CHANGED
@@ -6,22 +6,27 @@ require_relative '../readers/yaml_reader'
|
|
6
6
|
module KrakendOpenAPI
|
7
7
|
# Reads OpenAPI spec files
|
8
8
|
class OA3Reader
|
9
|
-
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def paths
|
14
|
+
read unless @data
|
15
|
+
@data['paths']
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@data =
|
18
|
+
private
|
19
|
+
|
20
|
+
def read
|
21
|
+
if ['.json'].include?(File.extname(@path))
|
22
|
+
@data = JsonReader.new(@path).read
|
23
|
+
elsif %w[.yaml .yml].include?(File.extname(@path))
|
24
|
+
@data = YamlReader.new(@path).read
|
16
25
|
else
|
17
26
|
raise StandardError, 'OA3Reader does not support this format'
|
18
27
|
end
|
19
28
|
|
20
29
|
self
|
21
30
|
end
|
22
|
-
|
23
|
-
def paths
|
24
|
-
data['paths']
|
25
|
-
end
|
26
31
|
end
|
27
32
|
end
|
@@ -5,14 +5,17 @@ require_relative './jwt_validator_transformer'
|
|
5
5
|
module KrakendOpenAPI
|
6
6
|
# Transforms OpenAPI paths to KrakenD endpoints
|
7
7
|
class OA3ToKrakendTransformer
|
8
|
-
def initialize(importer_config)
|
8
|
+
def initialize(paths, importer_config)
|
9
|
+
@paths = paths
|
9
10
|
@importer_config = importer_config
|
10
11
|
end
|
11
12
|
|
12
|
-
def transform_paths
|
13
|
-
paths.map { |path, methods| transform_path(path, methods) }.flatten
|
13
|
+
def transform_paths
|
14
|
+
@paths.map { |path, methods| transform_path(path, methods) }.flatten
|
14
15
|
end
|
15
16
|
|
17
|
+
private
|
18
|
+
|
16
19
|
def transform_path(path, methods)
|
17
20
|
methods.map { |method, operation| transform_method(path, method, operation) }
|
18
21
|
end
|
@@ -32,7 +35,7 @@ module KrakendOpenAPI
|
|
32
35
|
output_encoding: @importer_config['defaults']['endpoint']['output_encoding'],
|
33
36
|
input_headers: @importer_config['defaults']['endpoint']['input_headers'],
|
34
37
|
input_query_strings: @importer_config['defaults']['endpoint']['input_query_strings'],
|
35
|
-
backend: [{ url_pattern: path }]
|
38
|
+
backend: [{ url_pattern: path, encoding: @importer_config['defaults']['backend'][0]['encoding'] }]
|
36
39
|
}
|
37
40
|
|
38
41
|
extra_config = plugins.each_with_object({}) do |plugin, memo|
|
@@ -5,16 +5,21 @@ require 'json'
|
|
5
5
|
module KrakendOpenAPI
|
6
6
|
# Writes KrakenD configuration to a file
|
7
7
|
class KrakendWriter
|
8
|
-
def initialize
|
9
|
-
@
|
8
|
+
def initialize(endpoints, importer_config)
|
9
|
+
@endpoints = endpoints
|
10
|
+
@importer_config = importer_config
|
11
|
+
@output = @importer_config['output'] || 'output.json'
|
12
|
+
@file_path = "#{Dir.pwd}/#{@output}"
|
10
13
|
end
|
11
14
|
|
12
|
-
def write
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def write
|
16
|
+
pretty_output = !!@importer_config['pretty'] # rubocop:disable Style/DoubleNegation
|
17
|
+
json_generate = pretty_output ? ->(obj) { JSON.pretty_generate(obj) } : ->(obj) { JSON.dump(obj) }
|
18
|
+
File.write(@file_path, json_generate.call({
|
19
|
+
'$schema': 'https://www.krakend.io/schema/v3.json',
|
20
|
+
version: 3,
|
21
|
+
endpoints: @endpoints
|
22
|
+
}))
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: krakend-openapi-importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Semenenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|