rc-minitest-openapi-api 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 03e7af9c0cb24c4b9d40abc84cec7ccad1c07f0e2aff6f129c9861ae2e58106d
4
+ data.tar.gz: 1d4b26f07bc3c9d9d068653ce038259c74232808e8044b2b5c51398ec354f1df
5
+ SHA512:
6
+ metadata.gz: 31ae0efe0d957785608757303e3a6707542f2b9be42ff4e81a0792822012e7e83c44adf25c4f048d4c8e85fb682efc953dce1e60e556bde81bebf46d18d17b2b
7
+ data.tar.gz: 0a1f05ebdb044edb21bde871c7c606f08b587d685d607c25bc25d6c35eb0896ccd8425bb4a368ea19391167fa205af7d89e3cc4e0ac383492cba062c9a3afa5d
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # rc-minitest-openapi-api
2
+
3
+ A mountable Rails engine that serves the OpenAPI document generated by
4
+ [`rc-minitest-openapi`](https://github.com/RailsComposer/minitest-openapi).
5
+
6
+ ```ruby
7
+ # config/routes.rb
8
+ mount Minitest::OpenAPI::Api::Engine => "/api-docs"
9
+
10
+ # config/initializers/minitest_openapi.rb
11
+ Minitest::OpenAPI::Api.configure { |c| c.document_path = "openapi/v1/openapi.json" }
12
+ ```
13
+
14
+ See the [repository README](https://github.com/RailsComposer/minitest-openapi)
15
+ for full documentation.
16
+
17
+ ## License
18
+
19
+ MIT
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Minitest::OpenAPI::Api::Engine.routes.draw do
4
+ get "/" => Minitest::OpenAPI::Api::DocumentEndpoint.new, :as => :document
5
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minitest
4
+ module OpenAPI
5
+ module Api
6
+ class Configuration
7
+ # Path to the generated document, relative to Rails.root (or absolute).
8
+ attr_accessor :document_path
9
+
10
+ def initialize
11
+ @document_path = "openapi/openapi.json"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module Minitest
6
+ module OpenAPI
7
+ module Api
8
+ # Rack endpoint that serves the generated OpenAPI document.
9
+ class DocumentEndpoint
10
+ JSON_HEADERS = {"content-type" => "application/json; charset=utf-8"}.freeze
11
+
12
+ def call(_env)
13
+ path = resolved_path
14
+
15
+ if File.file?(path)
16
+ [200, JSON_HEADERS.dup, [File.read(path)]]
17
+ else
18
+ [404, JSON_HEADERS.dup, [not_found_body]]
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def resolved_path
25
+ configured = Minitest::OpenAPI::Api.configuration.document_path
26
+ return configured if Pathname.new(configured).absolute?
27
+
28
+ File.join(Rails.root.to_s, configured)
29
+ end
30
+
31
+ def not_found_body
32
+ %({"error":"OpenAPI document not found. Run `bin/rails openapi:generate`."})
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/engine"
4
+
5
+ module Minitest
6
+ module OpenAPI
7
+ module Api
8
+ # Mountable engine. In the host app's routes:
9
+ #
10
+ # mount Minitest::OpenAPI::Api::Engine => "/api-docs"
11
+ #
12
+ # The document is then served at GET /api-docs.
13
+ class Engine < ::Rails::Engine
14
+ isolate_namespace Minitest::OpenAPI::Api
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minitest
4
+ module OpenAPI
5
+ module Api
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api/version"
4
+ require_relative "api/configuration"
5
+ require_relative "api/document_endpoint"
6
+ require_relative "api/engine" if defined?(::Rails::Engine)
7
+
8
+ module Minitest
9
+ module OpenAPI
10
+ # Serves the OpenAPI document produced by minitest-openapi.
11
+ module Api
12
+ class << self
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield configuration
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rc-minitest-openapi-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RailsComposer
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: railties
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ description: A mountable Rails engine that serves the OpenAPI document produced by
27
+ rc-minitest-openapi at a configurable route.
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - README.md
33
+ - config/routes.rb
34
+ - lib/minitest/openapi/api.rb
35
+ - lib/minitest/openapi/api/configuration.rb
36
+ - lib/minitest/openapi/api/document_endpoint.rb
37
+ - lib/minitest/openapi/api/engine.rb
38
+ - lib/minitest/openapi/api/version.rb
39
+ homepage: https://github.com/RailsComposer/minitest-openapi
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/RailsComposer/minitest-openapi
44
+ source_code_uri: https://github.com/RailsComposer/minitest-openapi
45
+ rubygems_mfa_required: 'true'
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '3.2'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.6.9
61
+ specification_version: 4
62
+ summary: Serve the OpenAPI document generated by rc-minitest-openapi.
63
+ test_files: []