Skip to content

Commit

Permalink
fix: Return only json sample for C# response (#117)
Browse files Browse the repository at this point in the history
* Return only json sample for C# response

* ci: Generate code

---------

Co-authored-by: Seam Bot <devops@getseam.com>
  • Loading branch information
andrii-balitskyi and seambot authored Oct 9, 2024
1 parent 1a79077 commit 2c2329e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 50 deletions.
21 changes: 1 addition & 20 deletions src/lib/code-sample/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,4 @@ const formatCsharpObject = (value: Record<string, Json>): string => {
return `new { ${formattedEntries} }`
}

export const createCsharpResponse = (
codeSampleDefinition: CodeSampleDefinition,
context: Context,
): string => {
const { response, title } = codeSampleDefinition
const { endpoint } = context

if (endpoint.response.responseType === 'void') return 'null'

const { responseKey, resourceType } = endpoint.response
const responseValue = response?.body?.[responseKey]

if (responseValue == null) {
throw new Error(`Missing ${responseKey} for '${title}'`)
}

return Array.isArray(responseValue)
? `System.Collections.Generic.List\`1[Seam.Model.${pascalCase(resourceType)}]`
: createJsonResponse(codeSampleDefinition, context)
}
export const createCsharpResponse = createJsonResponse
60 changes: 30 additions & 30 deletions test/snapshots/blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Foos.List(objectProp: new { foo = "bar" })',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Foo]',
response: '[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -507,7 +507,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Foos.List(objectProp: new { foo = "bar" })',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Foo]',
response: '[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -859,7 +859,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Foos.List(objectProp: new { foo = "bar" })',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Foo]',
response: '[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -977,7 +977,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Foos.List(objectProp: new { foo = "bar" })',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Foo]',
response: '[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1329,7 +1329,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Foos.List(objectProp: new { foo = "bar" })',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Foo]',
response: '[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1447,7 +1447,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Foos.List(objectProp: new { foo = "bar" })',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Foo]',
response: '[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1576,7 +1576,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Transport.Air.Planes.List()',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Plane]',
response: '[{"plane_id":"9d3163f9-9185-40d3-a0ce-a03d3c7ce402","name":"Woosh"}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1679,7 +1679,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Transport.Air.Planes.List()',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Plane]',
response: '[{"plane_id":"9d3163f9-9185-40d3-a0ce-a03d3c7ce402","name":"Woosh"}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1782,7 +1782,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Transport.Air.Planes.List()',
request_syntax: 'csharp',
response: 'System.Collections.Generic.List`1[Seam.Model.Plane]',
response: '[{"plane_id":"9d3163f9-9185-40d3-a0ce-a03d3c7ce402","name":"Woosh"}]',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1901,7 +1901,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Deprecated.Undocumented.Endpoint()',
request_syntax: 'csharp',
response: 'null',
response: '{}',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -1995,7 +1995,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Deprecated.Undocumented.Endpoint()',
request_syntax: 'csharp',
response: 'null',
response: '{}',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -2089,7 +2089,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Deprecated.Undocumented.Endpoint()',
request_syntax: 'csharp',
response: 'null',
response: '{}',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -2199,7 +2199,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Draft.Endpoint()',
request_syntax: 'csharp',
response: 'null',
response: '{}',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -2293,7 +2293,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Draft.Endpoint()',
request_syntax: 'csharp',
response: 'null',
response: '{}',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -2387,7 +2387,7 @@ Generated by [AVA](https://avajs.dev).
csharp: {
request: 'seam.Draft.Endpoint()',
request_syntax: 'csharp',
response: 'null',
response: '{}',
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -2906,7 +2906,7 @@ Generated by [AVA](https://avajs.dev).
seam.Foos.List(objectProp: new { foo = "bar" })`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Foo]`,
[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -3040,7 +3040,7 @@ Generated by [AVA](https://avajs.dev).
seam.Foos.List(objectProp: new { foo = "bar" })`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Foo]`,
[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -3440,7 +3440,7 @@ Generated by [AVA](https://avajs.dev).
seam.Foos.List(objectProp: new { foo = "bar" })`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Foo]`,
[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -3574,7 +3574,7 @@ Generated by [AVA](https://avajs.dev).
seam.Foos.List(objectProp: new { foo = "bar" })`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Foo]`,
[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -3974,7 +3974,7 @@ Generated by [AVA](https://avajs.dev).
seam.Foos.List(objectProp: new { foo = "bar" })`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Foo]`,
[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4108,7 +4108,7 @@ Generated by [AVA](https://avajs.dev).
seam.Foos.List(objectProp: new { foo = "bar" })`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Foo]`,
[{"foo_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33","name":"Best foo","nullable_prop":null,"number_prop":10,"object_prop":{"foo":"bar"},"array_prop":["foo","bar"]}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4253,7 +4253,7 @@ Generated by [AVA](https://avajs.dev).
seam.Transport.Air.Planes.List()`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Plane]`,
[{"plane_id":"9d3163f9-9185-40d3-a0ce-a03d3c7ce402","name":"Woosh"}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4372,7 +4372,7 @@ Generated by [AVA](https://avajs.dev).
seam.Transport.Air.Planes.List()`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Plane]`,
[{"plane_id":"9d3163f9-9185-40d3-a0ce-a03d3c7ce402","name":"Woosh"}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4491,7 +4491,7 @@ Generated by [AVA](https://avajs.dev).
seam.Transport.Air.Planes.List()`,
request_syntax: 'csharp',
response: `// json␊
System.Collections.Generic.List\`1[Seam.Model.Plane]`,
[{"plane_id":"9d3163f9-9185-40d3-a0ce-a03d3c7ce402","name":"Woosh"}]`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4626,7 +4626,7 @@ Generated by [AVA](https://avajs.dev).
seam.Deprecated.Undocumented.Endpoint()`,
request_syntax: 'csharp',
response: `// json␊
null`,
{}`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4736,7 +4736,7 @@ Generated by [AVA](https://avajs.dev).
seam.Deprecated.Undocumented.Endpoint()`,
request_syntax: 'csharp',
response: `// json␊
null`,
{}`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4846,7 +4846,7 @@ Generated by [AVA](https://avajs.dev).
seam.Deprecated.Undocumented.Endpoint()`,
request_syntax: 'csharp',
response: `// json␊
null`,
{}`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -4972,7 +4972,7 @@ Generated by [AVA](https://avajs.dev).
seam.Draft.Endpoint()`,
request_syntax: 'csharp',
response: `// json␊
null`,
{}`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -5082,7 +5082,7 @@ Generated by [AVA](https://avajs.dev).
seam.Draft.Endpoint()`,
request_syntax: 'csharp',
response: `// json␊
null`,
{}`,
response_syntax: 'json',
title: 'C#',
},
Expand Down Expand Up @@ -5192,7 +5192,7 @@ Generated by [AVA](https://avajs.dev).
seam.Draft.Endpoint()`,
request_syntax: 'csharp',
response: `// json␊
null`,
{}`,
response_syntax: 'json',
title: 'C#',
},
Expand Down
Binary file modified test/snapshots/blueprint.test.ts.snap
Binary file not shown.

0 comments on commit 2c2329e

Please sign in to comment.