eazypi 0.0.7 → 0.0.9
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/eazypi/api.rb +29 -4
- data/lib/eazypi/components.rb +7 -1
- data/lib/eazypi/info.rb +4 -2
- data/lib/eazypi/license.rb +20 -0
- data/lib/eazypi/operation.rb +21 -2
- data/lib/eazypi/security_requirement.rb +17 -0
- data/lib/eazypi/security_scheme.rb +31 -0
- data/lib/eazypi/serializer.rb +1 -1
- data/lib/eazypi/spec_object.rb +7 -2
- data/lib/eazypi/tag.rb +18 -0
- data/lib/eazypi/version.rb +1 -1
- data/lib/eazypi.rb +3 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a8508af82fe900f0f85371820abba867d0ea81f4fd36319c5fd60619528958d
|
4
|
+
data.tar.gz: e812f649abdae98402335d021045d0c35f036ccb8bb3cb4a168fc5ad2b780416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3fc4dc419af5e8de60a93aea62bf34aada19c5a294babffbddd4907bfae270ad44c245da454121c817269bc51bc10b21f1d7f79d05d665659b455b7182b0e7e
|
7
|
+
data.tar.gz: '09e57f0718756728fa2ae72d896f5377a844a0838e2629691f2c4f40e62c8f97df22d24b8f92a0a5a2811a7d3505fdf7d6b75e62f31fad9a4381770aaae215bb'
|
data/lib/eazypi/api.rb
CHANGED
@@ -8,7 +8,8 @@ module Eazypi
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# ClassMethods that can be used in your API definition
|
11
|
-
|
11
|
+
# Todo: Split this up
|
12
|
+
module ClassMethods # rubocop:todo Metrics/ModuleLength
|
12
13
|
def info(&block)
|
13
14
|
@info ||= Info.new
|
14
15
|
|
@@ -21,6 +22,28 @@ module Eazypi
|
|
21
22
|
@paths ||= {}
|
22
23
|
end
|
23
24
|
|
25
|
+
def tag(&block)
|
26
|
+
@tags ||= []
|
27
|
+
|
28
|
+
tag = Tag.new
|
29
|
+
tag.load(&block)
|
30
|
+
|
31
|
+
@tags.append(tag)
|
32
|
+
end
|
33
|
+
|
34
|
+
def security_scheme(name, &block)
|
35
|
+
scheme = SecurityScheme.new
|
36
|
+
scheme.load(&block)
|
37
|
+
|
38
|
+
components.add_security_scheme(name, scheme)
|
39
|
+
end
|
40
|
+
|
41
|
+
def security(name, scopes = [])
|
42
|
+
@security ||= []
|
43
|
+
|
44
|
+
@security.append(SecurityRequirement.new(name, scopes))
|
45
|
+
end
|
46
|
+
|
24
47
|
def load_controller(controller_klass)
|
25
48
|
controller_klass.operations.each do |operation|
|
26
49
|
paths[operation.path] ||= PathItem.new
|
@@ -45,7 +68,7 @@ module Eazypi
|
|
45
68
|
to_openapi_spec_with_servers(servers)
|
46
69
|
end
|
47
70
|
|
48
|
-
def to_openapi_spec_with_servers(override_servers)
|
71
|
+
def to_openapi_spec_with_servers(override_servers) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
49
72
|
actual_servers = override_servers || servers
|
50
73
|
|
51
74
|
{
|
@@ -55,8 +78,10 @@ module Eazypi
|
|
55
78
|
Operation.normalized_path(path)
|
56
79
|
end.transform_values(&:to_openapi_spec),
|
57
80
|
"servers" => actual_servers.map(&:to_openapi_spec),
|
58
|
-
"components" => components.to_openapi_spec
|
59
|
-
|
81
|
+
"components" => components.to_openapi_spec,
|
82
|
+
"security" => @security&.map(&:to_openapi_spec),
|
83
|
+
"tags" => @tags&.map(&:to_openapi_spec)
|
84
|
+
}.compact
|
60
85
|
end
|
61
86
|
|
62
87
|
def mount(router) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
data/lib/eazypi/components.rb
CHANGED
@@ -5,6 +5,11 @@ module Eazypi
|
|
5
5
|
class Components
|
6
6
|
def initialize
|
7
7
|
@schemas = {}
|
8
|
+
@security_schemes = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_security_scheme(name, scheme)
|
12
|
+
@security_schemes[name] = scheme
|
8
13
|
end
|
9
14
|
|
10
15
|
def add_schema(name, schema)
|
@@ -16,7 +21,8 @@ module Eazypi
|
|
16
21
|
|
17
22
|
def to_openapi_spec
|
18
23
|
{
|
19
|
-
"schemas" => @schemas.empty? ? nil : @schemas.transform_values(&:to_openapi_spec)
|
24
|
+
"schemas" => @schemas.empty? ? nil : @schemas.transform_values(&:to_openapi_spec),
|
25
|
+
"securitySchemes" => @security_schemes.empty? ? nil : @security_schemes.transform_values(&:to_openapi_spec)
|
20
26
|
}.compact
|
21
27
|
end
|
22
28
|
end
|
data/lib/eazypi/info.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "eazypi/license"
|
4
|
+
|
3
5
|
module Eazypi
|
4
6
|
# OpenAPI spec InfoObject
|
5
7
|
class Info
|
@@ -10,7 +12,7 @@ module Eazypi
|
|
10
12
|
spec_attribute :description
|
11
13
|
spec_attribute :terms_of_service
|
12
14
|
spec_attribute :contact
|
13
|
-
spec_attribute :license
|
15
|
+
spec_attribute :license, License
|
14
16
|
spec_attribute :version
|
15
17
|
|
16
18
|
def to_openapi_spec
|
@@ -20,7 +22,7 @@ module Eazypi
|
|
20
22
|
"description" => description,
|
21
23
|
"termsOfService" => terms_of_service,
|
22
24
|
"contact" => contact,
|
23
|
-
"license" => license,
|
25
|
+
"license" => license&.to_openapi_spec,
|
24
26
|
"version" => version
|
25
27
|
}.compact
|
26
28
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eazypi
|
4
|
+
# OpenAPI spec InfoObject
|
5
|
+
class License
|
6
|
+
include SpecObject
|
7
|
+
|
8
|
+
spec_attribute :name
|
9
|
+
spec_attribute :identifier
|
10
|
+
spec_attribute :url
|
11
|
+
|
12
|
+
def to_openapi_spec
|
13
|
+
{
|
14
|
+
"name" => name,
|
15
|
+
"identifier" => identifier,
|
16
|
+
"url" => url
|
17
|
+
}.compact
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/eazypi/operation.rb
CHANGED
@@ -18,6 +18,8 @@ module Eazypi
|
|
18
18
|
@path = path
|
19
19
|
@method = method
|
20
20
|
@parameters = []
|
21
|
+
@security = nil
|
22
|
+
@tags = nil
|
21
23
|
|
22
24
|
super(&block)
|
23
25
|
end
|
@@ -54,20 +56,37 @@ module Eazypi
|
|
54
56
|
@renderer = block
|
55
57
|
end
|
56
58
|
|
59
|
+
def security!
|
60
|
+
@security = []
|
61
|
+
end
|
62
|
+
|
63
|
+
def security(name, scopes = [])
|
64
|
+
@security ||= []
|
65
|
+
|
66
|
+
@security.append(SecurityRequirement.new(name, scopes))
|
67
|
+
end
|
68
|
+
|
57
69
|
def call(controller)
|
58
70
|
controller.instance_variable_set(:@current_operation, self)
|
59
71
|
controller.instance_exec(&@renderer)
|
60
72
|
end
|
61
73
|
|
62
|
-
def
|
74
|
+
def tag(tag_name)
|
75
|
+
@tags ||= []
|
76
|
+
@tags.append(tag_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_openapi_spec # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
63
80
|
{
|
64
81
|
"summary" => summary,
|
65
82
|
"description" => description,
|
83
|
+
"tags" => @tags,
|
66
84
|
"operationId" => operation_id,
|
67
85
|
"depcrecated" => depcrecated,
|
68
86
|
"parameters" => @parameters.empty? ? nil : @parameters&.map(&:to_openapi_spec),
|
69
87
|
"requestBody" => @request_body&.to_openapi_spec,
|
70
|
-
"responses" => @responses&.to_openapi_spec
|
88
|
+
"responses" => @responses&.to_openapi_spec,
|
89
|
+
"security" => @security&.map(&:to_openapi_spec)
|
71
90
|
}.compact
|
72
91
|
end
|
73
92
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eazypi
|
4
|
+
# Security Requirement OpenAPI object
|
5
|
+
class SecurityRequirement
|
6
|
+
def initialize(name, scopes = [])
|
7
|
+
@name = name
|
8
|
+
@scopes = scopes
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_openapi_spec
|
12
|
+
{
|
13
|
+
@name => @scopes
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eazypi
|
4
|
+
# OpenAPI spec SecurityScheme
|
5
|
+
class SecurityScheme
|
6
|
+
include SpecObject
|
7
|
+
|
8
|
+
spec_attribute :type
|
9
|
+
spec_attribute :description
|
10
|
+
|
11
|
+
spec_attribute :name # Applies only to apiKey
|
12
|
+
spec_attribute :api_key_in # Applies only to apiKey
|
13
|
+
|
14
|
+
spec_attribute :schema # Applies only to http
|
15
|
+
spec_attribute :bearer_format # Applies only to http
|
16
|
+
|
17
|
+
# spec_attribute :flows # Not supported yet
|
18
|
+
# spec_attribute :open_id_connect_url # Not supported yet
|
19
|
+
|
20
|
+
def to_openapi_spec
|
21
|
+
{
|
22
|
+
"type" => type,
|
23
|
+
"description" => description,
|
24
|
+
"name" => name,
|
25
|
+
"in" => api_key_in,
|
26
|
+
"schema" => schema,
|
27
|
+
"bearerFormat" => bearer_format
|
28
|
+
}.compact
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/eazypi/serializer.rb
CHANGED
data/lib/eazypi/spec_object.rb
CHANGED
@@ -21,8 +21,13 @@ module Eazypi
|
|
21
21
|
|
22
22
|
# ClassMethods for SpecObject
|
23
23
|
module ClassMethods
|
24
|
-
def spec_attribute(attribute_name)
|
25
|
-
define_method(attribute_name) do |v = nil|
|
24
|
+
def spec_attribute(attribute_name, spec_type = nil)
|
25
|
+
define_method(attribute_name) do |v = nil, &block|
|
26
|
+
if spec_type && block
|
27
|
+
v = spec_type.new
|
28
|
+
v.load(&block)
|
29
|
+
end
|
30
|
+
|
26
31
|
instance_variable_set(:"@#{attribute_name}", v) if v
|
27
32
|
|
28
33
|
instance_variable_get(:"@#{attribute_name}")
|
data/lib/eazypi/tag.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eazypi
|
4
|
+
# OpenAPI spec Tag
|
5
|
+
class Tag
|
6
|
+
include SpecObject
|
7
|
+
|
8
|
+
spec_attribute :name
|
9
|
+
spec_attribute :description
|
10
|
+
|
11
|
+
def to_openapi_spec
|
12
|
+
{
|
13
|
+
"name" => name,
|
14
|
+
"description" => description
|
15
|
+
}.compact
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/eazypi/version.rb
CHANGED
data/lib/eazypi.rb
CHANGED
@@ -22,5 +22,8 @@ require "eazypi/response"
|
|
22
22
|
require "eazypi/responses"
|
23
23
|
require "eazypi/schema"
|
24
24
|
require "eazypi/serializer"
|
25
|
+
require "eazypi/security_requirement"
|
26
|
+
require "eazypi/security_scheme"
|
25
27
|
require "eazypi/server"
|
28
|
+
require "eazypi/tag"
|
26
29
|
require "eazypi/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eazypi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Samson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/eazypi/api_controller.rb
|
57
57
|
- lib/eazypi/components.rb
|
58
58
|
- lib/eazypi/info.rb
|
59
|
+
- lib/eazypi/license.rb
|
59
60
|
- lib/eazypi/media_type.rb
|
60
61
|
- lib/eazypi/operation.rb
|
61
62
|
- lib/eazypi/parameter.rb
|
@@ -67,9 +68,12 @@ files:
|
|
67
68
|
- lib/eazypi/schema/array.rb
|
68
69
|
- lib/eazypi/schema/object.rb
|
69
70
|
- lib/eazypi/schema/primitive.rb
|
71
|
+
- lib/eazypi/security_requirement.rb
|
72
|
+
- lib/eazypi/security_scheme.rb
|
70
73
|
- lib/eazypi/serializer.rb
|
71
74
|
- lib/eazypi/server.rb
|
72
75
|
- lib/eazypi/spec_object.rb
|
76
|
+
- lib/eazypi/tag.rb
|
73
77
|
- lib/eazypi/version.rb
|
74
78
|
homepage: https://gitlab.com/nathansamson/eazypi/-/blob/main/README.md
|
75
79
|
licenses:
|
@@ -94,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
98
|
- !ruby/object:Gem::Version
|
95
99
|
version: '0'
|
96
100
|
requirements: []
|
97
|
-
rubygems_version: 3.5.
|
101
|
+
rubygems_version: 3.5.9
|
98
102
|
signing_key:
|
99
103
|
specification_version: 4
|
100
104
|
summary: An opinionated framework to generate OpenAPI API's for Rails
|