Skip to content

Commit 48b4fff

Browse files
committed
fix(tags): definition type name filter
Signed-off-by: Vojtech Mašek <[email protected]>
1 parent 2ea4caf commit 48b4fff

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/parser.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,34 @@ function parseDefinitions(
112112
];
113113

114114
if (methods) {
115-
const usedDefs: Definition[] = [];
116-
const filterByName = (name?: string) => {
117-
const filtered = allDefs.filter(d => d.name === name);
118-
119-
const children: Definition[] = [];
120-
filtered.forEach(d => d.properties.forEach(p => {
121-
if (p.typescriptType && p.isRef) {
122-
children.push(...filterByName(p.typescriptType));
123-
}
124-
}));
125-
filtered.push(...children);
126-
return filtered;
115+
const filterByName = (name: string): Definition[] => {
116+
const namedDefs = allDefs.filter(def => def.name === name);
117+
return namedDefs
118+
.reduce<Definition[]>(
119+
(acc, def) => [
120+
...acc,
121+
...def.properties
122+
.filter(prop => prop.typescriptType && prop.isRef)
123+
.reduce<Definition[]>((a, prop) => [...a, ...filterByName(prop.typescriptType!)], [])
124+
],
125+
namedDefs
126+
);
127127
};
128-
methods.forEach(method => {
129-
usedDefs.push(...filterByName(method.responseTypeName));
130-
method.parameters.forEach(param => {
131-
usedDefs.push(...filterByName(param.typescriptType));
132-
});
133-
});
134-
135-
return Array.from(new Set(usedDefs));
128+
129+
return Array.from(new Set(
130+
methods.reduce<Definition[]>(
131+
(acc, method) => [
132+
...acc,
133+
...method.parameters.reduce(
134+
(a, param) => [
135+
...a,
136+
...filterByName(camelCase(param.typescriptType, false)),
137+
],
138+
filterByName(camelCase(method.responseTypeName, false))
139+
)
140+
],
141+
[]
142+
)));
136143
} else {
137144
return allDefs;
138145
}
@@ -281,7 +288,7 @@ function determineResponseType(responses: { [responseName: string]: Response }):
281288
return {name: 'any', type: 'any'};
282289
}
283290

284-
const nullable = (schema as Schema & {'x-nullable'?: boolean})['x-nullable'] || false;
291+
const nullable = (schema as Schema & { 'x-nullable'?: boolean })['x-nullable'] || false;
285292
if (schema.type === 'array') {
286293
const {items} = schema;
287294
if (items == null) {

0 commit comments

Comments
 (0)