├── .gitignore ├── .rubocop.yml ├── .tool-versions ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── ROADMAP.md ├── bin └── rubocop ├── lib └── minitest │ ├── openapi.rb │ └── openapi │ ├── endpoint_metadata.rb │ ├── methods.rb │ ├── minitest_hook.rb │ ├── path.rb │ └── schema.rb ├── minitest-openapi.gemspec └── test └── petstore ├── .dockerignore ├── .gitattributes ├── .gitignore ├── .ruby-version ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── pets_controller.rb ├── jobs │ └── application_job.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── api_error.rb │ ├── application_record.rb │ ├── concerns │ │ └── .keep │ └── pet.rb └── views │ └── layouts │ ├── mailer.html.erb │ └── mailer.text.erb ├── bin ├── bundle ├── docker-entrypoint ├── rails ├── rake └── setup ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── credentials.yml.enc ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── cors.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ └── openapi.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb └── storage.yml ├── db ├── migrate │ └── 20240106205109_create_pets.rb ├── schema.rb └── seeds.rb ├── docs └── openapi.json ├── lib └── tasks │ └── .keep ├── log └── .keep ├── public └── robots.txt ├── storage └── .keep ├── test ├── channels │ └── application_cable │ │ └── connection_test.rb ├── controllers │ ├── .keep │ └── pets_controller_test.rb ├── fixtures │ ├── files │ │ └── .keep │ └── pets.yml ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ └── pet_test.rb └── test_helper.rb ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep └── vendor └── .keep /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | *.gem 3 | 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # Omakase Ruby styling for Rails 2 | inherit_gem: 3 | rubocop-rails-omakase: rubocop.yml 4 | 5 | # Your own specialized rules go here -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 3.3.4 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails" 6 | 7 | group :development do 8 | gem "pry" 9 | gem "rubocop-rails-omakase", require: false 10 | end 11 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.1.2) 5 | actionpack (= 7.1.2) 6 | activesupport (= 7.1.2) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | zeitwerk (~> 2.6) 10 | actionmailbox (7.1.2) 11 | actionpack (= 7.1.2) 12 | activejob (= 7.1.2) 13 | activerecord (= 7.1.2) 14 | activestorage (= 7.1.2) 15 | activesupport (= 7.1.2) 16 | mail (>= 2.7.1) 17 | net-imap 18 | net-pop 19 | net-smtp 20 | actionmailer (7.1.2) 21 | actionpack (= 7.1.2) 22 | actionview (= 7.1.2) 23 | activejob (= 7.1.2) 24 | activesupport (= 7.1.2) 25 | mail (~> 2.5, >= 2.5.4) 26 | net-imap 27 | net-pop 28 | net-smtp 29 | rails-dom-testing (~> 2.2) 30 | actionpack (7.1.2) 31 | actionview (= 7.1.2) 32 | activesupport (= 7.1.2) 33 | nokogiri (>= 1.8.5) 34 | racc 35 | rack (>= 2.2.4) 36 | rack-session (>= 1.0.1) 37 | rack-test (>= 0.6.3) 38 | rails-dom-testing (~> 2.2) 39 | rails-html-sanitizer (~> 1.6) 40 | actiontext (7.1.2) 41 | actionpack (= 7.1.2) 42 | activerecord (= 7.1.2) 43 | activestorage (= 7.1.2) 44 | activesupport (= 7.1.2) 45 | globalid (>= 0.6.0) 46 | nokogiri (>= 1.8.5) 47 | actionview (7.1.2) 48 | activesupport (= 7.1.2) 49 | builder (~> 3.1) 50 | erubi (~> 1.11) 51 | rails-dom-testing (~> 2.2) 52 | rails-html-sanitizer (~> 1.6) 53 | activejob (7.1.2) 54 | activesupport (= 7.1.2) 55 | globalid (>= 0.3.6) 56 | activemodel (7.1.2) 57 | activesupport (= 7.1.2) 58 | activerecord (7.1.2) 59 | activemodel (= 7.1.2) 60 | activesupport (= 7.1.2) 61 | timeout (>= 0.4.0) 62 | activestorage (7.1.2) 63 | actionpack (= 7.1.2) 64 | activejob (= 7.1.2) 65 | activerecord (= 7.1.2) 66 | activesupport (= 7.1.2) 67 | marcel (~> 1.0) 68 | activesupport (7.1.2) 69 | base64 70 | bigdecimal 71 | concurrent-ruby (~> 1.0, >= 1.0.2) 72 | connection_pool (>= 2.2.5) 73 | drb 74 | i18n (>= 1.6, < 2) 75 | minitest (>= 5.1) 76 | mutex_m 77 | tzinfo (~> 2.0) 78 | ast (2.4.2) 79 | base64 (0.2.0) 80 | bigdecimal (3.1.5) 81 | builder (3.2.4) 82 | coderay (1.1.3) 83 | concurrent-ruby (1.2.2) 84 | connection_pool (2.4.1) 85 | crass (1.0.6) 86 | date (3.3.4) 87 | drb (2.2.0) 88 | ruby2_keywords 89 | erubi (1.12.0) 90 | globalid (1.2.1) 91 | activesupport (>= 6.1) 92 | i18n (1.14.1) 93 | concurrent-ruby (~> 1.0) 94 | io-console (0.7.1) 95 | irb (1.11.0) 96 | rdoc 97 | reline (>= 0.3.8) 98 | json (2.7.1) 99 | language_server-protocol (3.17.0.3) 100 | loofah (2.22.0) 101 | crass (~> 1.0.2) 102 | nokogiri (>= 1.12.0) 103 | mail (2.8.1) 104 | mini_mime (>= 0.1.1) 105 | net-imap 106 | net-pop 107 | net-smtp 108 | marcel (1.0.2) 109 | method_source (1.0.0) 110 | mini_mime (1.1.5) 111 | minitest (5.20.0) 112 | mutex_m (0.2.0) 113 | net-imap (0.4.9.1) 114 | date 115 | net-protocol 116 | net-pop (0.1.2) 117 | net-protocol 118 | net-protocol (0.2.2) 119 | timeout 120 | net-smtp (0.4.0.1) 121 | net-protocol 122 | nio4r (2.7.0) 123 | nokogiri (1.16.0-arm64-darwin) 124 | racc (~> 1.4) 125 | parallel (1.24.0) 126 | parser (3.3.0.0) 127 | ast (~> 2.4.1) 128 | racc 129 | pry (0.14.2) 130 | coderay (~> 1.1) 131 | method_source (~> 1.0) 132 | psych (5.1.2) 133 | stringio 134 | racc (1.7.3) 135 | rack (3.0.8) 136 | rack-session (2.0.0) 137 | rack (>= 3.0.0) 138 | rack-test (2.1.0) 139 | rack (>= 1.3) 140 | rackup (2.1.0) 141 | rack (>= 3) 142 | webrick (~> 1.8) 143 | rails (7.1.2) 144 | actioncable (= 7.1.2) 145 | actionmailbox (= 7.1.2) 146 | actionmailer (= 7.1.2) 147 | actionpack (= 7.1.2) 148 | actiontext (= 7.1.2) 149 | actionview (= 7.1.2) 150 | activejob (= 7.1.2) 151 | activemodel (= 7.1.2) 152 | activerecord (= 7.1.2) 153 | activestorage (= 7.1.2) 154 | activesupport (= 7.1.2) 155 | bundler (>= 1.15.0) 156 | railties (= 7.1.2) 157 | rails-dom-testing (2.2.0) 158 | activesupport (>= 5.0.0) 159 | minitest 160 | nokogiri (>= 1.6) 161 | rails-html-sanitizer (1.6.0) 162 | loofah (~> 2.21) 163 | nokogiri (~> 1.14) 164 | railties (7.1.2) 165 | actionpack (= 7.1.2) 166 | activesupport (= 7.1.2) 167 | irb 168 | rackup (>= 1.0.0) 169 | rake (>= 12.2) 170 | thor (~> 1.0, >= 1.2.2) 171 | zeitwerk (~> 2.6) 172 | rainbow (3.1.1) 173 | rake (13.1.0) 174 | rdoc (6.6.2) 175 | psych (>= 4.0.0) 176 | regexp_parser (2.8.3) 177 | reline (0.4.2) 178 | io-console (~> 0.5) 179 | rexml (3.2.6) 180 | rubocop (1.59.0) 181 | json (~> 2.3) 182 | language_server-protocol (>= 3.17.0) 183 | parallel (~> 1.10) 184 | parser (>= 3.2.2.4) 185 | rainbow (>= 2.2.2, < 4.0) 186 | regexp_parser (>= 1.8, < 3.0) 187 | rexml (>= 3.2.5, < 4.0) 188 | rubocop-ast (>= 1.30.0, < 2.0) 189 | ruby-progressbar (~> 1.7) 190 | unicode-display_width (>= 2.4.0, < 3.0) 191 | rubocop-ast (1.30.0) 192 | parser (>= 3.2.1.0) 193 | rubocop-minitest (0.34.3) 194 | rubocop (>= 1.39, < 2.0) 195 | rubocop-ast (>= 1.30.0, < 2.0) 196 | rubocop-performance (1.20.1) 197 | rubocop (>= 1.48.1, < 2.0) 198 | rubocop-ast (>= 1.30.0, < 2.0) 199 | rubocop-rails (2.23.1) 200 | activesupport (>= 4.2.0) 201 | rack (>= 1.1) 202 | rubocop (>= 1.33.0, < 2.0) 203 | rubocop-ast (>= 1.30.0, < 2.0) 204 | rubocop-rails-omakase (1.0.0) 205 | rubocop 206 | rubocop-minitest 207 | rubocop-performance 208 | rubocop-rails 209 | ruby-progressbar (1.13.0) 210 | ruby2_keywords (0.0.5) 211 | stringio (3.1.0) 212 | thor (1.3.0) 213 | timeout (0.4.1) 214 | tzinfo (2.0.6) 215 | concurrent-ruby (~> 1.0) 216 | unicode-display_width (2.5.0) 217 | webrick (1.8.1) 218 | websocket-driver (0.7.6) 219 | websocket-extensions (>= 0.1.0) 220 | websocket-extensions (0.1.5) 221 | zeitwerk (2.6.12) 222 | 223 | PLATFORMS 224 | arm64-darwin-23 225 | arm64-darwin-24 226 | 227 | DEPENDENCIES 228 | pry 229 | rails 230 | rubocop-rails-omakase 231 | 232 | BUNDLED WITH 233 | 2.5.4 234 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Austin Wasson, Bijan Rahnema 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # minitest-openapi 2 | Generate OpenAPI schema from MiniTest request specs. `minitest-openapi` 3 | is inspired by [rspec-openapi](https://github.com/exoego/rspec-openapi). 4 | 5 | ## Installation 6 | ``` 7 | gem 'minitest-openapi', '~> 0.0.2' 8 | ``` 9 | 10 | Note: 0.0.2 excludes some core features required by OpenAPI v3.1 11 | 12 | ## Getting started 13 | To use `minitest-openapi`, add `require 'minitest/openapi'` to 14 | the top of your request spec (if you're not using an initializer), and `include OpenAPI` 15 | at the top of your class declaration. 16 | 17 | By default, test cases are evaluated as `paths`. That is, 18 | they're not `webhooks`. If a test case is testing a 19 | `webhook`, call `webhook!` within the test block. Note: `components` 20 | are not currently supported, but `components` are expected to launch 21 | with `v0.1`. 22 | 23 | ```rb 24 | class PetsControllerTest < ActionDispatch::IntegrationTest 25 | include MiniAPI 26 | 27 | setup do 28 | @pet = pets(:one) 29 | end 30 | 31 | test "will get /pets" do 32 | description "Returns a list of pets" 33 | response_schema { "$ref" => "#/components/schemas/Pets" } 34 | 35 | get pets_url, as: :json 36 | assert_response :success 37 | end 38 | end 39 | ``` 40 | 41 | ## Configuration 42 | To configure how your code will interact with `minitest-openapi`, 43 | create a new file in `config/initializers` (ex: `config/initializers/openapi.rb`). 44 | 45 | ```rb 46 | require 'minitest/openapi' 47 | 48 | # Your project metadata 49 | Minitest::OpenAPI.info = { 50 | title: "Petstore API", 51 | description: "API documentation for the Petstore app.", 52 | version: "0.1.9" 53 | } 54 | 55 | Minitest::OpenAPI.servers << { 56 | url: "http://localhost:3000", 57 | description: "Main (production) server." 58 | } 59 | 60 | # For non-versioned APIs 61 | Minitest::OpenAPI.path = 'docs/openapi.json' 62 | 63 | # For versioned APIs 64 | Minitest::OpenAPI.path = ->(test_case) { 65 | case test_case.path 66 | when %r[controllers/api/v1] then 'docs/openapi/v1.json' 67 | when %r[controllers/api/v2] then 'docs/openapi/v2.json' 68 | else 'docs/openapi.json' 69 | end 70 | } 71 | ``` 72 | 73 | 74 | ## Run 75 | Running: 76 | ```bash 77 | DOC=1 bundle exec rails t 78 | ``` 79 | 80 | will generate a `.json` file. This file will either be called 81 | `docs/openapi.json` (default), or the custom path you passed into the initializer 82 | if on exists. 83 | 84 | ```json 85 | { 86 | "openapi": "3.0.3", 87 | "info": { 88 | "version": "1.2.3", 89 | "title": "minitest-openapi", 90 | "license": { 91 | "name": "MIT", 92 | "url": "https://opensource.org/licenses/MIT" 93 | } 94 | }, 95 | "paths": { 96 | "/pets": { 97 | "get": { 98 | "summary": "Example #1", 99 | "operationId": "listPets", 100 | "tags": [ 101 | "pets" 102 | ], 103 | "parameters": [ 104 | { 105 | "name": "limit", 106 | "in": "query", 107 | "description": "How many items to return at one time (max 100)", 108 | "required": false, 109 | "schema": { 110 | "type": "integer", 111 | "format": "int32" 112 | } 113 | } 114 | ], 115 | "responses": { 116 | "200": { 117 | "description": "A paged array of pets", 118 | "headers": { 119 | "x-next": { 120 | "description": "A link to the next page of responses", 121 | "schema": { 122 | "type": "string" 123 | } 124 | } 125 | }, 126 | "content": { 127 | "application/json": { 128 | "schema": { 129 | "$ref": "#/components/schemas/Pets" 130 | } 131 | } 132 | } 133 | }, 134 | "default": { 135 | "description": "unexpected error", 136 | "content": { 137 | "application/json": { 138 | "schema": { 139 | "$ref": "#/components/schemas/Error" 140 | } 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | }, 148 | "webhooks": { ... }, 149 | "components": { 150 | "schema": { 151 | "Pet": { 152 | "required": ["id"] 153 | } 154 | } 155 | } 156 | } 157 | ``` 158 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Roadmap 2 | 3 | ## Todo 4 | 1. Testing (Rails Petstore API; Merge Petstore YAML) [SPEC](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml) 5 | 6 | Full petstore example can be found here: https://petstore31.swagger.io 7 | OpenAPI File: https://petstore31.swagger.io/api/v31/openapi.json 8 | 9 | 2. Output `Minitest::OpenAPI.paths` & `Minitest::OpenAPI.webhooks` to file paths 10 | 3. Sorting the paths & webhooks (alphanumeric?) 11 | 4. Minimum Ruby version support? (3.1.4 ?) 12 | 5. [Rubocop](https://github.com/rails/rubocop-rails-omakase) 13 | 6. .github/workflows - Rails 8 14 | 15 | ## v0.1.0 16 | -------------------------------------------------------------------------------- /bin/rubocop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rubocop' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 12 | 13 | bundle_binstub = File.expand_path("bundle", __dir__) 14 | 15 | if File.file?(bundle_binstub) 16 | if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") 17 | load(bundle_binstub) 18 | else 19 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 20 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 21 | end 22 | end 23 | 24 | require "rubygems" 25 | require "bundler/setup" 26 | 27 | load Gem.bin_path("rubocop", "rubocop") 28 | -------------------------------------------------------------------------------- /lib/minitest/openapi.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "minitest/openapi/minitest_hook" 4 | require "minitest/openapi/endpoint_metadata" 5 | require "minitest/openapi/path" 6 | require "minitest/openapi/schema" 7 | 8 | module Minitest 9 | module OpenAPI 10 | @spec_version = "3.0.0" 11 | @info = {} 12 | @servers = [] 13 | @path = "docs/openapi.json" 14 | @paths = Hash.new { |h, k| h[k] = {} } 15 | 16 | class << self 17 | attr_accessor :spec_version, 18 | :info, 19 | :servers, 20 | :path, 21 | :paths, 22 | :title 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/minitest/openapi/endpoint_metadata.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "action_dispatch" 4 | require "active_support/inflector" 5 | 6 | module Minitest 7 | module OpenAPI 8 | module EndpointMetadata 9 | class << self 10 | def call(context, _test) 11 | @request = context.request 12 | @response = context.response 13 | return if @request.nil? 14 | 15 | @endpoint = @request.filtered_path || "unknown" 16 | metadata 17 | end 18 | 19 | private 20 | 21 | def metadata 22 | { 23 | endpoint: format_endpoint, 24 | method: @request.method.downcase, 25 | parameters: @request.env["action_dispatch.request.parameters"], 26 | summary: "", 27 | status: @response.status, 28 | content_type: @request.env["CONTENT_TYPE"] 29 | } 30 | end 31 | 32 | # TODO: Rails.application.routes.recognize_path(request.path) 33 | # Convert "owners/1234/pets/5678" to "owners/{ownerId}/pets/{petId}" 34 | def format_endpoint 35 | ep = @endpoint.split("/")[1..-1] || [] 36 | resource = "" 37 | 38 | ep.each_with_index do |e, i| 39 | i.odd? ? 40 | ep[i] = "{#{resource}Id}" : 41 | resource = ActiveSupport::Inflector.singularize(e) 42 | end 43 | "/#{ep.join("/")}" 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/minitest/openapi/methods.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module MiniAPI 4 | def self.included(base) 5 | base.extend(ClassMethods) 6 | end 7 | 8 | # API methods 9 | module ClassMethods 10 | attr_reader :api_operation_id, :api_summary, :api_tags 11 | 12 | def describe_api(&block) 13 | class_eval &block 14 | end 15 | 16 | def operation_id(id) 17 | @api_operation_id = id 18 | end 19 | 20 | def summary(text) 21 | @pending_summary = text 22 | end 23 | 24 | # This hook runs every time a method is added to the class 25 | def method_added(method_name) 26 | return unless @pending_summary 27 | 28 | @summaries ||= {} 29 | @summaries[method_name] = @pending_summary 30 | 31 | puts @pending_summary 32 | @pending_summary = nil 33 | end 34 | 35 | def get_summary(method_name) 36 | @summaries&.[](method_name) 37 | end 38 | 39 | def tags(*tags) 40 | @api_tags = tags 41 | end 42 | end 43 | end 44 | 45 | module Minitest 46 | module OpenAPI 47 | module Methods 48 | def self.prepended(base) 49 | base.extend(MiniAPI) 50 | 51 | # Response methods 52 | base.class_eval do 53 | attr_reader :response_description, :response_schema 54 | 55 | def description(text) 56 | @response_description = text 57 | end 58 | 59 | def response_schema(reference) 60 | @response_schema = reference 61 | end 62 | end 63 | end 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/minitest/openapi/minitest_hook.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "minitest" 4 | require "minitest/openapi/methods" 5 | 6 | module Minitest 7 | module OpenAPI 8 | TestCase = Struct.new(:path) 9 | 10 | module RunPatch 11 | def run(*args) 12 | return super unless ENV["DOC"] 13 | 14 | test_file_path = super.source_location.first 15 | test_case = TestCase.new(test_file_path) 16 | metadata = Minitest::OpenAPI::EndpointMetadata.call(self, test_case) || {} 17 | 18 | Minitest::OpenAPI::Path.build(metadata, test_case) 19 | 20 | super 21 | end 22 | end 23 | end 24 | end 25 | 26 | Minitest::Test.prepend Minitest::OpenAPI::Methods 27 | 28 | if ENV["DOC"] 29 | Minitest::Test.prepend Minitest::OpenAPI::RunPatch 30 | 31 | Minitest.after_run do 32 | Minitest::OpenAPI::Schema.build 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/minitest/openapi/path.rb: -------------------------------------------------------------------------------- 1 | module Minitest 2 | module OpenAPI 3 | module Path 4 | TestCase = Struct.new(:path) 5 | 6 | def self.build(metadata, test_case) 7 | export_file_path = Minitest::OpenAPI.path.yield_self { |p| p.is_a?(Proc) ? p.call(test_case) : p } 8 | file_path_data = Minitest::OpenAPI.paths[export_file_path] 9 | 10 | if file_path_data[metadata[:endpoint]] 11 | if file_path_data[metadata[:endpoint]][metadata[:method]] 12 | file_path_data[metadata[:endpoint]][metadata[:method]][:responses].merge!({ metadata[:status] => self.response(metadata) }) 13 | else 14 | file_path_data[metadata[:endpoint]].merge! self.format_endpoint(metadata) 15 | end 16 | else 17 | file_path_data.merge!(metadata[:endpoint] => self.format_endpoint(metadata)) 18 | end 19 | end 20 | 21 | def self.format_endpoint(metadata) 22 | { 23 | metadata[:method] => { 24 | parameters: [], 25 | responses: { 26 | metadata[:status] => self.response(metadata), 27 | default: { description: "" } 28 | } 29 | } 30 | } 31 | end 32 | 33 | def self.response(metadata) 34 | { 35 | description: "", 36 | headers: {}, 37 | content: { metadata[:content_type] => {} } 38 | } 39 | end 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /lib/minitest/openapi/schema.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Minitest 4 | module OpenAPI 5 | class InvalidFileFormat < StandardError; end 6 | 7 | module Schema 8 | ALLOWED_EXTENSIONS = %w[.json .yaml .yml].freeze 9 | 10 | def self.build 11 | file_paths = self.parse_files 12 | 13 | Dir.mkdir("docs") unless File.exist?("docs") 14 | file_paths.each do |file| 15 | raise InvalidFileFormat unless valid_file_ext?(file) 16 | 17 | File.open(file, "w") do |f| 18 | f.write(JSON.pretty_generate(json_schema(file), indent: " ")) 19 | puts "File generated!" 20 | end 21 | end 22 | end 23 | 24 | # IDK 25 | def self.json_schema(file) 26 | { 27 | openapi: Minitest::OpenAPI.spec_version, 28 | info: Minitest::OpenAPI.info, 29 | servers: Minitest::OpenAPI.servers, 30 | paths: Minitest::OpenAPI.paths[file], 31 | } 32 | end 33 | 34 | def self.parse_files 35 | file_paths = [] 36 | file_paths.concat(Minitest::OpenAPI.paths.keys) 37 | file_paths.uniq 38 | end 39 | 40 | def self.valid_file_ext?(file) 41 | ALLOWED_EXTENSIONS.include?(File.extname(file)) 42 | end 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /minitest-openapi.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'minitest-openapi' 5 | s.version = '0.0.2' 6 | s.summary = 'API documentation generator based on the OpenAPI spec.' 7 | s.description = 'API documentation generator based on the OpenAPI spec.' 8 | s.required_ruby_version = '>= 3.1' 9 | s.authors = [ 'Austin Wasson', 'Bijan Rahnema' ] 10 | s.email = 'austinpwasson@gmail.com' 11 | s.files = Dir['lib/minitest/**/*'] 12 | s.license = 'MIT' 13 | end 14 | -------------------------------------------------------------------------------- /test/petstore/.dockerignore: -------------------------------------------------------------------------------- 1 | # See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. 2 | 3 | # Ignore git directory. 4 | /.git/ 5 | 6 | # Ignore bundler config. 7 | /.bundle 8 | 9 | # Ignore all environment files (except templates). 10 | /.env* 11 | !/.env*.erb 12 | 13 | # Ignore all default key files. 14 | /config/master.key 15 | /config/credentials/*.key 16 | 17 | # Ignore all logfiles and tempfiles. 18 | /log/* 19 | /tmp/* 20 | !/log/.keep 21 | !/tmp/.keep 22 | 23 | # Ignore pidfiles, but keep the directory. 24 | /tmp/pids/* 25 | !/tmp/pids/.keep 26 | 27 | # Ignore storage (uploaded files in development and any SQLite databases). 28 | /storage/* 29 | !/storage/.keep 30 | /tmp/storage/* 31 | !/tmp/storage/.keep 32 | -------------------------------------------------------------------------------- /test/petstore/.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | config/credentials/*.yml.enc diff=rails_credentials 9 | config/credentials.yml.enc diff=rails_credentials 10 | -------------------------------------------------------------------------------- /test/petstore/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all environment files (except templates). 11 | /.env* 12 | !/.env*.erb 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore pidfiles, but keep the directory. 21 | /tmp/pids/* 22 | !/tmp/pids/ 23 | !/tmp/pids/.keep 24 | 25 | # Ignore storage (uploaded files in development and any SQLite databases). 26 | /storage/* 27 | !/storage/.keep 28 | /tmp/storage/* 29 | !/tmp/storage/ 30 | !/tmp/storage/.keep 31 | 32 | # Ignore master key for decrypting credentials and more. 33 | /config/master.key 34 | -------------------------------------------------------------------------------- /test/petstore/.ruby-version: -------------------------------------------------------------------------------- 1 | 3.3.0 2 | -------------------------------------------------------------------------------- /test/petstore/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax = docker/dockerfile:1 2 | 3 | # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile 4 | ARG RUBY_VERSION=3.3.0 5 | FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base 6 | 7 | # Rails app lives here 8 | WORKDIR /rails 9 | 10 | # Set production environment 11 | ENV RAILS_ENV="production" \ 12 | BUNDLE_DEPLOYMENT="1" \ 13 | BUNDLE_PATH="/usr/local/bundle" \ 14 | BUNDLE_WITHOUT="development" 15 | 16 | 17 | # Throw-away build stage to reduce size of final image 18 | FROM base as build 19 | 20 | # Install packages needed to build gems 21 | RUN apt-get update -qq && \ 22 | apt-get install --no-install-recommends -y build-essential git libvips pkg-config 23 | 24 | # Install application gems 25 | COPY Gemfile Gemfile.lock ./ 26 | RUN bundle install && \ 27 | rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ 28 | bundle exec bootsnap precompile --gemfile 29 | 30 | # Copy application code 31 | COPY . . 32 | 33 | # Precompile bootsnap code for faster boot times 34 | RUN bundle exec bootsnap precompile app/ lib/ 35 | 36 | 37 | # Final stage for app image 38 | FROM base 39 | 40 | # Install packages needed for deployment 41 | RUN apt-get update -qq && \ 42 | apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \ 43 | rm -rf /var/lib/apt/lists /var/cache/apt/archives 44 | 45 | # Copy built artifacts: gems, application 46 | COPY --from=build /usr/local/bundle /usr/local/bundle 47 | COPY --from=build /rails /rails 48 | 49 | # Run and own only the runtime files as a non-root user for security 50 | RUN useradd rails --create-home --shell /bin/bash && \ 51 | chown -R rails:rails db log storage tmp 52 | USER rails:rails 53 | 54 | # Entrypoint prepares the database. 55 | ENTRYPOINT ["/rails/bin/docker-entrypoint"] 56 | 57 | # Start the server by default, this can be overwritten at runtime 58 | EXPOSE 3000 59 | CMD ["./bin/rails", "server"] 60 | -------------------------------------------------------------------------------- /test/petstore/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | ruby "3.3.4" 4 | 5 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 6 | gem "rails", "~> 7.1.2" 7 | 8 | # Use sqlite3 as the database for Active Record 9 | gem "sqlite3", "~> 1.4" 10 | 11 | # Use the Puma web server [https://github.com/puma/puma] 12 | gem "puma", ">= 5.0" 13 | 14 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 15 | # gem "jbuilder" 16 | 17 | # Use Redis adapter to run Action Cable in production 18 | # gem "redis", ">= 4.0.1" 19 | 20 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 21 | # gem "kredis" 22 | 23 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 24 | # gem "bcrypt", "~> 3.1.7" 25 | 26 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 27 | gem "tzinfo-data", platforms: %i[ windows jruby ] 28 | 29 | # Reduces boot times through caching; required in config/boot.rb 30 | gem "bootsnap", require: false 31 | 32 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 33 | # gem "image_processing", "~> 1.2" 34 | 35 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible 36 | # gem "rack-cors" 37 | 38 | gem "minitest-openapi", path: "../../" 39 | 40 | group :development, :test do 41 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 42 | gem "debug", platforms: %i[ mri windows ] 43 | end 44 | 45 | group :development do 46 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 47 | # gem "spring" 48 | end 49 | -------------------------------------------------------------------------------- /test/petstore/Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: ../.. 3 | specs: 4 | minitest-openapi (0.0.2) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | actioncable (7.1.2) 10 | actionpack (= 7.1.2) 11 | activesupport (= 7.1.2) 12 | nio4r (~> 2.0) 13 | websocket-driver (>= 0.6.1) 14 | zeitwerk (~> 2.6) 15 | actionmailbox (7.1.2) 16 | actionpack (= 7.1.2) 17 | activejob (= 7.1.2) 18 | activerecord (= 7.1.2) 19 | activestorage (= 7.1.2) 20 | activesupport (= 7.1.2) 21 | mail (>= 2.7.1) 22 | net-imap 23 | net-pop 24 | net-smtp 25 | actionmailer (7.1.2) 26 | actionpack (= 7.1.2) 27 | actionview (= 7.1.2) 28 | activejob (= 7.1.2) 29 | activesupport (= 7.1.2) 30 | mail (~> 2.5, >= 2.5.4) 31 | net-imap 32 | net-pop 33 | net-smtp 34 | rails-dom-testing (~> 2.2) 35 | actionpack (7.1.2) 36 | actionview (= 7.1.2) 37 | activesupport (= 7.1.2) 38 | nokogiri (>= 1.8.5) 39 | racc 40 | rack (>= 2.2.4) 41 | rack-session (>= 1.0.1) 42 | rack-test (>= 0.6.3) 43 | rails-dom-testing (~> 2.2) 44 | rails-html-sanitizer (~> 1.6) 45 | actiontext (7.1.2) 46 | actionpack (= 7.1.2) 47 | activerecord (= 7.1.2) 48 | activestorage (= 7.1.2) 49 | activesupport (= 7.1.2) 50 | globalid (>= 0.6.0) 51 | nokogiri (>= 1.8.5) 52 | actionview (7.1.2) 53 | activesupport (= 7.1.2) 54 | builder (~> 3.1) 55 | erubi (~> 1.11) 56 | rails-dom-testing (~> 2.2) 57 | rails-html-sanitizer (~> 1.6) 58 | activejob (7.1.2) 59 | activesupport (= 7.1.2) 60 | globalid (>= 0.3.6) 61 | activemodel (7.1.2) 62 | activesupport (= 7.1.2) 63 | activerecord (7.1.2) 64 | activemodel (= 7.1.2) 65 | activesupport (= 7.1.2) 66 | timeout (>= 0.4.0) 67 | activestorage (7.1.2) 68 | actionpack (= 7.1.2) 69 | activejob (= 7.1.2) 70 | activerecord (= 7.1.2) 71 | activesupport (= 7.1.2) 72 | marcel (~> 1.0) 73 | activesupport (7.1.2) 74 | base64 75 | bigdecimal 76 | concurrent-ruby (~> 1.0, >= 1.0.2) 77 | connection_pool (>= 2.2.5) 78 | drb 79 | i18n (>= 1.6, < 2) 80 | minitest (>= 5.1) 81 | mutex_m 82 | tzinfo (~> 2.0) 83 | base64 (0.2.0) 84 | bigdecimal (3.1.5) 85 | bootsnap (1.17.0) 86 | msgpack (~> 1.2) 87 | builder (3.2.4) 88 | concurrent-ruby (1.2.2) 89 | connection_pool (2.4.1) 90 | crass (1.0.6) 91 | date (3.3.4) 92 | debug (1.9.1) 93 | irb (~> 1.10) 94 | reline (>= 0.3.8) 95 | drb (2.2.0) 96 | ruby2_keywords 97 | erubi (1.12.0) 98 | globalid (1.2.1) 99 | activesupport (>= 6.1) 100 | i18n (1.14.1) 101 | concurrent-ruby (~> 1.0) 102 | io-console (0.7.1) 103 | irb (1.11.0) 104 | rdoc 105 | reline (>= 0.3.8) 106 | loofah (2.22.0) 107 | crass (~> 1.0.2) 108 | nokogiri (>= 1.12.0) 109 | mail (2.8.1) 110 | mini_mime (>= 0.1.1) 111 | net-imap 112 | net-pop 113 | net-smtp 114 | marcel (1.0.2) 115 | mini_mime (1.1.5) 116 | minitest (5.20.0) 117 | msgpack (1.7.2) 118 | mutex_m (0.2.0) 119 | net-imap (0.4.9.1) 120 | date 121 | net-protocol 122 | net-pop (0.1.2) 123 | net-protocol 124 | net-protocol (0.2.2) 125 | timeout 126 | net-smtp (0.4.0.1) 127 | net-protocol 128 | nio4r (2.7.0) 129 | nokogiri (1.16.0-aarch64-linux) 130 | racc (~> 1.4) 131 | nokogiri (1.16.0-arm-linux) 132 | racc (~> 1.4) 133 | nokogiri (1.16.0-arm64-darwin) 134 | racc (~> 1.4) 135 | nokogiri (1.16.0-x86-linux) 136 | racc (~> 1.4) 137 | nokogiri (1.16.0-x86_64-darwin) 138 | racc (~> 1.4) 139 | nokogiri (1.16.0-x86_64-linux) 140 | racc (~> 1.4) 141 | psych (5.1.2) 142 | stringio 143 | puma (6.4.1) 144 | nio4r (~> 2.0) 145 | racc (1.7.3) 146 | rack (3.0.8) 147 | rack-session (2.0.0) 148 | rack (>= 3.0.0) 149 | rack-test (2.1.0) 150 | rack (>= 1.3) 151 | rackup (2.1.0) 152 | rack (>= 3) 153 | webrick (~> 1.8) 154 | rails (7.1.2) 155 | actioncable (= 7.1.2) 156 | actionmailbox (= 7.1.2) 157 | actionmailer (= 7.1.2) 158 | actionpack (= 7.1.2) 159 | actiontext (= 7.1.2) 160 | actionview (= 7.1.2) 161 | activejob (= 7.1.2) 162 | activemodel (= 7.1.2) 163 | activerecord (= 7.1.2) 164 | activestorage (= 7.1.2) 165 | activesupport (= 7.1.2) 166 | bundler (>= 1.15.0) 167 | railties (= 7.1.2) 168 | rails-dom-testing (2.2.0) 169 | activesupport (>= 5.0.0) 170 | minitest 171 | nokogiri (>= 1.6) 172 | rails-html-sanitizer (1.6.0) 173 | loofah (~> 2.21) 174 | nokogiri (~> 1.14) 175 | railties (7.1.2) 176 | actionpack (= 7.1.2) 177 | activesupport (= 7.1.2) 178 | irb 179 | rackup (>= 1.0.0) 180 | rake (>= 12.2) 181 | thor (~> 1.0, >= 1.2.2) 182 | zeitwerk (~> 2.6) 183 | rake (13.1.0) 184 | rdoc (6.6.2) 185 | psych (>= 4.0.0) 186 | reline (0.4.2) 187 | io-console (~> 0.5) 188 | ruby2_keywords (0.0.5) 189 | sqlite3 (1.7.0-aarch64-linux) 190 | sqlite3 (1.7.0-arm-linux) 191 | sqlite3 (1.7.0-arm64-darwin) 192 | sqlite3 (1.7.0-x86-linux) 193 | sqlite3 (1.7.0-x86_64-darwin) 194 | sqlite3 (1.7.0-x86_64-linux) 195 | stringio (3.1.0) 196 | thor (1.3.0) 197 | timeout (0.4.1) 198 | tzinfo (2.0.6) 199 | concurrent-ruby (~> 1.0) 200 | webrick (1.8.1) 201 | websocket-driver (0.7.6) 202 | websocket-extensions (>= 0.1.0) 203 | websocket-extensions (0.1.5) 204 | zeitwerk (2.6.12) 205 | 206 | PLATFORMS 207 | aarch64-linux 208 | arm-linux 209 | arm64-darwin 210 | x86-linux 211 | x86_64-darwin 212 | x86_64-linux 213 | 214 | DEPENDENCIES 215 | bootsnap 216 | debug 217 | minitest-openapi! 218 | puma (>= 5.0) 219 | rails (~> 7.1.2) 220 | sqlite3 (~> 1.4) 221 | tzinfo-data 222 | 223 | RUBY VERSION 224 | ruby 3.3.4p94 225 | 226 | BUNDLED WITH 227 | 2.5.4 228 | -------------------------------------------------------------------------------- /test/petstore/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | -------------------------------------------------------------------------------- /test/petstore/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/petstore/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/petstore/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/petstore/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | end 3 | -------------------------------------------------------------------------------- /test/petstore/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /test/petstore/app/controllers/pets_controller.rb: -------------------------------------------------------------------------------- 1 | # Purpose: Pets Controller that handles requests according to: 2 | # https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml 3 | class PetsController < ApplicationController 4 | include MiniAPI 5 | 6 | before_action :set_pet, only: %i[ show update destroy ] 7 | 8 | # GET /pets 9 | summary "Test" 10 | def index 11 | @pets = Pet.all 12 | # Just hardcoding the next link for now to fullfill the spec 13 | response.set_header("X-Next", "http://localhost:3000/pets?next") 14 | render json: @pets 15 | end 16 | 17 | # GET /pets/1 18 | summary "Test 2" 19 | def show 20 | render json: @pet 21 | end 22 | 23 | # POST /pets 24 | def create 25 | @pet = Pet.new(pet_params) 26 | 27 | if @pet.save 28 | render json: @pet, status: :created, location: @pet 29 | else 30 | error = ApiError.new(422, @pet.errors.full_messages.join(", ")) 31 | render json: { error: error }, status: :unprocessable_entity 32 | end 33 | end 34 | 35 | # PATCH/PUT /pets/1 36 | def update 37 | if @pet.update(pet_params) 38 | render json: @pet 39 | else 40 | render json: @pet.errors, status: :unprocessable_entity 41 | end 42 | end 43 | 44 | # DELETE /pets/1 45 | def destroy 46 | @pet.destroy! 47 | end 48 | 49 | private 50 | # Use callbacks to share common setup or constraints between actions. 51 | def set_pet 52 | @pet = Pet.find(params[:id]) 53 | rescue ActiveRecord::RecordNotFound 54 | error = ApiError.new(404, "Pet not found") 55 | render json: { error: error }, status: :not_found 56 | end 57 | 58 | # Only allow a list of trusted parameters through. 59 | def pet_params 60 | params.require(:pet).permit(:name) 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /test/petstore/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /test/petstore/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /test/petstore/app/models/api_error.rb: -------------------------------------------------------------------------------- 1 | # app/models/api_error.rb 2 | 3 | class ApiError 4 | attr_reader :code, :message 5 | 6 | def initialize(code, message) 7 | @code = code 8 | @message = message 9 | end 10 | 11 | def as_json(options = {}) 12 | { 13 | code: code, 14 | message: message 15 | } 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/petstore/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /test/petstore/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/app/models/concerns/.keep -------------------------------------------------------------------------------- /test/petstore/app/models/pet.rb: -------------------------------------------------------------------------------- 1 | class Pet < ApplicationRecord 2 | validates :name, presence: true 3 | end 4 | -------------------------------------------------------------------------------- /test/petstore/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/petstore/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /test/petstore/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../Gemfile", __dir__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_requirement 64 | @bundler_requirement ||= 65 | env_var_version || 66 | cli_arg_version || 67 | bundler_requirement_for(lockfile_version) 68 | end 69 | 70 | def bundler_requirement_for(version) 71 | return "#{Gem::Requirement.default}.a" unless version 72 | 73 | bundler_gem_version = Gem::Version.new(version) 74 | 75 | bundler_gem_version.approximate_recommendation 76 | end 77 | 78 | def load_bundler! 79 | ENV["BUNDLE_GEMFILE"] ||= gemfile 80 | 81 | activate_bundler 82 | end 83 | 84 | def activate_bundler 85 | gem_error = activation_error_handling do 86 | gem "bundler", bundler_requirement 87 | end 88 | return if gem_error.nil? 89 | require_error = activation_error_handling do 90 | require "bundler/version" 91 | end 92 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 93 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 94 | exit 42 95 | end 96 | 97 | def activation_error_handling 98 | yield 99 | nil 100 | rescue StandardError, LoadError => e 101 | e 102 | end 103 | end 104 | 105 | m.load_bundler! 106 | 107 | if m.invoked_as_script? 108 | load Gem.bin_path("bundler", "bundle") 109 | end 110 | -------------------------------------------------------------------------------- /test/petstore/bin/docker-entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # If running the rails server then create or migrate existing database 4 | if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then 5 | ./bin/rails db:prepare 6 | fi 7 | 8 | exec "${@}" 9 | -------------------------------------------------------------------------------- /test/petstore/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /test/petstore/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/petstore/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args, exception: true) 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /test/petstore/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /test/petstore/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Petstore 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 7.1 13 | 14 | # Please, add to the `ignore` list any other `lib` subdirectories that do 15 | # not contain `.rb` files, or that should not be reloaded or eager loaded. 16 | # Common ones are `templates`, `generators`, or `middleware`, for example. 17 | config.autoload_lib(ignore: %w[assets tasks]) 18 | 19 | # Configuration for the application, engines, and railties goes here. 20 | # 21 | # These settings can be overridden in specific environments using the files 22 | # in config/environments, which are processed later. 23 | # 24 | # config.time_zone = "Central Time (US & Canada)" 25 | # config.eager_load_paths << Rails.root.join("extras") 26 | 27 | # Only loads a smaller set of middleware suitable for API only apps. 28 | # Middleware like session, flash, cookies can be added back manually. 29 | # Skip views, helpers and assets when generating a new resource. 30 | config.api_only = true 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /test/petstore/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /test/petstore/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: petstore_production 11 | -------------------------------------------------------------------------------- /test/petstore/config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | q0f0N1rDQqvtYzsSnP2y589aVOXkCPHtuyr43b33DGcNe1xRaXg0GkCqp9XVerf8RV38U4aRRomOwbX/db86NRZqMwDUARfvSNBJYTYAAfyp80IBiKcgzNmzO1aJqRlmM4rDUy8aE5eJJmbT4sxC5WtqszV3EV/jt7kc5FuaAG6yq3jqulOGVG+pAnW4hpcDZnyOvTyJBvYVIcqMNlaWjc7gWQie2L5mPhUjEgpdjLW5lhUh2J0b/dYkOr+Y9i3A4QRzfa7lNAs4nsTKVNr1SBA0box8g1IAbsQ6QmuLXu8PsccCfa2cz1fNOY3PHRxVMCSjrMv1qE+hQYOvXbRbiP0zTWecVzcG+FxmQIgp5/SLSrprBko0KIDzOeqqkJUI5arzkehlBXLHjjwv5Nkp+WBnMbZ/--j+Z8p/N48r8kpYZ+--fX0Yxb58GN9buqBvctt9Ow== -------------------------------------------------------------------------------- /test/petstore/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: storage/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: storage/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: storage/production.sqlite3 26 | -------------------------------------------------------------------------------- /test/petstore/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/petstore/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.enable_reloading = true 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.cache_store = :memory_store 24 | config.public_file_server.headers = { 25 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 26 | } 27 | else 28 | config.action_controller.perform_caching = false 29 | 30 | config.cache_store = :null_store 31 | end 32 | 33 | # Store uploaded files on the local file system (see config/storage.yml for options). 34 | config.active_storage.service = :local 35 | 36 | # Don't care if the mailer can't send. 37 | config.action_mailer.raise_delivery_errors = false 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Print deprecation notices to the Rails logger. 42 | config.active_support.deprecation = :log 43 | 44 | # Raise exceptions for disallowed deprecations. 45 | config.active_support.disallowed_deprecation = :raise 46 | 47 | # Tell Active Support which deprecation messages to disallow. 48 | config.active_support.disallowed_deprecation_warnings = [] 49 | 50 | # Raise an error on page load if there are pending migrations. 51 | config.active_record.migration_error = :page_load 52 | 53 | # Highlight code that triggered database queries in logs. 54 | config.active_record.verbose_query_logs = true 55 | 56 | # Highlight code that enqueued background job in logs. 57 | config.active_job.verbose_enqueue_logs = true 58 | 59 | 60 | # Raises error for missing translations. 61 | # config.i18n.raise_on_missing_translations = true 62 | 63 | # Annotate rendered view with file names. 64 | # config.action_view.annotate_rendered_view_with_filenames = true 65 | 66 | # Uncomment if you wish to allow Action Cable access from any origin. 67 | # config.action_cable.disable_request_forgery_protection = true 68 | 69 | # Raise error when a before_action's only/except options reference missing actions 70 | config.action_controller.raise_on_missing_callback_actions = true 71 | end 72 | -------------------------------------------------------------------------------- /test/petstore/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.enable_reloading = false 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | 18 | # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment 19 | # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). 20 | # config.require_master_key = true 21 | 22 | # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. 23 | # config.public_file_server.enabled = false 24 | 25 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 26 | # config.asset_host = "http://assets.example.com" 27 | 28 | # Specifies the header that your server uses for sending files. 29 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 30 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 31 | 32 | # Store uploaded files on the local file system (see config/storage.yml for options). 33 | config.active_storage.service = :local 34 | 35 | # Mount Action Cable outside main process or domain. 36 | # config.action_cable.mount_path = nil 37 | # config.action_cable.url = "wss://example.com/cable" 38 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 39 | 40 | # Assume all access to the app is happening through a SSL-terminating reverse proxy. 41 | # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. 42 | # config.assume_ssl = true 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | config.force_ssl = true 46 | 47 | # Log to STDOUT by default 48 | config.logger = ActiveSupport::Logger.new(STDOUT) 49 | .tap { |logger| logger.formatter = ::Logger::Formatter.new } 50 | .then { |logger| ActiveSupport::TaggedLogging.new(logger) } 51 | 52 | # Prepend all log lines with the following tags. 53 | config.log_tags = [ :request_id ] 54 | 55 | # Info include generic and useful information about system operation, but avoids logging too much 56 | # information to avoid inadvertent exposure of personally identifiable information (PII). If you 57 | # want to log everything, set the level to "debug". 58 | config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") 59 | 60 | # Use a different cache store in production. 61 | # config.cache_store = :mem_cache_store 62 | 63 | # Use a real queuing backend for Active Job (and separate queues per environment). 64 | # config.active_job.queue_adapter = :resque 65 | # config.active_job.queue_name_prefix = "petstore_production" 66 | 67 | config.action_mailer.perform_caching = false 68 | 69 | # Ignore bad email addresses and do not raise email delivery errors. 70 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 71 | # config.action_mailer.raise_delivery_errors = false 72 | 73 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 74 | # the I18n.default_locale when a translation cannot be found). 75 | config.i18n.fallbacks = true 76 | 77 | # Don't log any deprecations. 78 | config.active_support.report_deprecations = false 79 | 80 | # Do not dump schema after migrations. 81 | config.active_record.dump_schema_after_migration = false 82 | 83 | # Enable DNS rebinding protection and other `Host` header attacks. 84 | # config.hosts = [ 85 | # "example.com", # Allow requests from example.com 86 | # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` 87 | # ] 88 | # Skip DNS rebinding protection for the default health check endpoint. 89 | # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } 90 | end 91 | -------------------------------------------------------------------------------- /test/petstore/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # While tests run files are not watched, reloading is not necessary. 12 | config.enable_reloading = false 13 | 14 | # Eager loading loads your entire application. When running a single test locally, 15 | # this is usually not necessary, and can slow down your test suite. However, it's 16 | # recommended that you enable it in continuous integration systems to ensure eager 17 | # loading is working properly before deploying your code. 18 | config.eager_load = ENV["CI"].present? 19 | 20 | # Configure public file server for tests with Cache-Control for performance. 21 | config.public_file_server.enabled = true 22 | config.public_file_server.headers = { 23 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 24 | } 25 | 26 | # Show full error reports and disable caching. 27 | config.consider_all_requests_local = true 28 | config.action_controller.perform_caching = false 29 | config.cache_store = :null_store 30 | 31 | # Render exception templates for rescuable exceptions and raise for other exceptions. 32 | config.action_dispatch.show_exceptions = :rescuable 33 | 34 | # Disable request forgery protection in test environment. 35 | config.action_controller.allow_forgery_protection = false 36 | 37 | # Store uploaded files on the local file system in a temporary directory. 38 | config.active_storage.service = :test 39 | 40 | config.action_mailer.perform_caching = false 41 | 42 | # Tell Action Mailer not to deliver emails to the real world. 43 | # The :test delivery method accumulates sent emails in the 44 | # ActionMailer::Base.deliveries array. 45 | config.action_mailer.delivery_method = :test 46 | 47 | # Print deprecation notices to the stderr. 48 | config.active_support.deprecation = :stderr 49 | 50 | # Raise exceptions for disallowed deprecations. 51 | config.active_support.disallowed_deprecation = :raise 52 | 53 | # Tell Active Support which deprecation messages to disallow. 54 | config.active_support.disallowed_deprecation_warnings = [] 55 | 56 | # Raises error for missing translations. 57 | # config.i18n.raise_on_missing_translations = true 58 | 59 | # Annotate rendered view with file names. 60 | # config.action_view.annotate_rendered_view_with_filenames = true 61 | 62 | # Raise error when a before_action's only/except options reference missing actions 63 | config.action_controller.raise_on_missing_callback_actions = true 64 | end 65 | -------------------------------------------------------------------------------- /test/petstore/config/initializers/cors.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Avoid CORS issues when API is called from the frontend app. 4 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. 5 | 6 | # Read more: https://github.com/cyu/rack-cors 7 | 8 | # Rails.application.config.middleware.insert_before 0, Rack::Cors do 9 | # allow do 10 | # origins "example.com" 11 | # 12 | # resource "*", 13 | # headers: :any, 14 | # methods: [:get, :post, :put, :patch, :delete, :options, :head] 15 | # end 16 | # end 17 | -------------------------------------------------------------------------------- /test/petstore/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. 4 | # Use this to limit dissemination of sensitive information. 5 | # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /test/petstore/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /test/petstore/config/initializers/openapi.rb: -------------------------------------------------------------------------------- 1 | Minitest::OpenAPI.info = { 2 | title: "Petstore API", 3 | description: "API documentation for the Petstore app.", 4 | version: "0.1.9" 5 | } 6 | 7 | Minitest::OpenAPI.servers << { 8 | url: "http://localhost:3000", 9 | description: "Main (production) server." 10 | } 11 | -------------------------------------------------------------------------------- /test/petstore/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization and 2 | # are automatically loaded by Rails. If you want to use locales other than 3 | # English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more about the API, please read the Rails Internationalization guide 20 | # at https://guides.rubyonrails.org/i18n.html. 21 | # 22 | # Be aware that YAML interprets the following case-insensitive strings as 23 | # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings 24 | # must be quoted to be interpreted as strings. For example: 25 | # 26 | # en: 27 | # "yes": yup 28 | # enabled: "ON" 29 | 30 | en: 31 | hello: "Hello world" 32 | -------------------------------------------------------------------------------- /test/petstore/config/puma.rb: -------------------------------------------------------------------------------- 1 | # This configuration file will be evaluated by Puma. The top-level methods that 2 | # are invoked here are part of Puma's configuration DSL. For more information 3 | # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. 4 | 5 | # Puma can serve each request in a thread from an internal thread pool. 6 | # The `threads` method setting takes two numbers: a minimum and maximum. 7 | # Any libraries that use thread pools should be configured to match 8 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 9 | # and maximum; this matches the default thread size of Active Record. 10 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 11 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 12 | threads min_threads_count, max_threads_count 13 | 14 | # Specifies that the worker count should equal the number of processors in production. 15 | if ENV["RAILS_ENV"] == "production" 16 | require "concurrent-ruby" 17 | worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count }) 18 | workers worker_count if worker_count > 1 19 | end 20 | 21 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 22 | # terminating a worker in development environments. 23 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 24 | 25 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 26 | port ENV.fetch("PORT") { 3000 } 27 | 28 | # Specifies the `environment` that Puma will run in. 29 | environment ENV.fetch("RAILS_ENV") { "development" } 30 | 31 | # Specifies the `pidfile` that Puma will use. 32 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 33 | 34 | # Allow puma to be restarted by `bin/rails restart` command. 35 | plugin :tmp_restart 36 | -------------------------------------------------------------------------------- /test/petstore/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | resources :pets 3 | # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html 4 | 5 | # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. 6 | # Can be used by load balancers and uptime monitors to verify that the app is live. 7 | get "up" => "rails/health#show", as: :rails_health_check 8 | 9 | # Defines the root path route ("/") 10 | # root "posts#index" 11 | end 12 | -------------------------------------------------------------------------------- /test/petstore/config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /test/petstore/db/migrate/20240106205109_create_pets.rb: -------------------------------------------------------------------------------- 1 | class CreatePets < ActiveRecord::Migration[7.1] 2 | def change 3 | create_table :pets do |t| 4 | t.string :name 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/petstore/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.1].define(version: 2024_01_06_205109) do 14 | create_table "pets", force: :cascade do |t| 15 | t.string "name" 16 | t.datetime "created_at", null: false 17 | t.datetime "updated_at", null: false 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/petstore/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should ensure the existence of records required to run the application in every environment (production, 2 | # development, test). The code here should be idempotent so that it can be executed at any point in every environment. 3 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 4 | # 5 | # Example: 6 | # 7 | # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| 8 | # MovieGenre.find_or_create_by!(name: genre_name) 9 | # end 10 | -------------------------------------------------------------------------------- /test/petstore/docs/openapi.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.0", 3 | "info": { 4 | "title": "Petstore API", 5 | "description": "API documentation for the Petstore app.", 6 | "version": "0.1.9" 7 | }, 8 | "servers": [ 9 | { 10 | "url": "http://localhost:3000", 11 | "description": "Main (production) server." 12 | } 13 | ], 14 | "paths": { 15 | "/pets": { 16 | "get": { 17 | "parameters": [ 18 | 19 | ], 20 | "responses": { 21 | "200": { 22 | "description": "", 23 | "headers": { 24 | }, 25 | "content": { 26 | "application/json": { 27 | } 28 | } 29 | }, 30 | "default": { 31 | "description": "" 32 | } 33 | } 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /test/petstore/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/lib/tasks/.keep -------------------------------------------------------------------------------- /test/petstore/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/log/.keep -------------------------------------------------------------------------------- /test/petstore/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /test/petstore/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/storage/.keep -------------------------------------------------------------------------------- /test/petstore/test/channels/application_cable/connection_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | module ApplicationCable 4 | class ConnectionTest < ActionCable::Connection::TestCase 5 | # test "connects with cookies" do 6 | # cookies.signed[:user_id] = 42 7 | # 8 | # connect 9 | # 10 | # assert_equal connection.user_id, "42" 11 | # end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/petstore/test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/test/controllers/.keep -------------------------------------------------------------------------------- /test/petstore/test/controllers/pets_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class PetsControllerTest < ActionDispatch::IntegrationTest 4 | include Minitest::OpenAPI 5 | 6 | setup do 7 | @pet = pets(:one) 8 | end 9 | 10 | test "will get index" do 11 | get pets_url, as: :json 12 | assert_response :success 13 | end 14 | 15 | # test "should create pet" do 16 | # assert_difference("Pet.count") do 17 | # post pets_url, params: { pet: { name: @pet.name } }, as: :json 18 | # end 19 | 20 | # assert_response :created 21 | # end 22 | 23 | # test "should not create pet with empty name" do 24 | # assert_no_difference("Pet.count") do 25 | # post pets_url, params: { pet: { name: "" } }, as: :json 26 | # end 27 | 28 | # assert_response :unprocessable_entity # or the specific error code your API returns 29 | # assert_includes @response.body, "error" # check if the response body contains 'error' 30 | # end 31 | 32 | # test "should show pet" do 33 | # get pet_url(@pet), as: :json 34 | # assert_response :success 35 | # end 36 | 37 | # test "should update pet" do 38 | # patch pet_url(@pet), params: { pet: { name: @pet.name } }, as: :json 39 | # assert_response :success 40 | # end 41 | 42 | # test "should destroy pet" do 43 | # assert_difference("Pet.count", -1) do 44 | # delete pet_url(@pet), as: :json 45 | # end 46 | 47 | # assert_response :no_content 48 | # end 49 | end 50 | -------------------------------------------------------------------------------- /test/petstore/test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/test/fixtures/files/.keep -------------------------------------------------------------------------------- /test/petstore/test/fixtures/pets.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | name: MyString 5 | 6 | two: 7 | name: MyString 8 | -------------------------------------------------------------------------------- /test/petstore/test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/test/integration/.keep -------------------------------------------------------------------------------- /test/petstore/test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/test/mailers/.keep -------------------------------------------------------------------------------- /test/petstore/test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/test/models/.keep -------------------------------------------------------------------------------- /test/petstore/test/models/pet_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class PetTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/petstore/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= "test" 2 | require_relative "../config/environment" 3 | require "rails/test_help" 4 | 5 | module ActiveSupport 6 | class TestCase 7 | # Run tests in parallel with specified workers 8 | parallelize(workers: :number_of_processors) 9 | 10 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 11 | fixtures :all 12 | 13 | # Add more helper methods to be used by all tests here... 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /test/petstore/tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/tmp/.keep -------------------------------------------------------------------------------- /test/petstore/tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/tmp/pids/.keep -------------------------------------------------------------------------------- /test/petstore/tmp/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/tmp/storage/.keep -------------------------------------------------------------------------------- /test/petstore/vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wassson/minitest-openapi/b750d1623e805926bc467ffc53ba322e9bed7740/test/petstore/vendor/.keep --------------------------------------------------------------------------------