Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ interface GenerateApiParams {
* generate js api module with declaration file (default: false)
*/
toJS?: boolean;

/**
* url index from paths used for merging into modules
*/
moduleNameIndex?: number;
}

export declare function generateApi(
Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const config = {
componentsMap: {},
/** flag for catching convertion from swagger 2.0 */
convertedFromSwagger2: false,

/** url index from paths used for merging into modules */
moduleNameIndex: 0,
};

/** needs to use data everywhere in project */
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
generateRouteTypes = config.generateRouteTypes,
generateClient = config.generateClient,
generateUnionEnums = config.generateUnionEnums,
moduleNameIndex = config.moduleNameIndex,
}) =>
new Promise((resolve, reject) => {
addToConfig({
Expand All @@ -53,6 +54,7 @@ module.exports = {
generateResponses,
templates,
generateUnionEnums,
moduleNameIndex,
});
(spec ? convertSwaggerObject(spec) : getSwaggerObject(input, url))
.then(({ usageSchema, originalSchema }) => {
Expand All @@ -78,7 +80,7 @@ module.exports = {
const schemasMap = filterComponentsMap(componentsMap, "schemas");

const parsedSchemas = parseSchemas(components);
const routes = parseRoutes(usageSchema, parsedSchemas, componentsMap, components);
const routes = parseRoutes(usageSchema, parsedSchemas, componentsMap, components, moduleNameIndex);
const hasSecurityRoutes = routes.some((route) => route.security);
const hasQueryRoutes = routes.some((route) => route.hasQuery);
const hasFormDataRoutes = routes.some((route) => route.hasFormDataParams);
Expand Down
4 changes: 2 additions & 2 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const createRequestsMap = (requestInfoByMethodsMap) => {
);
};

const parseRoutes = ({ paths, security: globalSecurity }, parsedSchemas) =>
const parseRoutes = ({ paths, security: globalSecurity }, parsedSchemas, componentsMap, components, moduleNameIndex) =>
_.entries(paths).reduce((routes, [route, requestInfoByMethodsMap]) => {
if (route.startsWith("x-")) return routes;

Expand Down Expand Up @@ -224,7 +224,7 @@ const parseRoutes = ({ paths, security: globalSecurity }, parsedSchemas) =>
let formDataRequestBody =
requestBodyType && requestBodyType.dataType === "multipart/form-data";

const moduleName = _.camelCase(_.compact(_.split(route, "/"))[0]);
const moduleName = _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);

const routeName = getRouteName(operationId, method, route, moduleName);
const name = _.camelCase(routeName);
Expand Down