Skip to content

Commit c2884b7

Browse files
authored
[BUG][Go-server] attempt to fix the controller-api mustache template for a nullable bodyParam (#20478)
* go-server: attempt to fix the controller-api mustache template for a nullable bodyParam * added to petstore an example to trigger the issue which this PR fixes
1 parent cd7cdb1 commit c2884b7

File tree

14 files changed

+769
-1
lines changed

14 files changed

+769
-1
lines changed

modules/openapi-generator/src/main/resources/go-server/controller-api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
624624
{{/isArray}}
625625
{{/isBodyParam}}
626626
{{/allParams}}
627-
result, err := c.service.{{nickname}}(r.Context(){{#allParams}}, {{paramName}}Param{{/allParams}})
627+
result, err := c.service.{{nickname}}(r.Context(){{#allParams}}, {{#isNullable}}{{#isBodyParam}}&{{/isBodyParam}}{{/isNullable}}{{paramName}}Param{{/allParams}})
628628
// If an error occurred, encode the error with the status code
629629
if err != nil {
630630
c.errorHandler(w, r, err, &result)

modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,24 @@ paths:
582582
$ref: '#/components/schemas/User'
583583
description: Created user object
584584
required: true
585+
put:
586+
tags:
587+
- user
588+
summary: Create user
589+
description: This can only be done by the logged in user.
590+
operationId: createUserNullable
591+
responses:
592+
default:
593+
description: successful operation
594+
security:
595+
- api_key: []
596+
requestBody:
597+
content:
598+
application/json:
599+
schema:
600+
$ref: '#/components/schemas/UserNullable'
601+
description: Created user object, with a nullable bodyParam
602+
required: true
585603
/user/createWithArray:
586604
post:
587605
tags:
@@ -1052,6 +1070,66 @@ components:
10521070
name: User
10531071
required:
10541072
- deepSliceModel
1073+
UserNullable:
1074+
title: a User
1075+
description: A User who is purchasing from the pet store
1076+
type: object
1077+
nullable: true
1078+
properties:
1079+
id:
1080+
type: integer
1081+
format: int64
1082+
username:
1083+
type: string
1084+
firstName:
1085+
type: string
1086+
lastName:
1087+
type: string
1088+
email:
1089+
type: string
1090+
password:
1091+
type: string
1092+
phone:
1093+
type: string
1094+
nullable: true
1095+
userStatus:
1096+
type: integer
1097+
format: int32
1098+
description: User Status
1099+
deepSliceModel:
1100+
nullable: true
1101+
type: array
1102+
description: An array 1-deep.
1103+
items:
1104+
type: array
1105+
description: An array 2-deep.
1106+
items:
1107+
type: array
1108+
description: An array 3-deep.
1109+
items:
1110+
$ref: '#/components/schemas/Tag'
1111+
deepSliceMap:
1112+
type: array
1113+
description: An array 1-deep.
1114+
items:
1115+
type: array
1116+
description: An array 2-deep.
1117+
items:
1118+
title: an Object
1119+
type: object
1120+
description: An array 3-deep.
1121+
properties:
1122+
tag:
1123+
$ref: '#/components/schemas/Tag'
1124+
Pet:
1125+
type: array
1126+
description: An array of pet.
1127+
items:
1128+
$ref: '#/components/schemas/Pet'
1129+
xml:
1130+
name: User
1131+
required:
1132+
- deepSliceModel
10551133
Tag:
10561134
title: Pet Tag
10571135
description: A tag for a pet

samples/server/petstore/go-api-server/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ go/model_special_info.go
2727
go/model_species.go
2828
go/model_tag.go
2929
go/model_user.go
30+
go/model_user_nullable.go
3031
go/routers.go
3132
main.go

samples/server/petstore/go-api-server/api/openapi.yaml

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,24 @@ paths:
605605
summary: Create user
606606
tags:
607607
- user
608+
put:
609+
description: This can only be done by the logged in user.
610+
operationId: createUserNullable
611+
requestBody:
612+
content:
613+
application/json:
614+
schema:
615+
$ref: '#/components/schemas/UserNullable'
616+
description: "Created user object, with a nullable bodyParam"
617+
required: true
618+
responses:
619+
default:
620+
description: successful operation
621+
security:
622+
- api_key: []
623+
summary: Create user
624+
tags:
625+
- user
608626
/user/createWithArray:
609627
post:
610628
description: ""
@@ -1240,6 +1258,211 @@ components:
12401258
type: object
12411259
xml:
12421260
name: User
1261+
UserNullable:
1262+
description: A User who is purchasing from the pet store
1263+
example:
1264+
firstName: firstName
1265+
lastName: lastName
1266+
password: password
1267+
userStatus: 6
1268+
phone: phone
1269+
deepSliceModel:
1270+
- - - name: name
1271+
id: 1
1272+
- name: name
1273+
id: 1
1274+
- - name: name
1275+
id: 1
1276+
- name: name
1277+
id: 1
1278+
- - - name: name
1279+
id: 1
1280+
- name: name
1281+
id: 1
1282+
- - name: name
1283+
id: 1
1284+
- name: name
1285+
id: 1
1286+
id: 0
1287+
deepSliceMap:
1288+
- - tag:
1289+
name: name
1290+
id: 1
1291+
Pet:
1292+
- photoUrls:
1293+
- photoUrls
1294+
- photoUrls
1295+
name: doggie
1296+
id: 0
1297+
category:
1298+
name: name
1299+
id: 6
1300+
tags:
1301+
- name: name
1302+
id: 1
1303+
- name: name
1304+
id: 1
1305+
status: available
1306+
- photoUrls:
1307+
- photoUrls
1308+
- photoUrls
1309+
name: doggie
1310+
id: 0
1311+
category:
1312+
name: name
1313+
id: 6
1314+
tags:
1315+
- name: name
1316+
id: 1
1317+
- name: name
1318+
id: 1
1319+
status: available
1320+
- tag:
1321+
name: name
1322+
id: 1
1323+
Pet:
1324+
- photoUrls:
1325+
- photoUrls
1326+
- photoUrls
1327+
name: doggie
1328+
id: 0
1329+
category:
1330+
name: name
1331+
id: 6
1332+
tags:
1333+
- name: name
1334+
id: 1
1335+
- name: name
1336+
id: 1
1337+
status: available
1338+
- photoUrls:
1339+
- photoUrls
1340+
- photoUrls
1341+
name: doggie
1342+
id: 0
1343+
category:
1344+
name: name
1345+
id: 6
1346+
tags:
1347+
- name: name
1348+
id: 1
1349+
- name: name
1350+
id: 1
1351+
status: available
1352+
- - tag:
1353+
name: name
1354+
id: 1
1355+
Pet:
1356+
- photoUrls:
1357+
- photoUrls
1358+
- photoUrls
1359+
name: doggie
1360+
id: 0
1361+
category:
1362+
name: name
1363+
id: 6
1364+
tags:
1365+
- name: name
1366+
id: 1
1367+
- name: name
1368+
id: 1
1369+
status: available
1370+
- photoUrls:
1371+
- photoUrls
1372+
- photoUrls
1373+
name: doggie
1374+
id: 0
1375+
category:
1376+
name: name
1377+
id: 6
1378+
tags:
1379+
- name: name
1380+
id: 1
1381+
- name: name
1382+
id: 1
1383+
status: available
1384+
- tag:
1385+
name: name
1386+
id: 1
1387+
Pet:
1388+
- photoUrls:
1389+
- photoUrls
1390+
- photoUrls
1391+
name: doggie
1392+
id: 0
1393+
category:
1394+
name: name
1395+
id: 6
1396+
tags:
1397+
- name: name
1398+
id: 1
1399+
- name: name
1400+
id: 1
1401+
status: available
1402+
- photoUrls:
1403+
- photoUrls
1404+
- photoUrls
1405+
name: doggie
1406+
id: 0
1407+
category:
1408+
name: name
1409+
id: 6
1410+
tags:
1411+
- name: name
1412+
id: 1
1413+
- name: name
1414+
id: 1
1415+
status: available
1416+
email: email
1417+
username: username
1418+
nullable: true
1419+
properties:
1420+
id:
1421+
format: int64
1422+
type: integer
1423+
username:
1424+
type: string
1425+
firstName:
1426+
type: string
1427+
lastName:
1428+
type: string
1429+
email:
1430+
type: string
1431+
password:
1432+
type: string
1433+
phone:
1434+
nullable: true
1435+
type: string
1436+
userStatus:
1437+
description: User Status
1438+
format: int32
1439+
type: integer
1440+
deepSliceModel:
1441+
description: An array 1-deep.
1442+
items:
1443+
description: An array 2-deep.
1444+
items:
1445+
description: An array 3-deep.
1446+
items:
1447+
$ref: '#/components/schemas/Tag'
1448+
type: array
1449+
type: array
1450+
nullable: true
1451+
type: array
1452+
deepSliceMap:
1453+
description: An array 1-deep.
1454+
items:
1455+
description: An array 2-deep.
1456+
items:
1457+
$ref: '#/components/schemas/an_Object'
1458+
type: array
1459+
type: array
1460+
required:
1461+
- deepSliceModel
1462+
title: a User
1463+
type: object
1464+
xml:
1465+
name: User
12431466
Tag:
12441467
description: A tag for a pet
12451468
example:

samples/server/petstore/go-api-server/go/api.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)