Skip to content

webapi returns variables in JSON using snake case and I need camelCase #24681

Open
@csdougliss

Description

@csdougliss

Precondition (*)

Magento 2.3.x

Summary (*)

I want to return JSON in camelCase in my custom webapi.xml and interface that I have created.
There is no way to configure in webapi.xml the format that you wish to use.

By default M2 will return data like so: server_transaction_id but my third party JavaScript is expecting serverTransactionId for example.

Secondly, It is also rather annoying to have to create an interface to do this instead of just being able to use json_encode the data. Using json_encode is not the solution as you end up with \ in the format.

See below:

Examples (*)

interface Check3dsVersionInterface
{
    /**
     * @return string
     */
    public function getServerTransactionId();

    /**
     * @param string $serverTransactionId
     * @return $this
     */
    public function setServerTransactionId($serverTransactionId);

webapi.xml:

<route url="/V1/xx-payments/:cartId/check-3ds-version" method="POST">
        <service class="xx\xx\Api\xxServiceInterface" method="check3dsVersion"/>
        <resources>
            <resource ref="anonymous" />
        </resources>
    </route>

Proposed solution

In webapi.xml, it would be useful to specify the format of the json, for example to return as camelCase or as it is currently which is underscores

Metadata

Metadata

Labels

Component: Framework/ReflectionComponent: WebapiUse with concrete module component label E.g. "Component: Webapi" + "Catalog"Issue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P4No current plan to fix. Fixing can be deferred as a logical part of more important work.Progress: PR in progressReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseSeverity: S4Affects aesthetics, professional look and feel, “quality” or “usability”.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itfeature request

Type

No type

Projects

Status

Pull Request in Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions