Skip to content

MATLAB Generator for OpenAPI enables generation of RESTful Clients and Models based on OpenAPI 3.0 specifications

License

Notifications You must be signed in to change notification settings

mathworks-ref-arch/matlab-openapi-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MATLAB Generator for OpenAPI

MATLAB® Generator for OpenAPI™ provides a generator to enable generation of RESTful Clients and Models based on OpenAPI 3.0 specifications. OpenAPI was formerly known as Swagger. The core of this package is a Java class that extends the community Generator CLI and Mustache template files for APIs and Models.

Requirements

MathWorks Products https://www.mathworks.com

  • Requires MATLAB release R2020b or later.

3rd Party Products

  • Java Development Kit (JDK) 11 or compatible.
  • Maven 3.6 or greater.
  • OpenAPITools openapi-generator, downloaded by setup.m.
  • Node.js is required only if using the unit test suite or using npx at the command line.

Introduction

This package is developed and tested using OpenAPI version 3, in many cases it may work with a version 2 specifications however this is not supported. Please consider migrating the specification to version 3.

Getting Started

Please refer to the Documentation to get started. The Getting Started and Basic Usage documents provide more detailed instructions on setting up and using the interface.

Installation

The MathWorks provided Java code in this package uses the OpenAPITools openapi-generator package. A pom.xml files is provided. The resulting jar can be built using:

cd package-directory/Software/Java
mvn clean package

Usage

To generate MATLAB client code for the well known PetStore sample spec, download it and use commands similar to:

Using a MATLAB client builder

% Run startup to configure the package's MATLAB paths
cd <package_directory>/Software/MATLAB
startup
cd ..

% Create a builder object
c = openapi.build.Client;
% Set the package name, defaults to "OpenAPIClient"
c.packageName = "PetStore";
% Set the path to the spec., this may also be a HTTP URL
c.inputSpec = "openapi.yaml";
% Set a directory where the results will be stored
c.output = fullfile(pwd, "PetClient");
% Trigger the build process
c.build;

Using the command line

If there is a preference to work directly with the Node.js npx command rather than the higher-level MATLAB client, it can be called as follows. On Linux:

cd <package_directory>/Software
npx @openapitools/openapi-generator-cli --custom-generator MATLAB/lib/jar/MATLABClientCodegen-openapi-generator-0.0.1.jar generate -g MATLAB -i openapi.yaml -o PetClient --package-name PetStore

If not working in the package's Software directory, use full paths and add the following additional arguments:

-t "<package_directory>/Software/Mustache" --additional-properties openapiRoot="<package_directory>/Software/MATLAB

Or on Windows replace the forward slashes in local paths with back slashes:

cd <package_directory>\Software
npx @openapitools/openapi-generator-cli --custom-generator MATLAB\lib\jar\MATLABClientCodegen-openapi-generator-0.0.1.jar generate -g MATLAB -i openapi.yaml -o PetClient --package-name PetStore

If not working in the package's Software directory, use full paths and add the following additional arguments:

-t "c:\<package_directory>\Software\Mustache" --additional-properties openapiRoot="c:\ <package_directory>\Software\MATLAB"

The slash in @openapitools/openapi-generator-cli is Node/npx syntax and not a local path, so this needs to remain a forward slash.

License

The license for the MATLAB Generator for OpenAPI is available in the LICENSE.txt file in this repository. This package uses certain third-party content which is licensed under separate license agreements. Please see the pom.xml file for third-party software downloaded at build time.

Enhancement Requests

Provide suggestions for additional features or capabilities using the following link: https://www.mathworks.com/products/reference-architectures/request-new-reference-architectures.html

Support

Email: mwlab@mathworks.com or please log an issue.

About

MATLAB Generator for OpenAPI enables generation of RESTful Clients and Models based on OpenAPI 3.0 specifications

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published