odata-xtract v1.0.0
This package takes the metadata.xml
of an OData service and converts it to TypeScript interfaces.
Features
Automatically create TypeScript interfaces for
- Entity types
- Navigation properties
- Complex properties
- Complex types
- Function imports
- Importing parameters
- Return types
Installation
Global installation is recommended
npm i odata-xtract -g
Usage
Create a local copy of one or more metadata.xml
files and store them in your app. This is the tree of a sample UI5 app:
src
│ Component.ts
│ index.html
│ manifest.json
├───controller
├───fragment
├───i18n
├───localService
| |
│ ├───sflight
│ │ metadata.xml
│ │
│ └───northwind
│ metadata.xml
│
├───model
├───style
├───util
└───view
Then run the following command (preferably in the top level directory of your app)
odata-xtract
If you want to see a detailed log run the following command (at the moment there are no details)
odata-xtract --verbose
This will recursively look for file names that end with metadata.xml
. If the files are valid OData (V2) metadata files they will be parsed and transformed into TypeScript interfaces. A Model.ts
file is then created in the same directory.
Directories that start with a .
(dot) and the node_modules
directory are ignored (but only if they are in the directory where you run the command - if someone knows a more elegant solution please message me).
Limitations
Only one metadata.xml
per directory is supported. If you have multiple OData services put them in different directories.
Only OData V2 is supported. Maybe V4 works but I haven't tested it.
2 years ago