Skip to content

[ARP - lower camel responses - 1] set_key_transform :camel_lower #20621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InProgressFormsController < ApplicationController
def update
form = find_form || build_form
form.update!(
form_data: params[:form_data],
form_data: params[:formData],
metadata: params[:metadata]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ def show
# serialization layer.
render json: {
account: {
account_uuid: @current_user.user_account_uuid
accountUuid: @current_user.user_account_uuid
},
profile: {
first_name: @current_user.first_name,
last_name: @current_user.last_name,
firstName: @current_user.first_name,
lastName: @current_user.last_name,
verified: @current_user.user_account.verified?,
sign_in: {
service_name: @current_user.sign_in[:service_name]
signIn: {
serviceName: @current_user.sign_in[:service_name]
}
},
prefills_available: [],
in_progress_forms:
prefillsAvailable: [],
inProgressForms: in_progress_forms
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def set_location
return unless address

self.claimant_city = address['city']
self.claimant_state_code = address['state_code']
self.claimant_zip_code = address['zip_code']
self.claimant_state_code = address['stateCode']
self.claimant_zip_code = address['zipCode']
end

def data_must_comply_with_schema
Expand Down Expand Up @@ -83,11 +83,11 @@ def data_must_comply_with_schema
"authorizations": {
"type": "object",
"properties": {
"record_disclosure": {
"recordDisclosure": {
"type": "boolean",
"example": true
},
"record_disclosure_limitations": {
"recordDisclosureLimitations": {
"type": "array",
"items": {
"type": "string",
Expand All @@ -105,15 +105,15 @@ def data_must_comply_with_schema
"SICKLE_CELL"
]
},
"address_change": {
"addressChange": {
"type": "boolean",
"example": false
}
},
"required": [
"record_disclosure",
"record_disclosure_limitations",
"address_change"
"recordDisclosure",
"recordDisclosureLimitations",
"addressChange"
]
},
"dependent": {
Expand Down Expand Up @@ -144,46 +144,46 @@ def data_must_comply_with_schema
"address": {
"type": "object",
"properties": {
"address_line1": {
"addressLine1": {
"type": "string",
"example": "123 Main St"
},
"address_line2": {
"addressLine2": {
"type": ["string", "null"],
"example": "Apt 1"
},
"city": {
"type": "string",
"example": "Springfield"
},
"state_code": {
"stateCode": {
"type": "string",
"example": "IL"
},
"country": {
"type": "string",
"example": "US"
},
"zip_code": {
"zipCode": {
"type": "string",
"example": "62704"
},
"zip_code_suffix": {
"zipCodeSuffix": {
"type": ["string", "null"],
"example": "6789"
}
},
"required": [
"address_line1",
"address_line2",
"addressLine1",
"addressLine2",
"city",
"state_code",
"stateCode",
"country",
"zip_code",
"zip_code_suffix"
"zipCode",
"zipCodeSuffix"
]
},
"date_of_birth": {
"dateOfBirth": {
"type": "string",
"format": "date",
"example": "1980-12-31"
Expand All @@ -204,7 +204,7 @@ def data_must_comply_with_schema
"required": [
"name",
"address",
"date_of_birth",
"dateOfBirth",
"relationship",
"phone",
"email"
Expand Down Expand Up @@ -238,63 +238,63 @@ def data_must_comply_with_schema
"address": {
"type": "object",
"properties": {
"address_line1": {
"addressLine1": {
"type": "string",
"example": "123 Main St"
},
"address_line2": {
"addressLine2": {
"type": ["string", "null"],
"example": "Apt 1"
},
"city": {
"type": "string",
"example": "Springfield"
},
"state_code": {
"stateCode": {
"type": "string",
"example": "IL"
},
"country": {
"type": "string",
"example": "US"
},
"zip_code": {
"zipCode": {
"type": "string",
"example": "62704"
},
"zip_code_suffix": {
"zipCodeSuffix": {
"type": ["string", "null"],
"example": "6789"
}
},
"required": [
"address_line1",
"address_line2",
"addressLine1",
"addressLine2",
"city",
"state_code",
"stateCode",
"country",
"zip_code",
"zip_code_suffix"
"zipCode",
"zipCodeSuffix"
]
},
"ssn": {
"type": "string",
"example": "123456789"
},
"va_file_number": {
"vaFileNumber": {
"type": ["string", "null"],
"example": "123456789"
},
"date_of_birth": {
"dateOfBirth": {
"type": "string",
"format": "date",
"example": "1980-12-31"
},
"service_number": {
"serviceNumber": {
"type": ["string", "null"],
"example": "123456789"
},
"service_branch": {
"serviceBranch": {
"type": ["string", "null"],
"enum": [
"ARMY",
Expand All @@ -321,10 +321,10 @@ def data_must_comply_with_schema
"name",
"address",
"ssn",
"va_file_number",
"date_of_birth",
"service_number",
"service_branch",
"vaFileNumber",
"dateOfBirth",
"serviceNumber",
"serviceBranch",
"phone",
"email"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module AccreditedRepresentativePortal
class ApplicationSerializer
include JSONAPI::Serializer

set_key_transform :camel_lower

# We're not building to JSONAPI.
def serializable_hash
data = super[:data]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
##
# `olive_branch` transforms (a) request and (b) response payloads.
#
# (a) It deeply transforms request and query param keys.
# At times it is convenient for params to act as snake-cased setters at a Ruby
# interface, but not always. Form resources are a possible example where not.
#
# For now, let's wait to encounter the cases where we really want this
# convenience. If we do encounter some, we may discover that we want a more
# explicit and collocated way to opt in.
#
# (b) It reloads the response from JSON, deeply transforms keys, and dumps
# back to JSON.
# This is superfluous because our serialization layer `jsonapi-serializer`
# already has a configuration option for key casing. This realizes our desired
# casing the one and only time it is visiting an object during serialization.
#
module BypassOliveBranch
def call(env)
exclude_arp_route?(env) ? @app.call(env) : super
end

private

ARP_PATH_INFO_PREFIX = '/accredited_representative_portal'

def exclude_arp_route?(env)
env['PATH_INFO'].to_s.start_with?(ARP_PATH_INFO_PREFIX)
end
end
end

module OliveBranch
class Middleware
prepend AccreditedRepresentativePortal::BypassOliveBranch
end
end
Loading
Loading