Skip to content

Commit 6d15337

Browse files
committed
fix(python): fix duplicated DTO with user-defined name
1 parent 8c8b91a commit 6d15337

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/templates/routes.py.ejs

+10-5
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,30 @@ function dto2model(dto) {
150150
151151
let globalDtoCounter = 0
152152
const dtoCache = {}
153+
const namedDtoCache = {}
153154
154155
// LATER: reduce duplication with routes.go.ejs
155156
function cacheDto(dto) {
156-
dtoCache[dto.signature] = dto.name
157+
if (dto.hasUserProvidedName) {
158+
namedDtoCache[dto.signature] = dto.name
159+
} else {
160+
dtoCache[dto.signature] = dto.name
161+
}
157162
return dto
158163
}
159164
160165
// LATER: reduce duplication with routes.go.ejs
161166
function dtoInCache(dto) {
162-
// always prefer user specified name even when we have a similar DTO in cache
167+
// always prefer user specified name even when we have a similar DTO in cache for generated names
163168
if (dto.hasUserProvidedName) {
164-
return false
169+
return namedDtoCache.hasOwnProperty(dto.signature)
165170
}
166171
return dtoCache.hasOwnProperty(dto.signature)
167172
}
168173
169174
function obtainDtoName(dto) {
170-
const cacheKey = dto ? dto.signature : null
171-
return dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
175+
const cacheKey = dto.signature
176+
return namedDtoCache.hasOwnProperty(cacheKey) ? namedDtoCache[cacheKey] : dto.name
172177
}
173178
174179
// Generate models

0 commit comments

Comments
 (0)