-
Notifications
You must be signed in to change notification settings - Fork 21
NameMapping
OData2Poco can do explicit mapping of the names coming from
the OData feed. This is done using a JSON file and specifying
--name-map path/to/name-map.json
on the command line.
For both types of mapping, if an explicit map is not
found, then the program reverts to the setting of --case
.
Conversely, if a mapping is found, then the --case is ignored
for that class or property.
The class name map is a simple 1:1 match based on the original name. The match is not case sensitive, and typical map would look like:
{
"ClassNameMap": [
{
"OldName": "account",
"NewName": "MoreSpecificAccount"
}
]
}
The property name map has an extra layer of naming
the original class name or a special value of "ALL".
The "ALL" map also supports regex matching and the
regex matching is triggered by a leading ^
in the
OldName.
{
"PropertyNameMap": {
"account": [
{
"OldName": "last_name",
"NewName": "Surname",
}
],
"ALL": [
{
"OldName": "cr9f6_costapprover",
"NewName": "CostApprover"
},
{
"OldName": "^.*approver$",
"NewName": "Approver"
}
]
}
}
When mapping a property, first a match is attempted
on the properties with a specific class name (account
in this example). Then a check is made in the ALL
entries but with a case-insensitive exact match to
the OldName. Lastly, an attempt is made to match the
ALL entries using a regex if the OldName starts
with a ^
.
The complete file would look like:
{
"ClassNameMap": [
{
"OldName": "account",
"NewName": "MoreSpecificAccount"
}
],
"PropertyNameMap": {
"account": [
{
"OldName": "last_name",
"NewName": "Surname",
}
],
"ALL": [
{
"OldName": "cx6f4_costapprover",
"NewName": "CostApprover"
},
{
"OldName": "^.*approver$",
"NewName": "Approver"
}
]
}
}
It's required to rename the following classes of the model in the service :
class Name | New Name |
---|---|
City | a0_City |
Location | a0_Location |
- Create json file named
rename_map.json
in your working directory. The json file represent the mapping of the old name and the new name as given below:
{
"ClassNameMap": [
{
"OldName": "City",
"NewName": "a0_City"
},
{
"OldName": "Location",
"NewName": "a0_Location"
}
],
"PropertyNameMap": {}
}
You can download the template for rename Map file and edit it. You can write string values with double or single quotes and add comments like c#.
ClassNameMap
is array
- Run the next command:
o2pgen -r https://services.odata.org/TripPinRESTierService --name-map "path/to/rename_map.json"
- Review the generated poco.cs file.
It's required to rename the following properties of the model in the service :
class Name | Property Name | New Name |
---|---|---|
City | Name | f02_Name |
All | ^Name$ | Short_Name |
The class name map "ALL" is a special value of ALL classes.
The "ALL" map supports regex matching and the
regex matching is triggered by a leading ^
in the
OldName.
- Create json file named
rename_map.json
in your working directory as given below:
{
"ClassNameMap": [],
"PropertyNameMap": {
"City": [
{
"OldName": "Name",
"NewName": "f02_Name"
}
],
"All": [
{
"OldName": "^Name$",
"NewName": "Short_Name"
}
]
}
}
- Run the next command:
o2pgen -r https://services.odata.org/TripPinRESTierService --name-map "path/to/rename_map.json"
- Review the generated poco.cs file.
- home
- Announcing V6.0.0
- Features
- Getting started with c# generation
- Http Connection
- Using Parameter file
- User Defined Attributes
- Controlling c# code generation
- Model Filter
- Enable Nullable Reference type of c# 8
- Class with Init-Only Properties (c# 9)
- Generating Constructor
- Record-Type (c# 9)
- Name Map
- Securing Password
- Using Proxy Server
- Using Plugin Attributes
- Developing with OData2Poco
- Examples in dotnetfiddle.net
- CommandLine-Reference
- AttributeExamples
- typescript generation
- Help Screen
- How to
- New Feature 4.2.1
Samples of generated code: