-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tags): group paths by tags if provided
this will group paths by tags if provided fix #188
- Loading branch information
Showing
17 changed files
with
469 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { OpenAPIV2 } from 'openapi-types'; | ||
|
||
export class TagsCollection { | ||
private tags: { [key: string]: OpenAPIV2.TagObject } = {}; | ||
|
||
public get length(): number { | ||
return Object.keys(this.tags).length; | ||
} | ||
|
||
public tag(tag: OpenAPIV2.TagObject): TagsCollection { | ||
if (!('name' in tag)) { | ||
throw new Error('Tag must have name property'); | ||
} | ||
this.tags[tag.name] = tag; | ||
return this; | ||
} | ||
|
||
public getTag(name: string): OpenAPIV2.TagObject | null { | ||
if (name in this.tags) { | ||
return this.tags[name]; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { OpenAPIV2 } from 'openapi-types'; | ||
import { ALLOWED_METHODS } from '../types'; | ||
|
||
type Tagged = { [tag: string]: OpenAPIV2.PathsObject }; | ||
|
||
/** | ||
* Group path and methods by tags they have | ||
*/ | ||
export function groupPathsByTags( | ||
inputDoc: OpenAPIV2.PathsObject, | ||
): Tagged { | ||
const tagged: Tagged = {}; | ||
|
||
Object.keys(inputDoc).forEach((path: string) => { | ||
const data = inputDoc[path]; | ||
Object.keys(data).forEach((method) => { | ||
if (ALLOWED_METHODS.includes(method)) { | ||
const pathMethod = data[method]; | ||
const tags = pathMethod.tags || ['']; | ||
tags.forEach((tagName) => { | ||
if (!tagged[tagName]) { | ||
tagged[tagName] = { | ||
...tagged[tagName], | ||
[path]: { | ||
parameters: data.parameters, | ||
$ref: data.$ref, | ||
}, | ||
}; | ||
} | ||
tagged[tagName] = { | ||
...tagged[tagName], | ||
...{ | ||
[path]: { | ||
...tagged[tagName][path], | ||
[method]: pathMethod, | ||
}, | ||
}, | ||
}; | ||
}); | ||
} | ||
}); | ||
}); | ||
return tagged; | ||
} |
Oops, something went wrong.