jsapi 0.1.2 → 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/lib/jsapi/controller/response.rb +2 -0
- data/lib/jsapi/dsl/parameter.rb +0 -10
- data/lib/jsapi/dsl/request_body.rb +0 -10
- data/lib/jsapi/dsl/response.rb +0 -10
- data/lib/jsapi/dsl/schema.rb +1 -1
- data/lib/jsapi/json/array.rb +2 -3
- data/lib/jsapi/json/null.rb +2 -2
- data/lib/jsapi/json/object.rb +1 -1
- data/lib/jsapi/json/string.rb +25 -11
- data/lib/jsapi/json/value.rb +4 -4
- data/lib/jsapi/meta/openapi/root.rb +4 -3
- data/lib/jsapi/meta/parameter/model.rb +3 -1
- data/lib/jsapi/meta/property.rb +3 -1
- data/lib/jsapi/meta/request_body/model.rb +1 -0
- data/lib/jsapi/meta/response/model.rb +1 -0
- data/lib/jsapi/meta/schema/array.rb +9 -1
- data/lib/jsapi/meta/schema/object.rb +1 -1
- data/lib/jsapi/meta/schema/reference.rb +0 -3
- data/lib/jsapi/meta/schema/string.rb +2 -6
- data/lib/jsapi/meta/schema.rb +1 -3
- data/lib/jsapi/version.rb +3 -3
- 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: 72aa6ad77a99ade6acb3d5c70b6521b640e012cccc7e9ab00b9d55db3062d4d6
|
4
|
+
data.tar.gz: 96ec077740dde1963ca6b448662e1f4370f3bc0b54778db2d03d9447ba69aa3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec7997fbedc7c9035f9e36d5426b23502b87f4c4c654b1e02f93db711f514a8a434d371dc4761156165c439256ad3f339c7a151b1b35c8dcbf3d1e14f1fd4628
|
7
|
+
data.tar.gz: 1f2952e80bf883302fd835f9425bae0bd2e7629b2746d3abec4b19a259c5abbd9869534b18eb6c69afd94a9397e13c7d86d78720f3573d92ef355b1e66b99fb0
|
data/lib/jsapi/dsl/parameter.rb
CHANGED
@@ -24,16 +24,6 @@ module Jsapi
|
|
24
24
|
# Specifies the location of the parameter.
|
25
25
|
#
|
26
26
|
# See Meta::Parameter::Model#in for further information.
|
27
|
-
|
28
|
-
##
|
29
|
-
# :method: ref
|
30
|
-
# :args: name
|
31
|
-
# Specifies the name of the reusable parameter to be referred.
|
32
|
-
|
33
|
-
##
|
34
|
-
# :method: schema
|
35
|
-
# :args: name
|
36
|
-
# Specifies the name of the reusable schema to be referred.
|
37
27
|
end
|
38
28
|
end
|
39
29
|
end
|
@@ -17,16 +17,6 @@ module Jsapi
|
|
17
17
|
# :method: description
|
18
18
|
# :args: arg
|
19
19
|
# Specifies the description of the request body.
|
20
|
-
|
21
|
-
##
|
22
|
-
# :method: ref
|
23
|
-
# :args: name
|
24
|
-
# Specifies the name of the reusable request body to be referred.
|
25
|
-
|
26
|
-
##
|
27
|
-
# :method: schema
|
28
|
-
# :args: name
|
29
|
-
# Specifies the name of the reusable schema to be referred.
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
data/lib/jsapi/dsl/response.rb
CHANGED
@@ -47,16 +47,6 @@ module Jsapi
|
|
47
47
|
# Specifies the locale to be used when rendering a response.
|
48
48
|
#
|
49
49
|
# locale :en
|
50
|
-
|
51
|
-
##
|
52
|
-
# :method: ref
|
53
|
-
# :args: name
|
54
|
-
# Specifies the name of the reusable response to be referred.
|
55
|
-
|
56
|
-
##
|
57
|
-
# :method: schema
|
58
|
-
# :args: name
|
59
|
-
# Specifies the name of the reusable schema to be referred.
|
60
50
|
end
|
61
51
|
end
|
62
52
|
end
|
data/lib/jsapi/dsl/schema.rb
CHANGED
@@ -8,7 +8,7 @@ module Jsapi
|
|
8
8
|
# Includes all of the properties from +schemas+. Each argument must be the name of
|
9
9
|
# a schema defined by ClassMethods#api_schema or Definitions#schema.
|
10
10
|
def all_of(*schemas)
|
11
|
-
schemas.each { |schema| _meta_model.add_all_of({
|
11
|
+
schemas.each { |schema| _meta_model.add_all_of({ ref: schema }) }
|
12
12
|
end
|
13
13
|
|
14
14
|
##
|
data/lib/jsapi/json/array.rb
CHANGED
@@ -11,7 +11,7 @@ module Jsapi
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
# Returns
|
14
|
+
# Returns true if it contains no elements, false otherwise.
|
15
15
|
def empty?
|
16
16
|
@elements.empty?
|
17
17
|
end
|
@@ -20,8 +20,7 @@ module Jsapi
|
|
20
20
|
"#<#{self.class.name} [#{@elements.map(&:inspect).join(', ')}]>"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
def validate(errors)
|
23
|
+
def validate(errors) # :nodoc:
|
25
24
|
return false unless super
|
26
25
|
|
27
26
|
@elements.map { |element| element.validate(errors) }.all?
|
data/lib/jsapi/json/null.rb
CHANGED
@@ -5,7 +5,7 @@ module Jsapi
|
|
5
5
|
# Represents +null+.
|
6
6
|
class Null < Value
|
7
7
|
|
8
|
-
# Returns
|
8
|
+
# Returns true.
|
9
9
|
def empty?
|
10
10
|
true
|
11
11
|
end
|
@@ -14,7 +14,7 @@ module Jsapi
|
|
14
14
|
"#<#{self.class}>"
|
15
15
|
end
|
16
16
|
|
17
|
-
# Returns
|
17
|
+
# Returns true.
|
18
18
|
def null?
|
19
19
|
true
|
20
20
|
end
|
data/lib/jsapi/json/object.rb
CHANGED
data/lib/jsapi/json/string.rb
CHANGED
@@ -8,22 +8,36 @@ module Jsapi
|
|
8
8
|
|
9
9
|
def initialize(value, schema)
|
10
10
|
super(schema)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
|
12
|
+
@value =
|
13
|
+
begin
|
14
|
+
case schema.format
|
15
|
+
when 'date'
|
16
|
+
value.to_date
|
17
|
+
when 'date-time'
|
18
|
+
value.to_datetime
|
19
|
+
when 'duration'
|
20
|
+
ActiveSupport::Duration.parse(value)
|
21
|
+
else
|
22
|
+
value.to_s
|
23
|
+
end
|
24
|
+
rescue StandardError => e
|
25
|
+
@error = e
|
26
|
+
value
|
19
27
|
end
|
20
|
-
)
|
28
|
+
@value = schema.convert(@value) unless defined? @error
|
21
29
|
end
|
22
30
|
|
23
|
-
|
24
|
-
def empty?
|
31
|
+
def empty? # :nodoc:
|
25
32
|
value.blank?
|
26
33
|
end
|
34
|
+
|
35
|
+
def validate(errors) # :nodoc:
|
36
|
+
return super unless defined? @error
|
37
|
+
|
38
|
+
errors.add(:base, :invalid)
|
39
|
+
false
|
40
|
+
end
|
27
41
|
end
|
28
42
|
end
|
29
43
|
end
|
data/lib/jsapi/json/value.rb
CHANGED
@@ -14,7 +14,7 @@ module Jsapi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Used by #validate to test whether or not it is empty.
|
17
|
-
# Returns
|
17
|
+
# Returns false by default.
|
18
18
|
def empty?
|
19
19
|
false
|
20
20
|
end
|
@@ -23,13 +23,13 @@ module Jsapi
|
|
23
23
|
"#<#{self.class} #{value.inspect}>"
|
24
24
|
end
|
25
25
|
|
26
|
-
# Used by #validate to test whether or not it is
|
27
|
-
# Returns
|
26
|
+
# Used by #validate to test whether or not it is null.
|
27
|
+
# Returns false by default.
|
28
28
|
def null?
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
|
-
# Validates it against #schema. Returns
|
32
|
+
# Validates it against #schema. Returns true if it is valid, false otherwise.
|
33
33
|
# Detected errors are added to +errors+.
|
34
34
|
def validate(errors)
|
35
35
|
unless schema.existence.reach?(self)
|
@@ -96,12 +96,13 @@ module Jsapi
|
|
96
96
|
end
|
97
97
|
|
98
98
|
if version.major == 2
|
99
|
+
uri = servers&.first&.then { |server| URI(server.url) }
|
99
100
|
{
|
100
101
|
swagger: '2.0',
|
101
102
|
info: info&.to_openapi,
|
102
|
-
host: host,
|
103
|
-
basePath: base_path,
|
104
|
-
schemes: schemes,
|
103
|
+
host: host || uri&.hostname,
|
104
|
+
basePath: base_path || uri&.path,
|
105
|
+
schemes: schemes || uri&.scheme&.then { |scheme| [scheme] },
|
105
106
|
consumes: consumed_mime_types,
|
106
107
|
produces: produced_mime_types,
|
107
108
|
securityDefinitions: security_schemes,
|
@@ -47,12 +47,14 @@ module Jsapi
|
|
47
47
|
def initialize(name, keywords = {})
|
48
48
|
raise ArgumentError, "parameter name can't be blank" if name.blank?
|
49
49
|
|
50
|
+
@name = name.to_s
|
51
|
+
|
50
52
|
keywords = keywords.dup
|
51
53
|
super(keywords.extract!(:deprecated, :description, :examples, :in))
|
52
54
|
|
53
55
|
add_example(value: keywords.delete(:example)) if keywords.key?(:example)
|
56
|
+
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
54
57
|
|
55
|
-
@name = name.to_s
|
56
58
|
@schema = Schema.new(keywords)
|
57
59
|
end
|
58
60
|
|
data/lib/jsapi/meta/property.rb
CHANGED
@@ -34,10 +34,12 @@ module Jsapi
|
|
34
34
|
def initialize(name, keywords = {})
|
35
35
|
raise ArgumentError, "property name can't be blank" if name.blank?
|
36
36
|
|
37
|
+
@name = name.to_s
|
38
|
+
|
37
39
|
keywords = keywords.dup
|
38
40
|
super(keywords.extract!(:read_only, :source, :write_only))
|
41
|
+
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
39
42
|
|
40
|
-
@name = name.to_s
|
41
43
|
@schema = Schema.new(keywords)
|
42
44
|
end
|
43
45
|
|
@@ -36,6 +36,7 @@ module Jsapi
|
|
36
36
|
super(keywords.extract!(:description, :examples, :locale))
|
37
37
|
|
38
38
|
add_example(value: keywords.delete(:example)) if keywords.key?(:example)
|
39
|
+
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
39
40
|
|
40
41
|
@schema = Schema.new(**keywords)
|
41
42
|
end
|
@@ -7,7 +7,7 @@ module Jsapi
|
|
7
7
|
##
|
8
8
|
# :attr: items
|
9
9
|
# The Schema defining the kind of items.
|
10
|
-
attribute :items, Schema
|
10
|
+
attribute :items, Schema, writer: false
|
11
11
|
|
12
12
|
##
|
13
13
|
# :attr: max_items
|
@@ -19,6 +19,14 @@ module Jsapi
|
|
19
19
|
# The minimum length of an array.
|
20
20
|
attribute :min_items, writer: false
|
21
21
|
|
22
|
+
def items=(keywords = {}) # :nodoc:
|
23
|
+
if keywords.key?(:schema)
|
24
|
+
keywords = keywords.dup
|
25
|
+
keywords[:ref] = keywords.delete(:schema)
|
26
|
+
end
|
27
|
+
@items = Schema.new(keywords)
|
28
|
+
end
|
29
|
+
|
22
30
|
def max_items=(value) # :nodoc:
|
23
31
|
add_validation('max_items', Validation::MaxItems.new(value))
|
24
32
|
@max_items = value
|
@@ -72,7 +72,7 @@ module Jsapi
|
|
72
72
|
{}.tap do |properties|
|
73
73
|
all_of_references.each do |reference|
|
74
74
|
schema = reference.resolve(definitions)
|
75
|
-
raise "circular reference: #{reference.
|
75
|
+
raise "circular reference: #{reference.ref}" if schema.in?(path)
|
76
76
|
|
77
77
|
properties.merge!(schema.merge_properties(definitions, path + [self]))
|
78
78
|
end
|
@@ -8,12 +8,8 @@ module Jsapi
|
|
8
8
|
|
9
9
|
##
|
10
10
|
# :attr: format
|
11
|
-
# The format of a string.
|
12
|
-
|
13
|
-
# - <code>"date"</code>
|
14
|
-
# - <code>"date-time"</code>
|
15
|
-
#
|
16
|
-
attribute :format, ::String, values: %w[date date-time]
|
11
|
+
# The format of a string.
|
12
|
+
attribute :format, ::String
|
17
13
|
|
18
14
|
##
|
19
15
|
# :attr: max_length
|
data/lib/jsapi/meta/schema.rb
CHANGED
@@ -33,9 +33,7 @@ module Jsapi
|
|
33
33
|
#
|
34
34
|
# Raises an InvalidArgumentError if the given type is invalid.
|
35
35
|
def new(keywords = {})
|
36
|
-
|
37
|
-
return Reference.new(keywords)
|
38
|
-
end
|
36
|
+
return Reference.new(keywords) if keywords.key?(:ref)
|
39
37
|
|
40
38
|
type = keywords[:type]
|
41
39
|
case type&.to_s
|
data/lib/jsapi/version.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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Jsapi can be used to read requests, produce responses and create OpenAPI
|
14
14
|
documents
|