@api-components/api-model-generator
TypeScript icon, indicating that this package has built-in type declarations

0.2.14 • Public • Published

api-model-generator

AMF model generator for API components used for tests and demo pages.

Usage

$ npm i --saved-dev @api-components/api-model-generator

In a project define models.json in either demo/ or tes/ folders. In the JSON file place model description where keys are paths to the API main file (relative to opts.src option) and value is the API spec format. If the value is an array then first element must be API format and second is API media type.

Data structure

ApisListObject

ApisList.srcString - source path to the APIs. Default to demo/. ApisList.destString - path where output generated models. Default to demo/. ApisList.<path>String, Array, ApiDefinition - a definition of an API to process. Key is a path to the API main file. The value depending on a type has different meaning.

String value represents API type. Can be RAML 0.8, RAML 1.0, OAS 2.0, or OAS 3.0. It generates api model for application/yaml media type and for the editing resolution pipeline.

Array value is deprecated. Please don't use it.

ApiDefinitionObject ApiDefinition.typeString. API type to process. Can be RAML 0.8, RAML 1.0, OAS 2.0, or OAS 3.0. ApiDefinition.mimeString. API media type. Default to application/yaml. ApiDefinition.resolutionString. AMF resolution pipeline. Default to editing which is the original resolution pipeline for API Console. Future releases of AMF can support different options.

Example apis.json

{
  "api-1/api.raml": "RAML 1.0",
  "oas2/oas2.json": {
    "type": "OAS 2.0",
    "mime": "application/json"
  },
  "api/api.raml": {
    "type": "RAML 1.0",
    "mime": "application/raml",
    "resolution": "editing"
  }
}

then pass the location of the file to the library:

const generator = require('@api-components/api-model-generator');
await generator('./demo/models.json');

When using this format the element will be included in automated tests when AMF version change.

Alternatively it is possible to pass the map of files to the library:

const generator = require('@api-components/api-model-generator');

const files = new Map();
files.set('demo-api/demo-api.raml', 'RAML 1.0');
files.set('oas2/oas2.json', ["OAS 2.0", "application/json"]);

generator(files, {
  src: 'demo/' // default
  dest: 'demo/' // default
})
.then(() => console.log('Finito'));

Readme

Keywords

none

Package Sidebar

Install

npm i @api-components/api-model-generator

Weekly Downloads

65

Version

0.2.14

License

Apache-2.0

Unpacked Size

12.4 kB

Total Files

7

Last publish

Collaborators

  • jarrodek
  • twoplustwoone
  • lbauret
  • carowright