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

Request payload attributes which contains underscores are not getting mapped with Data Mapper Mediator input schema #3913

Open
JanithaSampathBandara opened this issue Jan 23, 2025 · 0 comments
Labels

Comments

@JanithaSampathBandara
Copy link

JanithaSampathBandara commented Jan 23, 2025

Description

Trying to map input and output payloads using the Data Mapper Mediator. However, observed an issue where certain fields in the request payload, which have names containing underscores, are not being correctly mapped to the input schema file. This results in missing attributes in the response payload.

Eg :

Request payload

<b10:person xmlns:b10="http://b10.abc.test.com">
   <f_name>Janitha</f_name>
   <lname>Bandara</lname>
   <city>Colombo</city>
</b10:person>

Input schema file

<b10:person xmlns:b10="http:/b10.abc.test.com">
    <f_name>firstname</f_name>
    <lname>lastname</lname>
    <city>city</city>
</b10:person>

Output schema file

<b10:person xmlns:b10="http://b10.abc.test.com">
    <f_name>firstname</f_name>
    <lname>lastname</lname>
</b10:person>

In this case, the values of f_name that is passed by the client is not seen inside the mediation and it’s not even mapped with the output schema file which results in no value for that attribute in the response.

As per the analysis, we could see that the auto generated input schema file will convert f_name into f:name as you can see below.

When deploying artifacts with VS Code Plugin

{
  "$schema": "http://wso2.org/json-schema/wso2-data-mapper-v5.0.0/schema#",
  "type": "object",
  "title": "b10:person",
  "properties": {
    "f:name": {
      "type": "string"
    },
    "lname": {
      "type": "string"
    },
    "city": {
      "type": "string"
    }
  },
  "namespaces": [
    {
      "prefix": "b10",
      "url": "http://b10.abc.test.com"
    }
  ],
  "inputType": "XML"
}

By the way, we have observed this behaviour when deploying artifacts using VS Code Plugin only. Integration Studio provides the expected results with the same artifacts.

When deploying artifacts with Integration Studio

{
  "$schema" : "http://wso2.org/json-schema/wso2-data-mapper-v5.0.0/schema#",
  "inputType" : "XML",
  "id" : "http://wso2jsonschema.org",
  "title" : "b10:person",
  "type" : "object",
  "properties" : {
    "f_name" : {
      "id" : "http://wso2jsonschema.org/f_name",
      "type" : "string"
    },
    "lname" : {
      "id" : "http://wso2jsonschema.org/lname",
      "type" : "string"
    },
    "city" : {
      "id" : "http://wso2jsonschema.org/city",
      "type" : "string"
    }
  },
  "namespaces" : [ {
    "prefix" : "b10",
    "url" : "http://b10.abc.test.com"
  } ]
}

Steps to Reproduce

  1. Install the MI for VS Code extension [1] and create a simple Proxy Service which contains Data Mapper Mediator as below using VS Code Plugin.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="test3" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <log level="full"/>
            <datamapper config="gov:datamapper/NewConfigNew.dmc" inputSchema="gov:datamapper/NewConfigNew_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/NewConfigNew_outputSchema.json" outputType="XML" xsltStyleSheet="gov:datamapper/NewConfigNew_xsltStyleSheet.xml"/>
            <log level="full"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>
  1. Load the below input and output files to the Data Mapper Mediator.

input.xml

<b10:person xmlns:b10="http://b10.abc.test.com">
    <f_name>firstname</f_name>
    <lname>lastname</lname>
    <city>city</city>
</b10:person>

output.xml

<b10:person xmlns:b10="http://b10.abc.test.com">
    <f_name>firstname</f_name>
    <lname>lastname</lname>
</b10:person>
  1. Map the f_name and lname attributes as below.
Image
  1. Build and deploy the project.
  2. Invoke the proxy service using below request payload.
curl --location 'http://localhost:8290/services/test3' \
--header 'Content-Type: application/xml' \
--data '<b10:person xmlns:b10="http://b10.abc.test.com">
  <f_name>Janitha</f_name>
  <lname>Bandara</lname>
  <city>Colombo</city>
</b10:person>
  1. You will get the response below where the f_name attribute has not been mapped correctly hence it’s not contain in the response.
 <b10:person xmlns:b10="http://b10.abc.test.com">
   <lname>Bandara</lname>
</b10:person>
  1. Follow the above steps and deploy it using Integration Studio then you will observe expected response as below.
<b10:person xmlns:b10="http://b10.abc.test.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <f_name>Janitha</f_name>
   <lname>Bandara</lname>
</b10:person>

Regards,
Janitha
[1] https://mi.docs.wso2.com/en/latest/develop/mi-for-vscode/install-wso2-mi-for-vscode/

Version

MI 4.3.0

Environment Details (with versions)

No response

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

No branches or pull requests

1 participant