Skip to content

Commit

Permalink
[openapi2kong] Fix server port parsing (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpoonwj committed Nov 13, 2023
1 parent 361b24e commit b73332c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
38 changes: 38 additions & 0 deletions openapi2kong/oas3_testfiles/04a-servers-upstream.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"_format_version": "3.0",
"services": [
{
"host": "server2.com",
"id": "0907c4ab-d9e4-5d21-813b-c57a97eeaad9",
"name": "simple-api-overview",
"path": "/",
"plugins": [],
"port": 65000,
"protocol": "https",
"routes": [
{
"id": "eee036de-517e-59cf-a2e0-17b3adfa31b5",
"methods": [
"GET"
],
"name": "simple-api-overview_opsid",
"paths": [
"~/$"
],
"plugins": [],
"regex_priority": 200,
"strip_path": false,
"tags": [
"OAS3_import",
"OAS3file_04a-servers-upstream.yaml"
]
}
],
"tags": [
"OAS3_import",
"OAS3file_04a-servers-upstream.yaml"
]
}
],
"upstreams": []
}
17 changes: 17 additions & 0 deletions openapi2kong/oas3_testfiles/04a-servers-upstream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# properly parses ports, see issue #104
# https://github.com/Kong/go-apiops/issues/104
openapi: '3.0.0'
info:
title: Simple API overview
version: v2
servers:
- url: https://server2.com:65000/
paths:
/:
get:
operationId: OpsId
summary: List API versions
responses:
'200':
description: |-
200 response
6 changes: 5 additions & 1 deletion openapi2kong/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ func CreateKongService(
if service["port"] == nil {
if targets[0].Port() != "" {
// port is provided, so parse it
service["port"], _ = strconv.ParseInt(targets[0].Port(), 10, 16)
parsedPort, err := strconv.ParseUint(targets[0].Port(), 10, 16)
if err != nil {
return nil, nil, err
}
service["port"] = parsedPort
} else {
// no port provided, so set it based on scheme, where https/443 is the default
if scheme != httpScheme {
Expand Down

0 comments on commit b73332c

Please sign in to comment.