openapi-sourcetools 0.7.0 → 0.8.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/bin/openapi-addheaders +11 -11
- data/bin/openapi-addparameters +52 -12
- data/bin/openapi-addresponses +11 -12
- data/bin/openapi-addschemas +41 -17
- data/bin/openapi-checkschemas +21 -21
- data/bin/openapi-frequencies +24 -26
- data/bin/openapi-generate +15 -12
- data/bin/openapi-merge +21 -15
- data/bin/openapi-modifypaths +17 -16
- data/bin/openapi-processpaths +16 -27
- data/lib/openapi/sourcetools/apiobjects.rb +191 -0
- data/lib/openapi/sourcetools/common.rb +82 -0
- data/lib/openapi/sourcetools/config.rb +158 -0
- data/lib/openapi/sourcetools/docs.rb +41 -0
- data/lib/{gen.rb → openapi/sourcetools/gen.rb} +38 -13
- data/lib/openapi/sourcetools/generate.rb +96 -0
- data/lib/openapi/sourcetools/helper.rb +93 -0
- data/lib/openapi/sourcetools/loaders.rb +164 -0
- data/lib/openapi/sourcetools/output.rb +83 -0
- data/lib/openapi/sourcetools/securityschemes.rb +268 -0
- data/lib/openapi/sourcetools/task.rb +137 -0
- data/lib/openapi/sourcetools/version.rb +13 -0
- data/lib/openapi/sourcetools.rb +15 -0
- metadata +42 -18
- data/lib/apiobjects.rb +0 -333
- data/lib/common.rb +0 -110
- data/lib/docs.rb +0 -33
- data/lib/generate.rb +0 -90
- data/lib/helper.rb +0 -94
- data/lib/loaders.rb +0 -96
- data/lib/output.rb +0 -58
- data/lib/task.rb +0 -101
data/lib/loaders.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright © 2024 Ismo Kärkkäinen
|
4
|
-
# Licensed under Universal Permissive License. See LICENSE.txt.
|
5
|
-
|
6
|
-
|
7
|
-
# Original loader functions. These are accessible via Gen.loaders. New loaders
|
8
|
-
# should be added there.
|
9
|
-
module Loaders
|
10
|
-
|
11
|
-
GEM_PREFIX = 'gem:'
|
12
|
-
|
13
|
-
def self.gem_loader(name)
|
14
|
-
return false unless name.downcase.start_with?(GEM_PREFIX)
|
15
|
-
begin
|
16
|
-
require(name.slice(GEM_PREFIX.size...name.size))
|
17
|
-
rescue LoadError => e
|
18
|
-
raise StandardError, "Failed to require #{name}\n#{e.to_s}"
|
19
|
-
rescue Exception => e
|
20
|
-
raise StandardError, "Problem with #{name}\n#{e.to_s}"
|
21
|
-
end
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
|
-
RUBY_EXT = '.rb'
|
26
|
-
|
27
|
-
def self.ruby_loader(name)
|
28
|
-
return false unless name.downcase.end_with?(RUBY_EXT)
|
29
|
-
origwd = Dir.pwd
|
30
|
-
d = File.dirname(name)
|
31
|
-
Dir.chdir(d) unless d == '.'
|
32
|
-
begin
|
33
|
-
require(File.join(Dir.pwd, File.basename(name)))
|
34
|
-
rescue LoadError => e
|
35
|
-
raise StandardError, "Failed to require #{name}\n#{e.to_s}"
|
36
|
-
rescue Exception => e
|
37
|
-
raise StandardError, "Problem with #{name}\n#{e.to_s}"
|
38
|
-
end
|
39
|
-
Dir.chdir(origwd) unless d == '.'
|
40
|
-
true
|
41
|
-
end
|
42
|
-
|
43
|
-
YAML_PREFIX = 'yaml:'
|
44
|
-
YAML_EXTS = [ '.yaml', '.yml' ]
|
45
|
-
|
46
|
-
def self.yaml_loader(name)
|
47
|
-
d = name.downcase
|
48
|
-
if d.start_with?(YAML_PREFIX)
|
49
|
-
name = name.slice(YAML_PREFIX.size...name.size)
|
50
|
-
else
|
51
|
-
return false if (YAML_EXTS.index { |s| d.end_with?(s) }).nil?
|
52
|
-
end
|
53
|
-
n, sep, f = name.partition(':')
|
54
|
-
raise StandardError, "No name given." if n.empty?
|
55
|
-
raise StandardError, "No filename given." if f.empty?
|
56
|
-
doc = YAML.safe_load(File.read(f))
|
57
|
-
raise StandardError, "#{name} #{n} exists already." unless Gen.d.add(n, doc)
|
58
|
-
true
|
59
|
-
rescue Errno::ENOENT
|
60
|
-
raise StandardError, "Not found: #{f}\n#{e.to_s}"
|
61
|
-
rescue Exception => e
|
62
|
-
raise StandardError, "Failed to read as YAML: #{f}\n#{e.to_s}"
|
63
|
-
end
|
64
|
-
|
65
|
-
BIN_PREFIX = 'bin:'
|
66
|
-
|
67
|
-
def self.bin_loader(name)
|
68
|
-
return false unless name.downcase.start_with?(BIN_PREFIX)
|
69
|
-
n, sep, f = name.slice(BIN_PREFIX.size...name.size).partition(':')
|
70
|
-
raise StandardError, "No name given." if n.empty?
|
71
|
-
raise StandardError, "No filename given." if f.empty?
|
72
|
-
doc = IO.binread(f)
|
73
|
-
raise StandardError, "#{name} #{n} exists already." unless Gen.d.add(n, doc)
|
74
|
-
true
|
75
|
-
rescue Errno::ENOENT
|
76
|
-
raise StandardError, "Not found: #{f}\n#{e.to_s}"
|
77
|
-
rescue Exception => e
|
78
|
-
raise StandardError, "Failed to read #{f}\n#{e.to_s}"
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.loaders
|
82
|
-
pre = @preloaders
|
83
|
-
[ method(:gem_loader), method(:ruby_loader), method(:yaml_loader), method(:bin_loader) ]
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.document
|
87
|
-
%(
|
88
|
-
- #{Loaders::GEM_PREFIX}gem_name : requires the gem.
|
89
|
-
- ruby_file#{Loaders::RUBY_EXT} : changes to Ruby file directory and requires the file.
|
90
|
-
- #{Loaders::YAML_PREFIX}name:filename : Loads YAML file into Gen.d.name.
|
91
|
-
- name:filename.{#{(Loaders::YAML_EXTS.map { |s| s[1...s.size] }).join('|')}} : Loads YAML file into Gen.d.name.
|
92
|
-
- #{Loaders::BIN_PREFIX}name:filename : Loads binary file into Gen.d.name.
|
93
|
-
)
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
data/lib/output.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright © 2024 Ismo Kärkkäinen
|
4
|
-
# Licensed under Universal Permissive License. See LICENSE.txt.
|
5
|
-
|
6
|
-
require_relative 'task'
|
7
|
-
|
8
|
-
|
9
|
-
class Output
|
10
|
-
# For indentation.
|
11
|
-
attr_accessor :indent_character, :indent_step
|
12
|
-
attr_accessor :tab, :tab_replaces_count
|
13
|
-
attr_accessor :last_indent
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@indent_character = ' '
|
17
|
-
@indent_step = 4
|
18
|
-
@tab = "\t"
|
19
|
-
@tab_replaces_count = 0
|
20
|
-
@last_indent = 0
|
21
|
-
end
|
22
|
-
|
23
|
-
def join(blocks, separator = "\n")
|
24
|
-
indented = []
|
25
|
-
blocks.flatten!
|
26
|
-
indent = 0
|
27
|
-
blocks.each do |block|
|
28
|
-
if block.nil?
|
29
|
-
indent = 0
|
30
|
-
elsif block.is_a?(Integer)
|
31
|
-
indent += block
|
32
|
-
elsif block.is_a?(TrueClass)
|
33
|
-
indent += @indent_step
|
34
|
-
elsif block.is_a?(FalseClass)
|
35
|
-
indent -= @indent_step
|
36
|
-
else
|
37
|
-
block = block.to_s unless block.is_a?(String)
|
38
|
-
if indent.zero?
|
39
|
-
indented.push(block)
|
40
|
-
next
|
41
|
-
end
|
42
|
-
if 0 < @tab_replaces_count
|
43
|
-
tabs = @tab * (indent / @tab_replaces_count)
|
44
|
-
chars = @indent_character * (indent % @tab_replaces_count)
|
45
|
-
else
|
46
|
-
tabs = ''
|
47
|
-
chars = @indent_character * indent
|
48
|
-
end
|
49
|
-
lines = block.lines(chomp: true)
|
50
|
-
lines.each do |line|
|
51
|
-
indented.push("#{tabs}#{chars}#{line}")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
@last_indent = indent
|
56
|
-
indented.join(separator)
|
57
|
-
end
|
58
|
-
end
|
data/lib/task.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright © 2024 Ismo Kärkkäinen
|
4
|
-
# Licensed under Universal Permissive License. See LICENSE.txt.
|
5
|
-
|
6
|
-
require 'erb'
|
7
|
-
require_relative 'common'
|
8
|
-
|
9
|
-
|
10
|
-
module TaskInterface
|
11
|
-
def generate(context_binding)
|
12
|
-
raise NotImplementedError
|
13
|
-
end
|
14
|
-
|
15
|
-
def output_name
|
16
|
-
raise NotImplementedError
|
17
|
-
end
|
18
|
-
|
19
|
-
def discard
|
20
|
-
false
|
21
|
-
end
|
22
|
-
|
23
|
-
def executable
|
24
|
-
false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Task
|
29
|
-
include TaskInterface
|
30
|
-
|
31
|
-
attr_reader :src, :template, :template_name
|
32
|
-
attr_accessor :name, :executable, :discard, :x
|
33
|
-
|
34
|
-
def initialize(src, template, template_name)
|
35
|
-
@src = src
|
36
|
-
@template = template
|
37
|
-
@template_name = template_name
|
38
|
-
if @template.nil?
|
39
|
-
raise ArgumentError, "template_name or template must be given" if @template_name.nil?
|
40
|
-
begin
|
41
|
-
@template = File.read(@template_name)
|
42
|
-
rescue Errno::ENOENT
|
43
|
-
raise StandardError, "Could not load #{@template_name}"
|
44
|
-
rescue StandardError => e
|
45
|
-
raise StandardError, "#{e}\nFailed to read #{@template_name}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
@name = nil
|
49
|
-
@executable = false
|
50
|
-
@discard = false
|
51
|
-
@x = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
# If this is overridden to perform some processing but not to produce output,
|
55
|
-
# set @discard = true and return value will be ignored. No other methods are
|
56
|
-
# called in that case.
|
57
|
-
def internal_generate(context_binding)
|
58
|
-
ERB.new(@template).result(context_binding)
|
59
|
-
end
|
60
|
-
|
61
|
-
# You can override this instead of internal_generate if you do not need the
|
62
|
-
# exception handling.
|
63
|
-
def generate(context_binding)
|
64
|
-
n = @template_name.nil? ? '' : "#{@template_name} "
|
65
|
-
internal_generate(context_binding)
|
66
|
-
rescue SyntaxError => e
|
67
|
-
aargh("Template #{n}syntax error: #{e.full_message}", 5)
|
68
|
-
rescue Exception => e
|
69
|
-
aargh("Template #{n}error: #{e.full_message}", 6)
|
70
|
-
end
|
71
|
-
|
72
|
-
# This is only called when generate produced output that is not discarded.
|
73
|
-
def output_name
|
74
|
-
return @name unless @name.nil?
|
75
|
-
# Using template name may show where name assignment is missing.
|
76
|
-
# Name assignment may also be missing in the task creation stage.
|
77
|
-
return File.basename(@template_name) unless @template_name.nil?
|
78
|
-
nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class WriteTask
|
83
|
-
include TaskInterface
|
84
|
-
|
85
|
-
attr_reader :name, :contents, :executable
|
86
|
-
|
87
|
-
def initialize(name, contents, executable = false)
|
88
|
-
raise ArgumentError, "name and contents must be given" if name.nil? || contents.nil?
|
89
|
-
@name = name
|
90
|
-
@contents = contents
|
91
|
-
@executable = executable
|
92
|
-
end
|
93
|
-
|
94
|
-
def generate(context_binding)
|
95
|
-
@contents
|
96
|
-
end
|
97
|
-
|
98
|
-
def output_name
|
99
|
-
@name
|
100
|
-
end
|
101
|
-
end
|