Class: Rodauth::OpenAPI

Inherits:
Object
  • Object
show all
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

DOCS_URL =
"https://rodauth.jeremyevans.net/documentation.html"
SPEC_VERSION =
"3.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(auth_class, json: nil, password: true) ⇒ OpenAPI

Returns a new instance of OpenAPI.



11
12
13
14
15
# File 'lib/rodauth/openapi.rb', line 11

def initialize(auth_class, json: nil, password: true)
  @auth_class = auth_class
  @json = json
  @password = password
end

Instance Method Details

#generateObject



25
26
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
# File 'lib/rodauth/openapi.rb', line 25

def generate
  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
  all_tags = data[:paths].values.flat_map(&:values).flat_map { |route| route[:tags] }.uniq
  data[:tags].select! { |tag| all_tags.include?(tag[:name]) }

  data
end

#to_jsonObject



21
22
23
# File 'lib/rodauth/openapi.rb', line 21

def to_json
  JSON.pretty_generate(generate)
end

#to_yamlObject



17
18
19
# File 'lib/rodauth/openapi.rb', line 17

def to_yaml
  YAML.dump(JSON.parse(JSON.generate(generate))).lines[1..-1].join
end