From d4556aae0ca73774f54f6e98a56d629af8c1b681 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Fri, 30 Aug 2024 00:45:02 +0000 Subject: [PATCH] fix: Render ruby response as literal (#71) * fix: Do not render class in ruby response * ci: Generate code * fix: Ruby hash map format * ci: Format code * ci: Generate code * Wrap ruby hash with curly braces * ci: Generate code * Remove responseRubyClassName * Fix curly brace location * ci: Generate code * ci: Format code * Use comma not newline * ci: Generate code --------- Co-authored-by: Seam Bot --- src/lib/code-sample/ruby.ts | 31 +++++++------------- test/snapshots/blueprint.test.ts.md | 40 ++++++-------------------- test/snapshots/blueprint.test.ts.snap | Bin 4004 -> 3997 bytes 3 files changed, 18 insertions(+), 53 deletions(-) diff --git a/src/lib/code-sample/ruby.ts b/src/lib/code-sample/ruby.ts index be224355..af0c9034 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 008f71af..30b50bcd 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 dc1d4cfcdc16e68912a1be587dfc02d870f7816e..3c66bbee360d1e3acc06b0547e6b38f1bcdbb11e 100644 GIT binary patch literal 3997 zcmY*ZXEYp)(zbeCy{xi25mBN<)YV0gsL^{3Ru{b!AqA^Ni5jflMX*+jx=KXv@~X@7 zVzqE{bME)!n{(!zndh1FO!+ZNCQ2NJUUpDFS8sogKygw$oGJPMnOZZWxvE_$UXvzH z`)`R71Wo#Wd0)2Ld&maWJlNk7E27q`G?!^Nq4gdpd4zZknTU{^gUu zB>i(Tom_L`f#i>xR~#31M;gogcrElCq0^rrVy9g@p%Fc6*aE+Zor2H_EQ=v9%Vm@K zejF^MxhLe@^LermsWo0iXW%>YRh1NiN^7LZ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