Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Introduction


This page contains the folder and file schema that will be generated from the swagger editor.

The approach relies on the composer to generate the service at init time ( also allows us the ability to support update service in later stages ).

This means that the folders and files will be generated to be composer dependent. To learn more about the composer click here.

Generated schema


This is the generated folder schema that you will get when you press generate service button. We will check that every input is valid before we create the service folder that will be downloaded into your PC.

This won't be your final folder schema, proceed with the following steps to completely build your service.

View file
name

...

sampleSchema.zip
height250

After you got your folder, go to your terminal and run the following commands :

Code Block
languagepowershell
$ cd yourNewServiceLocalPath
$ mkdir node_modules
$ npm install
$ grunt build


These commands will create a folder "node_modules" inside your main folder, download all the dependencies needed inside it and finally build your files and folders.

On build, we will create the following files :

  • The config.js file containing all your APIs. Each API will point to a middleware located in the folder lib/mw that was created after the command grunt build, where you will write your business logic.
  • The folder lib will contain another folder named models where we will create you database models pending on your database information captured in the service information. In each model, you will find all the essential function written and ready to use like save, update, find, insert, etc... . You should enter the database name and collection directly in case you have created one instance of a database model, or make it dynamic in case of multiple instance of a database model.
  • The index file created will call the composer that deploys your service.
  • The test folder will contain what is necessary to write and run your test cases with the help of GruntFile.js.

This is the final generated schema :

View file
namesimpleService.zip
height250

Editing your code


In this version, after you build your service, you can only edit your swagger.yml and run the following command to rebuild your service :

Warning
  • Don't change the files name after the first generate.
  • Don't change the service name after the first generate.
  • Don't change the folder schema after the first generate.
Code Block
languagepowershell
$ grunt rebuild


When we rebuild your service, we will keep all your middleware files even if you deleted an API or changed its name.

The file config.js file will be updated and the new middlewares will be created in case of any.