Skip to content

Commit

Permalink
feat: add parameter guard for language in magic link options (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 authored Jan 10, 2025
1 parent 4d3c634 commit a1ce3e7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/openapi_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
require_relative 'openapi_client/models/list_paginated_users_response'
require_relative 'openapi_client/models/magic_link'
require_relative 'openapi_client/models/magic_link_channel'
require_relative 'openapi_client/models/magic_link_language'
require_relative 'openapi_client/models/magic_link_response'
require_relative 'openapi_client/models/magic_link_type'
require_relative 'openapi_client/models/model400_error'
Expand Down
23 changes: 21 additions & 2 deletions lib/openapi_client/models/create_magic_link_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class CreateMagicLinkRequest

attr_accessor :email

# language of the email to send (optional)
attr_accessor :language

# must be a relative url
Expand All @@ -31,6 +30,7 @@ class CreateMagicLinkRequest

attr_accessor :_send

# time to live in minutes
attr_accessor :ttl

attr_accessor :type
Expand Down Expand Up @@ -85,7 +85,7 @@ def self.openapi_types
{
:'channel' => :'MagicLinkChannel',
:'email' => :'String',
:'language' => :'String',
:'language' => :'MagicLinkLanguage',
:'magic_link_path' => :'String',
:'phone' => :'String',
:'redirect_url' => :'String',
Expand Down Expand Up @@ -163,16 +163,35 @@ def initialize(attributes = {})
def list_invalid_properties
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
invalid_properties = Array.new
if !@ttl.nil? && @ttl < 1
invalid_properties.push('invalid value for "ttl", must be greater than or equal to 1.')
end

invalid_properties
end

# Check to see if the all the properties in the model are valid
# @return true if the model is valid
def valid?
warn '[DEPRECATED] the `valid?` method is obsolete'
return false if !@ttl.nil? && @ttl < 1
true
end

# Custom attribute writer method with validation
# @param [Object] ttl Value to be assigned
def ttl=(ttl)
if ttl.nil?
fail ArgumentError, 'ttl cannot be nil'
end

if ttl < 1
fail ArgumentError, 'invalid value for "ttl", must be greater than or equal to 1.'
end

@ttl = ttl
end

# Checks equality by comparing each attribute.
# @param [Object] Object to be compared
def ==(o)
Expand Down
1 change: 1 addition & 0 deletions lib/openapi_client/models/magic_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MagicLink

attr_accessor :secret

# time to live in minutes
attr_accessor :ttl

attr_accessor :type
Expand Down
45 changes: 45 additions & 0 deletions lib/openapi_client/models/magic_link_language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
=begin
#Passage Management API
#Passage's management API to manage your Passage apps and users.
The version of the OpenAPI document: 1
Contact: [email protected]
Generated by: https://openapi-generator.tech
Generator version: 7.11.0-SNAPSHOT
=end

require 'date'
require 'time'

module OpenapiClient
class MagicLinkLanguage
DE = "de".freeze
EN = "en".freeze
ES = "es".freeze
IT = "it".freeze
PL = "pl".freeze
PT = "pt".freeze
ZH = "zh".freeze

def self.all_vars
@all_vars ||= [DE, EN, ES, IT, PL, PT, ZH].freeze
end

# Builds the enum from string
# @param [String] The enum value in the form of the string
# @return [String] The enum value
def self.build_from_hash(value)
new.build_from_hash(value)
end

# Builds the enum from string
# @param [String] The enum value in the form of the string
# @return [String] The enum value
def build_from_hash(value)
return value if MagicLinkLanguage.all_vars.include?(value)
raise "Invalid ENUM value #{value} for class #MagicLinkLanguage"
end
end
end
7 changes: 6 additions & 1 deletion lib/passageidentity/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ def fetch_jwks
end

def create_magic_link(args, opts)
args['language'] = opts['language']
language = opts['language']
if language && !OpenapiClient::MagicLinkLanguage.all_vars.include?(language)
raise ArgumentError, "language must be one of #{OpenapiClient::MagicLinkLanguage.all_vars}"
end

args['language'] = language
args['magic_link_path'] = opts['magic_link_path']
args['redirect_url'] = opts['redirect_url']
args['ttl'] = opts['ttl']
Expand Down

0 comments on commit a1ce3e7

Please sign in to comment.