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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcf0121c7781a444cd9a6bc8201f03375b48931608fa9cb74da2c2baa03be0bf
4
- data.tar.gz: 480d12883093ede9c9d7d712d730496d91fee39741b2a58fc21eb18f6811701f
3
+ metadata.gz: d1a7b6aa237ddcad0132e8c293cd42181382f5f4e32cbf174b18c9760abb5120
4
+ data.tar.gz: 243242837fbc0ebca42f8e311eeb8da9a7a1aed32fc4b1f2d7ceddf9f70db7c7
5
5
  SHA512:
6
- metadata.gz: d93e9f5bff44369fb37669daf610baa79465dd40eae0f9fb43dd301da2198ed1a59dbfa6239d665052ce3d63b25a01956d78ffb6265cd8206981e359c51546c9
7
- data.tar.gz: 552b075ed012355bb4381b1a057aeed02054a71c644eceafde7ea466c342ecfe21a29542a01f30d0364cd2aae2a941398951380ea5e4ed62bf2d9564f7774077
6
+ metadata.gz: 9b6f24df2079fd9131a46a1cb2e19af2e17c4eba7a5b47db4b1fbccc57ed9c3d6b707663918117bf5f0d3b09bde7e8e122476eab8b8cfa2be6e8142af162ef1f
7
+ data.tar.gz: 67ec817c14e10bb62d087b7038750100fad0f3f219e32028d5531b054c2b74263df2ecdde38fb75fbdf6d35e196fa69bbb510c1f7a007b04eedc787e6471b9b4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- krakend-openapi-importer (0.1.0)
4
+ krakend-openapi-importer (0.2.0)
5
5
  thor (~> 1.2)
6
6
 
7
7
  GEM
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KrakendOpenAPI
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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
- File.write(@file_path, JSON.dump({
14
- '$schema': 'https://www.krakend.io/schema/v3.json',
15
- version: 3,
16
- endpoints: endpoints
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krakend-openapi-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Semenenko