Skip to content

Conversation

@iamnamananand996
Copy link
Contributor

@iamnamananand996 iamnamananand996 commented Dec 8, 2025

Description

Refs FER-7972

Implements three previously unimplemented type converters in the Ruby v2 dynamic snippets generator. These converters were returning nop() (no operation), causing snippet examples to show empty arrays or missing values for complex types like union recipients in email/message send operations.

Changes Made

  • Implemented convertDiscriminatedUnion to handle discriminated union types by resolving the union variant and converting its properties to a Ruby hash
  • Implemented convertEnum to convert enum values to Ruby strings using the wire value
  • Implemented convertUndiscriminatedUnion to try each variant type until one matches the value structure
  • Added helper methods: convertDiscriminatedUnionProperties, convertObjectToHashEntries, getEnumValueName, findMatchingUndiscriminatedUnionType
  • Added getBodyArgsForNonObjectType in EndpointSnippetGenerator to handle non-object request body types (arrays, undiscriminated unions, aliases)
  • Fixed duplicate error issue in undiscriminated union conversion by returning the already-converted result instead of calling convert() again on the main context
  • Implemented convertObjectToHashEntries helper to properly handle samePropertiesAsObject discriminated unions (removed the stub extractHashEntries method)
  • Updated versions.yml with changelog entries for 1.0.0-rc62 (feat + fix)

Testing

  • Lint checks pass (pnpm run check)
  • Unit tests updated - 29 tests pass

Snapshot diff examples:

# Discriminated union + enum + samePropertiesAsObject (POST /big-entity):
cast_member: {
  id: 'john.doe',
  name: 'John Doe'
},
event_info: {
  id: 'event-12345',
  data: {
    key1: 'val1',
    key2: 'val2'
  },
  json_string: 'abc'
},
migration: {
  name: 'Migration 31 Aug',
  status: 'RUNNING'  # enum value now included
}

# Array request body (POST /container/list-of-primitives):
client.endpoints.container.get_and_return_list_of_primitives(request: ['one', 'two', 'three']);

Human Review Checklist

  • Critical: The extractHashEntries method was a stub that always returned undefined. RESOLVED: Implemented convertObjectToHashEntries helper that properly handles samePropertiesAsObject discriminated unions.
  • Verify the undiscriminated union pattern (cloning context to avoid error pollution) matches the approach used in other generators (e.g., PHP)
  • Confirm enum values should use wire values as strings in Ruby snippets (matches PHP behavior)
  • The getBodyArgsForNonObjectType method uses hardcoded "request" as the keyword argument name for non-object body types. Verify this matches the actual Ruby SDK method signatures for endpoints with array/union request bodies.
  • Note: For Twilio's senders.resolve() and sender_pools.add_sender() endpoints, the snippets still show empty/minimal parameters. This is a version mismatch issue - Twilio config uses version 1.0.0-rc60, but these fixes are in 1.0.0-rc62. Once the new version is published and Twilio regenerates, the to arrays should be populated.

Link to Devin run: https://app.devin.ai/sessions/b477dd9fc0ea40209f2f32050aad3768
Requested by: [email protected] (@iamnamananand996)

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 5 commits December 8, 2025 19:16
Return the already-converted result from the cloned context instead of
calling convert() again on the main context. This prevents duplicate
errors when the same conversion is performed twice.

Co-Authored-By: [email protected] <[email protected]>
@iamnamananand996 iamnamananand996 force-pushed the namananand/fer-7972-twilio-dynamic-snippets-are-being-weird branch from a9eb032 to 642742c Compare December 9, 2025 14:17
@iamnamananand996 iamnamananand996 merged commit 8eb7426 into main Dec 9, 2025
142 of 144 checks passed
@iamnamananand996 iamnamananand996 deleted the namananand/fer-7972-twilio-dynamic-snippets-are-being-weird branch December 9, 2025 16:54
@iamnamananand996 iamnamananand996 restored the namananand/fer-7972-twilio-dynamic-snippets-are-being-weird branch December 10, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants