@@ -149,6 +149,11 @@ function dtoInCache(dto) {
149149 return dtoCache .hasOwnProperty (dto .signature )
150150}
151151
152+ function obtainDtoName (dto ) {
153+ const cacheKey = dto ? dto .signature : null
154+ return dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
155+ }
156+
152157const verbs_with_dto = [ ' get' , ' post' , ' put' ]
153158endpoints .forEach (function (endpoint ) {
154159 const dtos = endpoint .methods
@@ -181,8 +186,7 @@ endpoints.forEach(function(endpoint) {
181186 if (hasGetOne || hasGetMany) {
182187 const dto = query2dto (sqlParser, method)
183188 // LATER: do we really need signature and cache?
184- const cacheKey = dto ? dto .signature : null
185- const dtoName = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
189+ const dataType = obtainDtoName (dto)
186190 const resultVariableDeclaration = hasGetMany
187191 ? ` result := []${ dtoName} \{\} `
188192 : ` var result ${ dtoName} `
@@ -227,8 +231,7 @@ endpoints.forEach(function(endpoint) {
227231 if (method .name === ' post' ) {
228232 const dto = query2dto (sqlParser, method)
229233 // LATER: do we really need signature and cache?
230- const cacheKey = dto ? dto .signature : null
231- const dataType = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
234+ const dataType = obtainDtoName (dto)
232235% >
233236 r .Post (" <%- path %>" , func (w http .ResponseWriter , r * http .Request ) {
234237 var body < %- dataType % >
@@ -254,8 +257,7 @@ endpoints.forEach(function(endpoint) {
254257 if (method .name === ' put' ) {
255258 const dto = query2dto (sqlParser, method)
256259 // LATER: do we really need signature and cache?
257- const cacheKey = dto ? dto .signature : null
258- const dataType = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
260+ const dataType = obtainDtoName (dto)
259261% >
260262 r .Put (" <%- path %>" , func (w http .ResponseWriter , r * http .Request ) {
261263 var body < %- dataType % >
0 commit comments