From 287482da07c07816338e72f29978f0acb9039d9a Mon Sep 17 00:00:00 2001 From: Julius Foitzik Date: Wed, 21 Apr 2021 14:50:06 +0200 Subject: [PATCH 1/6] Upgrade to go 1.16 --- .travis.yml | 2 +- go.mod | 3 +-- go.sum | 34 ---------------------------------- vendor/modules.txt | 2 -- 4 files changed, 2 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 937b73019..50fbd970f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ services: - docker go: -- 1.14.x +- 1.16.x script: - make test diff --git a/go.mod b/go.mod index 428a743fc..49b11df03 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/pace/bricks -go 1.14 +go 1.16 require ( github.com/adjust/rmq/v3 v3.0.0 @@ -45,7 +45,6 @@ require ( github.com/uber/jaeger-client-go v2.14.0+incompatible github.com/uber/jaeger-lib v1.5.0 github.com/zenazn/goji v0.9.0 - go.uber.org/atomic v1.3.2 // indirect golang.org/x/tools v0.0.0-20200304024140-c4206d458c3f golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 ) diff --git a/go.sum b/go.sum index 8d36c090d..925651554 100644 --- a/go.sum +++ b/go.sum @@ -17,7 +17,6 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/dave/jennifer v1.0.2 h1:ixSwWgh8HCIJN9GlVNvdbKHrD/qfh5Mvd4ZCaFAJbr8= github.com/dave/jennifer v1.0.2/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -25,7 +24,6 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/flimzy/diff v0.1.5/go.mod h1:lFJtC7SPsK0EroDmGTSrdtWKAxOk3rO+q+e04LL05Hs= github.com/flimzy/testy v0.1.17-0.20190521133342-95b386c3ece6/go.mod h1:3szguN8NXqgq9bt9Gu8TQVj698PJWmyx/VY1frwwKrM= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/getkin/kin-openapi v0.0.0-20180813063848-e1956e8013e5 h1:gXUMwj0PndSd+Ub1PptoPX0nAwrrS8/SVFTJwOIzjyk= github.com/getkin/kin-openapi v0.0.0-20180813063848-e1956e8013e5/go.mod h1:+0ZtELZf+SlWH8ZdA/IeFb3L/PKOKJx8eGxAlUZ/sOU= @@ -43,7 +41,6 @@ github.com/go-pg/pg v6.14.5+incompatible h1:Tc74MTCCIVd8sAJshYHqutcHhO64/EBHBTyd github.com/go-pg/pg v6.14.5+incompatible/go.mod h1:a2oXow+aFOrvwcKs3eIA0lNFmMilrxK2sOkB5NWe0vA= github.com/go-redis/redis/v7 v7.2.0 h1:CrCexy/jYWZjW0AyVoHlcJUeZN19VWlbepTh1Vq6dJs= github.com/go-redis/redis/v7 v7.2.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -51,7 +48,6 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -80,7 +76,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= @@ -105,11 +100,9 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU= github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= -github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= @@ -119,12 +112,9 @@ github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt github.com/otiai10/copy v1.0.2 h1:DDNipYy6RkIkjMwy+AWzgKiNTyj2RUI9yEMeETEpVyc= github.com/otiai10/copy v1.0.2/go.mod h1:c7RpqBkwMom4bYTSkLSym4VSJz/XtncWRAj/J4PEIMY= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= -github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 h1:o59bHXu8Ejas8Kq6pjoVJQ9/neN66SM8AKh6wI42BBs= github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776/go.mod h1:3HNVkVOU7vZeFXocWuvtcS0XSFLcf2XUSDHkq9t1jU4= github.com/otiai10/mint v1.2.4/go.mod h1:d+b7n/0R3tdyUYYylALXpWQ/kTN+QobSq/4SRGBkR3M= -github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -175,75 +165,53 @@ github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxt gitlab.com/flimzy/testy v0.0.3/go.mod h1:YObF4cq711ubd/3U0ydRQQVz7Cnq/ChgJpVwNr/AJac= gitlab.com/flimzy/testy v0.3.2 h1:4djQFwBJ1ayM681Zx7Y3+OKns/E9zAfGFsLc967jfdk= gitlab.com/flimzy/testy v0.3.2/go.mod h1:YObF4cq711ubd/3U0ydRQQVz7Cnq/ChgJpVwNr/AJac= -go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74 h1:4cFkmztxtMslUX2SctSl+blCyXfpzhGOy9LhKAqSMA4= golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200113040837-eac381796e91 h1:OOkytthzFBKHY5EfEgLUabprb0LtJVkQtNxAQ02+UE4= golang.org/x/tools v0.0.0-20200113040837-eac381796e91/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200304024140-c4206d458c3f h1:haxFuLhmPh0vRpVv5MeXoGyfCB39/Ohsq7A68h65qAg= golang.org/x/tools v0.0.0-20200304024140-c4206d458c3f/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= @@ -254,10 +222,8 @@ gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww= gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/vendor/modules.txt b/vendor/modules.txt index 48ae0acf9..70f97220c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -197,8 +197,6 @@ github.com/uber/jaeger-lib/metrics/prometheus # github.com/zenazn/goji v0.9.0 ## explicit github.com/zenazn/goji/web/mutil -# go.uber.org/atomic v1.3.2 -## explicit # golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 golang.org/x/crypto/argon2 golang.org/x/crypto/blake2b From b09de357c78e50f6c143e07baacafa6af0488b21 Mon Sep 17 00:00:00 2001 From: Julius Foitzik Date: Wed, 21 Apr 2021 15:03:20 +0200 Subject: [PATCH 2/6] Rework jsonapi generator (go code) to ease composition of different routers/partial implementations --- http/jsonapi/generator/generate_handler.go | 94 ++++++++++++++-------- http/jsonapi/generator/generate_test.go | 11 +++ 2 files changed, 73 insertions(+), 32 deletions(-) diff --git a/http/jsonapi/generator/generate_handler.go b/http/jsonapi/generator/generate_handler.go index 5609ef304..ee02a41c3 100644 --- a/http/jsonapi/generator/generate_handler.go +++ b/http/jsonapi/generator/generate_handler.go @@ -14,6 +14,7 @@ import ( "github.com/dave/jennifer/jen" "github.com/getkin/kin-openapi/openapi3" + "github.com/pace/bricks/maintenance/log" ) @@ -308,23 +309,31 @@ func (g *Generator) generateRequestStruct(route *route, schema *openapi3.Swagger } func (g *Generator) buildServiceInterface(routes []*route, schema *openapi3.Swagger) error { - methods := make([]jen.Code, len(routes)) - for _, route := range routes { - if route.operation.Description != "" { - methods = append(methods, jen.Comment(fmt.Sprintf("%s %s\n\n%s", route.serviceFunc, route.operation.Summary, route.operation.Description))) - } else { - methods = append(methods, jen.Comment(fmt.Sprintf("%s %s", route.serviceFunc, route.operation.Summary))) + if err := g.buildSubServiceInterface(route, schema); err != nil { + return err } - methods = append(methods, jen.Id(route.serviceFunc).Params( - jen.Qual("context", "Context"), - jen.Id(route.responseType), - jen.Op("*").Id(route.requestType), - ).Id("error")) } - g.goSource.Line().Commentf("%s interface for all handlers", serviceInterface) - g.goSource.Type().Id(serviceInterface).Interface(methods...) + return nil +} + +func (g *Generator) buildSubServiceInterface(route *route, schema *openapi3.Swagger) error { + methods := make([]jen.Code, 0) + + if route.operation.Description != "" { + methods = append(methods, jen.Comment(fmt.Sprintf("%s %s\n\n%s", route.serviceFunc, route.operation.Summary, route.operation.Description))) + } else { + methods = append(methods, jen.Comment(fmt.Sprintf("%s %s", route.serviceFunc, route.operation.Summary))) + } + methods = append(methods, jen.Id(route.serviceFunc).Params( + jen.Qual("context", "Context"), + jen.Id(route.responseType), + jen.Op("*").Id(route.requestType), + ).Id("error")) + + g.goSource.Line().Commentf("%s interface for %s handler", serviceInterface, route.handler) + g.goSource.Type().Id(generateSubServiceName(route.handler)).Interface(methods...) return nil } @@ -350,7 +359,8 @@ func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error } // create new router - routeStmts[startInd] = jen.Id("router").Op(":=").Qual(pkgGorillaMux, "NewRouter").Call() + rootRouterName := "router" + routeStmts[startInd] = jen.Id(rootRouterName).Op(":=").Qual(pkgGorillaMux, "NewRouter").Call() // Note: we don't restrict host, scheme and port to ease development pathsIdx := make(map[string]struct{}) @@ -382,39 +392,55 @@ func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error // add all route handlers for i := 0; i < len(sortableRoutes); i++ { route := sortableRoutes[i] - var routeCallParams *jen.Statement - // generic route if needsSecurity { routeCallParams = jen.List(jen.Id("service"), jen.Id("authBackend")) } else { routeCallParams = jen.List(jen.Id("service")) } - routeStmt := jen.Id(subrouterID).Dot("Methods").Call(jen.Lit(route.method)). - Dot("Path").Call(jen.Lit(route.url.Path)). - Dot("Handler").Call(jen.Id(route.handler).Call(routeCallParams)) - - // add query parameters for route matching - if len(route.queryValues) > 0 { - for key, value := range route.queryValues { - if len(value) != 1 { - panic("query paths can only handle one query parameter with the same name!") + primaryHandler := jen.Id(route.handler).Call(routeCallParams) + notFoundHandler := jen.Id(rootRouterName).Dot("NotFoundHandler") + ifElse := make([]*jen.Statement, 0) + for _, handler := range []*jen.Statement{primaryHandler, notFoundHandler} { + // build single route + routeStmt := jen.Id(subrouterID).Dot("Methods").Call(jen.Lit(route.method)). + Dot("Path").Call(jen.Lit(route.url.Path)). + Dot("Handler").Call(handler) + + // add query parameters for route matching + if len(route.queryValues) > 0 { + for key, value := range route.queryValues { + if len(value) != 1 { + panic("query paths can only handle one query parameter with the same name!") + } + routeStmt.Dot("Queries").Call(jen.Lit(key), jen.Lit(value[0])) } - routeStmt.Dot("Queries").Call(jen.Lit(key), jen.Lit(value[0])) } + + // add the name to build routes + routeStmt.Dot("Name").Call(jen.Lit(route.serviceFunc)) + + // add to control-flow + ifElse = append(ifElse, routeStmt) } - // add the name to build routes - routeStmt.Dot("Name").Call(jen.Lit(route.serviceFunc)) + if len(ifElse) < 1 { + panic("if-else slice should contain two elements, one with the service interface being called and one passing the NotFoundHandler") + } + + implGuard := jen.If( + jen.List(jen.Id("service"), jen.Id("ok")).Op(":=").Id("service").Assert(jen.Id(generateSubServiceName(route.handler))), + jen.Id("ok")).Block(ifElse[0]).Else().Block(ifElse[1]) + + routeStmts = append(routeStmts, implGuard) - routeStmts = append(routeStmts, routeStmt) } } // return routeStmts = append(routeStmts, jen.Return(jen.Id("router"))) g.addGoDoc("Router", "implements: "+schema.Info.Title+"\n\n"+schema.Info.Description) - serviceInterfaceVariable := jen.Id("service").Id(serviceInterface) + serviceInterfaceVariable := jen.Id("service").Interface() if hasSecuritySchema(schema) { g.goSource.Func().Id("Router").Params( serviceInterfaceVariable, jen.Id("authBackend").Id(authBackendInterface)).Op("*").Qual(pkgGorillaMux, "Router").Block(routeStmts...) @@ -477,9 +503,9 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern method, pattern)) var params *jen.Statement if needsSecurity { - params = jen.List(jen.Id("service").Id(serviceInterface), jen.Id("authBackend").Id(authBackendInterface)) + params = jen.List(jen.Id("service").Id(generateSubServiceName(route.handler)), jen.Id("authBackend").Id(authBackendInterface)) } else { - params = jen.List(jen.Id("service").Id(serviceInterface)) + params = jen.List(jen.Id("service").Id(generateSubServiceName(route.handler))) } g.goSource.Func().Id(handler).Params(params).Qual("net/http", "Handler").Block( jen.Return().Qual("net/http", "HandlerFunc").Call( @@ -753,3 +779,7 @@ func generateMethodName(description string) string { func generateParamName(param *openapi3.ParameterRef) string { return "Param" + generateMethodName(param.Value.Name) } + +func generateSubServiceName(handler string) string { + return fmt.Sprintf("%s%s", handler, serviceInterface) +} diff --git a/http/jsonapi/generator/generate_test.go b/http/jsonapi/generator/generate_test.go index 8d889b120..cc1c6af1a 100644 --- a/http/jsonapi/generator/generate_test.go +++ b/http/jsonapi/generator/generate_test.go @@ -4,7 +4,9 @@ package generator import ( + "fmt" "io/ioutil" + "os" "path/filepath" "testing" @@ -34,6 +36,15 @@ func TestGenerator(t *testing.T) { if err != nil { t.Fatal(err) } + + f, err := os.Create(fmt.Sprintf("testout/test.%s.out.go", testCase.pkg)) + if err != nil { + t.Fatal(err) + } + _, err = f.WriteString(result) + if err != nil { + t.Fatal(err) + } if string(expected[:]) != result { diff := difflib.UnifiedDiff{ A: difflib.SplitLines(string(expected[:])), From 7b8a270d1ea0d076eab50f586e9d7cecf9fd1dc8 Mon Sep 17 00:00:00 2001 From: Julius Foitzik Date: Wed, 21 Apr 2021 16:19:35 +0200 Subject: [PATCH 3/6] Adjust generator test output --- http/jsonapi/generator/generate_test.go | 17 +- .../internal/articles/open-api_test.go | 38 +- .../internal/fueling/open-api_test.go | 74 ++- .../generator/internal/pay/open-api_test.go | 98 +++- .../generator/internal/poi/open-api_test.go | 434 +++++++++++++++--- .../internal/securitytest/open-api_test.go | 14 +- 6 files changed, 544 insertions(+), 131 deletions(-) diff --git a/http/jsonapi/generator/generate_test.go b/http/jsonapi/generator/generate_test.go index cc1c6af1a..35773f5fe 100644 --- a/http/jsonapi/generator/generate_test.go +++ b/http/jsonapi/generator/generate_test.go @@ -36,14 +36,15 @@ func TestGenerator(t *testing.T) { if err != nil { t.Fatal(err) } - - f, err := os.Create(fmt.Sprintf("testout/test.%s.out.go", testCase.pkg)) - if err != nil { - t.Fatal(err) - } - _, err = f.WriteString(result) - if err != nil { - t.Fatal(err) + if os.Getenv("PACE_TEST_GENERATOR_WRITE") != "" { + f, err := os.Create(fmt.Sprintf("testout/test.%s.out.go", testCase.pkg)) + if err != nil { + t.Fatal(err) + } + _, err = f.WriteString(result) + if err != nil { + t.Fatal(err) + } } if string(expected[:]) != result { diff := difflib.UnifiedDiff{ diff --git a/http/jsonapi/generator/internal/articles/open-api_test.go b/http/jsonapi/generator/internal/articles/open-api_test.go index 6b5575b9e..d7f84b22e 100644 --- a/http/jsonapi/generator/internal/articles/open-api_test.go +++ b/http/jsonapi/generator/internal/articles/open-api_test.go @@ -53,7 +53,7 @@ type MapTypeString map[string]string UpdateArticleCommentsHandler handles request/response marshaling and validation for Patch /api/articles/{uuid}/relationships/comments */ -func UpdateArticleCommentsHandler(service Service) http.Handler { +func UpdateArticleCommentsHandler(service UpdateArticleCommentsHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("UpdateArticleCommentsHandler", w, r) @@ -115,7 +115,7 @@ func UpdateArticleCommentsHandler(service Service) http.Handler { UpdateArticleInlineTypeHandler handles request/response marshaling and validation for Patch /api/articles/{uuid}/relationships/inline */ -func UpdateArticleInlineTypeHandler(service Service) http.Handler { +func UpdateArticleInlineTypeHandler(service UpdateArticleInlineTypeHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("UpdateArticleInlineTypeHandler", w, r) @@ -172,7 +172,7 @@ func UpdateArticleInlineTypeHandler(service Service) http.Handler { UpdateArticleInlineRefHandler handles request/response marshaling and validation for Patch /api/articles/{uuid}/relationships/inlineref */ -func UpdateArticleInlineRefHandler(service Service) http.Handler { +func UpdateArticleInlineRefHandler(service UpdateArticleInlineRefHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("UpdateArticleInlineRefHandler", w, r) @@ -338,12 +338,20 @@ type UpdateArticleInlineRefRequest struct { ParamUuid string `valid:"required"` } -// Service interface for all handlers -type Service interface { +// Service interface for UpdateArticleCommentsHandler handler +type UpdateArticleCommentsHandlerService interface { // UpdateArticleComments Updates the Article with Comment relationships UpdateArticleComments(context.Context, UpdateArticleCommentsResponseWriter, *UpdateArticleCommentsRequest) error +} + +// Service interface for UpdateArticleInlineTypeHandler handler +type UpdateArticleInlineTypeHandlerService interface { // UpdateArticleInlineType UpdateArticleInlineType(context.Context, UpdateArticleInlineTypeResponseWriter, *UpdateArticleInlineTypeRequest) error +} + +// Service interface for UpdateArticleInlineRefHandler handler +type UpdateArticleInlineRefHandlerService interface { // UpdateArticleInlineRef UpdateArticleInlineRef(context.Context, UpdateArticleInlineRefResponseWriter, *UpdateArticleInlineRefRequest) error } @@ -353,12 +361,24 @@ Router implements: Articles Test Service Articles Test Service */ -func Router(service Service) *mux.Router { +func Router(service interface{}) *mux.Router { router := mux.NewRouter() // Subrouter s1 - Path: s1 := router.PathPrefix("").Subrouter() - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(UpdateArticleCommentsHandler(service)).Name("UpdateArticleComments") - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(UpdateArticleInlineTypeHandler(service)).Name("UpdateArticleInlineType") - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(UpdateArticleInlineRefHandler(service)).Name("UpdateArticleInlineRef") + if service, ok := service.(UpdateArticleCommentsHandlerService); ok { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(UpdateArticleCommentsHandler(service)).Name("UpdateArticleComments") + } else { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(router.NotFoundHandler).Name("UpdateArticleComments") + } + if service, ok := service.(UpdateArticleInlineTypeHandlerService); ok { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(UpdateArticleInlineTypeHandler(service)).Name("UpdateArticleInlineType") + } else { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(router.NotFoundHandler).Name("UpdateArticleInlineType") + } + if service, ok := service.(UpdateArticleInlineRefHandlerService); ok { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(UpdateArticleInlineRefHandler(service)).Name("UpdateArticleInlineRef") + } else { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(router.NotFoundHandler).Name("UpdateArticleInlineRef") + } return router } diff --git a/http/jsonapi/generator/internal/fueling/open-api_test.go b/http/jsonapi/generator/internal/fueling/open-api_test.go index d99298095..e0aaab78b 100644 --- a/http/jsonapi/generator/internal/fueling/open-api_test.go +++ b/http/jsonapi/generator/internal/fueling/open-api_test.go @@ -126,7 +126,7 @@ type Currency string ProcessPaymentHandler handles request/response marshaling and validation for Post /gas-station/{gasStationId}/payment */ -func ProcessPaymentHandler(service Service) http.Handler { +func ProcessPaymentHandler(service ProcessPaymentHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("ProcessPaymentHandler", w, r) @@ -183,7 +183,7 @@ func ProcessPaymentHandler(service Service) http.Handler { ApproachingAtTheForecourtHandler handles request/response marshaling and validation for Post /gas-stations/{gasStationId}/approaching */ -func ApproachingAtTheForecourtHandler(service Service) http.Handler { +func ApproachingAtTheForecourtHandler(service ApproachingAtTheForecourtHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("ApproachingAtTheForecourtHandler", w, r) @@ -244,7 +244,7 @@ func ApproachingAtTheForecourtHandler(service Service) http.Handler { GetPumpHandler handles request/response marshaling and validation for Get /gas-stations/{gasStationId}/pumps/{pumpId} */ -func GetPumpHandler(service Service) http.Handler { +func GetPumpHandler(service GetPumpHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPumpHandler", w, r) @@ -303,7 +303,7 @@ func GetPumpHandler(service Service) http.Handler { WaitOnPumpStatusChangeHandler handles request/response marshaling and validation for Get /gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change */ -func WaitOnPumpStatusChangeHandler(service Service) http.Handler { +func WaitOnPumpStatusChangeHandler(service WaitOnPumpStatusChangeHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("WaitOnPumpStatusChangeHandler", w, r) @@ -551,14 +551,18 @@ type WaitOnPumpStatusChangeRequest struct { ParamTimeout int64 `valid:"optional"` } -// Service interface for all handlers -type Service interface { +// Service interface for ProcessPaymentHandler handler +type ProcessPaymentHandlerService interface { /* ProcessPayment Process payment Process payment and notify user if transaction is finished successfully. You can optionally provide `priceIncludingVAT`and `currency` in the request body to check if the price the user has seen is still correct. */ ProcessPayment(context.Context, ProcessPaymentResponseWriter, *ProcessPaymentRequest) error +} + +// Service interface for ApproachingAtTheForecourtHandler handler +type ApproachingAtTheForecourtHandlerService interface { /* ApproachingAtTheForecourt Gather information when approaching at the forecourt @@ -570,12 +574,20 @@ type Service interface { * Create payment tokens for all paymentMethods of the user and pre-authorise the calculated maximum amount of money (background task) */ ApproachingAtTheForecourt(context.Context, ApproachingAtTheForecourtResponseWriter, *ApproachingAtTheForecourtRequest) error +} + +// Service interface for GetPumpHandler handler +type GetPumpHandlerService interface { /* GetPump Return current pump information Returns the current pump status (free, inUse, readyToPay, outOfOrder) and identifier. If the status is readyToPay, the result also contains fuelType, productName, fuelAmount, VAT (amount & rate), priceWithoutVAT, priceIncludingVAT, currency. */ GetPump(context.Context, GetPumpResponseWriter, *GetPumpRequest) error +} + +// Service interface for WaitOnPumpStatusChangeHandler handler +type WaitOnPumpStatusChangeHandlerService interface { /* WaitOnPumpStatusChange Wait for a status change on a given pump @@ -589,19 +601,51 @@ Router implements: PACE Fueling API Fueling API */ -func Router(service Service) *mux.Router { +func Router(service interface{}) *mux.Router { router := mux.NewRouter() // Subrouter s1 - Path: /fueling/beta/ s1 := router.PathPrefix("/fueling/beta/").Subrouter() - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") - s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") - s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") + } else { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(router.NotFoundHandler).Name("WaitOnPumpStatusChange") + } + if service, ok := service.(GetPumpHandlerService); ok { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") + } else { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(router.NotFoundHandler).Name("GetPump") + } + if service, ok := service.(ProcessPaymentHandlerService); ok { + s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") + } else { + s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(router.NotFoundHandler).Name("ProcessPayment") + } + if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { + s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + } else { + s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(router.NotFoundHandler).Name("ApproachingAtTheForecourt") + } // Subrouter s2 - Path: /fueling/v1/ s2 := router.PathPrefix("/fueling/v1/").Subrouter() - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") - s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") - s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") + } else { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(router.NotFoundHandler).Name("WaitOnPumpStatusChange") + } + if service, ok := service.(GetPumpHandlerService); ok { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") + } else { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(router.NotFoundHandler).Name("GetPump") + } + if service, ok := service.(ProcessPaymentHandlerService); ok { + s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") + } else { + s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(router.NotFoundHandler).Name("ProcessPayment") + } + if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { + s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + } else { + s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(router.NotFoundHandler).Name("ApproachingAtTheForecourt") + } return router } diff --git a/http/jsonapi/generator/internal/pay/open-api_test.go b/http/jsonapi/generator/internal/pay/open-api_test.go index 3782404dc..bb0c52515 100644 --- a/http/jsonapi/generator/internal/pay/open-api_test.go +++ b/http/jsonapi/generator/internal/pay/open-api_test.go @@ -156,7 +156,7 @@ var cfgProfileKey = &apikey.Config{ GetPaymentMethodsHandler handles request/response marshaling and validation for Get /beta/payment-methods */ -func GetPaymentMethodsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPaymentMethodsHandler(service GetPaymentMethodsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPaymentMethodsHandler", w, r) @@ -198,7 +198,7 @@ func GetPaymentMethodsHandler(service Service, authBackend AuthorizationBackend) CreatePaymentMethodSEPAHandler handles request/response marshaling and validation for Post /beta/payment-methods/sepa-direct-debit */ -func CreatePaymentMethodSEPAHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func CreatePaymentMethodSEPAHandler(service CreatePaymentMethodSEPAHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("CreatePaymentMethodSEPAHandler", w, r) @@ -272,7 +272,7 @@ func CreatePaymentMethodSEPAHandler(service Service, authBackend AuthorizationBa DeletePaymentMethodHandler handles request/response marshaling and validation for Delete /beta/payment-methods/{paymentMethodId} */ -func DeletePaymentMethodHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeletePaymentMethodHandler(service DeletePaymentMethodHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeletePaymentMethodHandler", w, r) @@ -346,7 +346,7 @@ func DeletePaymentMethodHandler(service Service, authBackend AuthorizationBacken AuthorizePaymentMethodHandler handles request/response marshaling and validation for Post /beta/payment-methods/{paymentMethodId}/authorize */ -func AuthorizePaymentMethodHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func AuthorizePaymentMethodHandler(service AuthorizePaymentMethodHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("AuthorizePaymentMethodHandler", w, r) @@ -403,7 +403,7 @@ func AuthorizePaymentMethodHandler(service Service, authBackend AuthorizationBac DeletePaymentTokenHandler handles request/response marshaling and validation for Delete /beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId} */ -func DeletePaymentTokenHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeletePaymentTokenHandler(service DeletePaymentTokenHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeletePaymentTokenHandler", w, r) @@ -462,7 +462,7 @@ func DeletePaymentTokenHandler(service Service, authBackend AuthorizationBackend GetPaymentMethodsIncludingCreditCheckHandler handles request/response marshaling and validation for Get /beta/payment-methods?include=creditCheck */ -func GetPaymentMethodsIncludingCreditCheckHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPaymentMethodsIncludingCreditCheckHandler(service GetPaymentMethodsIncludingCreditCheckHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPaymentMethodsIncludingCreditCheckHandler", w, r) @@ -514,7 +514,7 @@ func GetPaymentMethodsIncludingCreditCheckHandler(service Service, authBackend A GetPaymentMethodsIncludingPaymentTokenHandler handles request/response marshaling and validation for Get /beta/payment-methods?include=paymentToken */ -func GetPaymentMethodsIncludingPaymentTokenHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPaymentMethodsIncludingPaymentTokenHandler(service GetPaymentMethodsIncludingPaymentTokenHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPaymentMethodsIncludingPaymentTokenHandler", w, r) @@ -566,7 +566,7 @@ func GetPaymentMethodsIncludingPaymentTokenHandler(service Service, authBackend ProcessPaymentHandler handles request/response marshaling and validation for Post /beta/transaction/{pathDecimal} */ -func ProcessPaymentHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func ProcessPaymentHandler(service ProcessPaymentHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("ProcessPaymentHandler", w, r) @@ -928,10 +928,14 @@ type ProcessPaymentRequest struct { ParamQueryDecimal decimal.Decimal `valid:"required,matches(^(\d*\.)?\d+$)"` } -// Service interface for all handlers -type Service interface { +// Service interface for GetPaymentMethodsHandler handler +type GetPaymentMethodsHandlerService interface { // GetPaymentMethods Get all payment methods for user GetPaymentMethods(context.Context, GetPaymentMethodsResponseWriter, *GetPaymentMethodsRequest) error +} + +// Service interface for CreatePaymentMethodSEPAHandler handler +type CreatePaymentMethodSEPAHandlerService interface { /* CreatePaymentMethodSEPA Register SEPA direct debit as a payment method @@ -939,16 +943,32 @@ type Service interface { The payment method ID is optional when posting data. */ CreatePaymentMethodSEPA(context.Context, CreatePaymentMethodSEPAResponseWriter, *CreatePaymentMethodSEPARequest) error +} + +// Service interface for DeletePaymentMethodHandler handler +type DeletePaymentMethodHandlerService interface { // DeletePaymentMethod Delete a payment method DeletePaymentMethod(context.Context, DeletePaymentMethodResponseWriter, *DeletePaymentMethodRequest) error +} + +// Service interface for AuthorizePaymentMethodHandler handler +type AuthorizePaymentMethodHandlerService interface { /* AuthorizePaymentMethod Authorize a payment using the payment method whose ID is paymentMethodId When successful, returns a paymentToken value. */ AuthorizePaymentMethod(context.Context, AuthorizePaymentMethodResponseWriter, *AuthorizePaymentMethodRequest) error +} + +// Service interface for DeletePaymentTokenHandler handler +type DeletePaymentTokenHandlerService interface { // DeletePaymentToken Delete the paymentToken record. DeletePaymentToken(context.Context, DeletePaymentTokenResponseWriter, *DeletePaymentTokenRequest) error +} + +// Service interface for GetPaymentMethodsIncludingCreditCheckHandler handler +type GetPaymentMethodsIncludingCreditCheckHandlerService interface { /* GetPaymentMethodsIncludingCreditCheck Get all ready-to-use payment methods for user @@ -958,6 +978,10 @@ type Service interface { If the list is empty, you can ask the user to add a payment method to use PACE fueling. */ GetPaymentMethodsIncludingCreditCheck(context.Context, GetPaymentMethodsIncludingCreditCheckResponseWriter, *GetPaymentMethodsIncludingCreditCheckRequest) error +} + +// Service interface for GetPaymentMethodsIncludingPaymentTokenHandler handler +type GetPaymentMethodsIncludingPaymentTokenHandlerService interface { /* GetPaymentMethodsIncludingPaymentToken Get all payment methods with pre-authorized amounts @@ -966,6 +990,10 @@ type Service interface { Empty list if there are no pre-authorized amounts. */ GetPaymentMethodsIncludingPaymentToken(context.Context, GetPaymentMethodsIncludingPaymentTokenResponseWriter, *GetPaymentMethodsIncludingPaymentTokenRequest) error +} + +// Service interface for ProcessPaymentHandler handler +type ProcessPaymentHandlerService interface { /* ProcessPayment Process payment @@ -980,20 +1008,52 @@ Router implements: PACE Payment API Welcome to the PACE Payment API documentation. This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. */ -func Router(service Service, authBackend AuthorizationBackend) *mux.Router { +func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { router := mux.NewRouter() authBackend.InitOAuth2(cfgOAuth2) authBackend.InitOpenID(cfgOpenID) authBackend.InitProfileKey(cfgProfileKey) // Subrouter s1 - Path: /pay s1 := router.PathPrefix("/pay").Subrouter() - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(DeletePaymentTokenHandler(service, authBackend)).Name("DeletePaymentToken") - s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(AuthorizePaymentMethodHandler(service, authBackend)).Name("AuthorizePaymentMethod") - s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(CreatePaymentMethodSEPAHandler(service, authBackend)).Name("CreatePaymentMethodSEPA") - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(DeletePaymentMethodHandler(service, authBackend)).Name("DeletePaymentMethod") - s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(ProcessPaymentHandler(service, authBackend)).Name("ProcessPayment") - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingCreditCheckHandler(service, authBackend)).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingPaymentTokenHandler(service, authBackend)).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsHandler(service, authBackend)).Name("GetPaymentMethods") + if service, ok := service.(DeletePaymentTokenHandlerService); ok { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(DeletePaymentTokenHandler(service, authBackend)).Name("DeletePaymentToken") + } else { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(router.NotFoundHandler).Name("DeletePaymentToken") + } + if service, ok := service.(AuthorizePaymentMethodHandlerService); ok { + s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(AuthorizePaymentMethodHandler(service, authBackend)).Name("AuthorizePaymentMethod") + } else { + s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(router.NotFoundHandler).Name("AuthorizePaymentMethod") + } + if service, ok := service.(CreatePaymentMethodSEPAHandlerService); ok { + s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(CreatePaymentMethodSEPAHandler(service, authBackend)).Name("CreatePaymentMethodSEPA") + } else { + s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(router.NotFoundHandler).Name("CreatePaymentMethodSEPA") + } + if service, ok := service.(DeletePaymentMethodHandlerService); ok { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(DeletePaymentMethodHandler(service, authBackend)).Name("DeletePaymentMethod") + } else { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(router.NotFoundHandler).Name("DeletePaymentMethod") + } + if service, ok := service.(ProcessPaymentHandlerService); ok { + s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(ProcessPaymentHandler(service, authBackend)).Name("ProcessPayment") + } else { + s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(router.NotFoundHandler).Name("ProcessPayment") + } + if service, ok := service.(GetPaymentMethodsIncludingCreditCheckHandlerService); ok { + s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingCreditCheckHandler(service, authBackend)).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") + } else { + s1.Methods("GET").Path("/beta/payment-methods").Handler(router.NotFoundHandler).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") + } + if service, ok := service.(GetPaymentMethodsIncludingPaymentTokenHandlerService); ok { + s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingPaymentTokenHandler(service, authBackend)).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") + } else { + s1.Methods("GET").Path("/beta/payment-methods").Handler(router.NotFoundHandler).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") + } + if service, ok := service.(GetPaymentMethodsHandlerService); ok { + s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsHandler(service, authBackend)).Name("GetPaymentMethods") + } else { + s1.Methods("GET").Path("/beta/payment-methods").Handler(router.NotFoundHandler).Name("GetPaymentMethods") + } return router } diff --git a/http/jsonapi/generator/internal/poi/open-api_test.go b/http/jsonapi/generator/internal/poi/open-api_test.go index d8de79549..98301e82d 100644 --- a/http/jsonapi/generator/internal/poi/open-api_test.go +++ b/http/jsonapi/generator/internal/poi/open-api_test.go @@ -424,7 +424,7 @@ var cfgOIDC = &oidc.Config{ DeduplicatePoiHandler handles request/response marshaling and validation for Patch /beta/admin/poi/dedupe */ -func DeduplicatePoiHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeduplicatePoiHandler(service DeduplicatePoiHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeduplicatePoiHandler", w, r) @@ -478,7 +478,7 @@ func DeduplicatePoiHandler(service Service, authBackend AuthorizationBackend) ht MovePoiAtPositionHandler handles request/response marshaling and validation for Patch /beta/admin/poi/move */ -func MovePoiAtPositionHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func MovePoiAtPositionHandler(service MovePoiAtPositionHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("MovePoiAtPositionHandler", w, r) @@ -532,7 +532,7 @@ func MovePoiAtPositionHandler(service Service, authBackend AuthorizationBackend) GetAppsHandler handles request/response marshaling and validation for Get /beta/apps */ -func GetAppsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetAppsHandler(service GetAppsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetAppsHandler", w, r) @@ -606,7 +606,7 @@ func GetAppsHandler(service Service, authBackend AuthorizationBackend) http.Hand CreateAppHandler handles request/response marshaling and validation for Post /beta/apps */ -func CreateAppHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func CreateAppHandler(service CreateAppHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("CreateAppHandler", w, r) @@ -660,7 +660,7 @@ func CreateAppHandler(service Service, authBackend AuthorizationBackend) http.Ha CheckForPaceAppHandler handles request/response marshaling and validation for Get /beta/apps/query */ -func CheckForPaceAppHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func CheckForPaceAppHandler(service CheckForPaceAppHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("CheckForPaceAppHandler", w, r) @@ -726,7 +726,7 @@ func CheckForPaceAppHandler(service Service, authBackend AuthorizationBackend) h DeleteAppHandler handles request/response marshaling and validation for Delete /beta/apps/{appID} */ -func DeleteAppHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeleteAppHandler(service DeleteAppHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeleteAppHandler", w, r) @@ -786,7 +786,7 @@ func DeleteAppHandler(service Service, authBackend AuthorizationBackend) http.Ha GetAppHandler handles request/response marshaling and validation for Get /beta/apps/{appID} */ -func GetAppHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetAppHandler(service GetAppHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetAppHandler", w, r) @@ -846,7 +846,7 @@ func GetAppHandler(service Service, authBackend AuthorizationBackend) http.Handl UpdateAppHandler handles request/response marshaling and validation for Put /beta/apps/{appID} */ -func UpdateAppHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func UpdateAppHandler(service UpdateAppHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("UpdateAppHandler", w, r) @@ -909,7 +909,7 @@ func UpdateAppHandler(service Service, authBackend AuthorizationBackend) http.Ha GetAppPOIsRelationshipsHandler handles request/response marshaling and validation for Get /beta/apps/{appID}/relationships/pois */ -func GetAppPOIsRelationshipsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetAppPOIsRelationshipsHandler(service GetAppPOIsRelationshipsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetAppPOIsRelationshipsHandler", w, r) @@ -969,7 +969,7 @@ func GetAppPOIsRelationshipsHandler(service Service, authBackend AuthorizationBa UpdateAppPOIsRelationshipsHandler handles request/response marshaling and validation for Patch /beta/apps/{appID}/relationships/pois */ -func UpdateAppPOIsRelationshipsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func UpdateAppPOIsRelationshipsHandler(service UpdateAppPOIsRelationshipsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("UpdateAppPOIsRelationshipsHandler", w, r) @@ -1032,7 +1032,7 @@ func UpdateAppPOIsRelationshipsHandler(service Service, authBackend Authorizatio GetDuplicatesKMLHandler handles request/response marshaling and validation for Get /beta/datadumps/duplicatemap/{countryCode} */ -func GetDuplicatesKMLHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetDuplicatesKMLHandler(service GetDuplicatesKMLHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetDuplicatesKMLHandler", w, r) @@ -1092,7 +1092,7 @@ func GetDuplicatesKMLHandler(service Service, authBackend AuthorizationBackend) GetPoisDumpHandler handles request/response marshaling and validation for Get /beta/datadumps/pois */ -func GetPoisDumpHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPoisDumpHandler(service GetPoisDumpHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPoisDumpHandler", w, r) @@ -1150,7 +1150,7 @@ func GetPoisDumpHandler(service Service, authBackend AuthorizationBackend) http. DeleteGasStationReferenceStatusHandler handles request/response marshaling and validation for Delete /beta/delivery/gas-stations/{gasStationId}/reference-status/{reference} */ -func DeleteGasStationReferenceStatusHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeleteGasStationReferenceStatusHandler(service DeleteGasStationReferenceStatusHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeleteGasStationReferenceStatusHandler", w, r) @@ -1215,7 +1215,7 @@ func DeleteGasStationReferenceStatusHandler(service Service, authBackend Authori PutGasStationReferenceStatusHandler handles request/response marshaling and validation for Put /beta/delivery/gas-stations/{gasStationId}/reference-status/{reference} */ -func PutGasStationReferenceStatusHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func PutGasStationReferenceStatusHandler(service PutGasStationReferenceStatusHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("PutGasStationReferenceStatusHandler", w, r) @@ -1283,7 +1283,7 @@ func PutGasStationReferenceStatusHandler(service Service, authBackend Authorizat GetEventsHandler handles request/response marshaling and validation for Get /beta/events */ -func GetEventsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetEventsHandler(service GetEventsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetEventsHandler", w, r) @@ -1353,7 +1353,7 @@ func GetEventsHandler(service Service, authBackend AuthorizationBackend) http.Ha GetGasStationsHandler handles request/response marshaling and validation for Get /beta/gas-stations */ -func GetGasStationsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetGasStationsHandler(service GetGasStationsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetGasStationsHandler", w, r) @@ -1447,7 +1447,7 @@ func GetGasStationsHandler(service Service, authBackend AuthorizationBackend) ht GetGasStationHandler handles request/response marshaling and validation for Get /beta/gas-stations/{id} */ -func GetGasStationHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetGasStationHandler(service GetGasStationHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetGasStationHandler", w, r) @@ -1511,7 +1511,7 @@ func GetGasStationHandler(service Service, authBackend AuthorizationBackend) htt GetPriceHistoryHandler handles request/response marshaling and validation for Get /beta/gas-stations/{id}/fuel-price-histories/{fuel_type} */ -func GetPriceHistoryHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPriceHistoryHandler(service GetPriceHistoryHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPriceHistoryHandler", w, r) @@ -1588,7 +1588,7 @@ func GetPriceHistoryHandler(service Service, authBackend AuthorizationBackend) h GetGasStationFuelTypeNameMappingHandler handles request/response marshaling and validation for Get /beta/gas-stations/{id}/fueltype */ -func GetGasStationFuelTypeNameMappingHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetGasStationFuelTypeNameMappingHandler(service GetGasStationFuelTypeNameMappingHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetGasStationFuelTypeNameMappingHandler", w, r) @@ -1652,7 +1652,7 @@ func GetGasStationFuelTypeNameMappingHandler(service Service, authBackend Author GetMetadataFiltersHandler handles request/response marshaling and validation for Get /beta/meta */ -func GetMetadataFiltersHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetMetadataFiltersHandler(service GetMetadataFiltersHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetMetadataFiltersHandler", w, r) @@ -1714,7 +1714,7 @@ func GetMetadataFiltersHandler(service Service, authBackend AuthorizationBackend GetPoisHandler handles request/response marshaling and validation for Get /beta/pois */ -func GetPoisHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPoisHandler(service GetPoisHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPoisHandler", w, r) @@ -1784,7 +1784,7 @@ func GetPoisHandler(service Service, authBackend AuthorizationBackend) http.Hand GetPoiHandler handles request/response marshaling and validation for Get /beta/pois/{poiId} */ -func GetPoiHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPoiHandler(service GetPoiHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPoiHandler", w, r) @@ -1844,7 +1844,7 @@ func GetPoiHandler(service Service, authBackend AuthorizationBackend) http.Handl ChangePoiHandler handles request/response marshaling and validation for Patch /beta/pois/{poiId} */ -func ChangePoiHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func ChangePoiHandler(service ChangePoiHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("ChangePoiHandler", w, r) @@ -1907,7 +1907,7 @@ func ChangePoiHandler(service Service, authBackend AuthorizationBackend) http.Ha GetPoliciesHandler handles request/response marshaling and validation for Get /beta/policies */ -func GetPoliciesHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPoliciesHandler(service GetPoliciesHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPoliciesHandler", w, r) @@ -1981,7 +1981,7 @@ func GetPoliciesHandler(service Service, authBackend AuthorizationBackend) http. CreatePolicyHandler handles request/response marshaling and validation for Post /beta/policies */ -func CreatePolicyHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func CreatePolicyHandler(service CreatePolicyHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("CreatePolicyHandler", w, r) @@ -2035,7 +2035,7 @@ func CreatePolicyHandler(service Service, authBackend AuthorizationBackend) http GetPolicyHandler handles request/response marshaling and validation for Get /beta/policies/{policyId} */ -func GetPolicyHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetPolicyHandler(service GetPolicyHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetPolicyHandler", w, r) @@ -2095,7 +2095,7 @@ func GetPolicyHandler(service Service, authBackend AuthorizationBackend) http.Ha GetRegionalPricesHandler handles request/response marshaling and validation for Get /beta/prices/regional */ -func GetRegionalPricesHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetRegionalPricesHandler(service GetRegionalPricesHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetRegionalPricesHandler", w, r) @@ -2151,7 +2151,7 @@ func GetRegionalPricesHandler(service Service, authBackend AuthorizationBackend) GetSourcesHandler handles request/response marshaling and validation for Get /beta/sources */ -func GetSourcesHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetSourcesHandler(service GetSourcesHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetSourcesHandler", w, r) @@ -2221,7 +2221,7 @@ func GetSourcesHandler(service Service, authBackend AuthorizationBackend) http.H CreateSourceHandler handles request/response marshaling and validation for Post /beta/sources */ -func CreateSourceHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func CreateSourceHandler(service CreateSourceHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("CreateSourceHandler", w, r) @@ -2275,7 +2275,7 @@ func CreateSourceHandler(service Service, authBackend AuthorizationBackend) http DeleteSourceHandler handles request/response marshaling and validation for Delete /beta/sources/{sourceId} */ -func DeleteSourceHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeleteSourceHandler(service DeleteSourceHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeleteSourceHandler", w, r) @@ -2335,7 +2335,7 @@ func DeleteSourceHandler(service Service, authBackend AuthorizationBackend) http GetSourceHandler handles request/response marshaling and validation for Get /beta/sources/{sourceId} */ -func GetSourceHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetSourceHandler(service GetSourceHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetSourceHandler", w, r) @@ -2395,7 +2395,7 @@ func GetSourceHandler(service Service, authBackend AuthorizationBackend) http.Ha UpdateSourceHandler handles request/response marshaling and validation for Put /beta/sources/{sourceId} */ -func UpdateSourceHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func UpdateSourceHandler(service UpdateSourceHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("UpdateSourceHandler", w, r) @@ -2458,7 +2458,7 @@ func UpdateSourceHandler(service Service, authBackend AuthorizationBackend) http GetSubscriptionsHandler handles request/response marshaling and validation for Get /beta/subscriptions */ -func GetSubscriptionsHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetSubscriptionsHandler(service GetSubscriptionsHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetSubscriptionsHandler", w, r) @@ -2512,7 +2512,7 @@ func GetSubscriptionsHandler(service Service, authBackend AuthorizationBackend) DeleteSubscriptionHandler handles request/response marshaling and validation for Delete /beta/subscriptions/{id} */ -func DeleteSubscriptionHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func DeleteSubscriptionHandler(service DeleteSubscriptionHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("DeleteSubscriptionHandler", w, r) @@ -2560,7 +2560,7 @@ func DeleteSubscriptionHandler(service Service, authBackend AuthorizationBackend StoreSubscriptionHandler handles request/response marshaling and validation for Put /beta/subscriptions/{id} */ -func StoreSubscriptionHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func StoreSubscriptionHandler(service StoreSubscriptionHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("StoreSubscriptionHandler", w, r) @@ -2614,7 +2614,7 @@ func StoreSubscriptionHandler(service Service, authBackend AuthorizationBackend) GetTilesHandler handles request/response marshaling and validation for Post /v1/tiles/query */ -func GetTilesHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetTilesHandler(service GetTilesHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetTilesHandler", w, r) @@ -3946,24 +3946,40 @@ type GetTilesRequest struct { Request *http.Request `valid:"-"` } -// Service interface for all handlers -type Service interface { +// Service interface for DeduplicatePoiHandler handler +type DeduplicatePoiHandlerService interface { // DeduplicatePoi Specify if a list of POI are considered to be duplicates of a specific POI DeduplicatePoi(context.Context, DeduplicatePoiResponseWriter, *DeduplicatePoiRequest) error +} + +// Service interface for MovePoiAtPositionHandler handler +type MovePoiAtPositionHandlerService interface { // MovePoiAtPosition Allows an admin to move a POI identified by its ID to a specific position MovePoiAtPosition(context.Context, MovePoiAtPositionResponseWriter, *MovePoiAtPositionRequest) error +} + +// Service interface for GetAppsHandler handler +type GetAppsHandlerService interface { /* GetApps Returns a paginated list of apps Returns a paginated list of apps optionally filtered by type and/or query. */ GetApps(context.Context, GetAppsResponseWriter, *GetAppsRequest) error +} + +// Service interface for CreateAppHandler handler +type CreateAppHandlerService interface { /* CreateApp Creates a new application Creates a new application */ CreateApp(context.Context, CreateAppResponseWriter, *CreateAppRequest) error +} + +// Service interface for CheckForPaceAppHandler handler +type CheckForPaceAppHandlerService interface { /* CheckForPaceApp Query for location-based apps @@ -3977,12 +3993,20 @@ type Service interface { Please note that calling this API is very cheap and can be done regularly. */ CheckForPaceApp(context.Context, CheckForPaceAppResponseWriter, *CheckForPaceAppRequest) error +} + +// Service interface for DeleteAppHandler handler +type DeleteAppHandlerService interface { /* DeleteApp Deletes App with specified id Deletes App with specified id */ DeleteApp(context.Context, DeleteAppResponseWriter, *DeleteAppRequest) error +} + +// Service interface for GetAppHandler handler +type GetAppHandlerService interface { /* GetApp Returns App with specified id @@ -3990,30 +4014,50 @@ type Service interface { In case the query returns a `404` (`Not Found`) the app was deleted and should be deleted from any caches. */ GetApp(context.Context, GetAppResponseWriter, *GetAppRequest) error +} + +// Service interface for UpdateAppHandler handler +type UpdateAppHandlerService interface { /* UpdateApp Updates App with specified id Updates App with specified id */ UpdateApp(context.Context, UpdateAppResponseWriter, *UpdateAppRequest) error +} + +// Service interface for GetAppPOIsRelationshipsHandler handler +type GetAppPOIsRelationshipsHandlerService interface { /* GetAppPOIsRelationships Returns all POI relations for specified app id Returns all POI relations for specified app id */ GetAppPOIsRelationships(context.Context, GetAppPOIsRelationshipsResponseWriter, *GetAppPOIsRelationshipsRequest) error +} + +// Service interface for UpdateAppPOIsRelationshipsHandler handler +type UpdateAppPOIsRelationshipsHandlerService interface { /* UpdateAppPOIsRelationships Update all POI relations for specified app id Update all POI relations for specified app id */ UpdateAppPOIsRelationships(context.Context, UpdateAppPOIsRelationshipsResponseWriter, *UpdateAppPOIsRelationshipsRequest) error +} + +// Service interface for GetDuplicatesKMLHandler handler +type GetDuplicatesKMLHandlerService interface { /* GetDuplicatesKML Duplicate Map for country (KML) Generates a map of potential gas station duplicates (closer than 50m to eachother) for specified country. */ GetDuplicatesKML(context.Context, GetDuplicatesKMLResponseWriter, *GetDuplicatesKMLRequest) error +} + +// Service interface for GetPoisDumpHandler handler +type GetPoisDumpHandlerService interface { /* GetPoisDump Create a full POI dump @@ -4021,24 +4065,40 @@ type Service interface { Dump all POI data in XLSX format, along with full amenities. */ GetPoisDump(context.Context, GetPoisDumpResponseWriter, *GetPoisDumpRequest) error +} + +// Service interface for DeleteGasStationReferenceStatusHandler handler +type DeleteGasStationReferenceStatusHandlerService interface { /* DeleteGasStationReferenceStatus Deletes a reference status of a gas station Deletes a reference status of a gas station */ DeleteGasStationReferenceStatus(context.Context, DeleteGasStationReferenceStatusResponseWriter, *DeleteGasStationReferenceStatusRequest) error +} + +// Service interface for PutGasStationReferenceStatusHandler handler +type PutGasStationReferenceStatusHandlerService interface { /* PutGasStationReferenceStatus Creates or updates a reference status of a gas station Creates or updates a reference status of a gas station */ PutGasStationReferenceStatus(context.Context, PutGasStationReferenceStatusResponseWriter, *PutGasStationReferenceStatusRequest) error +} + +// Service interface for GetEventsHandler handler +type GetEventsHandlerService interface { /* GetEvents Returns a list of events Returns a list of events optionally filtered by poi type and/or country id and/or user id */ GetEvents(context.Context, GetEventsResponseWriter, *GetEventsRequest) error +} + +// Service interface for GetGasStationsHandler handler +type GetGasStationsHandlerService interface { /* GetGasStations Query for gas stations @@ -4055,24 +4115,40 @@ type Service interface { * boundingBox */ GetGasStations(context.Context, GetGasStationsResponseWriter, *GetGasStationsRequest) error +} + +// Service interface for GetGasStationHandler handler +type GetGasStationHandlerService interface { /* GetGasStation Get a specific gas station Returns an individual gas station */ GetGasStation(context.Context, GetGasStationResponseWriter, *GetGasStationRequest) error +} + +// Service interface for GetPriceHistoryHandler handler +type GetPriceHistoryHandlerService interface { /* GetPriceHistory Get price history for a specific gas station Get the price history for a specific gas station and fuel type on a period of time which can begin no sooner than 37 days ago; the time interval between price changes can be set to minute, hour, day, week, month or year */ GetPriceHistory(context.Context, GetPriceHistoryResponseWriter, *GetPriceHistoryRequest) error +} + +// Service interface for GetGasStationFuelTypeNameMappingHandler handler +type GetGasStationFuelTypeNameMappingHandlerService interface { /* GetGasStationFuelTypeNameMapping Get a mapping from gas station specific fuel product name mapped to a normalized fuel type Every gas station potential has different names for the same fuel types. This endpoint accepts the gas station's specific name and return a mapping where the specific name is mapped to a normalized version which should be globally the same across gas stations. */ GetGasStationFuelTypeNameMapping(context.Context, GetGasStationFuelTypeNameMappingResponseWriter, *GetGasStationFuelTypeNameMappingRequest) error +} + +// Service interface for GetMetadataFiltersHandler handler +type GetMetadataFiltersHandlerService interface { /* GetMetadataFilters Query for filterable values inside a radius @@ -4086,78 +4162,130 @@ type Service interface { * amenities */ GetMetadataFilters(context.Context, GetMetadataFiltersResponseWriter, *GetMetadataFiltersRequest) error +} + +// Service interface for GetPoisHandler handler +type GetPoisHandlerService interface { /* GetPois Returns a paginated list of POIs Returns a paginated list of POIs optionally filtered by type, appId and/or query */ GetPois(context.Context, GetPoisResponseWriter, *GetPoisRequest) error +} + +// Service interface for GetPoiHandler handler +type GetPoiHandlerService interface { /* GetPoi Returns POI with specified id Returns POI with specified id */ GetPoi(context.Context, GetPoiResponseWriter, *GetPoiRequest) error +} + +// Service interface for ChangePoiHandler handler +type ChangePoiHandlerService interface { /* ChangePoi Updates POI with specified id (only passed attributes will be updated) Returns POI with specified id (only passed attributes will be updated) */ ChangePoi(context.Context, ChangePoiResponseWriter, *ChangePoiRequest) error +} + +// Service interface for GetPoliciesHandler handler +type GetPoliciesHandlerService interface { /* GetPolicies Returns a paginated list of policies Returns a paginated list of policies optionally filtered by poi type and/or country id and/or user id */ GetPolicies(context.Context, GetPoliciesResponseWriter, *GetPoliciesRequest) error +} + +// Service interface for CreatePolicyHandler handler +type CreatePolicyHandlerService interface { /* CreatePolicy Creates a new policy Creates a new policy */ CreatePolicy(context.Context, CreatePolicyResponseWriter, *CreatePolicyRequest) error +} + +// Service interface for GetPolicyHandler handler +type GetPolicyHandlerService interface { /* GetPolicy Returns policy with specified id Returns policy with specified id */ GetPolicy(context.Context, GetPolicyResponseWriter, *GetPolicyRequest) error +} + +// Service interface for GetRegionalPricesHandler handler +type GetRegionalPricesHandlerService interface { /* GetRegionalPrices Search for regional prices in the area Search for regional prices in the area centered at input latitude/longitude. Lower/Upper limits are set for each fuel type returned. */ GetRegionalPrices(context.Context, GetRegionalPricesResponseWriter, *GetRegionalPricesRequest) error +} + +// Service interface for GetSourcesHandler handler +type GetSourcesHandlerService interface { /* GetSources Returns a paginated list of sources Returns a paginated list of sources optionally filtered by poi type and/or name */ GetSources(context.Context, GetSourcesResponseWriter, *GetSourcesRequest) error +} + +// Service interface for CreateSourceHandler handler +type CreateSourceHandlerService interface { /* CreateSource Creates a new source Creates a new source */ CreateSource(context.Context, CreateSourceResponseWriter, *CreateSourceRequest) error +} + +// Service interface for DeleteSourceHandler handler +type DeleteSourceHandlerService interface { /* DeleteSource Deletes source with specified id Deletes source with specified id */ DeleteSource(context.Context, DeleteSourceResponseWriter, *DeleteSourceRequest) error +} + +// Service interface for GetSourceHandler handler +type GetSourceHandlerService interface { /* GetSource Returns source with specified id Returns source with specified id */ GetSource(context.Context, GetSourceResponseWriter, *GetSourceRequest) error +} + +// Service interface for UpdateSourceHandler handler +type UpdateSourceHandlerService interface { /* UpdateSource Updates source with specified id Updates source with specified id */ UpdateSource(context.Context, UpdateSourceResponseWriter, *UpdateSourceRequest) error +} + +// Service interface for GetSubscriptionsHandler handler +type GetSubscriptionsHandlerService interface { /* GetSubscriptions Get the list of POI subscriptions for the user or device @@ -4165,10 +4293,18 @@ type Service interface { Returns a list of all current (not expired) subscriptions of the user. */ GetSubscriptions(context.Context, GetSubscriptionsResponseWriter, *GetSubscriptionsRequest) error +} + +// Service interface for DeleteSubscriptionHandler handler +type DeleteSubscriptionHandlerService interface { /* DeleteSubscription Deletes a previously created POI subscription */ DeleteSubscription(context.Context, DeleteSubscriptionResponseWriter, *DeleteSubscriptionRequest) error +} + +// Service interface for StoreSubscriptionHandler handler +type StoreSubscriptionHandlerService interface { /* StoreSubscription Stores a POI subscription @@ -4189,6 +4325,10 @@ type Service interface { ``` */ StoreSubscription(context.Context, StoreSubscriptionResponseWriter, *StoreSubscriptionRequest) error +} + +// Service interface for GetTilesHandler handler +type GetTilesHandlerService interface { /* GetTiles Query for tiles @@ -4203,48 +4343,192 @@ Router implements: PACE POI API POI API */ -func Router(service Service, authBackend AuthorizationBackend) *mux.Router { +func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { router := mux.NewRouter() authBackend.InitDeviceID(cfgDeviceID) authBackend.InitOAuth2(cfgOAuth2) authBackend.InitOIDC(cfgOIDC) // Subrouter s1 - Path: /poi s1 := router.PathPrefix("/poi").Subrouter() - s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(DeleteGasStationReferenceStatusHandler(service, authBackend)).Name("DeleteGasStationReferenceStatus") - s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(PutGasStationReferenceStatusHandler(service, authBackend)).Name("PutGasStationReferenceStatus") - s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(GetAppPOIsRelationshipsHandler(service, authBackend)).Name("GetAppPOIsRelationships") - s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(UpdateAppPOIsRelationshipsHandler(service, authBackend)).Name("UpdateAppPOIsRelationships") - s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(GetPriceHistoryHandler(service, authBackend)).Name("GetPriceHistory") - s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(DeduplicatePoiHandler(service, authBackend)).Name("DeduplicatePoi") - s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(MovePoiAtPositionHandler(service, authBackend)).Name("MovePoiAtPosition") - s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(GetDuplicatesKMLHandler(service, authBackend)).Name("GetDuplicatesKML") - s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(GetGasStationFuelTypeNameMappingHandler(service, authBackend)).Name("GetGasStationFuelTypeNameMapping") - s1.Methods("GET").Path("/beta/apps/query").Handler(CheckForPaceAppHandler(service, authBackend)).Name("CheckForPaceApp") - s1.Methods("GET").Path("/beta/datadumps/pois").Handler(GetPoisDumpHandler(service, authBackend)).Name("GetPoisDump") - s1.Methods("GET").Path("/beta/prices/regional").Handler(GetRegionalPricesHandler(service, authBackend)).Name("GetRegionalPrices") - s1.Methods("POST").Path("/v1/tiles/query").Handler(GetTilesHandler(service, authBackend)).Name("GetTiles") - s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(DeleteAppHandler(service, authBackend)).Name("DeleteApp") - s1.Methods("GET").Path("/beta/apps/{appID}").Handler(GetAppHandler(service, authBackend)).Name("GetApp") - s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(UpdateAppHandler(service, authBackend)).Name("UpdateApp") - s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(GetGasStationHandler(service, authBackend)).Name("GetGasStation") - s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(GetPoiHandler(service, authBackend)).Name("GetPoi") - s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(ChangePoiHandler(service, authBackend)).Name("ChangePoi") - s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(GetPolicyHandler(service, authBackend)).Name("GetPolicy") - s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(DeleteSourceHandler(service, authBackend)).Name("DeleteSource") - s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(GetSourceHandler(service, authBackend)).Name("GetSource") - s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(UpdateSourceHandler(service, authBackend)).Name("UpdateSource") - s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(DeleteSubscriptionHandler(service, authBackend)).Name("DeleteSubscription") - s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(StoreSubscriptionHandler(service, authBackend)).Name("StoreSubscription") - s1.Methods("GET").Path("/beta/apps").Handler(GetAppsHandler(service, authBackend)).Name("GetApps") - s1.Methods("POST").Path("/beta/apps").Handler(CreateAppHandler(service, authBackend)).Name("CreateApp") - s1.Methods("GET").Path("/beta/events").Handler(GetEventsHandler(service, authBackend)).Name("GetEvents") - s1.Methods("GET").Path("/beta/gas-stations").Handler(GetGasStationsHandler(service, authBackend)).Name("GetGasStations") - s1.Methods("GET").Path("/beta/meta").Handler(GetMetadataFiltersHandler(service, authBackend)).Name("GetMetadataFilters") - s1.Methods("GET").Path("/beta/pois").Handler(GetPoisHandler(service, authBackend)).Name("GetPois") - s1.Methods("GET").Path("/beta/policies").Handler(GetPoliciesHandler(service, authBackend)).Name("GetPolicies") - s1.Methods("POST").Path("/beta/policies").Handler(CreatePolicyHandler(service, authBackend)).Name("CreatePolicy") - s1.Methods("GET").Path("/beta/sources").Handler(GetSourcesHandler(service, authBackend)).Name("GetSources") - s1.Methods("POST").Path("/beta/sources").Handler(CreateSourceHandler(service, authBackend)).Name("CreateSource") - s1.Methods("GET").Path("/beta/subscriptions").Handler(GetSubscriptionsHandler(service, authBackend)).Name("GetSubscriptions") + if service, ok := service.(DeleteGasStationReferenceStatusHandlerService); ok { + s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(DeleteGasStationReferenceStatusHandler(service, authBackend)).Name("DeleteGasStationReferenceStatus") + } else { + s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(router.NotFoundHandler).Name("DeleteGasStationReferenceStatus") + } + if service, ok := service.(PutGasStationReferenceStatusHandlerService); ok { + s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(PutGasStationReferenceStatusHandler(service, authBackend)).Name("PutGasStationReferenceStatus") + } else { + s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(router.NotFoundHandler).Name("PutGasStationReferenceStatus") + } + if service, ok := service.(GetAppPOIsRelationshipsHandlerService); ok { + s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(GetAppPOIsRelationshipsHandler(service, authBackend)).Name("GetAppPOIsRelationships") + } else { + s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(router.NotFoundHandler).Name("GetAppPOIsRelationships") + } + if service, ok := service.(UpdateAppPOIsRelationshipsHandlerService); ok { + s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(UpdateAppPOIsRelationshipsHandler(service, authBackend)).Name("UpdateAppPOIsRelationships") + } else { + s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(router.NotFoundHandler).Name("UpdateAppPOIsRelationships") + } + if service, ok := service.(GetPriceHistoryHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(GetPriceHistoryHandler(service, authBackend)).Name("GetPriceHistory") + } else { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(router.NotFoundHandler).Name("GetPriceHistory") + } + if service, ok := service.(DeduplicatePoiHandlerService); ok { + s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(DeduplicatePoiHandler(service, authBackend)).Name("DeduplicatePoi") + } else { + s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(router.NotFoundHandler).Name("DeduplicatePoi") + } + if service, ok := service.(MovePoiAtPositionHandlerService); ok { + s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(MovePoiAtPositionHandler(service, authBackend)).Name("MovePoiAtPosition") + } else { + s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(router.NotFoundHandler).Name("MovePoiAtPosition") + } + if service, ok := service.(GetDuplicatesKMLHandlerService); ok { + s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(GetDuplicatesKMLHandler(service, authBackend)).Name("GetDuplicatesKML") + } else { + s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(router.NotFoundHandler).Name("GetDuplicatesKML") + } + if service, ok := service.(GetGasStationFuelTypeNameMappingHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(GetGasStationFuelTypeNameMappingHandler(service, authBackend)).Name("GetGasStationFuelTypeNameMapping") + } else { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(router.NotFoundHandler).Name("GetGasStationFuelTypeNameMapping") + } + if service, ok := service.(CheckForPaceAppHandlerService); ok { + s1.Methods("GET").Path("/beta/apps/query").Handler(CheckForPaceAppHandler(service, authBackend)).Name("CheckForPaceApp") + } else { + s1.Methods("GET").Path("/beta/apps/query").Handler(router.NotFoundHandler).Name("CheckForPaceApp") + } + if service, ok := service.(GetPoisDumpHandlerService); ok { + s1.Methods("GET").Path("/beta/datadumps/pois").Handler(GetPoisDumpHandler(service, authBackend)).Name("GetPoisDump") + } else { + s1.Methods("GET").Path("/beta/datadumps/pois").Handler(router.NotFoundHandler).Name("GetPoisDump") + } + if service, ok := service.(GetRegionalPricesHandlerService); ok { + s1.Methods("GET").Path("/beta/prices/regional").Handler(GetRegionalPricesHandler(service, authBackend)).Name("GetRegionalPrices") + } else { + s1.Methods("GET").Path("/beta/prices/regional").Handler(router.NotFoundHandler).Name("GetRegionalPrices") + } + if service, ok := service.(GetTilesHandlerService); ok { + s1.Methods("POST").Path("/v1/tiles/query").Handler(GetTilesHandler(service, authBackend)).Name("GetTiles") + } else { + s1.Methods("POST").Path("/v1/tiles/query").Handler(router.NotFoundHandler).Name("GetTiles") + } + if service, ok := service.(DeleteAppHandlerService); ok { + s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(DeleteAppHandler(service, authBackend)).Name("DeleteApp") + } else { + s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(router.NotFoundHandler).Name("DeleteApp") + } + if service, ok := service.(GetAppHandlerService); ok { + s1.Methods("GET").Path("/beta/apps/{appID}").Handler(GetAppHandler(service, authBackend)).Name("GetApp") + } else { + s1.Methods("GET").Path("/beta/apps/{appID}").Handler(router.NotFoundHandler).Name("GetApp") + } + if service, ok := service.(UpdateAppHandlerService); ok { + s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(UpdateAppHandler(service, authBackend)).Name("UpdateApp") + } else { + s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(router.NotFoundHandler).Name("UpdateApp") + } + if service, ok := service.(GetGasStationHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(GetGasStationHandler(service, authBackend)).Name("GetGasStation") + } else { + s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(router.NotFoundHandler).Name("GetGasStation") + } + if service, ok := service.(GetPoiHandlerService); ok { + s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(GetPoiHandler(service, authBackend)).Name("GetPoi") + } else { + s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(router.NotFoundHandler).Name("GetPoi") + } + if service, ok := service.(ChangePoiHandlerService); ok { + s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(ChangePoiHandler(service, authBackend)).Name("ChangePoi") + } else { + s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(router.NotFoundHandler).Name("ChangePoi") + } + if service, ok := service.(GetPolicyHandlerService); ok { + s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(GetPolicyHandler(service, authBackend)).Name("GetPolicy") + } else { + s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(router.NotFoundHandler).Name("GetPolicy") + } + if service, ok := service.(DeleteSourceHandlerService); ok { + s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(DeleteSourceHandler(service, authBackend)).Name("DeleteSource") + } else { + s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(router.NotFoundHandler).Name("DeleteSource") + } + if service, ok := service.(GetSourceHandlerService); ok { + s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(GetSourceHandler(service, authBackend)).Name("GetSource") + } else { + s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(router.NotFoundHandler).Name("GetSource") + } + if service, ok := service.(UpdateSourceHandlerService); ok { + s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(UpdateSourceHandler(service, authBackend)).Name("UpdateSource") + } else { + s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(router.NotFoundHandler).Name("UpdateSource") + } + if service, ok := service.(DeleteSubscriptionHandlerService); ok { + s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(DeleteSubscriptionHandler(service, authBackend)).Name("DeleteSubscription") + } else { + s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(router.NotFoundHandler).Name("DeleteSubscription") + } + if service, ok := service.(StoreSubscriptionHandlerService); ok { + s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(StoreSubscriptionHandler(service, authBackend)).Name("StoreSubscription") + } else { + s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(router.NotFoundHandler).Name("StoreSubscription") + } + if service, ok := service.(GetAppsHandlerService); ok { + s1.Methods("GET").Path("/beta/apps").Handler(GetAppsHandler(service, authBackend)).Name("GetApps") + } else { + s1.Methods("GET").Path("/beta/apps").Handler(router.NotFoundHandler).Name("GetApps") + } + if service, ok := service.(CreateAppHandlerService); ok { + s1.Methods("POST").Path("/beta/apps").Handler(CreateAppHandler(service, authBackend)).Name("CreateApp") + } else { + s1.Methods("POST").Path("/beta/apps").Handler(router.NotFoundHandler).Name("CreateApp") + } + if service, ok := service.(GetEventsHandlerService); ok { + s1.Methods("GET").Path("/beta/events").Handler(GetEventsHandler(service, authBackend)).Name("GetEvents") + } else { + s1.Methods("GET").Path("/beta/events").Handler(router.NotFoundHandler).Name("GetEvents") + } + if service, ok := service.(GetGasStationsHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations").Handler(GetGasStationsHandler(service, authBackend)).Name("GetGasStations") + } else { + s1.Methods("GET").Path("/beta/gas-stations").Handler(router.NotFoundHandler).Name("GetGasStations") + } + if service, ok := service.(GetMetadataFiltersHandlerService); ok { + s1.Methods("GET").Path("/beta/meta").Handler(GetMetadataFiltersHandler(service, authBackend)).Name("GetMetadataFilters") + } else { + s1.Methods("GET").Path("/beta/meta").Handler(router.NotFoundHandler).Name("GetMetadataFilters") + } + if service, ok := service.(GetPoisHandlerService); ok { + s1.Methods("GET").Path("/beta/pois").Handler(GetPoisHandler(service, authBackend)).Name("GetPois") + } else { + s1.Methods("GET").Path("/beta/pois").Handler(router.NotFoundHandler).Name("GetPois") + } + if service, ok := service.(GetPoliciesHandlerService); ok { + s1.Methods("GET").Path("/beta/policies").Handler(GetPoliciesHandler(service, authBackend)).Name("GetPolicies") + } else { + s1.Methods("GET").Path("/beta/policies").Handler(router.NotFoundHandler).Name("GetPolicies") + } + if service, ok := service.(CreatePolicyHandlerService); ok { + s1.Methods("POST").Path("/beta/policies").Handler(CreatePolicyHandler(service, authBackend)).Name("CreatePolicy") + } else { + s1.Methods("POST").Path("/beta/policies").Handler(router.NotFoundHandler).Name("CreatePolicy") + } + if service, ok := service.(GetSourcesHandlerService); ok { + s1.Methods("GET").Path("/beta/sources").Handler(GetSourcesHandler(service, authBackend)).Name("GetSources") + } else { + s1.Methods("GET").Path("/beta/sources").Handler(router.NotFoundHandler).Name("GetSources") + } + if service, ok := service.(CreateSourceHandlerService); ok { + s1.Methods("POST").Path("/beta/sources").Handler(CreateSourceHandler(service, authBackend)).Name("CreateSource") + } else { + s1.Methods("POST").Path("/beta/sources").Handler(router.NotFoundHandler).Name("CreateSource") + } + if service, ok := service.(GetSubscriptionsHandlerService); ok { + s1.Methods("GET").Path("/beta/subscriptions").Handler(GetSubscriptionsHandler(service, authBackend)).Name("GetSubscriptions") + } else { + s1.Methods("GET").Path("/beta/subscriptions").Handler(router.NotFoundHandler).Name("GetSubscriptions") + } return router } diff --git a/http/jsonapi/generator/internal/securitytest/open-api_test.go b/http/jsonapi/generator/internal/securitytest/open-api_test.go index 5e4a6e3ca..a96e60cb8 100644 --- a/http/jsonapi/generator/internal/securitytest/open-api_test.go +++ b/http/jsonapi/generator/internal/securitytest/open-api_test.go @@ -41,7 +41,7 @@ var cfgProfileKey = &apikey.Config{ GetTestHandler handles request/response marshaling and validation for Get /beta/test */ -func GetTestHandler(service Service, authBackend AuthorizationBackend) http.Handler { +func GetTestHandler(service GetTestHandlerService, authBackend AuthorizationBackend) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetTestHandler", w, r) @@ -125,8 +125,8 @@ type GetTestRequest struct { Request *http.Request `valid:"-"` } -// Service interface for all handlers -type Service interface { +// Service interface for GetTestHandler handler +type GetTestHandlerService interface { // GetTest Test GetTest(context.Context, GetTestResponseWriter, *GetTestRequest) error } @@ -137,12 +137,16 @@ Router implements: PACE Payment API Welcome to the PACE Payment API documentation. This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. */ -func Router(service Service, authBackend AuthorizationBackend) *mux.Router { +func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { router := mux.NewRouter() authBackend.InitOAuth2(cfgOAuth2) authBackend.InitProfileKey(cfgProfileKey) // Subrouter s1 - Path: /pay s1 := router.PathPrefix("/pay").Subrouter() - s1.Methods("GET").Path("/beta/test").Handler(GetTestHandler(service, authBackend)).Name("GetTest") + if service, ok := service.(GetTestHandlerService); ok { + s1.Methods("GET").Path("/beta/test").Handler(GetTestHandler(service, authBackend)).Name("GetTest") + } else { + s1.Methods("GET").Path("/beta/test").Handler(router.NotFoundHandler).Name("GetTest") + } return router } From 27fcea8f9e39924be59d582c11d26d90eda983b9 Mon Sep 17 00:00:00 2001 From: Julius Foitzik Date: Thu, 22 Apr 2021 13:06:44 +0200 Subject: [PATCH 4/6] Add legacy service interface to allow complete implementation reference --- http/jsonapi/generator/generate_handler.go | 11 +++++ .../internal/articles/open-api_test.go | 8 ++++ .../internal/fueling/open-api_test.go | 9 ++++ .../generator/internal/pay/open-api_test.go | 13 ++++++ .../generator/internal/poi/open-api_test.go | 41 +++++++++++++++++++ .../internal/securitytest/open-api_test.go | 6 +++ 6 files changed, 88 insertions(+) diff --git a/http/jsonapi/generator/generate_handler.go b/http/jsonapi/generator/generate_handler.go index ee02a41c3..9abe4750c 100644 --- a/http/jsonapi/generator/generate_handler.go +++ b/http/jsonapi/generator/generate_handler.go @@ -315,6 +315,17 @@ func (g *Generator) buildServiceInterface(routes []*route, schema *openapi3.Swag } } + subServices := make([]jen.Code, 0) + for _, route := range routes { + subServices = append(subServices, jen.Id(generateSubServiceName(route.handler))) + } + + g.goSource.Line() + g.goSource.Line() + g.goSource.Comment("Legacy Interface.") + g.goSource.Comment("Use this if you want to fully implement a service.") + g.goSource.Type().Id(serviceInterface).Interface(subServices...) + return nil } diff --git a/http/jsonapi/generator/internal/articles/open-api_test.go b/http/jsonapi/generator/internal/articles/open-api_test.go index d7f84b22e..dea27aed3 100644 --- a/http/jsonapi/generator/internal/articles/open-api_test.go +++ b/http/jsonapi/generator/internal/articles/open-api_test.go @@ -356,6 +356,14 @@ type UpdateArticleInlineRefHandlerService interface { UpdateArticleInlineRef(context.Context, UpdateArticleInlineRefResponseWriter, *UpdateArticleInlineRefRequest) error } +// Legacy Interface. +// Use this if you want to fully implement a service. +type Service interface { + UpdateArticleCommentsHandlerService + UpdateArticleInlineTypeHandlerService + UpdateArticleInlineRefHandlerService +} + /* Router implements: Articles Test Service diff --git a/http/jsonapi/generator/internal/fueling/open-api_test.go b/http/jsonapi/generator/internal/fueling/open-api_test.go index e0aaab78b..17cc823b4 100644 --- a/http/jsonapi/generator/internal/fueling/open-api_test.go +++ b/http/jsonapi/generator/internal/fueling/open-api_test.go @@ -596,6 +596,15 @@ type WaitOnPumpStatusChangeHandlerService interface { WaitOnPumpStatusChange(context.Context, WaitOnPumpStatusChangeResponseWriter, *WaitOnPumpStatusChangeRequest) error } +// Legacy Interface. +// Use this if you want to fully implement a service. +type Service interface { + ProcessPaymentHandlerService + ApproachingAtTheForecourtHandlerService + GetPumpHandlerService + WaitOnPumpStatusChangeHandlerService +} + /* Router implements: PACE Fueling API diff --git a/http/jsonapi/generator/internal/pay/open-api_test.go b/http/jsonapi/generator/internal/pay/open-api_test.go index bb0c52515..37dd4c86a 100644 --- a/http/jsonapi/generator/internal/pay/open-api_test.go +++ b/http/jsonapi/generator/internal/pay/open-api_test.go @@ -1002,6 +1002,19 @@ type ProcessPaymentHandlerService interface { ProcessPayment(context.Context, ProcessPaymentResponseWriter, *ProcessPaymentRequest) error } +// Legacy Interface. +// Use this if you want to fully implement a service. +type Service interface { + GetPaymentMethodsHandlerService + CreatePaymentMethodSEPAHandlerService + DeletePaymentMethodHandlerService + AuthorizePaymentMethodHandlerService + DeletePaymentTokenHandlerService + GetPaymentMethodsIncludingCreditCheckHandlerService + GetPaymentMethodsIncludingPaymentTokenHandlerService + ProcessPaymentHandlerService +} + /* Router implements: PACE Payment API diff --git a/http/jsonapi/generator/internal/poi/open-api_test.go b/http/jsonapi/generator/internal/poi/open-api_test.go index 98301e82d..0ccb3a545 100644 --- a/http/jsonapi/generator/internal/poi/open-api_test.go +++ b/http/jsonapi/generator/internal/poi/open-api_test.go @@ -4338,6 +4338,47 @@ type GetTilesHandlerService interface { GetTiles(context.Context, GetTilesResponseWriter, *GetTilesRequest) error } +// Legacy Interface. +// Use this if you want to fully implement a service. +type Service interface { + DeduplicatePoiHandlerService + MovePoiAtPositionHandlerService + GetAppsHandlerService + CreateAppHandlerService + CheckForPaceAppHandlerService + DeleteAppHandlerService + GetAppHandlerService + UpdateAppHandlerService + GetAppPOIsRelationshipsHandlerService + UpdateAppPOIsRelationshipsHandlerService + GetDuplicatesKMLHandlerService + GetPoisDumpHandlerService + DeleteGasStationReferenceStatusHandlerService + PutGasStationReferenceStatusHandlerService + GetEventsHandlerService + GetGasStationsHandlerService + GetGasStationHandlerService + GetPriceHistoryHandlerService + GetGasStationFuelTypeNameMappingHandlerService + GetMetadataFiltersHandlerService + GetPoisHandlerService + GetPoiHandlerService + ChangePoiHandlerService + GetPoliciesHandlerService + CreatePolicyHandlerService + GetPolicyHandlerService + GetRegionalPricesHandlerService + GetSourcesHandlerService + CreateSourceHandlerService + DeleteSourceHandlerService + GetSourceHandlerService + UpdateSourceHandlerService + GetSubscriptionsHandlerService + DeleteSubscriptionHandlerService + StoreSubscriptionHandlerService + GetTilesHandlerService +} + /* Router implements: PACE POI API diff --git a/http/jsonapi/generator/internal/securitytest/open-api_test.go b/http/jsonapi/generator/internal/securitytest/open-api_test.go index a96e60cb8..545a7a79f 100644 --- a/http/jsonapi/generator/internal/securitytest/open-api_test.go +++ b/http/jsonapi/generator/internal/securitytest/open-api_test.go @@ -131,6 +131,12 @@ type GetTestHandlerService interface { GetTest(context.Context, GetTestResponseWriter, *GetTestRequest) error } +// Legacy Interface. +// Use this if you want to fully implement a service. +type Service interface { + GetTestHandlerService +} + /* Router implements: PACE Payment API From ba58ac2ba07a323d91521d5f8cb53af7438932f1 Mon Sep 17 00:00:00 2001 From: Julius Foitzik Date: Fri, 23 Apr 2021 12:35:24 +0200 Subject: [PATCH 5/6] Add new method to pass fallback router to api router --- http/jsonapi/generator/generate_handler.go | 59 ++++-- .../internal/articles/open-api_test.go | 27 +++ .../internal/fueling/open-api_test.go | 54 +++++ .../generator/internal/pay/open-api_test.go | 56 +++++ .../generator/internal/poi/open-api_test.go | 195 ++++++++++++++++++ .../internal/securitytest/open-api_test.go | 20 ++ 6 files changed, 395 insertions(+), 16 deletions(-) diff --git a/http/jsonapi/generator/generate_handler.go b/http/jsonapi/generator/generate_handler.go index 9abe4750c..f4012e586 100644 --- a/http/jsonapi/generator/generate_handler.go +++ b/http/jsonapi/generator/generate_handler.go @@ -31,6 +31,7 @@ const ( ) const serviceInterface = "Service" +const rootRouterName = "router" const jsonapiContent = "application/vnd.api+json" var noValidation = map[string]string{"valid": "-"} @@ -75,6 +76,7 @@ func (g *Generator) BuildHandler(schema *openapi3.Swagger) error { g.generateRequestResponseTypes, g.buildServiceInterface, g.buildRouter, + g.buildRouterWithFallbackAsArg, } for _, fn := range funcs { err := fn(routes, schema) @@ -350,6 +352,42 @@ func (g *Generator) buildSubServiceInterface(route *route, schema *openapi3.Swag } func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error { + routerBody, err := g.buildRouterBodyWithFallback(routes, schema, jen.Id(rootRouterName).Dot("NotFoundHandler")) + if err != nil { + return nil + } + g.addGoDoc("Router", "implements: "+schema.Info.Title+"\n\n"+schema.Info.Description) + serviceInterfaceVariable := jen.Id("service").Interface() + if hasSecuritySchema(schema) { + g.goSource.Func().Id("Router").Params( + serviceInterfaceVariable, jen.Id("authBackend").Id(authBackendInterface)).Op("*").Qual(pkgGorillaMux, "Router").Block(routerBody...) + + } else { + g.goSource.Func().Id("Router").Params( + serviceInterfaceVariable).Op("*").Qual(pkgGorillaMux, "Router").Block(routerBody...) + } + return nil +} + +func (g *Generator) buildRouterWithFallbackAsArg(routes []*route, schema *openapi3.Swagger) error { + routerBody, err := g.buildRouterBodyWithFallback(routes, schema, jen.Id("fallback")) + if err != nil { + return nil + } + g.addGoDoc("Router", "implements: "+schema.Info.Title+"\n\n"+schema.Info.Description) + serviceInterfaceVariable := jen.Id("service").Interface() + if hasSecuritySchema(schema) { + g.goSource.Func().Id("RouterWithFallback").Params( + serviceInterfaceVariable, jen.Id("authBackend").Id(authBackendInterface), jen.Id("fallback").Qual("net/http", "Handler")).Op("*").Qual(pkgGorillaMux, "Router").Block(routerBody...) + + } else { + g.goSource.Func().Id("RouterWithFallback").Params( + serviceInterfaceVariable).Op("*").Qual(pkgGorillaMux, "Router").Block(routerBody...) + } + return nil +} + +func (g *Generator) buildRouterBodyWithFallback(routes []*route, schema *openapi3.Swagger, fallback jen.Code) ([]jen.Code, error) { needsSecurity := hasSecuritySchema(schema) startInd := 0 var routeStmts []jen.Code @@ -370,7 +408,6 @@ func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error } // create new router - rootRouterName := "router" routeStmts[startInd] = jen.Id(rootRouterName).Op(":=").Qual(pkgGorillaMux, "NewRouter").Call() // Note: we don't restrict host, scheme and port to ease development @@ -379,7 +416,7 @@ func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error for _, server := range schema.Servers { serverUrl, err := url.Parse(server.URL) if err != nil { - return err + return nil, err } if _, ok := pathsIdx[serverUrl.Path]; !ok { paths = append(paths, serverUrl.Path) @@ -410,9 +447,9 @@ func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error routeCallParams = jen.List(jen.Id("service")) } primaryHandler := jen.Id(route.handler).Call(routeCallParams) - notFoundHandler := jen.Id(rootRouterName).Dot("NotFoundHandler") - ifElse := make([]*jen.Statement, 0) - for _, handler := range []*jen.Statement{primaryHandler, notFoundHandler} { + fallbackHandler := fallback + ifElse := make([]jen.Code, 0) + for _, handler := range []jen.Code{primaryHandler, fallbackHandler} { // build single route routeStmt := jen.Id(subrouterID).Dot("Methods").Call(jen.Lit(route.method)). Dot("Path").Call(jen.Lit(route.url.Path)). @@ -450,18 +487,8 @@ func (g *Generator) buildRouter(routes []*route, schema *openapi3.Swagger) error // return routeStmts = append(routeStmts, jen.Return(jen.Id("router"))) - g.addGoDoc("Router", "implements: "+schema.Info.Title+"\n\n"+schema.Info.Description) - serviceInterfaceVariable := jen.Id("service").Interface() - if hasSecuritySchema(schema) { - g.goSource.Func().Id("Router").Params( - serviceInterfaceVariable, jen.Id("authBackend").Id(authBackendInterface)).Op("*").Qual(pkgGorillaMux, "Router").Block(routeStmts...) - - } else { - g.goSource.Func().Id("Router").Params( - serviceInterfaceVariable).Op("*").Qual(pkgGorillaMux, "Router").Block(routeStmts...) - } - return nil + return routeStmts, nil } func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern string, pathItem *openapi3.PathItem, secSchemes map[string]*openapi3.SecuritySchemeRef) (*route, error) { diff --git a/http/jsonapi/generator/internal/articles/open-api_test.go b/http/jsonapi/generator/internal/articles/open-api_test.go index dea27aed3..12ebb24f2 100644 --- a/http/jsonapi/generator/internal/articles/open-api_test.go +++ b/http/jsonapi/generator/internal/articles/open-api_test.go @@ -390,3 +390,30 @@ func Router(service interface{}) *mux.Router { } return router } + +/* +Router implements: Articles Test Service + +Articles Test Service +*/ +func RouterWithFallback(service interface{}) *mux.Router { + router := mux.NewRouter() + // Subrouter s1 - Path: + s1 := router.PathPrefix("").Subrouter() + if service, ok := service.(UpdateArticleCommentsHandlerService); ok { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(UpdateArticleCommentsHandler(service)).Name("UpdateArticleComments") + } else { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(fallback).Name("UpdateArticleComments") + } + if service, ok := service.(UpdateArticleInlineTypeHandlerService); ok { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(UpdateArticleInlineTypeHandler(service)).Name("UpdateArticleInlineType") + } else { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(fallback).Name("UpdateArticleInlineType") + } + if service, ok := service.(UpdateArticleInlineRefHandlerService); ok { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(UpdateArticleInlineRefHandler(service)).Name("UpdateArticleInlineRef") + } else { + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(fallback).Name("UpdateArticleInlineRef") + } + return router +} diff --git a/http/jsonapi/generator/internal/fueling/open-api_test.go b/http/jsonapi/generator/internal/fueling/open-api_test.go index 17cc823b4..24a5d49f7 100644 --- a/http/jsonapi/generator/internal/fueling/open-api_test.go +++ b/http/jsonapi/generator/internal/fueling/open-api_test.go @@ -658,3 +658,57 @@ func Router(service interface{}) *mux.Router { } return router } + +/* +Router implements: PACE Fueling API + +Fueling API +*/ +func RouterWithFallback(service interface{}) *mux.Router { + router := mux.NewRouter() + // Subrouter s1 - Path: /fueling/beta/ + s1 := router.PathPrefix("/fueling/beta/").Subrouter() + if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") + } else { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(fallback).Name("WaitOnPumpStatusChange") + } + if service, ok := service.(GetPumpHandlerService); ok { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") + } else { + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(fallback).Name("GetPump") + } + if service, ok := service.(ProcessPaymentHandlerService); ok { + s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") + } else { + s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(fallback).Name("ProcessPayment") + } + if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { + s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + } else { + s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(fallback).Name("ApproachingAtTheForecourt") + } + // Subrouter s2 - Path: /fueling/v1/ + s2 := router.PathPrefix("/fueling/v1/").Subrouter() + if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") + } else { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(fallback).Name("WaitOnPumpStatusChange") + } + if service, ok := service.(GetPumpHandlerService); ok { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") + } else { + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(fallback).Name("GetPump") + } + if service, ok := service.(ProcessPaymentHandlerService); ok { + s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") + } else { + s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(fallback).Name("ProcessPayment") + } + if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { + s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + } else { + s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(fallback).Name("ApproachingAtTheForecourt") + } + return router +} diff --git a/http/jsonapi/generator/internal/pay/open-api_test.go b/http/jsonapi/generator/internal/pay/open-api_test.go index 37dd4c86a..e8cbeb923 100644 --- a/http/jsonapi/generator/internal/pay/open-api_test.go +++ b/http/jsonapi/generator/internal/pay/open-api_test.go @@ -1070,3 +1070,59 @@ func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { } return router } + +/* +Router implements: PACE Payment API + +Welcome to the PACE Payment API documentation. +This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. +*/ +func RouterWithFallback(service interface{}, authBackend AuthorizationBackend, fallback http.Handler) *mux.Router { + router := mux.NewRouter() + authBackend.InitOAuth2(cfgOAuth2) + authBackend.InitOpenID(cfgOpenID) + authBackend.InitProfileKey(cfgProfileKey) + // Subrouter s1 - Path: /pay + s1 := router.PathPrefix("/pay").Subrouter() + if service, ok := service.(DeletePaymentTokenHandlerService); ok { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(DeletePaymentTokenHandler(service, authBackend)).Name("DeletePaymentToken") + } else { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(fallback).Name("DeletePaymentToken") + } + if service, ok := service.(AuthorizePaymentMethodHandlerService); ok { + s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(AuthorizePaymentMethodHandler(service, authBackend)).Name("AuthorizePaymentMethod") + } else { + s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(fallback).Name("AuthorizePaymentMethod") + } + if service, ok := service.(CreatePaymentMethodSEPAHandlerService); ok { + s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(CreatePaymentMethodSEPAHandler(service, authBackend)).Name("CreatePaymentMethodSEPA") + } else { + s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(fallback).Name("CreatePaymentMethodSEPA") + } + if service, ok := service.(DeletePaymentMethodHandlerService); ok { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(DeletePaymentMethodHandler(service, authBackend)).Name("DeletePaymentMethod") + } else { + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(fallback).Name("DeletePaymentMethod") + } + if service, ok := service.(ProcessPaymentHandlerService); ok { + s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(ProcessPaymentHandler(service, authBackend)).Name("ProcessPayment") + } else { + s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(fallback).Name("ProcessPayment") + } + if service, ok := service.(GetPaymentMethodsIncludingCreditCheckHandlerService); ok { + s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingCreditCheckHandler(service, authBackend)).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") + } else { + s1.Methods("GET").Path("/beta/payment-methods").Handler(fallback).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") + } + if service, ok := service.(GetPaymentMethodsIncludingPaymentTokenHandlerService); ok { + s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingPaymentTokenHandler(service, authBackend)).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") + } else { + s1.Methods("GET").Path("/beta/payment-methods").Handler(fallback).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") + } + if service, ok := service.(GetPaymentMethodsHandlerService); ok { + s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsHandler(service, authBackend)).Name("GetPaymentMethods") + } else { + s1.Methods("GET").Path("/beta/payment-methods").Handler(fallback).Name("GetPaymentMethods") + } + return router +} diff --git a/http/jsonapi/generator/internal/poi/open-api_test.go b/http/jsonapi/generator/internal/poi/open-api_test.go index 0ccb3a545..965e78c4d 100644 --- a/http/jsonapi/generator/internal/poi/open-api_test.go +++ b/http/jsonapi/generator/internal/poi/open-api_test.go @@ -4573,3 +4573,198 @@ func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { } return router } + +/* +Router implements: PACE POI API + +POI API +*/ +func RouterWithFallback(service interface{}, authBackend AuthorizationBackend, fallback http.Handler) *mux.Router { + router := mux.NewRouter() + authBackend.InitDeviceID(cfgDeviceID) + authBackend.InitOAuth2(cfgOAuth2) + authBackend.InitOIDC(cfgOIDC) + // Subrouter s1 - Path: /poi + s1 := router.PathPrefix("/poi").Subrouter() + if service, ok := service.(DeleteGasStationReferenceStatusHandlerService); ok { + s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(DeleteGasStationReferenceStatusHandler(service, authBackend)).Name("DeleteGasStationReferenceStatus") + } else { + s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(fallback).Name("DeleteGasStationReferenceStatus") + } + if service, ok := service.(PutGasStationReferenceStatusHandlerService); ok { + s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(PutGasStationReferenceStatusHandler(service, authBackend)).Name("PutGasStationReferenceStatus") + } else { + s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(fallback).Name("PutGasStationReferenceStatus") + } + if service, ok := service.(GetAppPOIsRelationshipsHandlerService); ok { + s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(GetAppPOIsRelationshipsHandler(service, authBackend)).Name("GetAppPOIsRelationships") + } else { + s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(fallback).Name("GetAppPOIsRelationships") + } + if service, ok := service.(UpdateAppPOIsRelationshipsHandlerService); ok { + s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(UpdateAppPOIsRelationshipsHandler(service, authBackend)).Name("UpdateAppPOIsRelationships") + } else { + s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(fallback).Name("UpdateAppPOIsRelationships") + } + if service, ok := service.(GetPriceHistoryHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(GetPriceHistoryHandler(service, authBackend)).Name("GetPriceHistory") + } else { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(fallback).Name("GetPriceHistory") + } + if service, ok := service.(DeduplicatePoiHandlerService); ok { + s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(DeduplicatePoiHandler(service, authBackend)).Name("DeduplicatePoi") + } else { + s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(fallback).Name("DeduplicatePoi") + } + if service, ok := service.(MovePoiAtPositionHandlerService); ok { + s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(MovePoiAtPositionHandler(service, authBackend)).Name("MovePoiAtPosition") + } else { + s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(fallback).Name("MovePoiAtPosition") + } + if service, ok := service.(GetDuplicatesKMLHandlerService); ok { + s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(GetDuplicatesKMLHandler(service, authBackend)).Name("GetDuplicatesKML") + } else { + s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(fallback).Name("GetDuplicatesKML") + } + if service, ok := service.(GetGasStationFuelTypeNameMappingHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(GetGasStationFuelTypeNameMappingHandler(service, authBackend)).Name("GetGasStationFuelTypeNameMapping") + } else { + s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(fallback).Name("GetGasStationFuelTypeNameMapping") + } + if service, ok := service.(CheckForPaceAppHandlerService); ok { + s1.Methods("GET").Path("/beta/apps/query").Handler(CheckForPaceAppHandler(service, authBackend)).Name("CheckForPaceApp") + } else { + s1.Methods("GET").Path("/beta/apps/query").Handler(fallback).Name("CheckForPaceApp") + } + if service, ok := service.(GetPoisDumpHandlerService); ok { + s1.Methods("GET").Path("/beta/datadumps/pois").Handler(GetPoisDumpHandler(service, authBackend)).Name("GetPoisDump") + } else { + s1.Methods("GET").Path("/beta/datadumps/pois").Handler(fallback).Name("GetPoisDump") + } + if service, ok := service.(GetRegionalPricesHandlerService); ok { + s1.Methods("GET").Path("/beta/prices/regional").Handler(GetRegionalPricesHandler(service, authBackend)).Name("GetRegionalPrices") + } else { + s1.Methods("GET").Path("/beta/prices/regional").Handler(fallback).Name("GetRegionalPrices") + } + if service, ok := service.(GetTilesHandlerService); ok { + s1.Methods("POST").Path("/v1/tiles/query").Handler(GetTilesHandler(service, authBackend)).Name("GetTiles") + } else { + s1.Methods("POST").Path("/v1/tiles/query").Handler(fallback).Name("GetTiles") + } + if service, ok := service.(DeleteAppHandlerService); ok { + s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(DeleteAppHandler(service, authBackend)).Name("DeleteApp") + } else { + s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(fallback).Name("DeleteApp") + } + if service, ok := service.(GetAppHandlerService); ok { + s1.Methods("GET").Path("/beta/apps/{appID}").Handler(GetAppHandler(service, authBackend)).Name("GetApp") + } else { + s1.Methods("GET").Path("/beta/apps/{appID}").Handler(fallback).Name("GetApp") + } + if service, ok := service.(UpdateAppHandlerService); ok { + s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(UpdateAppHandler(service, authBackend)).Name("UpdateApp") + } else { + s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(fallback).Name("UpdateApp") + } + if service, ok := service.(GetGasStationHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(GetGasStationHandler(service, authBackend)).Name("GetGasStation") + } else { + s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(fallback).Name("GetGasStation") + } + if service, ok := service.(GetPoiHandlerService); ok { + s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(GetPoiHandler(service, authBackend)).Name("GetPoi") + } else { + s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(fallback).Name("GetPoi") + } + if service, ok := service.(ChangePoiHandlerService); ok { + s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(ChangePoiHandler(service, authBackend)).Name("ChangePoi") + } else { + s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(fallback).Name("ChangePoi") + } + if service, ok := service.(GetPolicyHandlerService); ok { + s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(GetPolicyHandler(service, authBackend)).Name("GetPolicy") + } else { + s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(fallback).Name("GetPolicy") + } + if service, ok := service.(DeleteSourceHandlerService); ok { + s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(DeleteSourceHandler(service, authBackend)).Name("DeleteSource") + } else { + s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(fallback).Name("DeleteSource") + } + if service, ok := service.(GetSourceHandlerService); ok { + s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(GetSourceHandler(service, authBackend)).Name("GetSource") + } else { + s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(fallback).Name("GetSource") + } + if service, ok := service.(UpdateSourceHandlerService); ok { + s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(UpdateSourceHandler(service, authBackend)).Name("UpdateSource") + } else { + s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(fallback).Name("UpdateSource") + } + if service, ok := service.(DeleteSubscriptionHandlerService); ok { + s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(DeleteSubscriptionHandler(service, authBackend)).Name("DeleteSubscription") + } else { + s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(fallback).Name("DeleteSubscription") + } + if service, ok := service.(StoreSubscriptionHandlerService); ok { + s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(StoreSubscriptionHandler(service, authBackend)).Name("StoreSubscription") + } else { + s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(fallback).Name("StoreSubscription") + } + if service, ok := service.(GetAppsHandlerService); ok { + s1.Methods("GET").Path("/beta/apps").Handler(GetAppsHandler(service, authBackend)).Name("GetApps") + } else { + s1.Methods("GET").Path("/beta/apps").Handler(fallback).Name("GetApps") + } + if service, ok := service.(CreateAppHandlerService); ok { + s1.Methods("POST").Path("/beta/apps").Handler(CreateAppHandler(service, authBackend)).Name("CreateApp") + } else { + s1.Methods("POST").Path("/beta/apps").Handler(fallback).Name("CreateApp") + } + if service, ok := service.(GetEventsHandlerService); ok { + s1.Methods("GET").Path("/beta/events").Handler(GetEventsHandler(service, authBackend)).Name("GetEvents") + } else { + s1.Methods("GET").Path("/beta/events").Handler(fallback).Name("GetEvents") + } + if service, ok := service.(GetGasStationsHandlerService); ok { + s1.Methods("GET").Path("/beta/gas-stations").Handler(GetGasStationsHandler(service, authBackend)).Name("GetGasStations") + } else { + s1.Methods("GET").Path("/beta/gas-stations").Handler(fallback).Name("GetGasStations") + } + if service, ok := service.(GetMetadataFiltersHandlerService); ok { + s1.Methods("GET").Path("/beta/meta").Handler(GetMetadataFiltersHandler(service, authBackend)).Name("GetMetadataFilters") + } else { + s1.Methods("GET").Path("/beta/meta").Handler(fallback).Name("GetMetadataFilters") + } + if service, ok := service.(GetPoisHandlerService); ok { + s1.Methods("GET").Path("/beta/pois").Handler(GetPoisHandler(service, authBackend)).Name("GetPois") + } else { + s1.Methods("GET").Path("/beta/pois").Handler(fallback).Name("GetPois") + } + if service, ok := service.(GetPoliciesHandlerService); ok { + s1.Methods("GET").Path("/beta/policies").Handler(GetPoliciesHandler(service, authBackend)).Name("GetPolicies") + } else { + s1.Methods("GET").Path("/beta/policies").Handler(fallback).Name("GetPolicies") + } + if service, ok := service.(CreatePolicyHandlerService); ok { + s1.Methods("POST").Path("/beta/policies").Handler(CreatePolicyHandler(service, authBackend)).Name("CreatePolicy") + } else { + s1.Methods("POST").Path("/beta/policies").Handler(fallback).Name("CreatePolicy") + } + if service, ok := service.(GetSourcesHandlerService); ok { + s1.Methods("GET").Path("/beta/sources").Handler(GetSourcesHandler(service, authBackend)).Name("GetSources") + } else { + s1.Methods("GET").Path("/beta/sources").Handler(fallback).Name("GetSources") + } + if service, ok := service.(CreateSourceHandlerService); ok { + s1.Methods("POST").Path("/beta/sources").Handler(CreateSourceHandler(service, authBackend)).Name("CreateSource") + } else { + s1.Methods("POST").Path("/beta/sources").Handler(fallback).Name("CreateSource") + } + if service, ok := service.(GetSubscriptionsHandlerService); ok { + s1.Methods("GET").Path("/beta/subscriptions").Handler(GetSubscriptionsHandler(service, authBackend)).Name("GetSubscriptions") + } else { + s1.Methods("GET").Path("/beta/subscriptions").Handler(fallback).Name("GetSubscriptions") + } + return router +} diff --git a/http/jsonapi/generator/internal/securitytest/open-api_test.go b/http/jsonapi/generator/internal/securitytest/open-api_test.go index 545a7a79f..a02fa981d 100644 --- a/http/jsonapi/generator/internal/securitytest/open-api_test.go +++ b/http/jsonapi/generator/internal/securitytest/open-api_test.go @@ -156,3 +156,23 @@ func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { } return router } + +/* +Router implements: PACE Payment API + +Welcome to the PACE Payment API documentation. +This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. +*/ +func RouterWithFallback(service interface{}, authBackend AuthorizationBackend, fallback http.Handler) *mux.Router { + router := mux.NewRouter() + authBackend.InitOAuth2(cfgOAuth2) + authBackend.InitProfileKey(cfgProfileKey) + // Subrouter s1 - Path: /pay + s1 := router.PathPrefix("/pay").Subrouter() + if service, ok := service.(GetTestHandlerService); ok { + s1.Methods("GET").Path("/beta/test").Handler(GetTestHandler(service, authBackend)).Name("GetTest") + } else { + s1.Methods("GET").Path("/beta/test").Handler(fallback).Name("GetTest") + } + return router +} From d159c800edd123f413dba3e2e048790de240e1a6 Mon Sep 17 00:00:00 2001 From: Julius Foitzik Date: Tue, 27 Apr 2021 17:18:05 +0200 Subject: [PATCH 6/6] Add helper to restore one-line readability for routes --- http/jsonapi/generator/generate_handler.go | 106 +++- .../internal/articles/open-api_test.go | 65 +- .../internal/fueling/open-api_test.go | 128 ++-- .../generator/internal/pay/open-api_test.go | 146 ++--- .../generator/internal/poi/open-api_test.go | 564 ++++++++++-------- .../internal/securitytest/open-api_test.go | 21 +- 6 files changed, 546 insertions(+), 484 deletions(-) diff --git a/http/jsonapi/generator/generate_handler.go b/http/jsonapi/generator/generate_handler.go index f4012e586..d1ee45e3a 100644 --- a/http/jsonapi/generator/generate_handler.go +++ b/http/jsonapi/generator/generate_handler.go @@ -75,6 +75,7 @@ func (g *Generator) BuildHandler(schema *openapi3.Swagger) error { funcs := []routeGeneratorFunc{ g.generateRequestResponseTypes, g.buildServiceInterface, + g.buildRouterHelpers, g.buildRouter, g.buildRouterWithFallbackAsArg, } @@ -382,11 +383,63 @@ func (g *Generator) buildRouterWithFallbackAsArg(routes []*route, schema *openap } else { g.goSource.Func().Id("RouterWithFallback").Params( - serviceInterfaceVariable).Op("*").Qual(pkgGorillaMux, "Router").Block(routerBody...) + serviceInterfaceVariable, jen.Id("fallback").Qual("net/http", "Handler")).Op("*").Qual(pkgGorillaMux, "Router").Block(routerBody...) } return nil } +func (g *Generator) buildRouterHelpers(routes []*route, schema *openapi3.Swagger) error { + needsSecurity := hasSecuritySchema(schema) + + // sort the routes with query parameter to the top + sortableRoutes := sortableRouteList(routes) + sort.Stable(&sortableRoutes) + + fallbackName := "fallback" + fallback := jen.Id(fallbackName).Qual("net/http", "Handler") + // add all route handlers + for i := 0; i < len(sortableRoutes); i++ { + route := sortableRoutes[i] + var routeCallParams *jen.Statement + if needsSecurity { + routeCallParams = jen.List(jen.Id("service"), jen.Id("authBackend")) + } else { + routeCallParams = jen.List(jen.Id("service")) + } + primaryHandler := jen.Id(route.handler).Call(routeCallParams) + fallbackHandler := jen.Id(fallbackName) + ifElse := make([]jen.Code, 0) + for _, handler := range []jen.Code{primaryHandler, fallbackHandler} { + block := jen.Return(handler) + ifElse = append(ifElse, block) + } + + if len(ifElse) < 1 { + panic("if-else slice should contain two elements, one with the service interface being called and one passing the NotFoundHandler") + } + + implGuard := jen.If( + jen.List(jen.Id("service"), jen.Id("ok")).Op(":=").Id("service").Assert(jen.Id(generateSubServiceName(route.handler))), + jen.Id("ok")).Block(ifElse[0]).Else().Block(ifElse[1]) + + comment := jen.Commentf("%s helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler.", generateHandlerTypeAssertionHelperName(route.handler)) + + var callParams *jen.Statement + if needsSecurity { + callParams = jen.List(jen.Id("service").Id("interface{}"), fallback, jen.Id("authBackend").Id(authBackendInterface)) + } else { + callParams = jen.List(jen.Id("service").Id("interface{}"), fallback) + } + helper := jen.Func().Id(generateHandlerTypeAssertionHelperName(route.handler)). + Params(callParams).Qual("net/http", "Handler").Block(implGuard).Line().Line() + + g.goSource.Line().Add(comment) + g.goSource.Add(helper) + } + + return nil +} + func (g *Generator) buildRouterBodyWithFallback(routes []*route, schema *openapi3.Swagger, fallback jen.Code) ([]jen.Code, error) { needsSecurity := hasSecuritySchema(schema) startInd := 0 @@ -442,45 +495,30 @@ func (g *Generator) buildRouterBodyWithFallback(routes []*route, schema *openapi route := sortableRoutes[i] var routeCallParams *jen.Statement if needsSecurity { - routeCallParams = jen.List(jen.Id("service"), jen.Id("authBackend")) + routeCallParams = jen.List(jen.Id("service"), fallback, jen.Id("authBackend")) } else { - routeCallParams = jen.List(jen.Id("service")) + routeCallParams = jen.List(jen.Id("service"), fallback) } - primaryHandler := jen.Id(route.handler).Call(routeCallParams) - fallbackHandler := fallback - ifElse := make([]jen.Code, 0) - for _, handler := range []jen.Code{primaryHandler, fallbackHandler} { - // build single route - routeStmt := jen.Id(subrouterID).Dot("Methods").Call(jen.Lit(route.method)). - Dot("Path").Call(jen.Lit(route.url.Path)). - Dot("Handler").Call(handler) - - // add query parameters for route matching - if len(route.queryValues) > 0 { - for key, value := range route.queryValues { - if len(value) != 1 { - panic("query paths can only handle one query parameter with the same name!") - } - routeStmt.Dot("Queries").Call(jen.Lit(key), jen.Lit(value[0])) + helper := jen.Id(generateHandlerTypeAssertionHelperName(route.handler)).Call(routeCallParams) + routeStmt := jen.Id(subrouterID).Dot("Methods").Call(jen.Lit(route.method)). + Dot("Path").Call(jen.Lit(route.url.Path)) + + // add query parameters for route matching + if len(route.queryValues) > 0 { + for key, value := range route.queryValues { + if len(value) != 1 { + panic("query paths can only handle one query parameter with the same name!") } + routeStmt.Dot("Queries").Call(jen.Lit(key), jen.Lit(value[0])) } - - // add the name to build routes - routeStmt.Dot("Name").Call(jen.Lit(route.serviceFunc)) - - // add to control-flow - ifElse = append(ifElse, routeStmt) } - if len(ifElse) < 1 { - panic("if-else slice should contain two elements, one with the service interface being called and one passing the NotFoundHandler") - } + // add the name to build routes + routeStmt.Dot("Name").Call(jen.Lit(route.serviceFunc)) - implGuard := jen.If( - jen.List(jen.Id("service"), jen.Id("ok")).Op(":=").Id("service").Assert(jen.Id(generateSubServiceName(route.handler))), - jen.Id("ok")).Block(ifElse[0]).Else().Block(ifElse[1]) + routeStmt.Dot("Handler").Call(helper) - routeStmts = append(routeStmts, implGuard) + routeStmts = append(routeStmts, routeStmt) } } @@ -821,3 +859,7 @@ func generateParamName(param *openapi3.ParameterRef) string { func generateSubServiceName(handler string) string { return fmt.Sprintf("%s%s", handler, serviceInterface) } + +func generateHandlerTypeAssertionHelperName(handler string) string { + return fmt.Sprintf("%sWithFallbackHelper", handler) +} diff --git a/http/jsonapi/generator/internal/articles/open-api_test.go b/http/jsonapi/generator/internal/articles/open-api_test.go index 12ebb24f2..c91bb3913 100644 --- a/http/jsonapi/generator/internal/articles/open-api_test.go +++ b/http/jsonapi/generator/internal/articles/open-api_test.go @@ -364,30 +364,45 @@ type Service interface { UpdateArticleInlineRefHandlerService } -/* -Router implements: Articles Test Service - -Articles Test Service -*/ -func Router(service interface{}) *mux.Router { - router := mux.NewRouter() - // Subrouter s1 - Path: - s1 := router.PathPrefix("").Subrouter() +// UpdateArticleCommentsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func UpdateArticleCommentsHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(UpdateArticleCommentsHandlerService); ok { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(UpdateArticleCommentsHandler(service)).Name("UpdateArticleComments") + return UpdateArticleCommentsHandler(service) } else { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(router.NotFoundHandler).Name("UpdateArticleComments") + return fallback } +} + +// UpdateArticleInlineTypeHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func UpdateArticleInlineTypeHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(UpdateArticleInlineTypeHandlerService); ok { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(UpdateArticleInlineTypeHandler(service)).Name("UpdateArticleInlineType") + return UpdateArticleInlineTypeHandler(service) } else { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(router.NotFoundHandler).Name("UpdateArticleInlineType") + return fallback } +} + +// UpdateArticleInlineRefHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func UpdateArticleInlineRefHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(UpdateArticleInlineRefHandlerService); ok { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(UpdateArticleInlineRefHandler(service)).Name("UpdateArticleInlineRef") + return UpdateArticleInlineRefHandler(service) } else { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(router.NotFoundHandler).Name("UpdateArticleInlineRef") + return fallback } +} + +/* +Router implements: Articles Test Service + +Articles Test Service +*/ +func Router(service interface{}) *mux.Router { + router := mux.NewRouter() + // Subrouter s1 - Path: + s1 := router.PathPrefix("").Subrouter() + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Name("UpdateArticleComments").Handler(UpdateArticleCommentsHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Name("UpdateArticleInlineType").Handler(UpdateArticleInlineTypeHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Name("UpdateArticleInlineRef").Handler(UpdateArticleInlineRefHandlerWithFallbackHelper(service, router.NotFoundHandler)) return router } @@ -396,24 +411,12 @@ Router implements: Articles Test Service Articles Test Service */ -func RouterWithFallback(service interface{}) *mux.Router { +func RouterWithFallback(service interface{}, fallback http.Handler) *mux.Router { router := mux.NewRouter() // Subrouter s1 - Path: s1 := router.PathPrefix("").Subrouter() - if service, ok := service.(UpdateArticleCommentsHandlerService); ok { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(UpdateArticleCommentsHandler(service)).Name("UpdateArticleComments") - } else { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Handler(fallback).Name("UpdateArticleComments") - } - if service, ok := service.(UpdateArticleInlineTypeHandlerService); ok { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(UpdateArticleInlineTypeHandler(service)).Name("UpdateArticleInlineType") - } else { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Handler(fallback).Name("UpdateArticleInlineType") - } - if service, ok := service.(UpdateArticleInlineRefHandlerService); ok { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(UpdateArticleInlineRefHandler(service)).Name("UpdateArticleInlineRef") - } else { - s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Handler(fallback).Name("UpdateArticleInlineRef") - } + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/comments").Name("UpdateArticleComments").Handler(UpdateArticleCommentsHandlerWithFallbackHelper(service, fallback)) + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inline").Name("UpdateArticleInlineType").Handler(UpdateArticleInlineTypeHandlerWithFallbackHelper(service, fallback)) + s1.Methods("PATCH").Path("/api/articles/{uuid}/relationships/inlineref").Name("UpdateArticleInlineRef").Handler(UpdateArticleInlineRefHandlerWithFallbackHelper(service, fallback)) return router } diff --git a/http/jsonapi/generator/internal/fueling/open-api_test.go b/http/jsonapi/generator/internal/fueling/open-api_test.go index 24a5d49f7..b569e54e1 100644 --- a/http/jsonapi/generator/internal/fueling/open-api_test.go +++ b/http/jsonapi/generator/internal/fueling/open-api_test.go @@ -605,57 +605,61 @@ type Service interface { WaitOnPumpStatusChangeHandlerService } -/* -Router implements: PACE Fueling API - -Fueling API -*/ -func Router(service interface{}) *mux.Router { - router := mux.NewRouter() - // Subrouter s1 - Path: /fueling/beta/ - s1 := router.PathPrefix("/fueling/beta/").Subrouter() +// WaitOnPumpStatusChangeHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func WaitOnPumpStatusChangeHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") + return WaitOnPumpStatusChangeHandler(service) } else { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(router.NotFoundHandler).Name("WaitOnPumpStatusChange") + return fallback } +} + +// GetPumpHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPumpHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(GetPumpHandlerService); ok { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") + return GetPumpHandler(service) } else { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(router.NotFoundHandler).Name("GetPump") + return fallback } +} + +// ProcessPaymentHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func ProcessPaymentHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(ProcessPaymentHandlerService); ok { - s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") + return ProcessPaymentHandler(service) } else { - s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(router.NotFoundHandler).Name("ProcessPayment") + return fallback } +} + +// ApproachingAtTheForecourtHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func ApproachingAtTheForecourtHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { - s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") + return ApproachingAtTheForecourtHandler(service) } else { - s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(router.NotFoundHandler).Name("ApproachingAtTheForecourt") + return fallback } +} + +/* +Router implements: PACE Fueling API + +Fueling API +*/ +func Router(service interface{}) *mux.Router { + router := mux.NewRouter() + // Subrouter s1 - Path: /fueling/beta/ + s1 := router.PathPrefix("/fueling/beta/").Subrouter() + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Name("WaitOnPumpStatusChange").Handler(WaitOnPumpStatusChangeHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Name("GetPump").Handler(GetPumpHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Name("ProcessPayment").Handler(ProcessPaymentHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Name("ApproachingAtTheForecourt").Handler(ApproachingAtTheForecourtHandlerWithFallbackHelper(service, router.NotFoundHandler)) // Subrouter s2 - Path: /fueling/v1/ s2 := router.PathPrefix("/fueling/v1/").Subrouter() - if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") - } else { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(router.NotFoundHandler).Name("WaitOnPumpStatusChange") - } - if service, ok := service.(GetPumpHandlerService); ok { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") - } else { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(router.NotFoundHandler).Name("GetPump") - } - if service, ok := service.(ProcessPaymentHandlerService); ok { - s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") - } else { - s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(router.NotFoundHandler).Name("ProcessPayment") - } - if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { - s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") - } else { - s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(router.NotFoundHandler).Name("ApproachingAtTheForecourt") - } + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Name("WaitOnPumpStatusChange").Handler(WaitOnPumpStatusChangeHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Name("GetPump").Handler(GetPumpHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Name("ProcessPayment").Handler(ProcessPaymentHandlerWithFallbackHelper(service, router.NotFoundHandler)) + s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Name("ApproachingAtTheForecourt").Handler(ApproachingAtTheForecourtHandlerWithFallbackHelper(service, router.NotFoundHandler)) return router } @@ -664,51 +668,19 @@ Router implements: PACE Fueling API Fueling API */ -func RouterWithFallback(service interface{}) *mux.Router { +func RouterWithFallback(service interface{}, fallback http.Handler) *mux.Router { router := mux.NewRouter() // Subrouter s1 - Path: /fueling/beta/ s1 := router.PathPrefix("/fueling/beta/").Subrouter() - if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") - } else { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(fallback).Name("WaitOnPumpStatusChange") - } - if service, ok := service.(GetPumpHandlerService); ok { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") - } else { - s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(fallback).Name("GetPump") - } - if service, ok := service.(ProcessPaymentHandlerService); ok { - s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") - } else { - s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(fallback).Name("ProcessPayment") - } - if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { - s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") - } else { - s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(fallback).Name("ApproachingAtTheForecourt") - } + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Name("WaitOnPumpStatusChange").Handler(WaitOnPumpStatusChangeHandlerWithFallbackHelper(service, fallback)) + s1.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Name("GetPump").Handler(GetPumpHandlerWithFallbackHelper(service, fallback)) + s1.Methods("POST").Path("/gas-station/{gasStationId}/payment").Name("ProcessPayment").Handler(ProcessPaymentHandlerWithFallbackHelper(service, fallback)) + s1.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Name("ApproachingAtTheForecourt").Handler(ApproachingAtTheForecourtHandlerWithFallbackHelper(service, fallback)) // Subrouter s2 - Path: /fueling/v1/ s2 := router.PathPrefix("/fueling/v1/").Subrouter() - if service, ok := service.(WaitOnPumpStatusChangeHandlerService); ok { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(WaitOnPumpStatusChangeHandler(service)).Name("WaitOnPumpStatusChange") - } else { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Handler(fallback).Name("WaitOnPumpStatusChange") - } - if service, ok := service.(GetPumpHandlerService); ok { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(GetPumpHandler(service)).Name("GetPump") - } else { - s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Handler(fallback).Name("GetPump") - } - if service, ok := service.(ProcessPaymentHandlerService); ok { - s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(ProcessPaymentHandler(service)).Name("ProcessPayment") - } else { - s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Handler(fallback).Name("ProcessPayment") - } - if service, ok := service.(ApproachingAtTheForecourtHandlerService); ok { - s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(ApproachingAtTheForecourtHandler(service)).Name("ApproachingAtTheForecourt") - } else { - s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Handler(fallback).Name("ApproachingAtTheForecourt") - } + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change").Name("WaitOnPumpStatusChange").Handler(WaitOnPumpStatusChangeHandlerWithFallbackHelper(service, fallback)) + s2.Methods("GET").Path("/gas-stations/{gasStationId}/pumps/{pumpId}").Name("GetPump").Handler(GetPumpHandlerWithFallbackHelper(service, fallback)) + s2.Methods("POST").Path("/gas-station/{gasStationId}/payment").Name("ProcessPayment").Handler(ProcessPaymentHandlerWithFallbackHelper(service, fallback)) + s2.Methods("POST").Path("/gas-stations/{gasStationId}/approaching").Name("ApproachingAtTheForecourt").Handler(ApproachingAtTheForecourtHandlerWithFallbackHelper(service, fallback)) return router } diff --git a/http/jsonapi/generator/internal/pay/open-api_test.go b/http/jsonapi/generator/internal/pay/open-api_test.go index e8cbeb923..e857dc086 100644 --- a/http/jsonapi/generator/internal/pay/open-api_test.go +++ b/http/jsonapi/generator/internal/pay/open-api_test.go @@ -1015,59 +1015,99 @@ type Service interface { ProcessPaymentHandlerService } -/* -Router implements: PACE Payment API - -Welcome to the PACE Payment API documentation. -This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. -*/ -func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { - router := mux.NewRouter() - authBackend.InitOAuth2(cfgOAuth2) - authBackend.InitOpenID(cfgOpenID) - authBackend.InitProfileKey(cfgProfileKey) - // Subrouter s1 - Path: /pay - s1 := router.PathPrefix("/pay").Subrouter() +// DeletePaymentTokenHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeletePaymentTokenHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeletePaymentTokenHandlerService); ok { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(DeletePaymentTokenHandler(service, authBackend)).Name("DeletePaymentToken") + return DeletePaymentTokenHandler(service, authBackend) } else { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(router.NotFoundHandler).Name("DeletePaymentToken") + return fallback } +} + +// AuthorizePaymentMethodHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func AuthorizePaymentMethodHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(AuthorizePaymentMethodHandlerService); ok { - s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(AuthorizePaymentMethodHandler(service, authBackend)).Name("AuthorizePaymentMethod") + return AuthorizePaymentMethodHandler(service, authBackend) } else { - s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(router.NotFoundHandler).Name("AuthorizePaymentMethod") + return fallback } +} + +// CreatePaymentMethodSEPAHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func CreatePaymentMethodSEPAHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(CreatePaymentMethodSEPAHandlerService); ok { - s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(CreatePaymentMethodSEPAHandler(service, authBackend)).Name("CreatePaymentMethodSEPA") + return CreatePaymentMethodSEPAHandler(service, authBackend) } else { - s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(router.NotFoundHandler).Name("CreatePaymentMethodSEPA") + return fallback } +} + +// DeletePaymentMethodHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeletePaymentMethodHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeletePaymentMethodHandlerService); ok { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(DeletePaymentMethodHandler(service, authBackend)).Name("DeletePaymentMethod") + return DeletePaymentMethodHandler(service, authBackend) } else { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(router.NotFoundHandler).Name("DeletePaymentMethod") + return fallback } +} + +// ProcessPaymentHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func ProcessPaymentHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(ProcessPaymentHandlerService); ok { - s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(ProcessPaymentHandler(service, authBackend)).Name("ProcessPayment") + return ProcessPaymentHandler(service, authBackend) } else { - s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(router.NotFoundHandler).Name("ProcessPayment") + return fallback } +} + +// GetPaymentMethodsIncludingCreditCheckHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPaymentMethodsIncludingCreditCheckHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPaymentMethodsIncludingCreditCheckHandlerService); ok { - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingCreditCheckHandler(service, authBackend)).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") + return GetPaymentMethodsIncludingCreditCheckHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/payment-methods").Handler(router.NotFoundHandler).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") + return fallback } +} + +// GetPaymentMethodsIncludingPaymentTokenHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPaymentMethodsIncludingPaymentTokenHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPaymentMethodsIncludingPaymentTokenHandlerService); ok { - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingPaymentTokenHandler(service, authBackend)).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") + return GetPaymentMethodsIncludingPaymentTokenHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/payment-methods").Handler(router.NotFoundHandler).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") + return fallback } +} + +// GetPaymentMethodsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPaymentMethodsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPaymentMethodsHandlerService); ok { - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsHandler(service, authBackend)).Name("GetPaymentMethods") + return GetPaymentMethodsHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/payment-methods").Handler(router.NotFoundHandler).Name("GetPaymentMethods") + return fallback } +} + +/* +Router implements: PACE Payment API + +Welcome to the PACE Payment API documentation. +This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. +*/ +func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { + router := mux.NewRouter() + authBackend.InitOAuth2(cfgOAuth2) + authBackend.InitOpenID(cfgOpenID) + authBackend.InitProfileKey(cfgProfileKey) + // Subrouter s1 - Path: /pay + s1 := router.PathPrefix("/pay").Subrouter() + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Name("DeletePaymentToken").Handler(DeletePaymentTokenHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Name("AuthorizePaymentMethod").Handler(AuthorizePaymentMethodHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Name("CreatePaymentMethodSEPA").Handler(CreatePaymentMethodSEPAHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Name("DeletePaymentMethod").Handler(DeletePaymentMethodHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Name("ProcessPayment").Handler(ProcessPaymentHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/payment-methods").Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck").Handler(GetPaymentMethodsIncludingCreditCheckHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/payment-methods").Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken").Handler(GetPaymentMethodsIncludingPaymentTokenHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/payment-methods").Name("GetPaymentMethods").Handler(GetPaymentMethodsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) return router } @@ -1084,45 +1124,13 @@ func RouterWithFallback(service interface{}, authBackend AuthorizationBackend, f authBackend.InitProfileKey(cfgProfileKey) // Subrouter s1 - Path: /pay s1 := router.PathPrefix("/pay").Subrouter() - if service, ok := service.(DeletePaymentTokenHandlerService); ok { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(DeletePaymentTokenHandler(service, authBackend)).Name("DeletePaymentToken") - } else { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Handler(fallback).Name("DeletePaymentToken") - } - if service, ok := service.(AuthorizePaymentMethodHandlerService); ok { - s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(AuthorizePaymentMethodHandler(service, authBackend)).Name("AuthorizePaymentMethod") - } else { - s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Handler(fallback).Name("AuthorizePaymentMethod") - } - if service, ok := service.(CreatePaymentMethodSEPAHandlerService); ok { - s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(CreatePaymentMethodSEPAHandler(service, authBackend)).Name("CreatePaymentMethodSEPA") - } else { - s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Handler(fallback).Name("CreatePaymentMethodSEPA") - } - if service, ok := service.(DeletePaymentMethodHandlerService); ok { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(DeletePaymentMethodHandler(service, authBackend)).Name("DeletePaymentMethod") - } else { - s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Handler(fallback).Name("DeletePaymentMethod") - } - if service, ok := service.(ProcessPaymentHandlerService); ok { - s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(ProcessPaymentHandler(service, authBackend)).Name("ProcessPayment") - } else { - s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Handler(fallback).Name("ProcessPayment") - } - if service, ok := service.(GetPaymentMethodsIncludingCreditCheckHandlerService); ok { - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingCreditCheckHandler(service, authBackend)).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") - } else { - s1.Methods("GET").Path("/beta/payment-methods").Handler(fallback).Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck") - } - if service, ok := service.(GetPaymentMethodsIncludingPaymentTokenHandlerService); ok { - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsIncludingPaymentTokenHandler(service, authBackend)).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") - } else { - s1.Methods("GET").Path("/beta/payment-methods").Handler(fallback).Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken") - } - if service, ok := service.(GetPaymentMethodsHandlerService); ok { - s1.Methods("GET").Path("/beta/payment-methods").Handler(GetPaymentMethodsHandler(service, authBackend)).Name("GetPaymentMethods") - } else { - s1.Methods("GET").Path("/beta/payment-methods").Handler(fallback).Name("GetPaymentMethods") - } + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}").Name("DeletePaymentToken").Handler(DeletePaymentTokenHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/beta/payment-methods/{paymentMethodId}/authorize").Name("AuthorizePaymentMethod").Handler(AuthorizePaymentMethodHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/beta/payment-methods/sepa-direct-debit").Name("CreatePaymentMethodSEPA").Handler(CreatePaymentMethodSEPAHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("DELETE").Path("/beta/payment-methods/{paymentMethodId}").Name("DeletePaymentMethod").Handler(DeletePaymentMethodHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/beta/transaction/{pathDecimal}").Name("ProcessPayment").Handler(ProcessPaymentHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/payment-methods").Queries("include", "creditCheck").Name("GetPaymentMethodsIncludingCreditCheck").Handler(GetPaymentMethodsIncludingCreditCheckHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/payment-methods").Queries("include", "paymentToken").Name("GetPaymentMethodsIncludingPaymentToken").Handler(GetPaymentMethodsIncludingPaymentTokenHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/payment-methods").Name("GetPaymentMethods").Handler(GetPaymentMethodsHandlerWithFallbackHelper(service, fallback, authBackend)) return router } diff --git a/http/jsonapi/generator/internal/poi/open-api_test.go b/http/jsonapi/generator/internal/poi/open-api_test.go index 965e78c4d..361afc50a 100644 --- a/http/jsonapi/generator/internal/poi/open-api_test.go +++ b/http/jsonapi/generator/internal/poi/open-api_test.go @@ -4379,198 +4379,378 @@ type Service interface { GetTilesHandlerService } -/* -Router implements: PACE POI API - -POI API -*/ -func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { - router := mux.NewRouter() - authBackend.InitDeviceID(cfgDeviceID) - authBackend.InitOAuth2(cfgOAuth2) - authBackend.InitOIDC(cfgOIDC) - // Subrouter s1 - Path: /poi - s1 := router.PathPrefix("/poi").Subrouter() +// DeleteGasStationReferenceStatusHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeleteGasStationReferenceStatusHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeleteGasStationReferenceStatusHandlerService); ok { - s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(DeleteGasStationReferenceStatusHandler(service, authBackend)).Name("DeleteGasStationReferenceStatus") + return DeleteGasStationReferenceStatusHandler(service, authBackend) } else { - s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(router.NotFoundHandler).Name("DeleteGasStationReferenceStatus") + return fallback } +} + +// PutGasStationReferenceStatusHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func PutGasStationReferenceStatusHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(PutGasStationReferenceStatusHandlerService); ok { - s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(PutGasStationReferenceStatusHandler(service, authBackend)).Name("PutGasStationReferenceStatus") + return PutGasStationReferenceStatusHandler(service, authBackend) } else { - s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(router.NotFoundHandler).Name("PutGasStationReferenceStatus") + return fallback } +} + +// GetAppPOIsRelationshipsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetAppPOIsRelationshipsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetAppPOIsRelationshipsHandlerService); ok { - s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(GetAppPOIsRelationshipsHandler(service, authBackend)).Name("GetAppPOIsRelationships") + return GetAppPOIsRelationshipsHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(router.NotFoundHandler).Name("GetAppPOIsRelationships") + return fallback } +} + +// UpdateAppPOIsRelationshipsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func UpdateAppPOIsRelationshipsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(UpdateAppPOIsRelationshipsHandlerService); ok { - s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(UpdateAppPOIsRelationshipsHandler(service, authBackend)).Name("UpdateAppPOIsRelationships") + return UpdateAppPOIsRelationshipsHandler(service, authBackend) } else { - s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(router.NotFoundHandler).Name("UpdateAppPOIsRelationships") + return fallback } +} + +// GetPriceHistoryHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPriceHistoryHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPriceHistoryHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(GetPriceHistoryHandler(service, authBackend)).Name("GetPriceHistory") + return GetPriceHistoryHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(router.NotFoundHandler).Name("GetPriceHistory") + return fallback } +} + +// DeduplicatePoiHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeduplicatePoiHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeduplicatePoiHandlerService); ok { - s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(DeduplicatePoiHandler(service, authBackend)).Name("DeduplicatePoi") + return DeduplicatePoiHandler(service, authBackend) } else { - s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(router.NotFoundHandler).Name("DeduplicatePoi") + return fallback } +} + +// MovePoiAtPositionHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func MovePoiAtPositionHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(MovePoiAtPositionHandlerService); ok { - s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(MovePoiAtPositionHandler(service, authBackend)).Name("MovePoiAtPosition") + return MovePoiAtPositionHandler(service, authBackend) } else { - s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(router.NotFoundHandler).Name("MovePoiAtPosition") + return fallback } +} + +// GetDuplicatesKMLHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetDuplicatesKMLHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetDuplicatesKMLHandlerService); ok { - s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(GetDuplicatesKMLHandler(service, authBackend)).Name("GetDuplicatesKML") + return GetDuplicatesKMLHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(router.NotFoundHandler).Name("GetDuplicatesKML") + return fallback } +} + +// GetGasStationFuelTypeNameMappingHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetGasStationFuelTypeNameMappingHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetGasStationFuelTypeNameMappingHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(GetGasStationFuelTypeNameMappingHandler(service, authBackend)).Name("GetGasStationFuelTypeNameMapping") + return GetGasStationFuelTypeNameMappingHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(router.NotFoundHandler).Name("GetGasStationFuelTypeNameMapping") + return fallback } +} + +// CheckForPaceAppHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func CheckForPaceAppHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(CheckForPaceAppHandlerService); ok { - s1.Methods("GET").Path("/beta/apps/query").Handler(CheckForPaceAppHandler(service, authBackend)).Name("CheckForPaceApp") + return CheckForPaceAppHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/apps/query").Handler(router.NotFoundHandler).Name("CheckForPaceApp") + return fallback } +} + +// GetPoisDumpHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPoisDumpHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPoisDumpHandlerService); ok { - s1.Methods("GET").Path("/beta/datadumps/pois").Handler(GetPoisDumpHandler(service, authBackend)).Name("GetPoisDump") + return GetPoisDumpHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/datadumps/pois").Handler(router.NotFoundHandler).Name("GetPoisDump") + return fallback } +} + +// GetRegionalPricesHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetRegionalPricesHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetRegionalPricesHandlerService); ok { - s1.Methods("GET").Path("/beta/prices/regional").Handler(GetRegionalPricesHandler(service, authBackend)).Name("GetRegionalPrices") + return GetRegionalPricesHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/prices/regional").Handler(router.NotFoundHandler).Name("GetRegionalPrices") + return fallback } +} + +// GetTilesHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetTilesHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetTilesHandlerService); ok { - s1.Methods("POST").Path("/v1/tiles/query").Handler(GetTilesHandler(service, authBackend)).Name("GetTiles") + return GetTilesHandler(service, authBackend) } else { - s1.Methods("POST").Path("/v1/tiles/query").Handler(router.NotFoundHandler).Name("GetTiles") + return fallback } +} + +// DeleteAppHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeleteAppHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeleteAppHandlerService); ok { - s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(DeleteAppHandler(service, authBackend)).Name("DeleteApp") + return DeleteAppHandler(service, authBackend) } else { - s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(router.NotFoundHandler).Name("DeleteApp") + return fallback } +} + +// GetAppHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetAppHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetAppHandlerService); ok { - s1.Methods("GET").Path("/beta/apps/{appID}").Handler(GetAppHandler(service, authBackend)).Name("GetApp") + return GetAppHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/apps/{appID}").Handler(router.NotFoundHandler).Name("GetApp") + return fallback } +} + +// UpdateAppHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func UpdateAppHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(UpdateAppHandlerService); ok { - s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(UpdateAppHandler(service, authBackend)).Name("UpdateApp") + return UpdateAppHandler(service, authBackend) } else { - s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(router.NotFoundHandler).Name("UpdateApp") + return fallback } +} + +// GetGasStationHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetGasStationHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetGasStationHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(GetGasStationHandler(service, authBackend)).Name("GetGasStation") + return GetGasStationHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(router.NotFoundHandler).Name("GetGasStation") + return fallback } +} + +// GetPoiHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPoiHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPoiHandlerService); ok { - s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(GetPoiHandler(service, authBackend)).Name("GetPoi") + return GetPoiHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(router.NotFoundHandler).Name("GetPoi") + return fallback } +} + +// ChangePoiHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func ChangePoiHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(ChangePoiHandlerService); ok { - s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(ChangePoiHandler(service, authBackend)).Name("ChangePoi") + return ChangePoiHandler(service, authBackend) } else { - s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(router.NotFoundHandler).Name("ChangePoi") + return fallback } +} + +// GetPolicyHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPolicyHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPolicyHandlerService); ok { - s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(GetPolicyHandler(service, authBackend)).Name("GetPolicy") + return GetPolicyHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(router.NotFoundHandler).Name("GetPolicy") + return fallback } +} + +// DeleteSourceHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeleteSourceHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeleteSourceHandlerService); ok { - s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(DeleteSourceHandler(service, authBackend)).Name("DeleteSource") + return DeleteSourceHandler(service, authBackend) } else { - s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(router.NotFoundHandler).Name("DeleteSource") + return fallback } +} + +// GetSourceHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetSourceHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetSourceHandlerService); ok { - s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(GetSourceHandler(service, authBackend)).Name("GetSource") + return GetSourceHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(router.NotFoundHandler).Name("GetSource") + return fallback } +} + +// UpdateSourceHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func UpdateSourceHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(UpdateSourceHandlerService); ok { - s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(UpdateSourceHandler(service, authBackend)).Name("UpdateSource") + return UpdateSourceHandler(service, authBackend) } else { - s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(router.NotFoundHandler).Name("UpdateSource") + return fallback } +} + +// DeleteSubscriptionHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func DeleteSubscriptionHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(DeleteSubscriptionHandlerService); ok { - s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(DeleteSubscriptionHandler(service, authBackend)).Name("DeleteSubscription") + return DeleteSubscriptionHandler(service, authBackend) } else { - s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(router.NotFoundHandler).Name("DeleteSubscription") + return fallback } +} + +// StoreSubscriptionHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func StoreSubscriptionHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(StoreSubscriptionHandlerService); ok { - s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(StoreSubscriptionHandler(service, authBackend)).Name("StoreSubscription") + return StoreSubscriptionHandler(service, authBackend) } else { - s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(router.NotFoundHandler).Name("StoreSubscription") + return fallback } +} + +// GetAppsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetAppsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetAppsHandlerService); ok { - s1.Methods("GET").Path("/beta/apps").Handler(GetAppsHandler(service, authBackend)).Name("GetApps") + return GetAppsHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/apps").Handler(router.NotFoundHandler).Name("GetApps") + return fallback } +} + +// CreateAppHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func CreateAppHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(CreateAppHandlerService); ok { - s1.Methods("POST").Path("/beta/apps").Handler(CreateAppHandler(service, authBackend)).Name("CreateApp") + return CreateAppHandler(service, authBackend) } else { - s1.Methods("POST").Path("/beta/apps").Handler(router.NotFoundHandler).Name("CreateApp") + return fallback } +} + +// GetEventsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetEventsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetEventsHandlerService); ok { - s1.Methods("GET").Path("/beta/events").Handler(GetEventsHandler(service, authBackend)).Name("GetEvents") + return GetEventsHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/events").Handler(router.NotFoundHandler).Name("GetEvents") + return fallback } +} + +// GetGasStationsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetGasStationsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetGasStationsHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations").Handler(GetGasStationsHandler(service, authBackend)).Name("GetGasStations") + return GetGasStationsHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/gas-stations").Handler(router.NotFoundHandler).Name("GetGasStations") + return fallback } +} + +// GetMetadataFiltersHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetMetadataFiltersHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetMetadataFiltersHandlerService); ok { - s1.Methods("GET").Path("/beta/meta").Handler(GetMetadataFiltersHandler(service, authBackend)).Name("GetMetadataFilters") + return GetMetadataFiltersHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/meta").Handler(router.NotFoundHandler).Name("GetMetadataFilters") + return fallback } +} + +// GetPoisHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPoisHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPoisHandlerService); ok { - s1.Methods("GET").Path("/beta/pois").Handler(GetPoisHandler(service, authBackend)).Name("GetPois") + return GetPoisHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/pois").Handler(router.NotFoundHandler).Name("GetPois") + return fallback } +} + +// GetPoliciesHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetPoliciesHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetPoliciesHandlerService); ok { - s1.Methods("GET").Path("/beta/policies").Handler(GetPoliciesHandler(service, authBackend)).Name("GetPolicies") + return GetPoliciesHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/policies").Handler(router.NotFoundHandler).Name("GetPolicies") + return fallback } +} + +// CreatePolicyHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func CreatePolicyHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(CreatePolicyHandlerService); ok { - s1.Methods("POST").Path("/beta/policies").Handler(CreatePolicyHandler(service, authBackend)).Name("CreatePolicy") + return CreatePolicyHandler(service, authBackend) } else { - s1.Methods("POST").Path("/beta/policies").Handler(router.NotFoundHandler).Name("CreatePolicy") + return fallback } +} + +// GetSourcesHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetSourcesHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetSourcesHandlerService); ok { - s1.Methods("GET").Path("/beta/sources").Handler(GetSourcesHandler(service, authBackend)).Name("GetSources") + return GetSourcesHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/sources").Handler(router.NotFoundHandler).Name("GetSources") + return fallback } +} + +// CreateSourceHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func CreateSourceHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(CreateSourceHandlerService); ok { - s1.Methods("POST").Path("/beta/sources").Handler(CreateSourceHandler(service, authBackend)).Name("CreateSource") + return CreateSourceHandler(service, authBackend) } else { - s1.Methods("POST").Path("/beta/sources").Handler(router.NotFoundHandler).Name("CreateSource") + return fallback } +} + +// GetSubscriptionsHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetSubscriptionsHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { if service, ok := service.(GetSubscriptionsHandlerService); ok { - s1.Methods("GET").Path("/beta/subscriptions").Handler(GetSubscriptionsHandler(service, authBackend)).Name("GetSubscriptions") + return GetSubscriptionsHandler(service, authBackend) } else { - s1.Methods("GET").Path("/beta/subscriptions").Handler(router.NotFoundHandler).Name("GetSubscriptions") + return fallback } +} + +/* +Router implements: PACE POI API + +POI API +*/ +func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { + router := mux.NewRouter() + authBackend.InitDeviceID(cfgDeviceID) + authBackend.InitOAuth2(cfgOAuth2) + authBackend.InitOIDC(cfgOIDC) + // Subrouter s1 - Path: /poi + s1 := router.PathPrefix("/poi").Subrouter() + s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Name("DeleteGasStationReferenceStatus").Handler(DeleteGasStationReferenceStatusHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Name("PutGasStationReferenceStatus").Handler(PutGasStationReferenceStatusHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Name("GetAppPOIsRelationships").Handler(GetAppPOIsRelationshipsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Name("UpdateAppPOIsRelationships").Handler(UpdateAppPOIsRelationshipsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Name("GetPriceHistory").Handler(GetPriceHistoryHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Name("DeduplicatePoi").Handler(DeduplicatePoiHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PATCH").Path("/beta/admin/poi/move").Name("MovePoiAtPosition").Handler(MovePoiAtPositionHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Name("GetDuplicatesKML").Handler(GetDuplicatesKMLHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Name("GetGasStationFuelTypeNameMapping").Handler(GetGasStationFuelTypeNameMappingHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/apps/query").Name("CheckForPaceApp").Handler(CheckForPaceAppHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/datadumps/pois").Name("GetPoisDump").Handler(GetPoisDumpHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/prices/regional").Name("GetRegionalPrices").Handler(GetRegionalPricesHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/v1/tiles/query").Name("GetTiles").Handler(GetTilesHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("DELETE").Path("/beta/apps/{appID}").Name("DeleteApp").Handler(DeleteAppHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/apps/{appID}").Name("GetApp").Handler(GetAppHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PUT").Path("/beta/apps/{appID}").Name("UpdateApp").Handler(UpdateAppHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations/{id}").Name("GetGasStation").Handler(GetGasStationHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/pois/{poiId}").Name("GetPoi").Handler(GetPoiHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PATCH").Path("/beta/pois/{poiId}").Name("ChangePoi").Handler(ChangePoiHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/policies/{policyId}").Name("GetPolicy").Handler(GetPolicyHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Name("DeleteSource").Handler(DeleteSourceHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/sources/{sourceId}").Name("GetSource").Handler(GetSourceHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PUT").Path("/beta/sources/{sourceId}").Name("UpdateSource").Handler(UpdateSourceHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Name("DeleteSubscription").Handler(DeleteSubscriptionHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("PUT").Path("/beta/subscriptions/{id}").Name("StoreSubscription").Handler(StoreSubscriptionHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/apps").Name("GetApps").Handler(GetAppsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/beta/apps").Name("CreateApp").Handler(CreateAppHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/events").Name("GetEvents").Handler(GetEventsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations").Name("GetGasStations").Handler(GetGasStationsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/meta").Name("GetMetadataFilters").Handler(GetMetadataFiltersHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/pois").Name("GetPois").Handler(GetPoisHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/policies").Name("GetPolicies").Handler(GetPoliciesHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/beta/policies").Name("CreatePolicy").Handler(CreatePolicyHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/sources").Name("GetSources").Handler(GetSourcesHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("POST").Path("/beta/sources").Name("CreateSource").Handler(CreateSourceHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) + s1.Methods("GET").Path("/beta/subscriptions").Name("GetSubscriptions").Handler(GetSubscriptionsHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) return router } @@ -4586,185 +4766,41 @@ func RouterWithFallback(service interface{}, authBackend AuthorizationBackend, f authBackend.InitOIDC(cfgOIDC) // Subrouter s1 - Path: /poi s1 := router.PathPrefix("/poi").Subrouter() - if service, ok := service.(DeleteGasStationReferenceStatusHandlerService); ok { - s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(DeleteGasStationReferenceStatusHandler(service, authBackend)).Name("DeleteGasStationReferenceStatus") - } else { - s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(fallback).Name("DeleteGasStationReferenceStatus") - } - if service, ok := service.(PutGasStationReferenceStatusHandlerService); ok { - s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(PutGasStationReferenceStatusHandler(service, authBackend)).Name("PutGasStationReferenceStatus") - } else { - s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Handler(fallback).Name("PutGasStationReferenceStatus") - } - if service, ok := service.(GetAppPOIsRelationshipsHandlerService); ok { - s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(GetAppPOIsRelationshipsHandler(service, authBackend)).Name("GetAppPOIsRelationships") - } else { - s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Handler(fallback).Name("GetAppPOIsRelationships") - } - if service, ok := service.(UpdateAppPOIsRelationshipsHandlerService); ok { - s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(UpdateAppPOIsRelationshipsHandler(service, authBackend)).Name("UpdateAppPOIsRelationships") - } else { - s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Handler(fallback).Name("UpdateAppPOIsRelationships") - } - if service, ok := service.(GetPriceHistoryHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(GetPriceHistoryHandler(service, authBackend)).Name("GetPriceHistory") - } else { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Handler(fallback).Name("GetPriceHistory") - } - if service, ok := service.(DeduplicatePoiHandlerService); ok { - s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(DeduplicatePoiHandler(service, authBackend)).Name("DeduplicatePoi") - } else { - s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Handler(fallback).Name("DeduplicatePoi") - } - if service, ok := service.(MovePoiAtPositionHandlerService); ok { - s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(MovePoiAtPositionHandler(service, authBackend)).Name("MovePoiAtPosition") - } else { - s1.Methods("PATCH").Path("/beta/admin/poi/move").Handler(fallback).Name("MovePoiAtPosition") - } - if service, ok := service.(GetDuplicatesKMLHandlerService); ok { - s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(GetDuplicatesKMLHandler(service, authBackend)).Name("GetDuplicatesKML") - } else { - s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Handler(fallback).Name("GetDuplicatesKML") - } - if service, ok := service.(GetGasStationFuelTypeNameMappingHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(GetGasStationFuelTypeNameMappingHandler(service, authBackend)).Name("GetGasStationFuelTypeNameMapping") - } else { - s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Handler(fallback).Name("GetGasStationFuelTypeNameMapping") - } - if service, ok := service.(CheckForPaceAppHandlerService); ok { - s1.Methods("GET").Path("/beta/apps/query").Handler(CheckForPaceAppHandler(service, authBackend)).Name("CheckForPaceApp") - } else { - s1.Methods("GET").Path("/beta/apps/query").Handler(fallback).Name("CheckForPaceApp") - } - if service, ok := service.(GetPoisDumpHandlerService); ok { - s1.Methods("GET").Path("/beta/datadumps/pois").Handler(GetPoisDumpHandler(service, authBackend)).Name("GetPoisDump") - } else { - s1.Methods("GET").Path("/beta/datadumps/pois").Handler(fallback).Name("GetPoisDump") - } - if service, ok := service.(GetRegionalPricesHandlerService); ok { - s1.Methods("GET").Path("/beta/prices/regional").Handler(GetRegionalPricesHandler(service, authBackend)).Name("GetRegionalPrices") - } else { - s1.Methods("GET").Path("/beta/prices/regional").Handler(fallback).Name("GetRegionalPrices") - } - if service, ok := service.(GetTilesHandlerService); ok { - s1.Methods("POST").Path("/v1/tiles/query").Handler(GetTilesHandler(service, authBackend)).Name("GetTiles") - } else { - s1.Methods("POST").Path("/v1/tiles/query").Handler(fallback).Name("GetTiles") - } - if service, ok := service.(DeleteAppHandlerService); ok { - s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(DeleteAppHandler(service, authBackend)).Name("DeleteApp") - } else { - s1.Methods("DELETE").Path("/beta/apps/{appID}").Handler(fallback).Name("DeleteApp") - } - if service, ok := service.(GetAppHandlerService); ok { - s1.Methods("GET").Path("/beta/apps/{appID}").Handler(GetAppHandler(service, authBackend)).Name("GetApp") - } else { - s1.Methods("GET").Path("/beta/apps/{appID}").Handler(fallback).Name("GetApp") - } - if service, ok := service.(UpdateAppHandlerService); ok { - s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(UpdateAppHandler(service, authBackend)).Name("UpdateApp") - } else { - s1.Methods("PUT").Path("/beta/apps/{appID}").Handler(fallback).Name("UpdateApp") - } - if service, ok := service.(GetGasStationHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(GetGasStationHandler(service, authBackend)).Name("GetGasStation") - } else { - s1.Methods("GET").Path("/beta/gas-stations/{id}").Handler(fallback).Name("GetGasStation") - } - if service, ok := service.(GetPoiHandlerService); ok { - s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(GetPoiHandler(service, authBackend)).Name("GetPoi") - } else { - s1.Methods("GET").Path("/beta/pois/{poiId}").Handler(fallback).Name("GetPoi") - } - if service, ok := service.(ChangePoiHandlerService); ok { - s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(ChangePoiHandler(service, authBackend)).Name("ChangePoi") - } else { - s1.Methods("PATCH").Path("/beta/pois/{poiId}").Handler(fallback).Name("ChangePoi") - } - if service, ok := service.(GetPolicyHandlerService); ok { - s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(GetPolicyHandler(service, authBackend)).Name("GetPolicy") - } else { - s1.Methods("GET").Path("/beta/policies/{policyId}").Handler(fallback).Name("GetPolicy") - } - if service, ok := service.(DeleteSourceHandlerService); ok { - s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(DeleteSourceHandler(service, authBackend)).Name("DeleteSource") - } else { - s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Handler(fallback).Name("DeleteSource") - } - if service, ok := service.(GetSourceHandlerService); ok { - s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(GetSourceHandler(service, authBackend)).Name("GetSource") - } else { - s1.Methods("GET").Path("/beta/sources/{sourceId}").Handler(fallback).Name("GetSource") - } - if service, ok := service.(UpdateSourceHandlerService); ok { - s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(UpdateSourceHandler(service, authBackend)).Name("UpdateSource") - } else { - s1.Methods("PUT").Path("/beta/sources/{sourceId}").Handler(fallback).Name("UpdateSource") - } - if service, ok := service.(DeleteSubscriptionHandlerService); ok { - s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(DeleteSubscriptionHandler(service, authBackend)).Name("DeleteSubscription") - } else { - s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Handler(fallback).Name("DeleteSubscription") - } - if service, ok := service.(StoreSubscriptionHandlerService); ok { - s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(StoreSubscriptionHandler(service, authBackend)).Name("StoreSubscription") - } else { - s1.Methods("PUT").Path("/beta/subscriptions/{id}").Handler(fallback).Name("StoreSubscription") - } - if service, ok := service.(GetAppsHandlerService); ok { - s1.Methods("GET").Path("/beta/apps").Handler(GetAppsHandler(service, authBackend)).Name("GetApps") - } else { - s1.Methods("GET").Path("/beta/apps").Handler(fallback).Name("GetApps") - } - if service, ok := service.(CreateAppHandlerService); ok { - s1.Methods("POST").Path("/beta/apps").Handler(CreateAppHandler(service, authBackend)).Name("CreateApp") - } else { - s1.Methods("POST").Path("/beta/apps").Handler(fallback).Name("CreateApp") - } - if service, ok := service.(GetEventsHandlerService); ok { - s1.Methods("GET").Path("/beta/events").Handler(GetEventsHandler(service, authBackend)).Name("GetEvents") - } else { - s1.Methods("GET").Path("/beta/events").Handler(fallback).Name("GetEvents") - } - if service, ok := service.(GetGasStationsHandlerService); ok { - s1.Methods("GET").Path("/beta/gas-stations").Handler(GetGasStationsHandler(service, authBackend)).Name("GetGasStations") - } else { - s1.Methods("GET").Path("/beta/gas-stations").Handler(fallback).Name("GetGasStations") - } - if service, ok := service.(GetMetadataFiltersHandlerService); ok { - s1.Methods("GET").Path("/beta/meta").Handler(GetMetadataFiltersHandler(service, authBackend)).Name("GetMetadataFilters") - } else { - s1.Methods("GET").Path("/beta/meta").Handler(fallback).Name("GetMetadataFilters") - } - if service, ok := service.(GetPoisHandlerService); ok { - s1.Methods("GET").Path("/beta/pois").Handler(GetPoisHandler(service, authBackend)).Name("GetPois") - } else { - s1.Methods("GET").Path("/beta/pois").Handler(fallback).Name("GetPois") - } - if service, ok := service.(GetPoliciesHandlerService); ok { - s1.Methods("GET").Path("/beta/policies").Handler(GetPoliciesHandler(service, authBackend)).Name("GetPolicies") - } else { - s1.Methods("GET").Path("/beta/policies").Handler(fallback).Name("GetPolicies") - } - if service, ok := service.(CreatePolicyHandlerService); ok { - s1.Methods("POST").Path("/beta/policies").Handler(CreatePolicyHandler(service, authBackend)).Name("CreatePolicy") - } else { - s1.Methods("POST").Path("/beta/policies").Handler(fallback).Name("CreatePolicy") - } - if service, ok := service.(GetSourcesHandlerService); ok { - s1.Methods("GET").Path("/beta/sources").Handler(GetSourcesHandler(service, authBackend)).Name("GetSources") - } else { - s1.Methods("GET").Path("/beta/sources").Handler(fallback).Name("GetSources") - } - if service, ok := service.(CreateSourceHandlerService); ok { - s1.Methods("POST").Path("/beta/sources").Handler(CreateSourceHandler(service, authBackend)).Name("CreateSource") - } else { - s1.Methods("POST").Path("/beta/sources").Handler(fallback).Name("CreateSource") - } - if service, ok := service.(GetSubscriptionsHandlerService); ok { - s1.Methods("GET").Path("/beta/subscriptions").Handler(GetSubscriptionsHandler(service, authBackend)).Name("GetSubscriptions") - } else { - s1.Methods("GET").Path("/beta/subscriptions").Handler(fallback).Name("GetSubscriptions") - } + s1.Methods("DELETE").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Name("DeleteGasStationReferenceStatus").Handler(DeleteGasStationReferenceStatusHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PUT").Path("/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}").Name("PutGasStationReferenceStatus").Handler(PutGasStationReferenceStatusHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/apps/{appID}/relationships/pois").Name("GetAppPOIsRelationships").Handler(GetAppPOIsRelationshipsHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PATCH").Path("/beta/apps/{appID}/relationships/pois").Name("UpdateAppPOIsRelationships").Handler(UpdateAppPOIsRelationshipsHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}").Name("GetPriceHistory").Handler(GetPriceHistoryHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PATCH").Path("/beta/admin/poi/dedupe").Name("DeduplicatePoi").Handler(DeduplicatePoiHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PATCH").Path("/beta/admin/poi/move").Name("MovePoiAtPosition").Handler(MovePoiAtPositionHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/datadumps/duplicatemap/{countryCode}").Name("GetDuplicatesKML").Handler(GetDuplicatesKMLHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations/{id}/fueltype").Name("GetGasStationFuelTypeNameMapping").Handler(GetGasStationFuelTypeNameMappingHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/apps/query").Name("CheckForPaceApp").Handler(CheckForPaceAppHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/datadumps/pois").Name("GetPoisDump").Handler(GetPoisDumpHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/prices/regional").Name("GetRegionalPrices").Handler(GetRegionalPricesHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/v1/tiles/query").Name("GetTiles").Handler(GetTilesHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("DELETE").Path("/beta/apps/{appID}").Name("DeleteApp").Handler(DeleteAppHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/apps/{appID}").Name("GetApp").Handler(GetAppHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PUT").Path("/beta/apps/{appID}").Name("UpdateApp").Handler(UpdateAppHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations/{id}").Name("GetGasStation").Handler(GetGasStationHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/pois/{poiId}").Name("GetPoi").Handler(GetPoiHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PATCH").Path("/beta/pois/{poiId}").Name("ChangePoi").Handler(ChangePoiHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/policies/{policyId}").Name("GetPolicy").Handler(GetPolicyHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("DELETE").Path("/beta/sources/{sourceId}").Name("DeleteSource").Handler(DeleteSourceHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/sources/{sourceId}").Name("GetSource").Handler(GetSourceHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PUT").Path("/beta/sources/{sourceId}").Name("UpdateSource").Handler(UpdateSourceHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("DELETE").Path("/beta/subscriptions/{id}").Name("DeleteSubscription").Handler(DeleteSubscriptionHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("PUT").Path("/beta/subscriptions/{id}").Name("StoreSubscription").Handler(StoreSubscriptionHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/apps").Name("GetApps").Handler(GetAppsHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/beta/apps").Name("CreateApp").Handler(CreateAppHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/events").Name("GetEvents").Handler(GetEventsHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/gas-stations").Name("GetGasStations").Handler(GetGasStationsHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/meta").Name("GetMetadataFilters").Handler(GetMetadataFiltersHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/pois").Name("GetPois").Handler(GetPoisHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/policies").Name("GetPolicies").Handler(GetPoliciesHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/beta/policies").Name("CreatePolicy").Handler(CreatePolicyHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/sources").Name("GetSources").Handler(GetSourcesHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("POST").Path("/beta/sources").Name("CreateSource").Handler(CreateSourceHandlerWithFallbackHelper(service, fallback, authBackend)) + s1.Methods("GET").Path("/beta/subscriptions").Name("GetSubscriptions").Handler(GetSubscriptionsHandlerWithFallbackHelper(service, fallback, authBackend)) return router } diff --git a/http/jsonapi/generator/internal/securitytest/open-api_test.go b/http/jsonapi/generator/internal/securitytest/open-api_test.go index a02fa981d..76872c07a 100644 --- a/http/jsonapi/generator/internal/securitytest/open-api_test.go +++ b/http/jsonapi/generator/internal/securitytest/open-api_test.go @@ -137,6 +137,15 @@ type Service interface { GetTestHandlerService } +// GetTestHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetTestHandlerWithFallbackHelper(service interface{}, fallback http.Handler, authBackend AuthorizationBackend) http.Handler { + if service, ok := service.(GetTestHandlerService); ok { + return GetTestHandler(service, authBackend) + } else { + return fallback + } +} + /* Router implements: PACE Payment API @@ -149,11 +158,7 @@ func Router(service interface{}, authBackend AuthorizationBackend) *mux.Router { authBackend.InitProfileKey(cfgProfileKey) // Subrouter s1 - Path: /pay s1 := router.PathPrefix("/pay").Subrouter() - if service, ok := service.(GetTestHandlerService); ok { - s1.Methods("GET").Path("/beta/test").Handler(GetTestHandler(service, authBackend)).Name("GetTest") - } else { - s1.Methods("GET").Path("/beta/test").Handler(router.NotFoundHandler).Name("GetTest") - } + s1.Methods("GET").Path("/beta/test").Name("GetTest").Handler(GetTestHandlerWithFallbackHelper(service, router.NotFoundHandler, authBackend)) return router } @@ -169,10 +174,6 @@ func RouterWithFallback(service interface{}, authBackend AuthorizationBackend, f authBackend.InitProfileKey(cfgProfileKey) // Subrouter s1 - Path: /pay s1 := router.PathPrefix("/pay").Subrouter() - if service, ok := service.(GetTestHandlerService); ok { - s1.Methods("GET").Path("/beta/test").Handler(GetTestHandler(service, authBackend)).Name("GetTest") - } else { - s1.Methods("GET").Path("/beta/test").Handler(fallback).Name("GetTest") - } + s1.Methods("GET").Path("/beta/test").Name("GetTest").Handler(GetTestHandlerWithFallbackHelper(service, fallback, authBackend)) return router }