fix(auth): add machine-readable codes to password validation 422 response (EVO-992)#15
Merged
Conversation
…onse Return structured `codes` array (e.g. `password.missing_special_char`) alongside human-readable messages in validation error details, so the frontend can map each failure to a localized message without screen-scraping. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds machine-readable password complexity error codes and exposes them through the existing validation error formatting, plus tests for password validation behavior. Sequence diagram for password validation 422 response with machine-readable codessequenceDiagram
actor ApiClient
participant UsersController
participant UserModel
participant ActiveModelErrors
participant BaseController
ApiClient->>UsersController: POST /users (password)
UsersController->>UserModel: assign_attributes(password)
UsersController->>UserModel: valid?
UserModel->>UserModel: password_complexity
alt password_missing_requirements
UserModel->>ActiveModelErrors: add password :missing_lowercase
UserModel->>ActiveModelErrors: add password :missing_uppercase
UserModel->>ActiveModelErrors: add password :missing_number
UserModel->>ActiveModelErrors: add password :missing_special_char
end
UserModel-->>UsersController: validation_result(errors)
UsersController->>BaseController: format_validation_errors(errors)
BaseController->>ActiveModelErrors: attribute_names
loop each field
BaseController->>ActiveModelErrors: where(field)
ActiveModelErrors-->>BaseController: field_errors
BaseController->>ActiveModelErrors: full_messages_for(field)
ActiveModelErrors-->>BaseController: full_messages
end
BaseController-->>UsersController: [{field,codes,messages,full_messages}]
UsersController-->>ApiClient: 422 JSON {errors:[{field,codes,messages,full_messages}]}
Class diagram for User password complexity and BaseController validation formattingclassDiagram
class User {
+String password
+password_complexity()
}
class ActiveModelErrors {
+attribute_names() Array~Symbol~
+where(attribute) Array~ActiveModelError~
+full_messages_for(attribute) Array~String~
}
class ActiveModelError {
+Symbol attribute
+Object type
+String message
}
class ApiBaseController {
+format_validation_errors(errors) Array~Hash~
}
User *-- ActiveModelErrors : has_errors
ActiveModelErrors o-- ActiveModelError : contains
ApiBaseController ..> ActiveModelErrors : formats
class PasswordErrorTypes {
<<enumeration>>
missing_lowercase
missing_uppercase
missing_number
missing_special_char
}
ActiveModelError ..> PasswordErrorTypes : type
note for User "password_complexity adds password errors with symbolic types and messages"
note for ApiBaseController "format_validation_errors builds field,codes,messages,full_messages"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The switch from
errors.messages.maptoerrors.attribute_names.mapinformat_validation_errorsmeans:baseerrors will no longer be emitted (sinceattribute_namesexcludes:base), so consider explicitly including:baseor iterating over the same keys as before to avoid changing behavior for non-attribute validation errors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The switch from `errors.messages.map` to `errors.attribute_names.map` in `format_validation_errors` means `:base` errors will no longer be emitted (since `attribute_names` excludes `:base`), so consider explicitly including `:base` or iterating over the same keys as before to avoid changing behavior for non-attribute validation errors.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
dpaes
approved these changes
May 11, 2026
dpaes
left a comment
Contributor
There was a problem hiding this comment.
Aprovado via /evo-code-review (EVO-992). Débito conhecido: ausência de spec de request cobrindo a serialização do array codes em error.details; cobertura de teste no frontend zero para o fluxo. Aprovação consciente do owner (Davidson).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User#password_complexityto use typed error symbols (:missing_lowercase,:missing_uppercase,:missing_number,:missing_special_char) instead of plain stringsformat_validation_errorsinBaseControllerto include acodesarray (e.g.password.missing_special_char) alongside existingmessagesandfull_messages— additive, no breaking changespec/models/user_password_spec.rbcovering all four complexity error codes and the happy pathValidation
evo-auth-service-community: ruby -c app/models/user.rb✓evo-auth-service-community: ruby -c app/controllers/api/base_controller.rb✓evo-auth-service-community: ruby -c spec/models/user_password_spec.rb✓Changed Files
app/models/user.rbapp/controllers/api/base_controller.rbspec/models/user_password_spec.rbRelated PRs
Linked Issue
🤖 Generated with Claude Code