Skip to content

Commit c3296ca

Browse files
committed
fix(golang): fix duplicated DTO with user-defined name
1 parent 056ecce commit c3296ca

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/templates/routes.go.ejs

+12-5
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,28 @@ function dto2struct(dto) {
137137
let globalDtoCounter = 0
138138
139139
const dtoCache = {}
140+
const namedDtoCache = {}
141+
140142
function cacheDto(dto) {
141-
dtoCache[dto.signature] = dto.name
143+
if (dto.hasUserProvidedName) {
144+
namedDtoCache[dto.signature] = dto.name
145+
} else {
146+
dtoCache[dto.signature] = dto.name
147+
}
142148
return dto
143149
}
150+
144151
function dtoInCache(dto) {
145-
// always prefer user specified name even when we have a similar DTO in cache
152+
// always prefer user specified name even when we have a similar DTO in cache for generated names
146153
if (dto.hasUserProvidedName) {
147-
return false
154+
return namedDtoCache.hasOwnProperty(dto.signature)
148155
}
149156
return dtoCache.hasOwnProperty(dto.signature)
150157
}
151158
152159
function obtainDtoName(dto) {
153-
const cacheKey = dto ? dto.signature : null
154-
return dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
160+
const cacheKey = dto.signature
161+
return namedDtoCache.hasOwnProperty(cacheKey) ? namedDtoCache[cacheKey] : dto.name
155162
}
156163
157164
const verbs_with_dto = [ 'get', 'post', 'put' ]

0 commit comments

Comments
 (0)