@team-supercharge/oasg 9.1.1 → 9.2.1

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/.gitlab-ci.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  include:
2
2
  - project: team-supercharge/jarvis/jarvis
3
3
  file: jarvis.yml
4
- ref: v8.0.0
4
+ ref: v9.1.0
5
5
 
6
6
  stages:
7
7
  - lint
@@ -11,7 +11,7 @@ stages:
11
11
 
12
12
  default:
13
13
  image:
14
- name: node:12.18
14
+ name: node:18.15.0
15
15
  tags: [arm64]
16
16
 
17
17
  # lint
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v18.15.0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [9.2.1](https://gitlab.com/team-supercharge/oasg/compare/v9.2.0...v9.2.1) (2023-04-13)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **nestjs:** use node for post-processing files instead of sed ([22d996b](https://gitlab.com/team-supercharge/oasg/commit/22d996bd0c958108871bc8d331a44aa4f72f99b7))
11
+
12
+
13
+ ### CI
14
+
15
+ * upgrade to latest jarvis ([c444628](https://gitlab.com/team-supercharge/oasg/commit/c4446285ce4a97e6fd75239be27cb08b054f9f68))
16
+ * use latest lts node version ([bdd39a6](https://gitlab.com/team-supercharge/oasg/commit/bdd39a663a5d8c1f37704c9ad0c12148dd217f6f))
17
+
18
+ ## [9.2.0](https://gitlab.com/team-supercharge/oasg/compare/v9.1.1...v9.2.0) (2023-04-03)
19
+
20
+
21
+ ### Features
22
+
23
+ * add glob patterns to merger ([e7ea3bd](https://gitlab.com/team-supercharge/oasg/commit/e7ea3bdc28958e3a8ea4de7af10a1cac48645b5b))
24
+
5
25
  ### [9.1.1](https://gitlab.com/team-supercharge/oasg/compare/v9.1.0...v9.1.1) (2023-03-06)
6
26
 
7
27
 
package/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:12.18
1
+ FROM node:18.15.0
2
2
 
3
3
  WORKDIR /app
4
4
  COPY . .
package/README.md CHANGED
@@ -263,6 +263,8 @@ Common source parameters
263
263
 
264
264
  #### Simple
265
265
 
266
+ A single file can be used as an input.
267
+
266
268
  ```json
267
269
  {
268
270
  "id": "source-simple",
@@ -277,20 +279,24 @@ Common source parameters
277
279
 
278
280
  #### Merged
279
281
 
282
+ More files are merged into a single OpenApi specification file and used as an input. The files are merged in the order they are defined in the `inputs` array. Take care during naming of the schemas, as they are merged into a single namespace.
283
+
284
+ Glob patterns are supported.
285
+
280
286
  ```json
281
287
  {
282
288
  "id": "source-merged",
283
289
  "type": "merged",
284
290
  "inputs": [
285
291
  "api/swagger1.yaml",
286
- "api/swagger2.yaml"
292
+ "api/swagger/*.yaml"
287
293
  ]
288
294
  }
289
295
  ```
290
296
 
291
297
  |Parameter| Description| Required | Default |
292
298
  |-|-|-|-|
293
- | inputs | Array of paths of specification files | Y | - |
299
+ | inputs | Array of paths of specification files or globs | Y | - |
294
300
 
295
301
  #### Overrides
296
302
 
package/bin/merger.js CHANGED
@@ -2,6 +2,7 @@ const crypto = require('crypto');
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
  const SwaggerParser = require("@apidevtools/swagger-parser");
5
+ const { glob } = require('glob');
5
6
 
6
7
  const { dump } = require(`${__dirname}/dump.js`);
7
8
 
@@ -10,8 +11,10 @@ async function merge(source) {
10
11
  fs.mkdirSync('./out');
11
12
  }
12
13
 
13
- if (source.inputs.length == 1) {
14
- return source.inputs[0];
14
+ const inputFiles = await glob(source.inputs);
15
+
16
+ if (inputFiles.length == 1) {
17
+ return inputFiles[0];
15
18
  }
16
19
 
17
20
  if (!fs.existsSync('./out/.tmp')) {
@@ -19,7 +22,7 @@ async function merge(source) {
19
22
  }
20
23
  const outFile = `./out/.tmp/${source.id}-${crypto.randomBytes(4).readUInt32LE(0)}.yaml`;
21
24
 
22
- const document = await mergeDocuments(source.inputs);
25
+ const document = await mergeDocuments(inputFiles);
23
26
 
24
27
  dump(document, outFile);
25
28
 
package/bin/oasg CHANGED
@@ -18,6 +18,7 @@ const { exec } = require(`${__dirname}/exec.js`);
18
18
  const { merge } = require(`${__dirname}/merger.js`);
19
19
  const { applyOverrides } = require(`${__dirname}/overrider.js`);
20
20
  const { openApiTarget } = require(`${__dirname}/openapi-target.js`);
21
+ const { globSync } = require('glob');
21
22
 
22
23
  let VERSION = JSON.parse(fs.readFileSync('package.json')).version;
23
24
 
@@ -274,10 +275,15 @@ async function parseConfig() {
274
275
 
275
276
  case 'merged':
276
277
  s.inputs.forEach(i => {
277
- if (!fs.existsSync(i)) {
278
- console.error(`input file: ${i} not found for source: ${s.id}`);
279
- exit(1);
278
+ if (fs.existsSync(i)) {
279
+ return;
280
280
  }
281
+ const matches = globSync(i);
282
+ if (matches.every(m => fs.existsSync(m))) {
283
+ return;
284
+ }
285
+ console.error(`input file: ${i} not found for source: ${s.id}`);
286
+ exit(1);
281
287
  });
282
288
 
283
289
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-supercharge/oasg",
3
- "version": "9.1.1",
3
+ "version": "9.2.1",
4
4
  "description": "Node-based tool to lint OpenAPI documents and generate clients, servers and documentation from them",
5
5
  "author": "Supercharge",
6
6
  "license": "MIT",
@@ -12,6 +12,10 @@
12
12
  "type": "git",
13
13
  "url": "git@gitlab.com:team-supercharge/oasg/oasg.git"
14
14
  },
15
+ "engines": {
16
+ "node": "^18",
17
+ "npm": "^9"
18
+ },
15
19
  "dependencies": {
16
20
  "@apidevtools/json-schema-ref-parser": "^9.0.6",
17
21
  "@apidevtools/swagger-parser": "^10.0.2",
@@ -22,6 +26,7 @@
22
26
  "command-exists": "^1.2.9",
23
27
  "express": "^4.17.1",
24
28
  "express-http-proxy": "^1.6.2",
29
+ "glob": "^9.2.1",
25
30
  "js-yaml": "^4.1.0",
26
31
  "json-schema-merge-allof": "^0.7.0",
27
32
  "openapi-types": "^7.0.1",
@@ -18,17 +18,13 @@ cd out/$targetId
18
18
  # remove unnecessary files
19
19
  rm -rf variables.ts configuration.ts api.module.ts encoder.ts ng-package.json
20
20
 
21
- # rewrite http method annotatinos
22
- sed -i 's/^ \/\/\/\/ @get/ @Get/g' api/*.api.ts
23
- sed -i 's/^ \/\/\/\/ @post/ @Post/g' api/*.api.ts
24
- sed -i 's/^ \/\/\/\/ @put/ @Put/g' api/*.api.ts
25
- sed -i 's/^ \/\/\/\/ @delete/ @Delete/g' api/*.api.ts
26
- sed -i 's/^ \/\/\/\/ @patch/ @Patch/g' api/*.api.ts
27
- sed -i 's/^ \/\/\/\/ @options/ @Options/g' api/*.api.ts
28
- sed -i 's/^ \/\/\/\/ @head/ @Head/g' api/*.api.ts
21
+ # rewrite http method annotations
22
+ node rewrite-http-annotations.js
23
+ rm rewrite-http-annotations.js
29
24
 
30
25
  # remove empty params objects from context objects
31
- sed -i 's/{ params: { }, /{ /g' api/*.api.ts
26
+ node remove-empty-param-objects-from-context.js
27
+ rm remove-empty-param-objects-from-context.js
32
28
 
33
29
  # reorder operations (place ones with path params backwards)
34
30
  node reorder-operations.js
@@ -38,8 +34,8 @@ rm reorder-operations.js
38
34
  node unescape-patterns.js
39
35
  rm unescape-patterns.js
40
36
 
41
- # rewrite path parameters
42
- sed -i 's/\${encodeURIComponent(String(\(.*\)))}/:\1/g' api/*.api.ts
37
+ node rewrite-path-parameters.js
38
+ rm rewrite-path-parameters.js
43
39
 
44
40
  npm install
45
41
  npm run build
@@ -23,6 +23,15 @@
23
23
  },
24
24
  "unescape-patterns.js": {
25
25
  "templateType": "SupportingFiles"
26
+ },
27
+ "rewrite-http-annotations.js": {
28
+ "templateType": "SupportingFiles"
29
+ },
30
+ "rewrite-path-parameters.js": {
31
+ "templateType": "SupportingFiles"
32
+ },
33
+ "remove-empty-param-objects-from-context.js": {
34
+ "templateType": "SupportingFiles"
26
35
  }
27
36
  },
28
37
  "typeMappings": {
@@ -0,0 +1,18 @@
1
+ var fs = require('fs')
2
+
3
+ const apiFolder = './api';
4
+ const apiFileSuffix = '.api.ts';
5
+
6
+ // remove empty param objects from context objects
7
+ const apiFiles = fs.readdirSync(apiFolder).filter(fn => fn.endsWith(apiFileSuffix));
8
+ apiFiles.forEach(apiFile => removeEmptyParamObjects(apiFile));
9
+
10
+ function removeEmptyParamObjects(fileName) {
11
+ const file = `${apiFolder}/${fileName}`;
12
+ const contents = fs.readFileSync(file, 'utf-8');
13
+
14
+ const result = contents.replace(/{ params: { }, /g, '{ ');
15
+
16
+ var options = { flag : 'w', encoding: 'utf8' };
17
+ fs.writeFileSync(file, result, options);
18
+ }
@@ -0,0 +1,24 @@
1
+ var fs = require('fs')
2
+
3
+ const apiFolder = './api';
4
+ const apiFileSuffix = '.api.ts';
5
+
6
+ // rewrite http annotations
7
+ const apiFiles = fs.readdirSync(apiFolder).filter(fn => fn.endsWith(apiFileSuffix));
8
+ apiFiles.forEach(apiFile => rewriteHttpAnnotations(apiFile));
9
+
10
+ function rewriteHttpAnnotations(fileName) {
11
+ const file = `${apiFolder}/${fileName}`;
12
+ const contents = fs.readFileSync(file, 'utf-8');
13
+
14
+ var result = contents.replace(/ \/\/\/\/ @get/g, ' @Get');
15
+ result = result.replace(/ \/\/\/\/ @post/g, ' @Post');
16
+ result = result.replace(/ \/\/\/\/ @put/g, ' @Put');
17
+ result = result.replace(/ \/\/\/\/ @delete/g, ' @Delete');
18
+ result = result.replace(/ \/\/\/\/ @patch/g, ' @Patch');
19
+ result = result.replace(/ \/\/\/\/ @options/g, ' @Options');
20
+ result = result.replace(/ \/\/\/\/ @head/g, ' @Head');
21
+
22
+ var options = { flag : 'w', encoding: 'utf8' };
23
+ fs.writeFileSync(file, result, options);
24
+ }
@@ -0,0 +1,19 @@
1
+ var fs = require('fs')
2
+
3
+ const apiFolder = './api';
4
+ const apiFileSuffix = '.api.ts';
5
+
6
+ // rewrite path parameters
7
+ const apiFiles = fs.readdirSync(apiFolder).filter(fn => fn.endsWith(apiFileSuffix));
8
+ apiFiles.forEach(apiFile => rewritePathParameters(apiFile));
9
+
10
+ function rewritePathParameters(fileName) {
11
+ const file = `${apiFolder}/${fileName}`;
12
+ const contents = fs.readFileSync(file, 'utf-8');
13
+
14
+ var result = contents.replace(/\${encodeURIComponent\(String\(/g, ':');
15
+ result = result.replace(/\)\)\}/g, '');
16
+
17
+ var options = { flag : 'w', encoding: 'utf8' };
18
+ fs.writeFileSync(file, result, options);
19
+ }
@@ -1,4 +1,4 @@
1
- FROM node:lts-alpine
1
+ FROM node:18.15-alpine
2
2
 
3
3
  RUN npm install -g stubby
4
4