jsapi 0.1.1 → 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/error_result.rb +1 -2
- data/lib/jsapi/controller/methods.rb +16 -19
- data/lib/jsapi/controller/parameters.rb +7 -8
- data/lib/jsapi/controller/parameters_invalid.rb +1 -2
- data/lib/jsapi/controller/response.rb +4 -2
- data/lib/jsapi/dsl/callbacks.rb +1 -1
- data/lib/jsapi/dsl/definitions.rb +3 -3
- data/lib/jsapi/dsl/error.rb +3 -5
- data/lib/jsapi/dsl/examples.rb +1 -1
- data/lib/jsapi/dsl/openapi/callback.rb +1 -1
- data/lib/jsapi/dsl/openapi/root.rb +115 -1
- data/lib/jsapi/dsl/operation.rb +50 -11
- data/lib/jsapi/dsl/parameter.rb +19 -0
- data/lib/jsapi/dsl/request_body.rb +12 -0
- data/lib/jsapi/dsl/response.rb +19 -0
- data/lib/jsapi/dsl/schema.rb +140 -14
- 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 +5 -5
- data/lib/jsapi/meta/attributes/type_caster.rb +3 -2
- data/lib/jsapi/meta/base.rb +3 -2
- data/lib/jsapi/meta/base_reference.rb +3 -2
- data/lib/jsapi/meta/definitions.rb +2 -1
- data/lib/jsapi/meta/example/model.rb +1 -2
- data/lib/jsapi/meta/example/reference.rb +0 -1
- data/lib/jsapi/meta/invalid_argument_error.rb +1 -0
- data/lib/jsapi/meta/openapi/callback/model.rb +1 -1
- data/lib/jsapi/meta/openapi/root.rb +8 -8
- data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +1 -2
- data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +2 -3
- data/lib/jsapi/meta/openapi/security_scheme.rb +2 -2
- data/lib/jsapi/meta/openapi/version.rb +3 -0
- data/lib/jsapi/meta/operation.rb +15 -24
- data/lib/jsapi/meta/parameter/model.rb +5 -3
- data/lib/jsapi/meta/parameter/reference.rb +3 -4
- data/lib/jsapi/meta/property.rb +6 -5
- data/lib/jsapi/meta/request_body/model.rb +2 -1
- data/lib/jsapi/meta/rescue_handler.rb +7 -0
- data/lib/jsapi/meta/response/model.rb +2 -1
- data/lib/jsapi/meta/schema/array.rb +9 -1
- data/lib/jsapi/meta/schema/base.rb +7 -9
- data/lib/jsapi/meta/schema/object.rb +1 -1
- data/lib/jsapi/meta/schema/reference.rb +1 -5
- data/lib/jsapi/meta/schema/string.rb +2 -6
- data/lib/jsapi/meta/schema/validation/maximum.rb +6 -2
- data/lib/jsapi/meta/schema/validation/minimum.rb +6 -2
- data/lib/jsapi/meta/schema/validation/multiple_of.rb +3 -1
- data/lib/jsapi/meta/schema.rb +1 -3
- data/lib/jsapi/model/base.rb +2 -2
- data/lib/jsapi/model/errors.rb +3 -4
- data/lib/jsapi/model/naming.rb +3 -4
- data/lib/jsapi/model/validations.rb +2 -2
- data/lib/jsapi/version.rb +5 -3
- metadata +5 -3
@@ -4,10 +4,9 @@ module Jsapi
|
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
6
|
class Reference < BaseReference
|
7
|
-
# Returns an array of hashes. Each element represents an \OpenAPI
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# hash representing the \OpenAPI reference object.
|
7
|
+
# Returns an array of hashes. Each element represents an \OpenAPI parameter object
|
8
|
+
# if the type of the referred parameter is <code>"object"</code>. Otherwise the
|
9
|
+
# array contains a single hash representing the \OpenAPI reference object.
|
11
10
|
#
|
12
11
|
# Raises a ReferenceError if the reference could not be resolved.
|
13
12
|
def to_openapi(version, definitions)
|
data/lib/jsapi/meta/property.rb
CHANGED
@@ -19,8 +19,7 @@ module Jsapi
|
|
19
19
|
|
20
20
|
##
|
21
21
|
# :attr: source
|
22
|
-
# The alternative method to read a property value when serializing
|
23
|
-
# an object.
|
22
|
+
# The alternative method to read a property value when serializing an object.
|
24
23
|
attribute :source, Symbol
|
25
24
|
|
26
25
|
##
|
@@ -35,15 +34,17 @@ module Jsapi
|
|
35
34
|
def initialize(name, keywords = {})
|
36
35
|
raise ArgumentError, "property name can't be blank" if name.blank?
|
37
36
|
|
37
|
+
@name = name.to_s
|
38
|
+
|
38
39
|
keywords = keywords.dup
|
39
40
|
super(keywords.extract!(:read_only, :source, :write_only))
|
41
|
+
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
40
42
|
|
41
|
-
@name = name.to_s
|
42
43
|
@schema = Schema.new(keywords)
|
43
44
|
end
|
44
45
|
|
45
|
-
# Returns true if the level of existence is greater than or equal to
|
46
|
-
#
|
46
|
+
# Returns true if the level of existence is greater than or equal to +ALLOW_NIL+,
|
47
|
+
# false otherwise.
|
47
48
|
def required?
|
48
49
|
schema.existence >= Existence::ALLOW_NIL
|
49
50
|
end
|
@@ -16,7 +16,7 @@ module Jsapi
|
|
16
16
|
|
17
17
|
##
|
18
18
|
# :attr_reader: schema
|
19
|
-
# The Schema of the
|
19
|
+
# The Schema of the request body.
|
20
20
|
attribute :schema, writer: false
|
21
21
|
|
22
22
|
delegate_missing_to :schema
|
@@ -26,6 +26,7 @@ module Jsapi
|
|
26
26
|
super(keywords.extract!(:description, :examples))
|
27
27
|
|
28
28
|
add_example(value: keywords.delete(:example)) if keywords.key?(:example)
|
29
|
+
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
29
30
|
|
30
31
|
@schema = Schema.new(keywords)
|
31
32
|
end
|
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
+
# Maps a +StandardError+ class to a response status.
|
5
6
|
class RescueHandler
|
7
|
+
# The response status.
|
6
8
|
attr_reader :status
|
7
9
|
|
10
|
+
# Creates a new rescue handler to map +klass+ to +status+. The default response status
|
11
|
+
# is <code>"default"</code>.
|
12
|
+
#
|
13
|
+
# Raises an +ArgumentError+ if +klass+ isn't a +StandardError+ class.
|
8
14
|
def initialize(klass, status: nil)
|
9
15
|
unless klass.is_a?(Class) && klass.ancestors.include?(StandardError)
|
10
16
|
raise ArgumentError, "#{klass.inspect} must be a standard error class"
|
@@ -18,6 +24,7 @@ module Jsapi
|
|
18
24
|
"#<#{self.class.name} class: #{@klass}, status: #{@status.inspect}>"
|
19
25
|
end
|
20
26
|
|
27
|
+
# Returns true if +exception+ is an instance of the class to be mapped, false otherwise.
|
21
28
|
def match?(exception)
|
22
29
|
exception.is_a?(@klass)
|
23
30
|
end
|
@@ -26,7 +26,7 @@ module Jsapi
|
|
26
26
|
|
27
27
|
##
|
28
28
|
# :attr_reader: schema
|
29
|
-
# The Schema of the
|
29
|
+
# The Schema of the response.
|
30
30
|
attribute :schema, writer: false
|
31
31
|
|
32
32
|
delegate_missing_to :schema
|
@@ -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
|
@@ -12,7 +12,7 @@ module Jsapi
|
|
12
12
|
|
13
13
|
##
|
14
14
|
# :attr: default
|
15
|
-
# The
|
15
|
+
# The default value.
|
16
16
|
attribute :default
|
17
17
|
|
18
18
|
##
|
@@ -22,7 +22,7 @@ module Jsapi
|
|
22
22
|
|
23
23
|
##
|
24
24
|
# :attr: description
|
25
|
-
# The
|
25
|
+
# The description of the schema.
|
26
26
|
attribute :description, ::String
|
27
27
|
|
28
28
|
##
|
@@ -32,23 +32,22 @@ module Jsapi
|
|
32
32
|
|
33
33
|
##
|
34
34
|
# :attr: examples
|
35
|
-
# The
|
35
|
+
# The samples matching the schema.
|
36
36
|
attribute :examples, [::Object]
|
37
37
|
|
38
38
|
##
|
39
39
|
# :attr: external_docs
|
40
|
-
# The
|
40
|
+
# The OpenAPI::ExternalDocumentation object.
|
41
41
|
attribute :external_docs, OpenAPI::ExternalDocumentation
|
42
42
|
|
43
43
|
##
|
44
44
|
# :attr: existence
|
45
|
-
# The level of Existence. The default level of existence
|
46
|
-
# is +ALLOW_OMITTED+.
|
45
|
+
# The level of Existence. The default level of existence is +ALLOW_OMITTED+.
|
47
46
|
attribute :existence, Existence, default: Existence::ALLOW_OMITTED
|
48
47
|
|
49
48
|
##
|
50
49
|
# :attr: title
|
51
|
-
# The
|
50
|
+
# The title of the schema.
|
52
51
|
attribute :title, String
|
53
52
|
|
54
53
|
##
|
@@ -73,8 +72,7 @@ module Jsapi
|
|
73
72
|
@enum = value
|
74
73
|
end
|
75
74
|
|
76
|
-
# Returns true if and only if values can be +null+ as specified
|
77
|
-
# by \JSON \Schema.
|
75
|
+
# Returns true if and only if values can be +null+ as specified by \JSON \Schema.
|
78
76
|
def nullable?
|
79
77
|
existence <= Existence::ALLOW_NIL
|
80
78
|
end
|
@@ -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
|
@@ -4,13 +4,9 @@ module Jsapi
|
|
4
4
|
module Meta
|
5
5
|
module Schema
|
6
6
|
class Reference < BaseReference
|
7
|
-
alias :schema :ref
|
8
|
-
alias :schema= :ref=
|
9
|
-
|
10
7
|
##
|
11
8
|
# :attr: existence
|
12
|
-
# The level of Existence. The default level of existence
|
13
|
-
# is +ALLOW_OMITTED+.
|
9
|
+
# The level of Existence. The default level of existence is +ALLOW_OMITTED+.
|
14
10
|
attribute :existence, Existence, default: Existence::ALLOW_OMITTED
|
15
11
|
|
16
12
|
def resolve(definitions) # :nodoc:
|
@@ -8,12 +8,8 @@ module Jsapi
|
|
8
8
|
|
9
9
|
##
|
10
10
|
# :attr: format
|
11
|
-
# The
|
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
|
@@ -9,9 +9,13 @@ module Jsapi
|
|
9
9
|
|
10
10
|
def initialize(value, exclusive: false)
|
11
11
|
if exclusive
|
12
|
-
|
12
|
+
unless value.respond_to?(:<)
|
13
|
+
raise ArgumentError, "invalid exclusive maximum: #{value.inspect}"
|
14
|
+
end
|
13
15
|
else
|
14
|
-
|
16
|
+
unless value.respond_to?(:<=)
|
17
|
+
raise ArgumentError, "invalid maximum: #{value.inspect}"
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
super(value)
|
@@ -9,9 +9,13 @@ module Jsapi
|
|
9
9
|
|
10
10
|
def initialize(value, exclusive: false)
|
11
11
|
if exclusive
|
12
|
-
|
12
|
+
unless value.respond_to?(:>)
|
13
|
+
raise ArgumentError, "invalid exclusive minimum: #{value.inspect}"
|
14
|
+
end
|
13
15
|
else
|
14
|
-
|
16
|
+
unless value.respond_to?(:>=)
|
17
|
+
raise ArgumentError, "invalid minimum: #{value.inspect}"
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
super(value)
|
@@ -6,7 +6,9 @@ module Jsapi
|
|
6
6
|
module Validation
|
7
7
|
class MultipleOf < Base
|
8
8
|
def initialize(value)
|
9
|
-
|
9
|
+
unless value.respond_to?(:%)
|
10
|
+
raise ArgumentError, "invalid multiple of: #{value.inspect}"
|
11
|
+
end
|
10
12
|
|
11
13
|
super
|
12
14
|
end
|
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/model/base.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Model
|
5
|
-
# The base API model used to represent top-level parameters and nested
|
6
|
-
#
|
5
|
+
# The base API model used to represent top-level parameters and nested object
|
6
|
+
# parameters by default.
|
7
7
|
class Base
|
8
8
|
extend Naming
|
9
9
|
|
data/lib/jsapi/model/errors.rb
CHANGED
@@ -9,16 +9,15 @@ module Jsapi
|
|
9
9
|
super
|
10
10
|
end
|
11
11
|
|
12
|
-
# Overrides <code>ActiveModel::Errors#add</code> to wrap errors related
|
13
|
-
# to nested models.
|
12
|
+
# Overrides <code>ActiveModel::Errors#add</code> to wrap errors related to nested models.
|
14
13
|
def add(attribute, type = :invalid, **options)
|
15
14
|
type = type.call(@base, options) if type.respond_to?(:call)
|
16
15
|
|
17
16
|
errors << wrap(Error.new(@base, attribute.to_sym, type, **options))
|
18
17
|
end
|
19
18
|
|
20
|
-
# Overrides <code>ActiveModel::Errors#import</code> to wrap errors
|
21
|
-
#
|
19
|
+
# Overrides <code>ActiveModel::Errors#import</code> to wrap errors related to
|
20
|
+
# nested models.
|
22
21
|
def import(error, options = {})
|
23
22
|
if (options = options.slice(:attribute, :type)).any?
|
24
23
|
attribute = (options[:attribute] || error.attribute).to_sym
|
data/lib/jsapi/model/naming.rb
CHANGED
@@ -6,8 +6,8 @@ module Jsapi
|
|
6
6
|
include ActiveModel::Naming
|
7
7
|
include ActiveModel::Translation
|
8
8
|
|
9
|
-
# Overrides <code>ActiveModel::Naming#model_name</code> to support
|
10
|
-
#
|
9
|
+
# Overrides <code>ActiveModel::Naming#model_name</code> to support anonymous
|
10
|
+
# model classes.
|
11
11
|
def model_name
|
12
12
|
@_model_name ||= begin
|
13
13
|
# Copied from ActiveModel::Naming#model_name
|
@@ -15,8 +15,7 @@ module Jsapi
|
|
15
15
|
m.respond_to?(:use_relative_model_naming?) &&
|
16
16
|
m.use_relative_model_naming?
|
17
17
|
end
|
18
|
-
# Prevent that ActiveModel::Name::new raises an error if this is
|
19
|
-
# an anonymous class
|
18
|
+
# Prevent that ActiveModel::Name::new raises an error if this is an anonymous class
|
20
19
|
klass = self
|
21
20
|
klass = klass.superclass while klass.name.nil?
|
22
21
|
|
@@ -11,8 +11,8 @@ module Jsapi
|
|
11
11
|
validate :nested_validity
|
12
12
|
end
|
13
13
|
|
14
|
-
# Overrides <code>ActiveModel::Validations#errors</code>
|
15
|
-
# Errors as error store.
|
14
|
+
# Overrides <code>ActiveModel::Validations#errors</code>
|
15
|
+
# to use Errors as error store.
|
16
16
|
def errors
|
17
17
|
@errors ||= Errors.new(self)
|
18
18
|
end
|
data/lib/jsapi/version.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jsapi
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Version
|
5
|
+
# NOTE: See https://bundler.io/guides/creating_gem.html
|
6
|
+
|
7
|
+
# The current GEM version.
|
8
|
+
VERSION = '0.2.0'
|
7
9
|
end
|
8
10
|
end
|
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-05
|
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
|
@@ -139,7 +139,9 @@ files:
|
|
139
139
|
homepage: https://github.com/dmgoeller/jsapi
|
140
140
|
licenses:
|
141
141
|
- MIT
|
142
|
-
metadata:
|
142
|
+
metadata:
|
143
|
+
homepage_uri: https://github.com/dmgoeller/jsapi
|
144
|
+
source_code_uri: https://github.com/dmgoeller/jsapi
|
143
145
|
post_install_message:
|
144
146
|
rdoc_options: []
|
145
147
|
require_paths:
|