very-express 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ an generator that generate [Express](https://github.com/expressjs/express) rest-
7
7
  - mongoDb
8
8
 
9
9
  ## TO DO
10
- - [ ] genarate express server from template
10
+ - [x] genarate express server from template
11
11
 
12
12
  - [x] generate openapi
13
13
  - [x] path
@@ -17,13 +17,8 @@ an generator that generate [Express](https://github.com/expressjs/express) rest-
17
17
  - [x] generate mongoose & collection interface
18
18
  - [ ] generate sql interface
19
19
 
20
- - [ ] genarate controllers from template
21
- - [ ] based on openapi spec
20
+ - [x] genarate controllers from template
21
+ - [x] based on openapi spec
22
22
 
23
- - [ ] genarate routes from template
24
- - [ ] based on controller
25
-
26
- ## Dependencies
27
- - [express](https://github.com/expressjs/express)
28
- - [json2mongoose](https://github.com/Justin26l/json2mongoose)
29
- - [js-yaml](https://github.com/nodeca/js-yaml)
23
+ - [x] genarate routes from template
24
+ - [x] based on controller
@@ -39,7 +39,7 @@ function compile(openapiPath, controllerToModelDir, outDir, options) {
39
39
  Object.keys(openApi.paths).forEach((endpoint) => {
40
40
  const interfaceName = openApi.paths[endpoint].summary;
41
41
  endpointsValidator[endpoint] = {};
42
- log_1.default.process(`Controller : ${endpoint} -> ${interfaceName}Controller`);
42
+ log_1.default.process(`Controller : ${openapiPath} > ${endpoint}`);
43
43
  Object.keys(openApi.paths[endpoint]).forEach((method) => {
44
44
  if (!Object.values(types.method).includes(method))
45
45
  return;
@@ -63,7 +63,7 @@ function compile(openapiPath, controllerToModelDir, outDir, options) {
63
63
  ;
64
64
  const outPath = `${outDir}/${interfaceName}Controller.gen.ts`;
65
65
  const controllerToModelPath = `${controllerToModelDir}/${interfaceName}Model.gen`;
66
- log_1.default.process(`Controller : ${outPath}`);
66
+ log_1.default.writing(`Controller : ${outPath}`);
67
67
  fs_1.default.writeFileSync(outPath, templates_1.default.controllerTemplate({
68
68
  endpoint: endpoint,
69
69
  modelPath: controllerToModelPath,
@@ -21,52 +21,19 @@ class {{interfaceName}}Controller {
21
21
  }
22
22
 
23
23
  public routes() {
24
- this.router.get(
25
- '/',
26
- [
27
- {{getListValidator}}
28
- ],
29
- this.get{{interfaceName}}List.bind(this)
30
- );
31
-
32
- this.router.get(
33
- '/:id',
34
- [
35
- {{getOneValidator}}
36
- ],
37
- this.get{{interfaceName}}.bind(this)
38
- );
39
-
40
- this.router.post(
41
- '/',
42
- [
43
- {{postValidator}}
44
- ],
45
- this.create{{interfaceName}}.bind(this)
46
- );
47
-
48
- this.router.put(
49
- '/:id',
50
- [
51
- {{putValidator}}
52
- ],
53
- this.update{{interfaceName}}.bind(this)
54
- );
55
- this.router.patch(
56
- '/:id',
57
- [
58
- {{patchValidator}}
59
- ],
60
- this.update{{interfaceName}}.bind(this)
61
- );
62
-
63
- this.router.delete(
64
- '/:id',
65
- [
66
- {{deleteValidator}}
67
- ],
68
- this.delete{{interfaceName}}.bind(this)
69
- );
24
+
25
+ {{getListRoute}}
26
+
27
+ {{getOneRoute}}
28
+
29
+ {{postRoute}}
30
+
31
+ {{putRoute}}
32
+
33
+ {{patchRoute}}
34
+
35
+ {{deleteRoute}}
36
+
70
37
  };
71
38
 
72
39
  public async get{{interfaceName}}(req: Request, res: Response): Promise<Response> {
@@ -88,7 +55,7 @@ class {{interfaceName}}Controller {
88
55
  }
89
56
  }
90
57
 
91
- public async get{{interfaceName}}List(req: Request, res: Response): Promise<Response> {
58
+ public async getList{{interfaceName}}(req: Request, res: Response): Promise<Response> {
92
59
  try {
93
60
  const user = await {{interfaceName}}Model.find();
94
61
  if (!user) {
@@ -150,12 +117,33 @@ export default new {{interfaceName}}Controller().router;
150
117
  template = template.replace(/{{headerComment}}/g, templateOptions.headerComment);
151
118
  template = template.replace(/{{interfaceName}}/g, templateOptions.interfaceName);
152
119
  template = template.replace(/{{modelPath}}/g, templateOptions.modelPath);
153
- template = template.replace(/{{getListValidator}}/g, templateOptions.validator[templateOptions.endpoint].get.join(',\n '));
154
- template = template.replace(/{{getOneValidator}}/g, templateOptions.validator[templateOptions.endpoint + '/{id}'].get.join(',\n '));
155
- template = template.replace(/{{postValidator}}/g, templateOptions.validator[templateOptions.endpoint].post.join(',\n '));
156
- template = template.replace(/{{putValidator}}/g, templateOptions.validator[templateOptions.endpoint + '/{id}'].put.join(',\n '));
157
- template = template.replace(/{{patchValidator}}/g, templateOptions.validator[templateOptions.endpoint + '/{id}'].patch.join(',\n '));
158
- template = template.replace(/{{deleteValidator}}/g, templateOptions.validator[templateOptions.endpoint + '/{id}'].delete.join(',\n '));
120
+ const indent2 = '\n ';
121
+ const indent3 = '\n ';
122
+ const indent4 = '\n ';
123
+ if (templateOptions.validator[templateOptions.endpoint].get) {
124
+ template = template.replace(/{{getListRoute}}/g, `this.router.get('/', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint].get.join(',' + indent4) + indent3}],${indent3}this.getList${templateOptions.interfaceName}.bind(this)${indent2});`);
125
+ }
126
+ ;
127
+ if (templateOptions.validator[templateOptions.endpoint + '/{id}'].get) {
128
+ template = template.replace(/{{getOneRoute}}/g, `this.router.get('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].get.join(',' + indent4) + indent3}],${indent3}this.get${templateOptions.interfaceName}.bind(this)${indent2});`);
129
+ }
130
+ ;
131
+ if (templateOptions.validator[templateOptions.endpoint].post) {
132
+ template = template.replace(/{{postRoute}}/g, `this.router.post('/', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint].post.join(',' + indent4) + indent3}],${indent3}this.create${templateOptions.interfaceName}.bind(this)${indent2});`);
133
+ }
134
+ ;
135
+ if (templateOptions.validator[templateOptions.endpoint + '/{id}'].put) {
136
+ template = template.replace(/{{putRoute}}/g, `this.router.put('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].put.join(',' + indent4) + indent3}],${indent3}this.update${templateOptions.interfaceName}.bind(this)${indent2});`);
137
+ }
138
+ ;
139
+ if (templateOptions.validator[templateOptions.endpoint + '/{id}'].patch) {
140
+ template = template.replace(/{{patchRoute}}/g, `this.router.patch('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].patch.join(',' + indent4) + indent3}],${indent3}this.update${templateOptions.interfaceName}.bind(this)${indent2});`);
141
+ }
142
+ ;
143
+ if (templateOptions.validator[templateOptions.endpoint + '/{id}'].delete) {
144
+ template = template.replace(/{{deleteRoute}}/g, `this.router.delete('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].delete.join(',' + indent4) + indent3}],${indent3}this.delete${templateOptions.interfaceName}.bind(this)${indent2});`);
145
+ }
146
+ ;
159
147
  return template;
160
148
  }
161
149
  exports.default = controllerTemplate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "justin26l",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "git+https://github.com/Justin26l/json2mongoose.git"
27
+ "url": "git+https://github.com/Justin26l/VeryExpress.git"
28
28
  },
29
29
  "dependencies": {
30
30
  "js-yaml": "4.1.0",