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

Transform request body for json-schema #2875

Open
jangot opened this issue Sep 29, 2021 · 3 comments
Open

Transform request body for json-schema #2875

jangot opened this issue Sep 29, 2021 · 3 comments

Comments

@jangot
Copy link

jangot commented Sep 29, 2021

I try to set up mesh for getting data from a service. The service has specific interface. I have no way to change the interface.
The service uses only POST requests to get and update data. All parameters for every method should be passed as an array in a request body.

Example

const accountId = 1;
const filter = {active: true}

const body = [accountId, filter];

fetch('/get/users', { method: 'POST', body });

When I try to setup it in json-schema I need to use requestSample in handler.operations. But it takes just object and if I set an array there the handler takes just first argument and ignore other.

What do you think about an opportunity to transform body before request. It can be a path to file like additionalResolvers

operations:
  - type: Query
    field: account
    path: /AccountsResource/getUsersByFilter
    method: POST
    requestSample: ./json-samples/account-input.json
    responseSchema: ./json-schemas/account.json#/definitions/Account

    # this is new option
    bodyTransform: ./json-transforms/account

requestSample can be like this

{
     "accountId": 1,
    "filter": {
        "active": true
    }
}

And this is transform example

// account-input.json

module.exports = {
    transform: (body) => {
        const { accountId, filter } = body;

        return [accountId, filter];
    }
}

It should work fine.

@ardatan
Copy link
Owner

ardatan commented Sep 29, 2021

I think you can provide the actual request schema and add a new field that redirects to this field within additionalResolvers

@jangot
Copy link
Author

jangot commented Sep 29, 2021

additionalResolvers do not work well, I created an issue.
Ok I think I can add this but I will need to write all fields in additionalResolvers and why I need use mesh if I write all resolvers manually?

@jangot
Copy link
Author

jangot commented Sep 29, 2021

And my be you have other way to pass array to request body?

@theguild-bot theguild-bot mentioned this issue Aug 11, 2022
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants