Skip to content

Commit 62eaeff

Browse files
Merge pull request #83 from JulienSergent/hotfix/ignore-file-type
Hotfix/ignore file type
2 parents 4f25d14 + c41b12a commit 62eaeff

File tree

9 files changed

+47
-6
lines changed

9 files changed

+47
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules
77
coverage
88
*.log
99
npm-debug.log*
10+
.idea

README.MD

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ See an example:
271271
"name": "access_token",
272272
"in": "query"
273273
}
274-
}
274+
},
275+
"ignore": [
276+
"**/node_modules/**"
277+
]
275278
}
276279
}
277280
```
@@ -296,4 +299,6 @@ swagger:
296299
type: apiKey
297300
name: access_token
298301
in: query
302+
ignore:
303+
- /node_modules/**
299304
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"swagger2openapi": "^5.3.0",
5858
"typescript": "^3.5.2",
5959
"typescript-rest": "^2.2.0",
60-
"yamljs": "^0.2.10"
60+
"yamljs": "^0.2.10",
61+
"minimatch": "^3.0.4"
6162
},
6263
"devDependencies": {
6364
"@types/argparse": "^1.0.36",
@@ -69,6 +70,7 @@
6970
"@types/mkdirp": "^0.3.29",
7071
"@types/mocha": "^2.2.48",
7172
"@types/yamljs": "^0.2.30",
73+
"@types/minimatch": "^3.0.3",
7274
"chai": "4.2.0",
7375
"coveralls": "^3.0.4",
7476
"cross-env": "^4.0.0",

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const swaggerConfig = validateSwaggerConfig(config.swagger);
6060
debugLog('Swagger Config: %j', swaggerConfig);
6161

6262
debugLog('Processing Services Metadata');
63-
const metadata = new MetadataGenerator(swaggerConfig.entryFile, compilerOptions).generate();
63+
const metadata = new MetadataGenerator(swaggerConfig.entryFile, compilerOptions, swaggerConfig.ignore).generate();
6464
debugLog('Generated Metadata: %j', metadata);
6565

6666
new SpecGenerator(metadata, swaggerConfig).generate()

src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,9 @@ export interface SwaggerConfig {
102102
* Possible values are `csv`, `ssv`, `tsv`, `pipes`, `multi`. If not specified, Swagger defaults to `csv`.
103103
*/
104104
collectionFormat?: string;
105+
106+
/**
107+
* Directory to ignore during TypeScript metadata scan
108+
*/
109+
ignore?: [string];
105110
}

src/metadata/metadataGenerator.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as debug from 'debug';
22
import * as glob from 'glob';
33
import * as _ from 'lodash';
4+
import * as mm from 'minimatch';
45
import * as ts from 'typescript';
56
import { ControllerGenerator } from './controllerGenerator';
67

@@ -13,7 +14,7 @@ export class MetadataGenerator {
1314
private circularDependencyResolvers = new Array<(referenceTypes: { [typeName: string]: ReferenceType }) => void>();
1415
private debugger = debug('typescript-rest-swagger:metadata');
1516

16-
constructor(entryFile: string | Array<string>, compilerOptions: ts.CompilerOptions) {
17+
constructor(entryFile: string | Array<string>, compilerOptions: ts.CompilerOptions, private readonly ignorePaths?: Array<string>) {
1718
const sourceFiles = this.getSourceFiles(entryFile);
1819
this.debugger('Starting Metadata Generator');
1920
this.debugger('Source files: %j ', sourceFiles);
@@ -25,6 +26,14 @@ export class MetadataGenerator {
2526

2627
public generate(): Metadata {
2728
this.program.getSourceFiles().forEach(sf => {
29+
if (this.ignorePaths && this.ignorePaths.length) {
30+
for (const path of this.ignorePaths) {
31+
if(!sf.fileName.includes('node_modules/typescript-rest-swagger/') && mm(sf.fileName, path)) {
32+
return;
33+
}
34+
}
35+
}
36+
2837
ts.forEachChild(sf, node => {
2938
this.nodes.push(node);
3039
});

test/data/apis.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import {
4-
Accept, DELETE, GET, Path,
4+
Accept, DELETE, FormParam, GET, Path,
55
PathParam, POST, PUT, QueryParam,
66
Return,
77
Security
@@ -96,6 +96,12 @@ export class MyService {
9696
public async testCompilerOptions(payload: TestInterface): Promise<TestInterface> {
9797
return { a: 'string', b: 123 };
9898
}
99+
100+
@POST
101+
@Path('test-form-param')
102+
public testFormParam(@FormParam('id') id: string): string {
103+
return id;
104+
}
99105
}
100106

101107
class BaseService {

test/unit/definitions.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ describe('Definition generation', () => {
234234
expression = jsonata('paths."/mypath/test-compiler-options".post.parameters[0].schema');
235235
expect(expression.evaluate(spec)).to.eql({ $ref: '#/definitions/TestInterface' });
236236
});
237+
it('should support formparam', () => {
238+
expect(spec.paths).to.have.property('/mypath/test-form-param');
239+
let expression = jsonata('paths."/mypath/test-form-param".post.responses."200".schema');
240+
expect(expression.evaluate(spec)).to.eql({ type: 'string' });
241+
expression = jsonata('paths."/mypath/test-form-param".post.parameters[0]');
242+
expect(expression.evaluate(spec)).to.eql({
243+
description: '',
244+
in: 'formData',
245+
name: 'id',
246+
required: true,
247+
type: 'string',
248+
});
249+
});
237250
});
238251

239252
describe('PrimitiveEndpoint', () => {

0 commit comments

Comments
 (0)