apicraft-rails 0.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/README.md +257 -0
  5. data/apicraft-rails.gemspec +41 -0
  6. data/bin/console +15 -0
  7. data/bin/setup +8 -0
  8. data/lib/apicraft/concerns/cacheable.rb +30 -0
  9. data/lib/apicraft/concerns.rb +8 -0
  10. data/lib/apicraft/config.rb +76 -0
  11. data/lib/apicraft/constants.rb +28 -0
  12. data/lib/apicraft/errors.rb +11 -0
  13. data/lib/apicraft/loader.rb +50 -0
  14. data/lib/apicraft/middlewares/introspector.rb +42 -0
  15. data/lib/apicraft/middlewares/mocker.rb +69 -0
  16. data/lib/apicraft/middlewares.rb +9 -0
  17. data/lib/apicraft/mocker/all_of.rb +27 -0
  18. data/lib/apicraft/mocker/any_of.rb +31 -0
  19. data/lib/apicraft/mocker/array.rb +33 -0
  20. data/lib/apicraft/mocker/base.rb +16 -0
  21. data/lib/apicraft/mocker/boolean.rb +12 -0
  22. data/lib/apicraft/mocker/integer.rb +12 -0
  23. data/lib/apicraft/mocker/number.rb +43 -0
  24. data/lib/apicraft/mocker/object.rb +35 -0
  25. data/lib/apicraft/mocker/one_of.rb +14 -0
  26. data/lib/apicraft/mocker/string.rb +44 -0
  27. data/lib/apicraft/mocker.rb +41 -0
  28. data/lib/apicraft/openapi/contract.rb +50 -0
  29. data/lib/apicraft/openapi/operation.rb +36 -0
  30. data/lib/apicraft/openapi/response.rb +47 -0
  31. data/lib/apicraft/openapi.rb +10 -0
  32. data/lib/apicraft/railtie.rb +11 -0
  33. data/lib/apicraft/version.rb +6 -0
  34. data/lib/apicraft/web/actions.rb +60 -0
  35. data/lib/apicraft/web/app.rb +65 -0
  36. data/lib/apicraft/web/router.rb +62 -0
  37. data/lib/apicraft/web.rb +10 -0
  38. data/lib/apicraft-rails.rb +37 -0
  39. data/web/views/index.html +15 -0
  40. data/web/views/redoc.erb +85 -0
  41. data/web/views/swaggerdoc.erb +38 -0
  42. metadata +187 -0
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apicraft
4
+ module Web
5
+ # Managing routes and view paths
6
+ module Router
7
+ WEB_ROOT = File.expand_path(
8
+ "#{File.dirname(__FILE__)}/../../../web"
9
+ )
10
+
11
+ def self.routes
12
+ @routes ||= {
13
+ "/": {
14
+ action: :index,
15
+ view_path: "#{WEB_ROOT}/views/index.html"
16
+ },
17
+ "/swaggerdoc": {
18
+ action: :swaggerdoc,
19
+ view_path: "#{WEB_ROOT}/views/swaggerdoc.erb"
20
+ },
21
+ "/redoc": {
22
+ action: :redoc,
23
+ view_path: "#{WEB_ROOT}/views/redoc.erb"
24
+ }
25
+ }.with_indifferent_access
26
+ end
27
+
28
+ def self.add(path, view_path)
29
+ routes[path] = {
30
+ action: :contract,
31
+ view_path: view_path
32
+ }
33
+ end
34
+
35
+ def self.load_response!(method, path)
36
+ return Actions.introspect(method, path) unless routes[path].present?
37
+
38
+ Actions.send(
39
+ routes[path][:action],
40
+ routes[path][:view_path]
41
+ )
42
+ end
43
+
44
+ def self.namespace=(namespace)
45
+ @namespace = namespace
46
+ end
47
+
48
+ def self.namespace
49
+ @namespace
50
+ end
51
+
52
+ def self.contract_urls
53
+ contract_keys = routes.select do |_k, v|
54
+ v[:action] == :contract
55
+ end.keys
56
+ contract_keys.map do |k|
57
+ "#{Router.namespace}#{k}"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "web/actions"
4
+ require_relative "web/app"
5
+ require_relative "web/router"
6
+
7
+ module Apicraft
8
+ # Namespace module for Concerns
9
+ module Web; end
10
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "find"
4
+ require "rack"
5
+ require "rails/railtie"
6
+ require "openapi_parser"
7
+ require "active_support"
8
+ require "active_support/core_ext"
9
+ require "faker"
10
+ require "mime/types"
11
+ require "erb"
12
+
13
+ require_relative "apicraft/version"
14
+ require_relative "apicraft/constants"
15
+ require_relative "apicraft/config"
16
+ require_relative "apicraft/concerns"
17
+ require_relative "apicraft/errors"
18
+
19
+ require_relative "apicraft/mocker"
20
+ require_relative "apicraft/openapi"
21
+
22
+ require_relative "apicraft/loader"
23
+ require_relative "apicraft/railtie"
24
+
25
+ require_relative "apicraft/web"
26
+ require_relative "apicraft/middlewares"
27
+
28
+ # Check README.md
29
+ module Apicraft
30
+ def self.configure
31
+ yield(config)
32
+ end
33
+
34
+ def self.config
35
+ @config ||= Config.new
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>APICraft</title>
5
+ <meta charset="utf-8"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
8
+ <style>
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <nav>
13
+ </nav>
14
+ </body>
15
+ </html>
@@ -0,0 +1,85 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>APICraft - Redoc</title>
5
+ <meta charset="utf-8"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
8
+ <style>
9
+ body {
10
+ margin: 0;
11
+ padding-top: 40px;
12
+ font-family: 'Montserrat', 'Roboto', sans-serif;
13
+ }
14
+
15
+ nav {
16
+ position: fixed;
17
+ top: 0;
18
+ width: 100%;
19
+ z-index: 100;
20
+ background-color: #1a1a1a;
21
+ padding: 10px 20px;
22
+ display: flex;
23
+ align-items: center;
24
+ }
25
+
26
+ .select-label {
27
+ color: white;
28
+ font-weight: 400;
29
+ margin-right: 10px;
30
+ font-size: 16px;
31
+ }
32
+
33
+ #api_select {
34
+ font-size: 16px;
35
+ padding: 5px 10px;
36
+ color: black;
37
+ background-color: white;
38
+ border: 2px solid #4CAF50;
39
+ border-radius: 4px;
40
+ cursor: pointer;
41
+ max-width: 300px;
42
+ }
43
+ </style>
44
+ </head>
45
+ <body>
46
+ <nav>
47
+ <span class="select-label">
48
+ <strong>Select a definition</strong>
49
+ </span>
50
+ <select id="api_select">
51
+ </select>
52
+ </nav>
53
+ <redoc scroll-y-offset="body > nav"></redoc>
54
+ <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
55
+ <script>
56
+ // List of APIs
57
+ var apis = <%=
58
+ @vars[:urls].map do |u|
59
+ { url: u, name: u.gsub(Apicraft::Web::Router.namespace, "") }
60
+ end.to_json
61
+ %>
62
+
63
+ // Initially render first API
64
+ Redoc.init(apis[0].url);
65
+
66
+ // Function to handle API selection change
67
+ function onSelectChange() {
68
+ var url = this.value;
69
+ Redoc.init(url);
70
+ }
71
+
72
+ // Dynamically building the select dropdown options
73
+ var $select = document.getElementById('api_select');
74
+ apis.forEach(function(api) {
75
+ var $option = document.createElement('option');
76
+ $option.setAttribute('value', api.url);
77
+ $option.innerText = api.name;
78
+ $select.appendChild($option);
79
+ });
80
+
81
+ // Adding event listener for select dropdown change
82
+ $select.addEventListener('change', onSelectChange);
83
+ </script>
84
+ </body>
85
+ </html>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="description" content="SwaggerUI" />
7
+ <title>APICraft - Swagger</title>
8
+ <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css" />
9
+ <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
10
+ <style>
11
+ body {
12
+ font-family: 'Montserrat', 'Roboto', sans-serif;
13
+ }
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <div id="swagger-ui"></div>
18
+ <script src="https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js" crossorigin></script>
19
+ <script src="https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-standalone-preset.js" crossorigin></script>
20
+ <script>
21
+ window.onload = () => {
22
+ window.ui = SwaggerUIBundle({
23
+ urls: <%=
24
+ @vars[:urls].map do |u|
25
+ { url: u, name: u.gsub(Apicraft::Web::Router.namespace, "") }
26
+ end.to_json
27
+ %>,
28
+ dom_id: '#swagger-ui',
29
+ presets: [
30
+ SwaggerUIBundle.presets.apis,
31
+ SwaggerUIStandalonePreset
32
+ ],
33
+ layout: "StandaloneLayout"
34
+ });
35
+ };
36
+ </script>
37
+ </body>
38
+ </html>
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apicraft-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Abhishek Sarkar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: erb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mime-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: openapi_parser
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: railties
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: "\U0001F680 Accelerates your development by 2-3x with an API Design First
112
+ approach. Seamlessly integrates with your Rails application server — no fancy tooling
113
+ or expenses required."
114
+ email:
115
+ - abhisheksarka@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - CHANGELOG.md
121
+ - CODE_OF_CONDUCT.md
122
+ - README.md
123
+ - apicraft-rails.gemspec
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/apicraft-rails.rb
127
+ - lib/apicraft/concerns.rb
128
+ - lib/apicraft/concerns/cacheable.rb
129
+ - lib/apicraft/config.rb
130
+ - lib/apicraft/constants.rb
131
+ - lib/apicraft/errors.rb
132
+ - lib/apicraft/loader.rb
133
+ - lib/apicraft/middlewares.rb
134
+ - lib/apicraft/middlewares/introspector.rb
135
+ - lib/apicraft/middlewares/mocker.rb
136
+ - lib/apicraft/mocker.rb
137
+ - lib/apicraft/mocker/all_of.rb
138
+ - lib/apicraft/mocker/any_of.rb
139
+ - lib/apicraft/mocker/array.rb
140
+ - lib/apicraft/mocker/base.rb
141
+ - lib/apicraft/mocker/boolean.rb
142
+ - lib/apicraft/mocker/integer.rb
143
+ - lib/apicraft/mocker/number.rb
144
+ - lib/apicraft/mocker/object.rb
145
+ - lib/apicraft/mocker/one_of.rb
146
+ - lib/apicraft/mocker/string.rb
147
+ - lib/apicraft/openapi.rb
148
+ - lib/apicraft/openapi/contract.rb
149
+ - lib/apicraft/openapi/operation.rb
150
+ - lib/apicraft/openapi/response.rb
151
+ - lib/apicraft/railtie.rb
152
+ - lib/apicraft/version.rb
153
+ - lib/apicraft/web.rb
154
+ - lib/apicraft/web/actions.rb
155
+ - lib/apicraft/web/app.rb
156
+ - lib/apicraft/web/router.rb
157
+ - web/views/index.html
158
+ - web/views/redoc.erb
159
+ - web/views/swaggerdoc.erb
160
+ homepage: https://github.com/apicraft-dev/apicraft-rails
161
+ licenses:
162
+ - MIT
163
+ metadata:
164
+ allowed_push_host: https://rubygems.org
165
+ homepage_uri: https://github.com/apicraft-dev/apicraft-rails
166
+ source_code_uri: https://github.com/apicraft-dev/apicraft-rails
167
+ changelog_uri: https://github.com/apicraft-dev/apicraft-rails/blob/main/CHANGELOG.md
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '2.7'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.5.11
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: APICraft Rails - Simplified API Design First Development
187
+ test_files: []