Generate TypeScript interface from OData $metadata
Asked Answered
E

1

10

I'm getting into OData and TypeScript and it struck me when learning about OData Client Code Generator that something similar could be done for getting TypeScript interfaces for OData endpoints. Would really help when refactoring :)

So was wondering if anyone got some experience on the matter. Like what tools they use. (if any exist) Problems they encountered.

Expatiate answered 11/3, 2015 at 22:21 Comment(4)
I'm not aware of anything but of course you could write some t4 templates to do it. If you do come up with anything, please share :)Coniology
type.litesolutions.net could be the tool you are looking for.Sakhuja
This questions quite old but this may be of use to someone in the futureGoddamn
@RafaelCichocki while ts-odata is cool and helps you write the odata queries. It doesn't help you generate the model from the $metadata so you'll still be using magic string property names.Widow
U
0

You can use odata2ts

  1. Configure ./odata2ts.config.ts
import { ConfigFileOptions, Modes } from "@odata2ts/odata2ts";

const config: ConfigFileOptions = {
  mode: Modes.models,
  services: {
    metadata: {
      source: "odata_metadata.xml",
      output: "odata/metadata",
    },
  }
}

export default config;
  1. Export your server's metadata file into ./odata_metadata.xml (Example: TripPin.xml)

  2. Generate types

npx odata2ts
Unquiet answered 29/5, 2023 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.