Class: Rodauth::OpenAPI
- Inherits:
-
Object
- Object
- Rodauth::OpenAPI
- Defined in:
- lib/rodauth/openapi.rb,
lib/rodauth/openapi/routes.rb,
lib/rodauth/openapi/routes/otp.rb,
lib/rodauth/openapi/routes/login.rb,
lib/rodauth/openapi/routes/logout.rb,
lib/rodauth/openapi/routes/lockout.rb,
lib/rodauth/openapi/routes/remember.rb,
lib/rodauth/openapi/routes/webauthn.rb,
lib/rodauth/openapi/routes/sms_codes.rb,
lib/rodauth/openapi/routes/email_auth.rb,
lib/rodauth/openapi/routes/otp_unlock.rb,
lib/rodauth/openapi/routes/jwt_refresh.rb,
lib/rodauth/openapi/routes/change_login.rb,
lib/rodauth/openapi/routes/close_account.rb,
lib/rodauth/openapi/routes/create_account.rb,
lib/rodauth/openapi/routes/recovery_codes.rb,
lib/rodauth/openapi/routes/reset_password.rb,
lib/rodauth/openapi/routes/verify_account.rb,
lib/rodauth/openapi/routes/webauthn_login.rb,
lib/rodauth/openapi/routes/change_password.rb,
lib/rodauth/openapi/routes/confirm_account.rb,
lib/rodauth/openapi/routes/two_factor_base.rb,
lib/rodauth/openapi/routes/verify_login_change.rb
Defined Under Namespace
Classes: Routes
Constant Summary collapse
- Error =
Class.new(StandardError)
- DOCS_URL =
"https://rodauth.jeremyevans.net/documentation.html"
- SPEC_VERSION =
"3.0.1"
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(auth_class, json: nil, password: true) ⇒ OpenAPI
constructor
A new instance of OpenAPI.
- #to_json ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(auth_class, json: nil, password: true) ⇒ OpenAPI
Returns a new instance of OpenAPI.
13 14 15 16 17 |
# File 'lib/rodauth/openapi.rb', line 13 def initialize(auth_class, json: nil, password: true) @auth_class = auth_class @json = json @password = password end |
Instance Method Details
#generate ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rodauth/openapi.rb', line 27 def generate if json? && !rodauth.features.include?(:json) fail Error, "JSON API documentation was requested, but JSON feature is not enabled" end data = { openapi: SPEC_VERSION, info: { title: "Rodauth", description: "This lists all the endpoints provided by Rodauth features.", version: Rodauth::VERSION, }, externalDocs: { description: "Rodauth documentation", url: DOCS_URL, }, tags: [], paths: {}, } rodauth.features.each do |feature| begin require "rodauth/openapi/routes/#{feature}" rescue LoadError next end routes = Routes.new(data, rodauth: rodauth, json: json?) routes.instance_exec(&Routes::FEATURES[feature]) end # remove tags that don't have any routes = data[:paths].values.flat_map(&:values).flat_map { |route| route[:tags] }.uniq data[:tags].select! { |tag| .include?(tag[:name]) } data end |
#to_json ⇒ Object
23 24 25 |
# File 'lib/rodauth/openapi.rb', line 23 def to_json JSON.pretty_generate(generate) end |
#to_yaml ⇒ Object
19 20 21 |
# File 'lib/rodauth/openapi.rb', line 19 def to_yaml YAML.dump(JSON.parse(JSON.generate(generate))).lines[1..-1].join end |