Skip to content
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

RFC: Remove response wrapper #131

Closed
moogmodular opened this issue Aug 24, 2022 · 5 comments · Fixed by #144
Closed

RFC: Remove response wrapper #131

moogmodular opened this issue Aug 24, 2022 · 5 comments · Fixed by #144

Comments

@moogmodular
Copy link

hi!

i need to satisfy a REST call which i can't influence. is there a way to return the response without the wrapper:

instead of this:

{
  "ok": true,
  "data": "This is good" /* Output from tRPC procedure */
}

return this:

{
  "name": "trpc", /* Output from tRPC procedure */
  "lang": "TS" /* Output from tRPC procedure */
}

if not, it would be a nice enhancement since i'm going to be not the only one with this issue. i'm probably going to fork this for now until i'm confident enough to make a PR.

const successResponseObject = {
    description: 'Successful response',
    content: {
      'application/json': {
        schema: zodSchemaToOpenApiSchemaObject(
          z.object({
            ok: z.literal(true),
            data: schema,
          }),
        ),
      },
    },
  };
```
@jlalmes jlalmes changed the title make wrappers in response objects optional RFC: Remove response wrapper Aug 25, 2022
@jlalmes
Copy link
Owner

jlalmes commented Aug 25, 2022

Out of interest, could you explain a little more regarding your use-case and constraints?

I'm keen to hear some more opinions on this. I'm happy to remove our response wrapper as a breaking change in the next major v1.0.0 if the general consensus is positive.

Proposed response payload changes

Success

- {
-   "ok": true,
-   "data": "This is good"
- }
+ "This is good"

Error

{
-   "ok": false,
-   "error": {
-     "message": "This is bad",
-     "code": "BAD_REQUEST",
-     "issues": [...]
-   }
+   "message": "This is bad",
+   "code": "BAD_REQUEST",
+   "issues": [...]
}

@moogmodular
Copy link
Author

I'm implementing a REST endpoint in my app for any ln-url compliant bitcoin wallet. In this case i'm generating a withdrawal request and the wallets expect the response to have certain properties.

{
  tag: "string",
  callback: "string",
  k1: "string",
  defaultDescription: "string",
  minWithdrawable: 10,
  maxWithdrawable: 10,
}

@jlalmes
Copy link
Owner

jlalmes commented Aug 25, 2022

Hi @moogmodular, I have implemented this feature and released it under the alpha tag. Please upgrade to trpc-openapi@alpha and let me know if you have any issues!

@jlalmes jlalmes closed this as completed Aug 25, 2022
@moogmodular
Copy link
Author

i did and it works exactly as intended.

thank you!

@jlalmes
Copy link
Owner

jlalmes commented Sep 8, 2022

@moogmodular - I'm just about the publish a new alpha version that supports v10. Please make sure you have pinned your trpc-openapi version in your package.json so that you're unaffected!

- "trpc-openapi": "^1.0.0-alpha.0"
+ "trpc-openapi": "1.0.0-alpha.0"

(tl;dr - remove the ^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants