Skip to content

Commit

Permalink
fix(oas): align generated names with inso naming (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske authored Sep 29, 2023
1 parent e878385 commit bdfeab4
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 223 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-logr/stdr v1.2.2
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.1
github.com/mozillazg/go-slugify v0.2.0
github.com/kong/go-slugify v0.0.0-20230929094618-0386fb4d426f
github.com/onsi/ginkgo/v2 v2.9.2
github.com/onsi/gomega v1.27.6
github.com/spf13/cobra v1.6.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc=
github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/kong/go-slugify v0.0.0-20230929094618-0386fb4d426f h1:ckkce39E0whuMO9DHH8t95JSRiqzLvjBJuLNWVzt8UI=
github.com/kong/go-slugify v0.0.0-20230929094618-0386fb4d426f/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -47,8 +49,6 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mozillazg/go-slugify v0.2.0 h1:SIhqDlnJWZH8OdiTmQgeXR28AOnypmAXPeOTcG7b9lk=
github.com/mozillazg/go-slugify v0.2.0/go.mod h1:z7dPH74PZf2ZPFkyxx+zjPD8CNzRJNa1CGacv0gg8Ns=
github.com/mozillazg/go-unidecode v0.2.0 h1:vFGEzAH9KSwyWmXCOblazEWDh7fOkpmy/Z4ArmamSUc=
github.com/mozillazg/go-unidecode v0.2.0/go.mod h1:zB48+/Z5toiRolOZy9ksLryJ976VIwmDmpQ2quyt1aA=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
62 changes: 48 additions & 14 deletions openapi2kong/oas3_testfiles/01-names-inferred.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"_format_version": "3.0",
"services": [
{
"host": "simple-api-overview.upstream",
"id": "0907c4ab-d9e4-5d21-813b-c57a97eeaad9",
"name": "simple-api-overview",
"host": "Simple_API_overview.upstream",
"id": "e3a95664-95d7-5b10-bc3d-11c9cc6c2b4e",
"name": "Simple_API_overview",
"path": "/some/path",
"plugins": [],
"port": 80,
"protocol": "http",
"routes": [
{
"id": "6fb3ba5b-774a-5b28-aa3c-ab9c6a26b484",
"id": "e8e63255-7b5f-52aa-9c17-305b78ad47d8",
"methods": [
"GET"
],
"name": "simple-api-overview_opsid1",
"name": "Simple_API_overview-opsid1",
"paths": [
"~/$"
],
Expand All @@ -28,11 +28,11 @@
]
},
{
"id": "2ab3e49d-7565-5ac2-aaee-18d060e2e712",
"id": "7b278888-6444-5b79-886d-d229459bd68e",
"methods": [
"POST"
],
"name": "simple-api-overview_~_post",
"name": "Simple_API_overview-post",
"paths": [
"~/$"
],
Expand All @@ -45,11 +45,11 @@
]
},
{
"id": "fc7203a1-3b29-5eac-ac56-a1d361e14d97",
"id": "63e8e8e9-19ce-58fe-90b6-b6f0403deb51",
"methods": [
"GET"
],
"name": "simple-api-overview_opsid2",
"name": "Simple_API_overview-opsid2",
"paths": [
"~/application$"
],
Expand All @@ -62,11 +62,11 @@
]
},
{
"id": "f388efcc-933e-54d5-a549-2b27ef4b935f",
"id": "3027eccd-19a1-5b22-a383-75f88e97321c",
"methods": [
"POST"
],
"name": "simple-api-overview_application_post",
"name": "Simple_API_overview-application-post",
"paths": [
"~/application$"
],
Expand All @@ -77,6 +77,40 @@
"OAS3_import",
"OAS3file_01-names-inferred.yaml"
]
},
{
"id": "07e067e8-bb7f-52c3-98e7-28e0b2ac1302",
"methods": [
"GET"
],
"name": "Simple_API_overview-opsid3",
"paths": [
"~/application/$"
],
"plugins": [],
"regex_priority": 200,
"strip_path": false,
"tags": [
"OAS3_import",
"OAS3file_01-names-inferred.yaml"
]
},
{
"id": "47527799-6eee-56a4-9f70-fd4e0b1a5867",
"methods": [
"POST"
],
"name": "Simple_API_overview-application~-post",
"paths": [
"~/application/$"
],
"plugins": [],
"regex_priority": 200,
"strip_path": false,
"tags": [
"OAS3_import",
"OAS3file_01-names-inferred.yaml"
]
}
],
"tags": [
Expand All @@ -87,8 +121,8 @@
],
"upstreams": [
{
"id": "811c42d6-ef18-5296-a550-7dca2262b4d8",
"name": "simple-api-overview.upstream",
"id": "dca5eafe-311a-520f-87bc-0e695b01eab6",
"name": "Simple_API_overview.upstream",
"tags": [
"OAS3_import",
"OAS3file_01-names-inferred.yaml"
Expand All @@ -111,4 +145,4 @@
]
}
]
}
}
23 changes: 18 additions & 5 deletions openapi2kong/oas3_testfiles/01-names-inferred.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,38 @@ paths:
get:
# operation with an ID
operationId: opsid1
responses:
responses:
'200':
description: 200 ok
post:
# operation without an ID
responses:
responses:
'200':
description: 200 ok
/application:
# non-empty path
# non-empty path, without trailing /
get:
# operation with an ID
operationId: opsid2
responses:
responses:
'200':
description: 200 ok
post:
# operation without an ID
responses:
responses:
'200':
description: 200 ok
/application/:
# non-empty path, same as above, but with trailing /
get:
# operation with an ID
operationId: opsid3
responses:
'200':
description: 200 ok
post:
# operation without an ID
responses:
'200':
description: 200 ok

Expand Down
24 changes: 12 additions & 12 deletions openapi2kong/oas3_testfiles/02-names-set.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"protocol": "http",
"routes": [
{
"id": "48ab920f-d500-53e2-a5e6-d368b9a4b99c",
"id": "8a772dcd-7622-5904-8bda-c4753598afbf",
"methods": [
"GET"
],
"name": "oas-spec-name_opsid1",
"name": "oas-spec-name-opsid1",
"paths": [
"~/app1$"
],
Expand All @@ -28,11 +28,11 @@
]
},
{
"id": "85bf9417-31c3-57d4-89e5-5daf7e45869e",
"id": "5b3c73d7-0816-53a0-a9ab-3914f16fca06",
"methods": [
"POST"
],
"name": "oas-spec-name_path-name_post",
"name": "oas-spec-name-path-name-post",
"paths": [
"~/app1$"
],
Expand All @@ -45,11 +45,11 @@
]
},
{
"id": "c70d6bba-42cb-552d-8c9a-5e6587b80099",
"id": "6c573ebb-44d2-5e36-be1a-6aa5e6fc8868",
"methods": [
"PUT"
],
"name": "oas-spec-name_path-name_my-put-operation",
"name": "oas-spec-name-path-name-my-put-operation",
"paths": [
"~/app1$"
],
Expand All @@ -62,11 +62,11 @@
]
},
{
"id": "56d986d8-4385-5e7c-82b4-895c6c6ea21b",
"id": "38ac897f-100e-5e62-b93c-f4ea6bede9d1",
"methods": [
"GET"
],
"name": "oas-spec-name_opsid2",
"name": "oas-spec-name-opsid2",
"paths": [
"~/app2$"
],
Expand All @@ -79,11 +79,11 @@
]
},
{
"id": "0f165a29-0674-58e8-be6c-19968f287dc0",
"id": "92d898bf-4bee-5dfe-8dae-4602533ca241",
"methods": [
"POST"
],
"name": "oas-spec-name_app2_post",
"name": "oas-spec-name-app2-post",
"paths": [
"~/app2$"
],
Expand All @@ -96,11 +96,11 @@
]
},
{
"id": "88084ff7-bde0-5954-bbcc-d8e563543a5d",
"id": "b9b808a1-29e6-596e-8980-f5218aee5440",
"methods": [
"PUT"
],
"name": "oas-spec-name_app2_my-put-operation",
"name": "oas-spec-name-app2-my-put-operation",
"paths": [
"~/app2$"
],
Expand Down
8 changes: 4 additions & 4 deletions openapi2kong/oas3_testfiles/03-servers-defaults.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"services": [
{
"host": "localhost",
"id": "0907c4ab-d9e4-5d21-813b-c57a97eeaad9",
"name": "simple-api-overview",
"id": "e3a95664-95d7-5b10-bc3d-11c9cc6c2b4e",
"name": "Simple_API_overview",
"path": "/",
"plugins": [],
"port": 443,
"protocol": "https",
"routes": [
{
"id": "eee036de-517e-59cf-a2e0-17b3adfa31b5",
"id": "5879685e-cf66-58a7-b7c5-4e8ef4699dbe",
"methods": [
"GET"
],
"name": "simple-api-overview_opsid",
"name": "Simple_API_overview-OpsId",
"paths": [
"~/$"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"services": [
{
"host": "example.com",
"id": "5434f850-a000-5ad5-8772-1a3cd10811e6",
"name": "server-with-no-trailing-slash",
"id": "455bef07-544f-551a-b9c8-ac47ed3f35ca",
"name": "Server_with_no_trailing_slash",
"path": "/",
"plugins": [],
"port": 443,
"protocol": "https",
"routes": [
{
"id": "d44c95fe-dc1c-596c-8b4a-e18ff50607c4",
"id": "2f02798c-98f3-5d02-a9e4-3ff7285148ad",
"methods": [
"GET"
],
"name": "server-with-no-trailing-slash_myid",
"name": "Server_with_no_trailing_slash-myId",
"paths": [
"~/path$"
],
Expand Down
14 changes: 7 additions & 7 deletions openapi2kong/oas3_testfiles/04-servers-upstream.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"_format_version": "3.0",
"services": [
{
"host": "simple-api-overview.upstream",
"id": "0907c4ab-d9e4-5d21-813b-c57a97eeaad9",
"name": "simple-api-overview",
"host": "Simple_API_overview.upstream",
"id": "e3a95664-95d7-5b10-bc3d-11c9cc6c2b4e",
"name": "Simple_API_overview",
"path": "/",
"plugins": [],
"port": 443,
"protocol": "https",
"routes": [
{
"id": "eee036de-517e-59cf-a2e0-17b3adfa31b5",
"id": "5879685e-cf66-58a7-b7c5-4e8ef4699dbe",
"methods": [
"GET"
],
"name": "simple-api-overview_opsid",
"name": "Simple_API_overview-OpsId",
"paths": [
"~/$"
],
Expand All @@ -36,8 +36,8 @@
],
"upstreams": [
{
"id": "811c42d6-ef18-5296-a550-7dca2262b4d8",
"name": "simple-api-overview.upstream",
"id": "dca5eafe-311a-520f-87bc-0e695b01eab6",
"name": "Simple_API_overview.upstream",
"tags": [
"OAS3_import",
"OAS3file_04-servers-upstream.yaml"
Expand Down
Loading

0 comments on commit bdfeab4

Please sign in to comment.