diff --git a/src/lib/code-sample/ruby.ts b/src/lib/code-sample/ruby.ts index be22435..af0c903 100644 --- a/src/lib/code-sample/ruby.ts +++ b/src/lib/code-sample/ruby.ts @@ -1,4 +1,4 @@ -import { pascalCase, snakeCase } from 'change-case' +import { snakeCase } from 'change-case' import type { Json, NonNullJson } from 'lib/json.js' @@ -34,16 +34,13 @@ export const createRubyResponse = ( throw new Error(`Missing ${responseKey} for '${title}'`) } - const responseRubyClassName = pascalCase(responseKey) - return Array.isArray(responseValue) - ? formatRubyArrayResponse(responseValue, responseRubyClassName, title) - : formatRubyResponse(responseValue, responseRubyClassName) + ? formatRubyArrayResponse(responseValue, title) + : formatRubyResponse(responseValue) } const formatRubyArrayResponse = ( responseArray: Json[], - responseRubyClassName: string, title: string, ): string => { const formattedItems = responseArray @@ -51,25 +48,17 @@ const formatRubyArrayResponse = ( if (item == null) { throw new Error(`Null value in response array for '${title}'`) } - return formatRubyResponse(item, responseRubyClassName) + return formatRubyResponse(item) }) .join(',\n') return `[${formattedItems}]` } -const formatRubyResponse = ( - responseParams: NonNullJson, - responseRubyClassName: string, -): string => { - const params = formatRubyArgs(responseParams) - return `` +const formatRubyResponse = (responseParams: NonNullJson): string => { + const values = Object.entries(responseParams as Record).map( + ([paramKey, paramValue]) => + `"${snakeCase(paramKey)}" => ${formatRubyValue(paramValue)}`, + ) + return `{${values.join(',')}}` } - -const formatRubyArgs = (jsonParams: NonNullJson): string => - Object.entries(jsonParams as Record) - .map( - ([paramKey, paramValue]) => - `${snakeCase(paramKey)}=${formatRubyValue(paramValue)}`, - ) - .join('\n') diff --git a/test/snapshots/blueprint.test.ts.md b/test/snapshots/blueprint.test.ts.md index 008f71a..30b50bc 100644 --- a/test/snapshots/blueprint.test.ts.md +++ b/test/snapshots/blueprint.test.ts.md @@ -94,10 +94,7 @@ Generated by [AVA](https://avajs.dev). ruby: { request: 'seam.foos.get(foo_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33")', request_syntax: 'ruby', - response: ``, + response: '{"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}', response_syntax: 'ruby', title: 'Ruby', }, @@ -178,10 +175,7 @@ Generated by [AVA](https://avajs.dev). ruby: { request: 'seam.foos.get(foo_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33")', request_syntax: 'ruby', - response: ``, + response: '{"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}', response_syntax: 'ruby', title: 'Ruby', }, @@ -262,10 +256,7 @@ Generated by [AVA](https://avajs.dev). ruby: { request: 'seam.foos.list()', request_syntax: 'ruby', - response: `[]`, + response: '[{"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}]', response_syntax: 'ruby', title: 'Ruby', }, @@ -346,10 +337,7 @@ Generated by [AVA](https://avajs.dev). ruby: { request: 'seam.foos.list()', request_syntax: 'ruby', - response: `[]`, + response: '[{"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}]', response_syntax: 'ruby', title: 'Ruby', }, @@ -510,10 +498,7 @@ Generated by [AVA](https://avajs.dev). seam.foos.get(foo_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33")`, request_syntax: 'ruby', response: `// ruby␊ - `, + {"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}`, response_syntax: 'ruby', title: 'Ruby', }, @@ -604,10 +589,7 @@ Generated by [AVA](https://avajs.dev). seam.foos.get(foo_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33")`, request_syntax: 'ruby', response: `// ruby␊ - `, + {"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}`, response_syntax: 'ruby', title: 'Ruby', }, @@ -698,10 +680,7 @@ Generated by [AVA](https://avajs.dev). seam.foos.list()`, request_syntax: 'ruby', response: `// ruby␊ - []`, + [{"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}]`, response_syntax: 'ruby', title: 'Ruby', }, @@ -792,10 +771,7 @@ Generated by [AVA](https://avajs.dev). seam.foos.list()`, request_syntax: 'ruby', response: `// ruby␊ - []`, + [{"foo_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33","name" => "Best foo","nullable_property" => nil}]`, response_syntax: 'ruby', title: 'Ruby', }, diff --git a/test/snapshots/blueprint.test.ts.snap b/test/snapshots/blueprint.test.ts.snap index dc1d4cf..3c66bbe 100644 Binary files a/test/snapshots/blueprint.test.ts.snap and b/test/snapshots/blueprint.test.ts.snap differ