Options
All
  • Public
  • Public/Protected
  • All
Menu

SAP Cloud SDK for JavaScript Logo

@sap-cloud-sdk/openapi-generator

This package contains the generator to create your own service module using a OpenAPI specification. This generator is based on the OpenAPI Tools generator for OpenAPI and adds some additional code for convenience to better integrate with the SAP Cloud SDK.

Installation

$ npm install @sap-cloud-sdk/openapi-generator

Usage (CLI)

generate-openapi-client --input <input> --outputDir <outputDirectory>

Generate OpenAPI client(s), that use the connectivity features of the SAP Cloud SDK for JavaScript/TypeScript.

USAGE
  $ generate-openapi-client --input <input> --outputDir <outputDirectory>

OPTIONS
  -c, --config=<path/to/config.json>
      Set the path to a file containing the options for generation instead of setting the options on the command line. 
      When combining the `config` option with other options on the command line, the command line options take precedence. 
      If a directory is passed, a `config.json` file is read from this directory.

  -i, --input=<path/to/input>
      (required) Specify the path to the directory or file containing the OpenAPI service definition(s) to generate 
      clients for. Accepts Swagger and OpenAPI definitions as YAML and JSON files. Throws an error if the path does not 
      exist.

  -o, --outputDir=<path/to/output>
      (required) Specify the path to the directory to generate the client(s) in. Each client is generated into a 
      subdirectory within the given output directory. Creates the directory if it does not exist. Customize subdirectory 
      naming through `--optionsPerService`.

  -t, --transpile
      Transpile the generated TypeScript code. When enabled a default `tsconfig.json` will be generated and used. It emits 
      `.js`, `.js.map`, `.d.ts` and `.d.ts.map` files. To configure transpilation set `--tsconfig`.

  --clearOutputDir
      Remove all files in the output directory before generation. Be cautious when using this option, as it really removes 
      EVERYTHING in the output directory.

  --include=<glob/to/include>
      Include files matching the given glob into the root of each generated client directory.

  --optionsPerService=<path/to/options-per-service.json>
      Set the path to a file containing the options per service. The configuration allows to set a `directoryName` and 
      `packageName` for every service, identified by the path to the original file. It also makes sure that names do not 
      change between generator runs. If a directory is passed, a `options-per-service.json` file is read/created in this 
      directory.

  --overwrite
      Allow to overwrite files, that already exist. This is useful, when running the generation regularly.

  --packageJson
      When enabled, a `package.json`, that specifies dependencies and scripts for transpilation and documentation 
      generation is generated.

  --skipValidation
      By default, the generation fails, when there are duplicate or invalid names for operations and/or path parameters 
      after transforming them to camel case. Set this to true to enable unique and valid name generation. The names will 
      then be generated by appending numbers and prepending prefixes.

  --tsConfig=<path/to/tsconfig.json>
      Replace the default `tsconfig.json` by passing a path to a custom config. By default, a `tsconfig.json` is only 
      generated, when transpilation is enabled (`--transpile`). If a directory is passed, a `tsconfig.json` file is read 
      from this directory.

  --verbose
      Turn on verbose logging.

EXAMPLES

  // generate TypeScript clients from OpenAPI definitions in a directory
  $ openapi-generator --input ./my-specs --outputDir ./clients

  // generate a JavaScript client from a OpenAPI definition file
  $ openapi-generator --input ./my-spec.yaml --outputDir ./client --transpile

See code: dist/cli/index.ts

Usage (programatically)

import { generate } from '@sap-cloud-sdk/openapi-generator';

// initialize generator options based on what you want to do
// note that inputDir and outputDir are mandatory
const options: GeneratorOptions = {
  inputDir: 'path/to/inputDir',
  outputDir: 'path/to/outputDir'
};

// generates the files and writes them to the outputDir
await generate(options);

For more detailed overview visit our generator documentation.

Support

The recommended way to get in touch with us is to create an issue in our github repository. Select the issue category Bug, Feature or Question depending on the nature of your request. We try to provide fixes, features and answers as soon as possible.

We also monitor questions on StackOverflow and ansers.sap.com but prefer issues on github.

Contribute

If you would like to contribute to the SAP Cloud SDK, please make yourself familiar with our contributing guidelines and follow the given instructions.

Links



License

The SAP Cloud SDK is released under the Apache License Version 2.0.

Index

Interfaces

Functions

Functions

generate