rails_ninja 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99a76115680edb87523d0a819db195e01041bd3ed09d6bfabc0226963505f2fc
4
- data.tar.gz: bedb6982e08bd7c32864052ef14d130d0f555503006ceef2a3a0f557e6165912
3
+ metadata.gz: 437ec40dd224b486cc4b24755700f6b8a1bbb7c77e88dd3523760d59d1af5ff5
4
+ data.tar.gz: 28600e208c8c37a36d20243614abd2b8b0096a8e3abd1731e728740d466591eb
5
5
  SHA512:
6
- metadata.gz: e21f4e9ea17198535d38b26a0f7e46d522cb09f84885eee3a92dc4e6c73e16606d446784262bff3841cae1578d3d88ce46ae1c66a6615564f1d2b4139a2ae891
7
- data.tar.gz: dd8f2cbee49dd08ecbbd95fb86ebb2aef82db49eb37f477db1094441e9c39104e7c15b793bba91abf1f6310ecf7e76237994bf16f60bc1ecaa113d57d8d1c31f
6
+ metadata.gz: dfa8f772a93844aff65ffdc59bfbb67379a014f26cb0f73569fcdc3e909086b12d49219db008507065a985fc6a05b73ae3ed6588ba9ab234b36619200aafd7d9
7
+ data.tar.gz: ea13a4f5d9daee6f4cd80c493d55c7518e2d90e78861266e8e575e21617009fde4e3d26d1620c7f2bf42828d10a8937adb9251c269e4879ab3273a07f7f5991f
data/README.md CHANGED
@@ -253,10 +253,13 @@ Generate an OpenAPI 3.2 JSON file for every API:
253
253
  ```sh
254
254
  bundle exec rake rails_ninja:openapi:generate
255
255
  bundle exec rake rails_ninja:openapi:generate OUTPUT=docs/api
256
+ bundle exec rake rails_ninja:openapi:generate OPENAPI_VERSION=3.1.0
256
257
  ```
257
258
 
258
- The default output directory is `public/openapi`. File names come from the API
259
- class name, such as `PublicApi` to `public_api.json`.
259
+ The default OpenAPI version is 3.2.0. Set `OPENAPI_VERSION` to a 3.0.x, 3.1.x,
260
+ or 3.2.x version when a consumer requires another dialect. The default output
261
+ directory is `public/openapi`. File names come from the API class name, such as
262
+ `PublicApi` to `public_api.json`.
260
263
 
261
264
  ## Development
262
265
 
@@ -3,8 +3,16 @@
3
3
  module RailsNinja
4
4
  module OpenAPI
5
5
  class Generator
6
- def initialize(api_class)
6
+ DEFAULT_VERSION = "3.2.0"
7
+ SUPPORTED_VERSION_PATTERN = /\A3\.(?:0|1|2)\.\d+\z/
8
+
9
+ def initialize(api_class, openapi_version: DEFAULT_VERSION)
10
+ unless openapi_version.match?(SUPPORTED_VERSION_PATTERN)
11
+ raise ArgumentError, "unsupported OpenAPI version: #{openapi_version.inspect} (expected 3.0.x, 3.1.x, or 3.2.x)"
12
+ end
13
+
7
14
  @api_class = api_class
15
+ @openapi_version = openapi_version
8
16
  end
9
17
 
10
18
  def to_hash
@@ -16,7 +24,7 @@ module RailsNinja
16
24
  end
17
25
 
18
26
  spec = {
19
- openapi: "3.2.0",
27
+ openapi: @openapi_version,
20
28
  info: {
21
29
  title: @api_class._title || @api_class.name || "API",
22
30
  version: @api_class._version || "0.1.0",
@@ -5,8 +5,9 @@ namespace :rails_ninja do
5
5
  desc "Generate OpenAPI JSON spec files for all registered APIs"
6
6
  task generate: :environment do
7
7
  output = ENV.fetch("OUTPUT", "public/openapi")
8
- RailsNinja.generate_openapi(output: output)
9
- puts "Generated OpenAPI specs in #{output}/"
8
+ openapi_version = ENV.fetch("OPENAPI_VERSION", RailsNinja::OpenAPI::Generator::DEFAULT_VERSION)
9
+ RailsNinja.generate_openapi(output: output, openapi_version: openapi_version)
10
+ puts "Generated OpenAPI #{openapi_version} specs in #{output}/"
10
11
  end
11
12
  end
12
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsNinja
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/rails_ninja.rb CHANGED
@@ -34,12 +34,12 @@ module RailsNinja
34
34
  @registered_apis ||= []
35
35
  end
36
36
 
37
- def self.generate_openapi(output: "public/openapi")
37
+ def self.generate_openapi(output: "public/openapi", openapi_version: OpenAPI::Generator::DEFAULT_VERSION)
38
38
  require "fileutils"
39
39
  FileUtils.mkdir_p(output)
40
40
 
41
41
  registered_apis.each do |api_class|
42
- generator = OpenAPI::Generator.new(api_class)
42
+ generator = OpenAPI::Generator.new(api_class, openapi_version: openapi_version)
43
43
 
44
44
  filename = api_class.name.split("::").last
45
45
  .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_ninja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Urrutia