Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @sap-cloud-sdk/openapi-generator

SAP Cloud SDK OpenAPI Client Generator (Beta)

Generate custom JavaScript/TypeScript clients for services with OpenAPI specifications. 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.

Prerequisites

The official OpenAPI generator is Java based, therefore you need to have a Java runtime installed to use the SAP Cloud SDK OpenAPI generator.

Installation

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

Usage (CLI)

generate-openapi-client autocomplete [SHELL]

display autocomplete installation instructions

USAGE
  $ generate-openapi-client autocomplete [SHELL]

ARGUMENTS
  SHELL  shell type

OPTIONS
  -r, --refresh-cache  Refresh cache (ignores displaying instructions)

EXAMPLES
  $ generate-openapi-client autocomplete
  $ generate-openapi-client autocomplete bash
  $ generate-openapi-client autocomplete zsh
  $ generate-openapi-client autocomplete --refresh-cache

See code: @oclif/plugin-autocomplete

generate-openapi-client help [COMMAND]

display help for generate-openapi-client

USAGE
  $ generate-openapi-client help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

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);

Documentation

Getting started guide API documentation

Helpful Links

Index

Type aliases

Method

Method: typeof supportedMethods[keyof typeof supportedMethods]
experimental

This API is experimental and might change in newer versions. Use with caution. Methods supported by OpenApi and SAP Cloud SDK.

Functions

apiFile

convertDocToGlobalTag

  • convertDocToGlobalTag(openApiDocument: Document): Document
  • Workaround for OpenAPI generation to build one and only one API for all tags. Modify spec to contain only one 'default' tag.

    Parameters

    • openApiDocument: Document

      OpenAPI JSON document.

    Returns Document

    The modified document.

convertDocToOpenApiV3

  • convertDocToOpenApiV3(openApiDocument: Record<string, any>): Promise<Document>
  • Convert Swagger documents to OpenAPI documents. If an OpenAPI document is passed it is not modified.

    Parameters

    • openApiDocument: Record<string, any>

      OpenAPI version 2 (Swagger) or 3 document to be converted to version 3.

    Returns Promise<Document>

    A promise of an OpenAPI version 3 document.

convertOpenApiSpec

  • convertOpenApiSpec(filePath: string): Promise<Document>
  • Convert an OpenAPI document to ensure smooth parsing and generation thereafter. Documents are expected to be formatted as JSON, OpenAPI version 3 and only have one "default" tag.

    Parameters

    • filePath: string

      File content of the original spec.

    Returns Promise<Document>

createFile

  • createFile(directoryPath: string, fileName: string, content: string, overwrite: boolean): Promise<void>
  • experimental

    This API is experimental and might change in newer versions. Use with caution. Write a file generated by the SAP Cloud SDK for JavaScript containing a copyright statement.

    Parameters

    • directoryPath: string

      Path of the directory to write to.

    • fileName: string

      Name of the file to write

    • content: string

      Content to be written to the file. A copyright statement will be added to this.

    • overwrite: boolean

      Whether or not existing files should be overwritten.

    Returns Promise<void>

filterDuplicateParams

  • filterDuplicateParams(parameters: ParameterObject[]): ParameterObject[]

generate

  • experimental

    This API is experimental and might change in newer versions. Use with caution. Main entry point for OpenApi client generation. Generates files using the OpenApi Generator CLI and wraps the resulting API in an SDK compatible API.

    Parameters

    Returns Promise<void>

getOperation

  • getOperation(pathItem: PathItemObject, method: Method): OperationObject
  • Get the operation for the given method and merge path parameters with operation parameters.

    Parameters

    • pathItem: PathItemObject

      Path Item to get the operation from.

    • method: Method

      HTTP method to get the operation for.

    Returns OperationObject

    The sanitized original operation.

getType

  • getType(originalType: string | undefined): string

indexFile

  • indexFile(): string

isArraySchemaObject

  • isArraySchemaObject(obj: any): obj is ArraySchemaObject
  • Type guard to check whether an object is of type OpenAPIV3.ArraySchemaObject.

    Parameters

    • obj: any

      Object to check.

    Returns obj is ArraySchemaObject

    True if the object is a array schema object, false otherwise.

isReferenceObject

  • isReferenceObject(obj: any): obj is ReferenceObject
  • Type guard to check whether an object is of type OpenAPIV3.ReferenceObject.

    Parameters

    • obj: any

      Object to check.

    Returns obj is ReferenceObject

    True if the object is a reference object, false otherwise.

methods

parseAllOperations

parseFileAsJson

  • parseFileAsJson(filePath: string): Promise<Record<string, any>>

parseOpenApiDocument

  • parseOpenApiDocument(fileContent: Document, serviceName: string): Promise<OpenApiDocument>

parseOperation

parseOperationName

  • parseOperationName(operation: OperationObject, pattern: string, method: Method): string

parseParameters

parseRequestBody

  • parseRequestBody(requestBody: ReferenceObject | RequestBodyObject | undefined, refs: $Refs): OpenApiRequestBody | undefined

parseSchemaMetadata

  • parseSchemaMetadata(schema?: ReferenceObject | ArraySchemaObject | NonArraySchemaObject): SchemaMetadata | undefined

parseTypeName

  • parseTypeName(obj: ReferenceObject): string

renameEquallyNamedParams

  • renameEquallyNamedParams(parameters: ParameterObject[]): ParameterObject[]

resolveObject

  • resolveObject<T>(obj: T | ReferenceObject, refs: $Refs): T
  • Check whether the given object is a reference object and resolve if necessary. This operates only on the current level and does not resolve the object recursively.

    Type parameters

    • T

    Parameters

    • obj: T | ReferenceObject

      Object to resolve if necessary.

    • refs: $Refs

      References to resolve by.

    Returns T

    A resolved object.