0.9.17 • Published 4 years ago

xsd2ts v0.9.17

Weekly downloads
36
License
UNLICENSED
Repository
github
Last release
4 years ago

xsd2ts

Tool for converting xsd files to typescript template classes

#tutorial:

Create an npm project(folder) with a package.json file with content:

{
  "name": "template-ts",
  "version": "0.1.0",
  "description": "generated template classes for xsd",
  "main": "index.js",
  "scripts": {
    "ts-gen": "ts-node ./src/generate.ts",
    "makelib": "tsc -p ./src/generated",
    "setup": "npm install"
  },
  "repository": {
    "type": "github",
    "url": "https://github.com/path/to/repo.git"
  },
  "author": "your name",
  "license": "GPL",
  "dependencies": {
    "ts-loader": "2.2.2",
    "ts-node": "3.3.0",
    "typescript": "3.9.9",
    "xsd2ts": "0.9.x"
  }
}

Replace the value 'template-ts' for the name property by your own package name. Create a src folder inside this project folder. Create a typescript file named 'generate.ts' in this folder and add the following content:

import {generateTemplateClassesFromXSD} from "xsd2ts";
generateTemplateClassesFromXSD('./yourXsdFile.xsd');

When dependencies must be included you can specify these as follows:

import {generateTemplateClassesFromXSD} from "xsd2ts";
generateTemplateClassesFromXSD('./dependency.xsd'); 
generateTemplateClassesFromXSD('./yourXsdFile.xsd', {libname, './dependency'});

The libname should equal the namespace for this dependency to generate the right import statements

You can specify a dependency for the default namespace with the third parameter when you omit this parameter it will deault to the name "xmlns"

import {generateTemplateClassesFromXSD} from "xsd2ts";
generateTemplateClassesFromXSD('./dependency.xsd'); 
generateTemplateClassesFromXSD('./yourXsdFile.xsd', {defaultns, './dependency'},defaultns);

Extra logging can be turned on by calling verbose()

import {generateTemplateClassesFromXSD,verbose} from "xsd2ts";
verbose();
generateTemplateClassesFromXSD('./dependency.xsd');
 

Generate a folder 'src/generated' with index.ts file by executing:

npm run ts-gen

Compile the generated index.ts file and generate declaration file by executing:

npm run makelib 

Then publish your npm package:

npm publish

Now you can use the npm lib in other npm projects by installing it:

npm install --save <your npm package name>

Remark: There was an error in version 3.1: it did not emit an index.ts

0.9.12

4 years ago

0.9.13

4 years ago

0.9.14

4 years ago

0.9.15

4 years ago

0.9.10

4 years ago

0.9.11

4 years ago

0.9.16

4 years ago

0.9.17

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.2

5 years ago

0.3.3

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

7 years ago

0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.16

7 years ago

0.1.11

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago