Skip to content

Commit 2d7cc77

Browse files
authored
Add a new NodeJS Express server generator (#3567)
* create nodejs express esrver * 1st commit of the express.js module. Express server working, api-docs loads properly. No real paths yet * 1st commit of the express.js module. Express server working, api-docs loads properly. No real paths yet (#2839) * Working Express server with successful routing to controllers. * rewrote controllers and services. Haven't tested yet * controllers and services have passed tests successfully * Added documentation * Added documentation * Support for openApi v3, using 'express-openapi-validator' for parsing and validation, and an internal router to pass arguments to controllers and services. /controllers/Pet.js and /services/PetService.js should be used for reverse engineering for future codegen script * update generator and template * update samples * more update * update service, controller * add vendor extensions * some updates to adapt to changes in the generator (removing references to swager); some work on handling file uploads; some work on tests * Update NodeJS server generator and templates based on new output (#3261) * update generator and template * update samples * more update * update service, controller * add vendor extensions * update doc * Changed routing code to follow the following convention: Each path operation has a 'x-openapi-router-controller' and 'x-openapi-router-service'. Automated files will be placed under /controllers and /services respectively. Controller file names will end with 'Controller.js'. Removed swaggerRouter, replaced it with openapiRouter Routing works and simple tests show a return of 200 to requests. * [nodejs-express-server] various updates, fixes (#3319) * various fix * remove dot from service * add space * better method empty argument * remove test service (#3379) * add new doc * 1. routingTests.js runs through all operations described in openapi.yaml and tries calling them, expecting 200 in return. Currently not all tests pass - not supporting xml, and problems with formData 2. Removed old testing files. 3. Added model files - contain data and structure as defined in openapi.yaml. Model.js has static methods relevant to all model files. 4. Changed openapi.yaml to allow running tests easily. * 1. routingTests.js runs through all operations described in openapi.yaml and tries calling them, expecting 200 in return. Currently not all tests pass - not supporting xml, and problems with formData (#3442) 2. Removed old testing files. 3. Added model files - contain data and structure as defined in openapi.yaml. Model.js has static methods relevant to all model files. 4. Changed openapi.yaml to allow running tests easily. * added model classes. Currently as a concept only. Seems like won't be in use * Updated README.md to be a detailed description of the project. Removed test files that are not needed. Removed utils/writer.js which is not needed, and the references to it in the codegen files * Removed redundant file app.js - this file has no benefit at this point. index.js now calls ExpressServer.js directly. Updated files that used to call app.js. Updated README.md accordingly Added a path to call the openapi.yaml, and a test file for all endpoints that are not in the openapi.yaml, ensuring that they return 200. Updated README.md accordingly * Remove test controller (#3575) * remove test controller * add back changes to templates * remove app.js * update wording
1 parent fbb2f1e commit 2d7cc77

60 files changed

Lines changed: 4257 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ Here is a list of template creators:
730730
* JAX-RS RestEasy (JBoss EAP): @jfiala
731731
* Kotlin: @jimschubert [:heart:](https://www.patreon.com/jimschubert)
732732
* Kotlin (Spring Boot): @dr4ke616
733+
* NodeJS Express: @YishTish
733734
* PHP Laravel: @renepardon
734735
* PHP Lumen: @abcsun
735736
* PHP Slim: @jfastnacht
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
echo "# START SCRIPT: $SCRIPT"
5+
6+
while [ -h "$SCRIPT" ] ; do
7+
ls=`ls -ld "$SCRIPT"`
8+
link=`expr "$ls" : '.*-> \(.*\)$'`
9+
if expr "$link" : '/.*' > /dev/null; then
10+
SCRIPT="$link"
11+
else
12+
SCRIPT=`dirname "$SCRIPT"`/"$link"
13+
fi
14+
done
15+
16+
if [ ! -d "${APP_DIR}" ]; then
17+
APP_DIR=`dirname "$SCRIPT"`/..
18+
APP_DIR=`cd "${APP_DIR}"; pwd`
19+
fi
20+
21+
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
22+
23+
if [ ! -f "$executable" ]
24+
then
25+
mvn -B clean package
26+
fi
27+
28+
# if you've executed sbt assembly previously it will use that instead.
29+
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
30+
ags="generate -t modules/openapi-generator/src/main/resources/nodejs-express-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g nodejs-express-server -o samples/server/petstore/nodejs-express-server -Dservice $@"
31+
32+
java $JAVA_OPTS -jar $executable $ags

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ The following generators are available:
9494
- [jaxrs-spec](generators/jaxrs-spec.md)
9595
- [kotlin-server](generators/kotlin-server.md)
9696
- [kotlin-spring](generators/kotlin-spring.md)
97+
- [nodejs-express-server](generators/nodejs-express-server.md) (beta)
9798
- [nodejs-server-deprecated](generators/nodejs-server-deprecated.md) (deprecated)
9899
- [php-laravel](generators/php-laravel.md)
99100
- [php-lumen](generators/php-lumen.md)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
---
3+
id: generator-opts-server-nodejs-express-server
4+
title: Config Options for nodejs-express-server
5+
sidebar_label: nodejs-express-server
6+
---
7+
8+
| Option | Description | Values | Default |
9+
| ------ | ----------- | ------ | ------- |
10+
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
11+
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
12+
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
13+
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
14+
|serverPort|TCP port to listen on.| |null|

0 commit comments

Comments
 (0)