Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit unique symbol names for Implementation / createRouter functions #258

Merged
merged 1 commit into from
Oct 27, 2024
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
9 changes: 7 additions & 2 deletions e2e/src/generated/routes/headers.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions e2e/src/generated/routes/validation.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/openapi-code-generator/src/core/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Input {
): OperationGroup[] {
switch (strategy) {
case "none": {
return [{name: "generated", operations: this.allOperations()}]
return [{name: "", operations: this.allOperations()}]
}
case "first-tag":
return this.operationsByFirstTag()
Expand Down Expand Up @@ -154,7 +154,7 @@ export class Input {

private operationsByFirstTag(): OperationGroup[] {
return this.groupOperations((operation) => {
const tag = operation.tags[0] ?? "generated"
const tag = operation.tags[0]

if (!tag) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,32 @@ export class ServerRouterBuilder implements ICompilable {
}

toString(): string {
const implementationExportName = "Implementation"
const moduleName = titleCase(this.name)

const implementationExportName = `${moduleName}Implementation`
const createRouterExportName = `create${moduleName}Router`

const routes = this.statements
const code = `
${this.operationTypes.flatMap((it) => it.statements).join("\n\n")}

${this.implementationExport(implementationExportName)}

export function createRouter(implementation: ${implementationExportName}): KoaRouter {
export function ${createRouterExportName}(implementation: ${implementationExportName}): KoaRouter {
const router = new KoaRouter()

${routes.join("\n\n")}

return router
}

${
moduleName &&
`
export {${createRouterExportName} as createRouter}
export ${this.implementationMethod === "type" || this.implementationMethod === "interface" ? "type" : ""} {${implementationExportName} as Implementation}
`
}
`
return code
}
Expand Down