Skip to content

Commit

Permalink
Merge pull request #134 from EricPoul/master
Browse files Browse the repository at this point in the history
Fix tags parsing into namespaces
  • Loading branch information
luisfpg authored Jan 5, 2021
2 parents eecd92e + 9c50beb commit c2b5864
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/gen-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ export function modelFile(pathToModels: string, name: string, options: Options):
}

/**
* Returns the namespace path, that is, the part before the last '.' splitted by '/' instead of '.'.
* Returns the namespace path, that is, the part before the last '.' split by '/' instead of '.'.
* If there's no namespace, returns undefined.
*/
export function namespace(name: string): string | undefined {
name = name.replace(/^\.+/g, '');
name = name.replace(/\.+$/g, '');
const pos = name.lastIndexOf('.');
return pos < 0 ? undefined : name.substring(0, pos).replace('.', '/');
return pos < 0 ? undefined : name.substring(0, pos).replace(/\./g, '/');
}

/**
Expand Down
8 changes: 7 additions & 1 deletion test/all-operations.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
{
"name": "tag2"
},
{
"name": "tag.tag2.tag3.tag4.tag5"
},
{
"name": "unused",
"description": "Unused description"
Expand Down Expand Up @@ -353,6 +356,9 @@
},
"/path5": {
"get": {
"tags": [
"tag.tag2.tag3.tag4.tag5"
],
"summary": "A path that contains a reference to response objects",
"responses": {
"200": {
Expand Down Expand Up @@ -422,4 +428,4 @@
}
}
}
}
}
12 changes: 10 additions & 2 deletions test/all-operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Generation tests using all-operations.json', () => {
});

it('Tags', () => {
expect(gen.services.size).toBe(3);
expect(gen.services.size).toBe(4);
});

it('Tag 1', done => {
Expand Down Expand Up @@ -98,11 +98,19 @@ describe('Generation tests using all-operations.json', () => {
});
});

it('Tag with nesting', () => {
const tagWithNesting = gen.services.get('tag.tag2.tag3.tag4.tag5');
expect(tagWithNesting).toBeDefined();
if (!tagWithNesting) return;

expect(tagWithNesting.namespace).toBe('tag/tag2/tag3/tag4');
});

it('No tag', done => {
const noTag = gen.services.get('noTag');
expect(noTag).toBeDefined();
if (!noTag) return;
expect(noTag.operations.length).toBe(4);
expect(noTag.operations.length).toBe(3);

const ts = gen.templates.apply('service', noTag);
const parser = new TypescriptParser();
Expand Down

0 comments on commit c2b5864

Please sign in to comment.