jsapi 0.9.0 → 0.9.2
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/lib/jsapi/configuration.rb +28 -0
- data/lib/jsapi/controller/methods.rb +1 -1
- data/lib/jsapi/dsl/base.rb +38 -1
- data/lib/jsapi/dsl/class_methods.rb +27 -6
- data/lib/jsapi/dsl/definitions.rb +1 -1
- data/lib/jsapi/dsl/operation.rb +20 -0
- data/lib/jsapi/dsl/schema.rb +12 -2
- data/lib/jsapi/meta/callback/reference.rb +1 -0
- data/lib/jsapi/meta/definitions.rb +6 -2
- data/lib/jsapi/meta/example/reference.rb +1 -0
- data/lib/jsapi/meta/header/reference.rb +1 -0
- data/lib/jsapi/meta/link/reference.rb +1 -0
- data/lib/jsapi/meta/operation.rb +1 -1
- data/lib/jsapi/meta/parameter/model.rb +2 -2
- data/lib/jsapi/meta/parameter/reference.rb +5 -3
- data/lib/jsapi/meta/parameter/to_openapi.rb +1 -0
- data/lib/jsapi/meta/property.rb +1 -0
- data/lib/jsapi/meta/request_body/model.rb +1 -1
- data/lib/jsapi/meta/request_body/reference.rb +1 -0
- data/lib/jsapi/meta/response/model.rb +1 -1
- data/lib/jsapi/meta/response/reference.rb +1 -0
- data/lib/jsapi/version.rb +1 -1
- data/lib/jsapi.rb +1 -1
- 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: 59c9ddcd1965cd62ee1b1bbb0e7f066061eaef6a5f8217c69b6d86ee92230b4a
|
4
|
+
data.tar.gz: f02a5ff2b0d13ca4c238356b8d11473432ec71b12b40218639335f9f2f45f1da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f8f331323ab4d88ba89133f37b0eee8fc6bdb1ab5159f3ce5885b7139d4376e74f6df42ed8232c6ea5c4cb7b373d8ea5a8c866c6833d23f5f1412f6a004ea14
|
7
|
+
data.tar.gz: f7061a754b6bbde17046b4cc4cb29eca42daede67f3978f474574c9389d555815e5e11f8f2af021f93985458511790699a64d8cd5fc95b03f421792dcd0dd4a5
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
# Holds the \Jsapi configuration.
|
5
|
+
class Configuration
|
6
|
+
# The path where the API definitions are located relative to +Rails.root+.
|
7
|
+
# The default is <code>"app/api_defs"</code>.
|
8
|
+
attr_accessor :api_defs_path
|
9
|
+
|
10
|
+
def initialize # :nodoc:
|
11
|
+
@api_defs_path = 'app/api_defs'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the absolute +Pathname+ for +args+ within +api_defs_path+.
|
15
|
+
def pathname(*args)
|
16
|
+
return unless (root = Rails.root)
|
17
|
+
|
18
|
+
root.join(*[api_defs_path, args].flatten)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
# The singleton \Jsapi configuration.
|
24
|
+
def configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/jsapi/dsl/base.rb
CHANGED
@@ -3,9 +3,26 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module DSL
|
5
5
|
class Base
|
6
|
-
def initialize(meta_model, &block)
|
6
|
+
def initialize(meta_model, pathname = nil, parent: nil, &block)
|
7
7
|
@meta_model = meta_model
|
8
|
+
@pathname = pathname
|
9
|
+
@parent = parent
|
8
10
|
|
11
|
+
# Raise an error when pathname is attempted to be imported again
|
12
|
+
if pathname && (ancestor = parent)
|
13
|
+
while ancestor
|
14
|
+
if ancestor.pathname == pathname
|
15
|
+
raise Error, "Attempted #{pathname.to_path.inspect} to be imported again"
|
16
|
+
end
|
17
|
+
|
18
|
+
ancestor = ancestor.parent
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Evaluate the file to be imported
|
23
|
+
instance_eval(pathname.read, pathname.to_path) if pathname
|
24
|
+
|
25
|
+
# Evaluate block
|
9
26
|
if block
|
10
27
|
if meta_model.reference?
|
11
28
|
raise Error, "reference can't be specified together with a block"
|
@@ -15,10 +32,30 @@ module Jsapi
|
|
15
32
|
end
|
16
33
|
end
|
17
34
|
|
35
|
+
# Imports the file named +filename+ relative to +Jsapi.configation.path+.
|
36
|
+
def import(filename)
|
37
|
+
raise ArgumentError, "file name can't be blank" if filename.blank?
|
38
|
+
|
39
|
+
pathname = Jsapi.configuration.pathname("#{filename}.rb")
|
40
|
+
self.class.new(@meta_model, pathname, parent: self)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Imports the file named +filename+ relative to the current file's path.
|
44
|
+
def import_relative(filename)
|
45
|
+
raise ArgumentError, "file name can't be blank" if filename.blank?
|
46
|
+
|
47
|
+
pathname = (@pathname&.parent || Jsapi.configuration.pathname) + "#{filename}.rb"
|
48
|
+
self.class.new(@meta_model, pathname, parent: self)
|
49
|
+
end
|
50
|
+
|
18
51
|
def respond_to_missing?(*args) # :nodoc:
|
19
52
|
keyword?(args.first)
|
20
53
|
end
|
21
54
|
|
55
|
+
protected
|
56
|
+
|
57
|
+
attr_reader :parent, :pathname
|
58
|
+
|
22
59
|
private
|
23
60
|
|
24
61
|
def define(*args, &block)
|
@@ -29,13 +29,29 @@ module Jsapi
|
|
29
29
|
api_definitions { default(type, **keywords, &block) }
|
30
30
|
end
|
31
31
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
# Returns the API definitions associated with the current class. Adds additional
|
33
|
+
# definitions when any keywords or a block is specified.
|
34
|
+
#
|
35
|
+
# api_definitions base_path: '/foo' do
|
36
|
+
# operation 'bar'
|
37
|
+
# end
|
38
|
+
def api_definitions(**keywords, &block)
|
39
|
+
unless defined? @api_definitions
|
40
|
+
@api_definitions = Meta::Definitions.new(
|
41
|
+
owner: self,
|
42
|
+
parent: superclass.try(:api_definitions)
|
43
|
+
)
|
44
|
+
if (name = try(:name))
|
45
|
+
pathname = Jsapi.configuration.pathname(
|
46
|
+
name.deconstantize.split('::').map(&:underscore),
|
47
|
+
"#{name.demodulize.delete_suffix('Controller').underscore}.rb"
|
48
|
+
)
|
49
|
+
Definitions.new(@api_definitions, pathname) if pathname&.file?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@api_definitions.merge!(keywords) if keywords.any?
|
38
53
|
Definitions.new(@api_definitions, &block) if block
|
54
|
+
|
39
55
|
@api_definitions
|
40
56
|
end
|
41
57
|
|
@@ -71,6 +87,11 @@ module Jsapi
|
|
71
87
|
api_definitions { host(arg) }
|
72
88
|
end
|
73
89
|
|
90
|
+
# Imports the file named +filename+ relative to +Jsapi.configation.path+.
|
91
|
+
def api_import(filename)
|
92
|
+
api_definitions { import(filename) }
|
93
|
+
end
|
94
|
+
|
74
95
|
# Includes API definitions from +klasses+.
|
75
96
|
def api_include(*klasses)
|
76
97
|
api_definitions { include(*klasses) }
|
data/lib/jsapi/dsl/operation.rb
CHANGED
@@ -38,6 +38,15 @@ module Jsapi
|
|
38
38
|
#
|
39
39
|
# deprecated true
|
40
40
|
|
41
|
+
##
|
42
|
+
# :method: external_docs
|
43
|
+
# :args: **keywords, &block
|
44
|
+
# Specifies the external documentation.
|
45
|
+
#
|
46
|
+
# external_docs url: 'https://foo.bar/docs'
|
47
|
+
#
|
48
|
+
# See Meta::Operation#external_docs for further information.
|
49
|
+
|
41
50
|
##
|
42
51
|
# :method: description
|
43
52
|
# :args: arg
|
@@ -162,6 +171,17 @@ module Jsapi
|
|
162
171
|
end
|
163
172
|
end
|
164
173
|
|
174
|
+
##
|
175
|
+
# :method: security_requirement
|
176
|
+
# :args: **keywords, &block
|
177
|
+
# Specifies a security requirement.
|
178
|
+
#
|
179
|
+
# security_requirement do
|
180
|
+
# scheme 'basic_auth'
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# See Meta::Operation#security_requirements for further information.
|
184
|
+
|
165
185
|
##
|
166
186
|
# :method: summary
|
167
187
|
# :args: arg
|
data/lib/jsapi/dsl/schema.rb
CHANGED
@@ -5,6 +5,15 @@ module Jsapi
|
|
5
5
|
# Used to define a schema.
|
6
6
|
class Schema < Base
|
7
7
|
|
8
|
+
##
|
9
|
+
# :method: additional_properties
|
10
|
+
# :args: **keywords, &block
|
11
|
+
# Specifies the schema of properties that are not explicity specified.
|
12
|
+
#
|
13
|
+
# additional_properties type: 'string'
|
14
|
+
#
|
15
|
+
# See Meta::Schema::Object#additional_properties for further information.
|
16
|
+
|
8
17
|
# Includes all of the properties from +schemas+. Each argument must be the name of
|
9
18
|
# a schema defined by ClassMethods#api_schema or Definitions#schema.
|
10
19
|
def all_of(*schemas)
|
@@ -47,8 +56,9 @@ module Jsapi
|
|
47
56
|
#
|
48
57
|
# enum %w[foo bar]
|
49
58
|
|
50
|
-
##
|
51
|
-
|
59
|
+
##
|
60
|
+
# :method: external_docs
|
61
|
+
# :args: **keywords, &block
|
52
62
|
# Specifies the external documentation.
|
53
63
|
#
|
54
64
|
# See Meta::Schema::Base#external_docs for further information.
|
@@ -382,10 +382,14 @@ module Jsapi
|
|
382
382
|
@objects ||= ancestors.each_with_object({}) do |ancestor, objects|
|
383
383
|
self.class.attribute_names.each do |key|
|
384
384
|
case value = ancestor.send(key)
|
385
|
-
when Hash
|
386
|
-
(objects[key] ||= {}).reverse_merge!(value)
|
387
385
|
when Array
|
388
386
|
(objects[key] ||= []).push(*value)
|
387
|
+
when Hash
|
388
|
+
if (hash = objects[key])
|
389
|
+
value.each { |k, v| hash[k] = v unless hash.key?(k) }
|
390
|
+
else
|
391
|
+
objects[key] = value.dup
|
392
|
+
end
|
389
393
|
else
|
390
394
|
objects[key] ||= value
|
391
395
|
end
|
data/lib/jsapi/meta/operation.rb
CHANGED
@@ -3,12 +3,14 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
|
+
# Specifies a parameter reference.
|
6
7
|
class Reference < Base::Reference
|
7
8
|
include ToOpenAPI
|
8
9
|
|
9
|
-
# Returns an array of hashes.
|
10
|
-
#
|
11
|
-
# array contains a single hash representing the \OpenAPI
|
10
|
+
# Returns an array of hashes. If the type of the referred parameter is
|
11
|
+
# <code>"object"</code>, each hash represents an \OpenAPI parameter object.
|
12
|
+
# Otherwise the array contains a single hash representing the \OpenAPI
|
13
|
+
# reference object.
|
12
14
|
#
|
13
15
|
# Raises a ReferenceError when the reference could not be resolved.
|
14
16
|
def to_openapi_parameters(version, definitions)
|
data/lib/jsapi/meta/property.rb
CHANGED
data/lib/jsapi/version.rb
CHANGED
data/lib/jsapi.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Göller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: denis@dmgoeller.de
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/jsapi.rb
|
20
|
+
- lib/jsapi/configuration.rb
|
20
21
|
- lib/jsapi/controller.rb
|
21
22
|
- lib/jsapi/controller/base.rb
|
22
23
|
- lib/jsapi/controller/error.rb
|