Skip to content

Commit

Permalink
fix(golang): fix duplicated DTO with user-defined name
Browse files Browse the repository at this point in the history
  • Loading branch information
php-coder committed Apr 9, 2024
1 parent 056ecce commit c3296ca
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/templates/routes.go.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,28 @@ function dto2struct(dto) {
let globalDtoCounter = 0
const dtoCache = {}
const namedDtoCache = {}
function cacheDto(dto) {
dtoCache[dto.signature] = dto.name
if (dto.hasUserProvidedName) {
namedDtoCache[dto.signature] = dto.name
} else {
dtoCache[dto.signature] = dto.name
}
return dto
}
function dtoInCache(dto) {
// always prefer user specified name even when we have a similar DTO in cache
// always prefer user specified name even when we have a similar DTO in cache for generated names
if (dto.hasUserProvidedName) {
return false
return namedDtoCache.hasOwnProperty(dto.signature)
}
return dtoCache.hasOwnProperty(dto.signature)
}
function obtainDtoName(dto) {
const cacheKey = dto ? dto.signature : null
return dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
const cacheKey = dto.signature
return namedDtoCache.hasOwnProperty(cacheKey) ? namedDtoCache[cacheKey] : dto.name
}
const verbs_with_dto = [ 'get', 'post', 'put' ]
Expand Down

0 comments on commit c3296ca

Please sign in to comment.