From 53faed02356743567f443470058a8ac5470c7273 Mon Sep 17 00:00:00 2001 From: Ahmad Faiz Kamaludin Date: Fri, 17 Oct 2025 07:08:27 +0700 Subject: [PATCH 1/6] feat: upgrade project dependency --- go.mod | 4 ++-- go.sum | 8 ++++---- go.work.sum | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index fd77354..dcc7eb7 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.21 require ( github.com/google/go-cmp v0.7.0 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 github.com/swaggest/jsonschema-go v0.3.78 - github.com/swaggest/openapi-go v0.2.59 + github.com/swaggest/openapi-go v0.2.60 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 2964851..2ddf1d2 100644 --- a/go.sum +++ b/go.sum @@ -14,14 +14,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= diff --git a/go.work.sum b/go.work.sum index 8a0da6d..c58e3bc 100644 --- a/go.work.sum +++ b/go.work.sum @@ -5,6 +5,7 @@ github.com/bool64/dev v0.2.29/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8 github.com/bool64/dev v0.2.31/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= github.com/bool64/dev v0.2.38/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -14,44 +15,59 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/knz/go-libedit v1.10.1 h1:0pHpWtx9vcvC0xGZqEQlQdfSQs7WRlAjuPvk3fOZDCo= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= 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.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oaswrap/spec/module/specui v0.3.1 h1:IENi94l8UVDK88Rv/Crhq0MgUFWIpETO/01zFXMaf10= github.com/oaswrap/spec/module/specui v0.3.1/go.mod h1:JA0E9IwEjEZEVQzn4ZDOeVECHmCSaAflS3RxUYJhi0A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.15.2 h1:l77YT15o814C2qVL47NOyjV/6RbaP7kKdrvZnxQ3Org= github.com/onsi/ginkgo v1.15.2/go.mod h1:Dd6YFfwBW84ETqqtL0CPyPXillHgY6XhQH3uuCCTr/o= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug= github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg= +github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c h1:dAMKvw0MlJT1GshSTtih8C2gDs04w8dReiOGXrGLNoY= github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0/go.mod h1:919LwcH0M7/W4fcZ0/jy0qGght1GIhqyS/EgWGH2j5Q= github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/swaggest/jsonschema-go v0.3.74/go.mod h1:qp+Ym2DIXHlHzch3HKz50gPf2wJhKOrAB/VYqLS2oJU= github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= github.com/swaggest/refl v1.3.1/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= +github.com/tinylib/msgp v1.2.5 h1:WeQg1whrXRFiZusidTQqzETkRpGjFjcIhW6uqWH09po= github.com/tinylib/msgp v1.2.5/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0= github.com/vearutop/statigz v1.4.0/go.mod h1:LYTolBLiz9oJISwiVKnOQoIwhO1LWX1A7OECawGS8XE= +github.com/yosuke-furukawa/json5 v0.1.2-0.20201207051438-cf7bb3f354ff h1:7YqG491bE4vstXRz1lD38rbSgbXnirvROz1lZiOnPO8= github.com/yosuke-furukawa/json5 v0.1.2-0.20201207051438-cf7bb3f354ff/go.mod h1:sw49aWDqNdRJ6DYUtIQiaA3xyj2IL9tjeNYmX2ixwcU= +github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -66,6 +82,7 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -92,6 +109,7 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 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= @@ -115,6 +133,7 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -127,6 +146,7 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -137,6 +157,7 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -144,10 +165,12 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= @@ -156,9 +179,13 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +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.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +nullprogram.com/x/optparse v1.0.0 h1:xGFgVi5ZaWOnYdac2foDT3vg0ZZC9ErXFV57mr4OHrI= +rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4= From ca5221e9b26056314dd9c6a1f585d72c426b5547 Mon Sep 17 00:00:00 2001 From: Ahmad Faiz Kamaludin Date: Fri, 17 Oct 2025 07:09:45 +0700 Subject: [PATCH 2/6] feat: add linter config and precommit --- .golangci.yml | 458 +++++++++++++++++++++++ adapter/chiopenapi/router_test.go | 2 +- adapter/echoopenapi/router_test.go | 2 +- adapter/fiberopenapi/router_test.go | 2 +- adapter/ginopenapi/router_test.go | 2 +- adapter/httpopenapi/router_test.go | 2 +- adapter/httprouteropenapi/router_test.go | 2 +- adapter/muxopenapi/router_test.go | 2 +- internal/debuglog/debuglog.go | 9 +- internal/debuglog/debuglog_test.go | 29 +- internal/{errors => errs}/error.go | 2 +- internal/{errors => errs}/error_test.go | 21 +- internal/mapper/openapi3.go | 10 +- internal/mapper/openapi31.go | 8 +- jsonschema.go | 21 +- lefthook.yml | 30 ++ operation.go | 77 ++-- option/openapi.go | 13 +- option/openapi_test.go | 2 +- option/reflector_test.go | 9 +- pkg/dto/pet.go | 16 +- pkg/parser/colon_param_parser_test.go | 3 +- pkg/util/util.go | 2 +- reflector.go | 12 +- reflector3.go | 8 +- reflector31.go | 8 +- router.go | 57 +-- router_test.go | 84 +++-- 28 files changed, 726 insertions(+), 167 deletions(-) create mode 100644 .golangci.yml rename internal/{errors => errs}/error.go (98%) rename internal/{errors => errs}/error_test.go (84%) create mode 100644 lefthook.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..7daf9fe --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,458 @@ +version: "2" + +issues: + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 50 + +formatters: + enable: + - goimports # checks if the code and import statements are formatted according to the 'goimports' command + - golines # checks if code is formatted, and fixes long lines + + ## you may want to enable + #- gci # checks if code and import statements are formatted, with additional rules + #- gofmt # checks if the code is formatted according to 'gofmt' command + #- gofumpt # enforces a stricter format than 'gofmt', while being backwards compatible + #- swaggo # formats swaggo comments + + # All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml + settings: + goimports: + # A list of prefixes, which, if set, checks import paths + # with the given prefixes are grouped after 3rd-party packages. + # Default: [] + local-prefixes: + - github.com/my/project + + golines: + # Target maximum line length. + # Default: 100 + max-len: 120 + +linters: + enable: + - asasalint # checks for pass []any as any in variadic func(...any) + - asciicheck # checks that your code does not contain non-ASCII identifiers + - bidichk # checks for dangerous unicode character sequences + - bodyclose # checks whether HTTP response body is closed successfully + - canonicalheader # checks whether net/http.Header uses canonical header + - copyloopvar # detects places where loop variables are copied (Go 1.22+) + - cyclop # checks function and package cyclomatic complexity + - depguard # checks if package imports are in a list of acceptable packages + - dupl # tool for code clone detection + - durationcheck # checks for two durations multiplied together + - embeddedstructfieldcheck # checks embedded types in structs + - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases + - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error + - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 + - exhaustive # checks exhaustiveness of enum switch statements + - exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions + - fatcontext # detects nested contexts in loops + - forbidigo # forbids identifiers + - funcorder # checks the order of functions, methods, and constructors + - funlen # tool for detection of long functions + - gocheckcompilerdirectives # validates go compiler directive comments (//go:) + - gochecknoglobals # checks that no global variables exist + - gochecknoinits # checks that no init functions are present in Go code + - gochecksumtype # checks exhaustiveness on Go "sum types" + - gocognit # computes and checks the cognitive complexity of functions + - goconst # finds repeated strings that could be replaced by a constant + - gocritic # provides diagnostics that check for bugs, performance and style issues + - gocyclo # computes and checks the cyclomatic complexity of functions + - godoclint # checks Golang's documentation practice + - godot # checks if comments end in a period + - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod + - goprintffuncname # checks that printf-like functions are named with f at the end + - gosec # inspects source code for security problems + - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string + - iface # checks the incorrect use of interfaces, helping developers avoid interface pollution + - ineffassign # detects when assignments to existing variables are not used + - intrange # finds places where for loops could make use of an integer range + - iotamixing # checks if iotas are being used in const blocks with other non-iota declarations + - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) + - makezero # finds slice declarations with non-zero initial length + - mirror # reports wrong mirror patterns of bytes/strings usage + - mnd # detects magic numbers + - musttag # enforces field tags in (un)marshaled structs + - nakedret # finds naked returns in functions greater than a specified function length + - nestif # reports deeply nested if statements + - nilerr # finds the code that returns nil even if it checks that the error is not nil + - nilnesserr # reports that it checks for err != nil, but it returns a different nil value error (powered by nilness and nilerr) + - nilnil # checks that there is no simultaneous return of nil error and an invalid value + - noctx # finds sending http request without context.Context + - nolintlint # reports ill-formed or insufficient nolint directives + - nonamedreturns # reports all named returns + - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL + - perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative + - predeclared # finds code that shadows one of Go's predeclared identifiers + - promlinter # checks Prometheus metrics naming via promlint + - protogetter # reports direct reads from proto message fields when getters should be used + - reassign # checks that package variables are not reassigned + - recvcheck # checks for receiver type consistency + - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint + - rowserrcheck # checks whether Err of rows is checked successfully + - sloglint # ensure consistent code style when using log/slog + - spancheck # checks for mistakes with OpenTelemetry/Census spans + - sqlclosecheck # checks that sql.Rows and sql.Stmt are closed + - staticcheck # is a go vet on steroids, applying a ton of static analysis checks + - testableexamples # checks if examples are testable (have an expected output) + - testifylint # checks usage of github.com/stretchr/testify + - testpackage # makes you use a separate _test package + - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes + - unconvert # removes unnecessary type conversions + - unparam # reports unused function parameters + - unqueryvet # detects SELECT * in SQL queries and SQL builders, encouraging explicit column selection + - unused # checks for unused constants, variables, functions and types + - usestdlibvars # detects the possibility to use variables/constants from the Go standard library + - usetesting # reports uses of functions with replacement inside the testing package + - wastedassign # finds wasted assignment statements + - whitespace # detects leading and trailing whitespace + + ## you may want to enable + #- arangolint # opinionated best practices for arangodb client + #- decorder # checks declaration order and count of types, constants, variables and functions + #- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized + #- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega + #- godox # detects usage of FIXME, TODO and other keywords inside comments + #- goheader # checks is file header matches to pattern + #- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters + #- interfacebloat # checks the number of methods inside an interface + #- ireturn # accept interfaces, return concrete types + #- noinlineerr # disallows inline error handling `if err := ...; err != nil {` + #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated + #- tagalign # checks that struct tags are well aligned + #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope + #- wrapcheck # checks that errors returned from external packages are wrapped + #- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event + + ## disabled + #- containedctx # detects struct contained context.Context field + #- contextcheck # [too many false positives] checks the function whether use a non-inherited context + #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) + #- dupword # [useless without config] checks for duplicate words in the source code + #- err113 # [too strict] checks the errors handling expressions + #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted + #- forcetypeassert # [replaced by errcheck] finds forced type assertions + #- gomodguard # [use more powerful depguard] allow and block lists linter for direct Go module dependencies + #- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase + #- grouper # analyzes expression groups + #- importas # enforces consistent import aliases + #- lll # [replaced by golines] reports long lines + #- maintidx # measures the maintainability index of each function + #- misspell # [useless] finds commonly misspelled English words in comments + #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity + #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test + #- tagliatelle # checks the struct tags + #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers + #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines + #- wsl_v5 # [too strict and mostly code is not more readable] add or remove empty lines + + # All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml + settings: + cyclop: + # The maximal code complexity to report. + # Default: 10 + max-complexity: 30 + # The maximal average package complexity. + # If it's higher than 0.0 (float) the check is enabled. + # Default: 0.0 + package-average: 10.0 + + depguard: + # Rules to apply. + # + # Variables: + # - File Variables + # Use an exclamation mark `!` to negate a variable. + # Example: `!$test` matches any file that is not a go test file. + # + # `$all` - matches all go files + # `$test` - matches all go test files + # + # - Package Variables + # + # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`) + # + # Default (applies if no custom rules are defined): Only allow $gostd in all files. + rules: + "deprecated": + # List of file globs that will match this list of settings to compare against. + # By default, if a path is relative, it is relative to the directory where the golangci-lint command is executed. + # The placeholder '${base-path}' is substituted with a path relative to the mode defined with `run.relative-path-mode`. + # The placeholder '${config-path}' is substituted with a path relative to the configuration file. + # Default: $all + files: + - "$all" + # List of packages that are not allowed. + # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $). + # Default: [] + deny: + - pkg: github.com/golang/protobuf + desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules + - pkg: github.com/satori/go.uuid + desc: Use github.com/google/uuid instead, satori's package is not maintained + - pkg: github.com/gofrs/uuid$ + desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5 + "non-test files": + files: + - "!$test" + deny: + - pkg: math/rand$ + desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2 + "non-main files": + files: + - "!**/main.go" + deny: + - pkg: log$ + desc: Use log/slog instead, see https://go.dev/blog/slog + + embeddedstructfieldcheck: + # Checks that sync.Mutex and sync.RWMutex are not used as embedded fields. + # Default: false + forbid-mutex: true + + errcheck: + # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. + # Such cases aren't reported by default. + # Default: false + check-type-assertions: true + + exhaustive: + # Program elements to check for exhaustiveness. + # Default: [ switch ] + check: + - switch + - map + + exhaustruct: + # List of regular expressions to match type names that should be excluded from processing. + # Anonymous structs can be matched by '' alias. + # Has precedence over `include`. + # Each regular expression must match the full type name, including package path. + # For example, to match type `net/http.Cookie` regular expression should be `.*/http\.Cookie`, + # but not `http\.Cookie`. + # Default: [] + exclude: + # std libs + - ^net/http.Client$ + - ^net/http.Cookie$ + - ^net/http.Request$ + - ^net/http.Response$ + - ^net/http.Server$ + - ^net/http.Transport$ + - ^net/url.URL$ + - ^os/exec.Cmd$ + - ^reflect.StructField$ + # public libs + - ^github.com/Shopify/sarama.Config$ + - ^github.com/Shopify/sarama.ProducerMessage$ + - ^github.com/mitchellh/mapstructure.DecoderConfig$ + - ^github.com/prometheus/client_golang/.+Opts$ + - ^github.com/spf13/cobra.Command$ + - ^github.com/spf13/cobra.CompletionOptions$ + - ^github.com/stretchr/testify/mock.Mock$ + - ^github.com/testcontainers/testcontainers-go.+Request$ + - ^github.com/testcontainers/testcontainers-go.FromDockerfile$ + - ^golang.org/x/tools/go/analysis.Analyzer$ + - ^google.golang.org/protobuf/.+Options$ + - ^gopkg.in/yaml.v3.Node$ + # Allows empty structures in return statements. + # Default: false + allow-empty-returns: true + + funcorder: + # Checks if the exported methods of a structure are placed before the non-exported ones. + # Default: true + struct-method: false + + funlen: + # Checks the number of lines in a function. + # If lower than 0, disable the check. + # Default: 60 + lines: 100 + # Checks the number of statements in a function. + # If lower than 0, disable the check. + # Default: 40 + statements: 50 + + gochecksumtype: + # Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed. + # Default: true + default-signifies-exhaustive: false + + gocognit: + # Minimal code complexity to report. + # Default: 30 (but we recommend 10-20) + min-complexity: 20 + + gocritic: + # Settings passed to gocritic. + # The settings key is the name of a supported gocritic checker. + # The list of supported checkers can be found at https://go-critic.com/overview. + settings: + captLocal: + # Whether to restrict checker to params only. + # Default: true + paramsOnly: false + underef: + # Whether to skip (*x).method() calls where x is a pointer receiver. + # Default: true + skipRecvDeref: false + + godoclint: + # List of rules to enable in addition to the default set. + # Default: empty + enable: + # Assert no unused link in godocs. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#no-unused-link + - no-unused-link + + govet: + # Enable all analyzers. + # Default: false + enable-all: true + # Disable analyzers by name. + # Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers. + # Default: [] + disable: + - fieldalignment # too strict + # Settings per analyzer. + settings: + shadow: + # Whether to be strict about shadowing; can be noisy. + # Default: false + strict: true + + inamedparam: + # Skips check for interface methods with only a single parameter. + # Default: false + skip-single-param: true + + mnd: + # List of function patterns to exclude from analysis. + # Values always ignored: `time.Date`, + # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`, + # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`. + # Default: [] + ignored-functions: + - args.Error + - flag.Arg + - flag.Duration.* + - flag.Float.* + - flag.Int.* + - flag.Uint.* + - os.Chmod + - os.Mkdir.* + - os.OpenFile + - os.WriteFile + - prometheus.ExponentialBuckets.* + - prometheus.LinearBuckets + + nakedret: + # Make an issue if func has more lines of code than this setting, and it has naked returns. + # Default: 30 + max-func-lines: 0 + + nolintlint: + # Exclude following linters from requiring an explanation. + # Default: [] + allow-no-explanation: [ funlen, gocognit, golines ] + # Enable to require an explanation of nonzero length after each nolint directive. + # Default: false + require-explanation: true + # Enable to require nolint directives to mention the specific linter being suppressed. + # Default: false + require-specific: true + + perfsprint: + # Optimizes into strings concatenation. + # Default: true + strconcat: false + + reassign: + # Patterns for global variable names that are checked for reassignment. + # See https://github.com/curioswitch/go-reassign#usage + # Default: ["EOF", "Err.*"] + patterns: + - ".*" + + rowserrcheck: + # database/sql is always checked. + # Default: [] + packages: + - github.com/jmoiron/sqlx + + sloglint: + # Enforce not using global loggers. + # Values: + # - "": disabled + # - "all": report all global loggers + # - "default": report only the default slog logger + # https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global + # Default: "" + no-global: all + # Enforce using methods that accept a context. + # Values: + # - "": disabled + # - "all": report all contextless calls + # - "scope": report only if a context exists in the scope of the outermost function + # https://github.com/go-simpler/sloglint?tab=readme-ov-file#context-only + # Default: "" + context: scope + + staticcheck: + # SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks + # Example (to disable some checks): [ "all", "-SA1000", "-SA1001"] + # Default: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"] + checks: + - all + # Incorrect or missing package comment. + # https://staticcheck.dev/docs/checks/#ST1000 + - -ST1000 + # Use consistent method receiver names. + # https://staticcheck.dev/docs/checks/#ST1016 + - -ST1016 + # Omit embedded fields from selector expression. + # https://staticcheck.dev/docs/checks/#QF1008 + - -QF1008 + + usetesting: + # Enable/disable `os.TempDir()` detections. + # Default: false + os-temp-dir: true + + exclusions: + # Log a warning if an exclusion rule is unused. + # Default: false + warn-unused: true + # Predefined exclusion rules. + # Default: [] + presets: + - std-error-handling + - common-false-positives + # Excluding configuration per-path, per-linter, per-text and per-source. + rules: + - source: 'TODO' + linters: [ godot ] + - text: 'should have a package comment' + linters: [ revive ] + - text: 'exported \S+ \S+ should have comment( \(or a comment on this block\))? or be unexported' + linters: [ revive ] + - text: 'package comment should be of the form ".+"' + source: '// ?(nolint|TODO)' + linters: [ revive ] + - text: 'comment on exported \S+ \S+ should be of the form ".+"' + source: '// ?(nolint|TODO)' + linters: [ revive, staticcheck ] + - path: '_test\.go' + linters: + - bodyclose + - dupl + - errcheck + - funlen + - goconst + - gosec + - noctx + - wrapcheck \ No newline at end of file diff --git a/adapter/chiopenapi/router_test.go b/adapter/chiopenapi/router_test.go index 1706827..a3ffedf 100644 --- a/adapter/chiopenapi/router_test.go +++ b/adapter/chiopenapi/router_test.go @@ -119,7 +119,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) r.Get("/{petId}", nil).With( option.OperationID("getPetById"), diff --git a/adapter/echoopenapi/router_test.go b/adapter/echoopenapi/router_test.go index d7258ff..6a827cc 100644 --- a/adapter/echoopenapi/router_test.go +++ b/adapter/echoopenapi/router_test.go @@ -184,7 +184,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.GET("/{petId}", nil).With( option.OperationID("getPetById"), diff --git a/adapter/fiberopenapi/router_test.go b/adapter/fiberopenapi/router_test.go index ef72e01..cedc243 100644 --- a/adapter/fiberopenapi/router_test.go +++ b/adapter/fiberopenapi/router_test.go @@ -125,7 +125,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.Get("/:petId", nil).With( option.OperationID("getPetById"), diff --git a/adapter/ginopenapi/router_test.go b/adapter/ginopenapi/router_test.go index 95f7081..e9d309b 100644 --- a/adapter/ginopenapi/router_test.go +++ b/adapter/ginopenapi/router_test.go @@ -123,7 +123,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.GET("/:petId", nil).With( option.OperationID("getPetById"), diff --git a/adapter/httpopenapi/router_test.go b/adapter/httpopenapi/router_test.go index a72da38..0bbcb40 100644 --- a/adapter/httpopenapi/router_test.go +++ b/adapter/httpopenapi/router_test.go @@ -121,7 +121,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.HandleFunc("GET /{petId}", nil).With( option.OperationID("getPetById"), diff --git a/adapter/httprouteropenapi/router_test.go b/adapter/httprouteropenapi/router_test.go index 4c4e4c0..7dc5f3f 100644 --- a/adapter/httprouteropenapi/router_test.go +++ b/adapter/httprouteropenapi/router_test.go @@ -127,7 +127,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.GET("/id/:petId", DummyHandler).With( option.OperationID("getPetById"), diff --git a/adapter/muxopenapi/router_test.go b/adapter/muxopenapi/router_test.go index 3060a85..fbb4cf9 100644 --- a/adapter/muxopenapi/router_test.go +++ b/adapter/muxopenapi/router_test.go @@ -122,7 +122,7 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.HandleFunc("/{petId}", nil).Methods("GET").With( option.OperationID("getPetById"), diff --git a/internal/debuglog/debuglog.go b/internal/debuglog/debuglog.go index d5a8829..5c5a000 100644 --- a/internal/debuglog/debuglog.go +++ b/internal/debuglog/debuglog.go @@ -104,13 +104,14 @@ func (l *Logger) LogTag(tag openapi.Tag) { func (l *Logger) LogSecurityScheme(name string, scheme *openapi.SecurityScheme) { var typeInfo string - if scheme.APIKey != nil { + switch { + case scheme.APIKey != nil: typeInfo = "APIKey" - } else if scheme.HTTPBearer != nil { + case scheme.HTTPBearer != nil: typeInfo = "HTTPBearer" - } else if scheme.OAuth2 != nil { + case scheme.OAuth2 != nil: typeInfo = "OAuth2" - } else { + default: typeInfo = "Unknown" } schemeInfo := "name: " + name + ", type: " + typeInfo diff --git a/internal/debuglog/debuglog_test.go b/internal/debuglog/debuglog_test.go index d23c47e..297e957 100644 --- a/internal/debuglog/debuglog_test.go +++ b/internal/debuglog/debuglog_test.go @@ -1,9 +1,10 @@ -package debuglog +package debuglog_test import ( "fmt" "testing" + "github.com/oaswrap/spec/internal/debuglog" "github.com/oaswrap/spec/openapi" "github.com/stretchr/testify/assert" ) @@ -16,17 +17,9 @@ func (m *mockLogger) Printf(format string, v ...any) { m.messages = append(m.messages, fmt.Sprintf(format, v...)) } -func TestNewLogger(t *testing.T) { - mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) - - assert.Equal(t, "[test]", logger.prefix) - assert.Equal(t, mockLog, logger.logger) -} - func TestLogger_Printf(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) logger.Printf("Hello %s", "world") @@ -37,7 +30,7 @@ func TestLogger_Printf(t *testing.T) { func TestLogger_LogOp(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("api", mockLog) + logger := debuglog.NewLogger("api", mockLog) logger.LogOp("GET", "/users", "fetch", "all users") @@ -48,7 +41,7 @@ func TestLogger_LogOp(t *testing.T) { func TestLogger_LogAction(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) logger.LogAction("validate", "schema") @@ -59,7 +52,7 @@ func TestLogger_LogAction(t *testing.T) { func TestLogger_LogContact(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) // Test with nil contact logger.LogContact(nil) @@ -80,7 +73,7 @@ func TestLogger_LogContact(t *testing.T) { func TestLogger_LogLicense(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) license := &openapi.License{ Name: "MIT", @@ -95,7 +88,7 @@ func TestLogger_LogLicense(t *testing.T) { func TestLogger_LogExternalDocs(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) docs := &openapi.ExternalDocs{ URL: "https://docs.example.com", @@ -110,7 +103,7 @@ func TestLogger_LogExternalDocs(t *testing.T) { func TestLogger_LogServer(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) desc := "Production server" server := openapi.Server{ @@ -132,7 +125,7 @@ func TestLogger_LogServer(t *testing.T) { func TestLogger_LogTag(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) tag := openapi.Tag{ Name: "users", @@ -151,7 +144,7 @@ func TestLogger_LogTag(t *testing.T) { func TestLogger_LogSecurityScheme(t *testing.T) { mockLog := &mockLogger{} - logger := NewLogger("test", mockLog) + logger := debuglog.NewLogger("test", mockLog) desc := "API Key authentication" scheme := &openapi.SecurityScheme{ diff --git a/internal/errors/error.go b/internal/errs/error.go similarity index 98% rename from internal/errors/error.go rename to internal/errs/error.go index 0ff06eb..fca894f 100644 --- a/internal/errors/error.go +++ b/internal/errs/error.go @@ -1,4 +1,4 @@ -package errors +package errs import ( "strings" diff --git a/internal/errors/error_test.go b/internal/errs/error_test.go similarity index 84% rename from internal/errors/error_test.go rename to internal/errs/error_test.go index 5a1a69c..6ca1c0c 100644 --- a/internal/errors/error_test.go +++ b/internal/errs/error_test.go @@ -1,30 +1,31 @@ -package errors +package errs_test import ( "errors" "sync" "testing" + "github.com/oaswrap/spec/internal/errs" "github.com/stretchr/testify/assert" ) func TestSpecError_Add(t *testing.T) { - se := &SpecError{} + se := &errs.SpecError{} // Test adding a valid error err := errors.New("test error") se.Add(err) - assert.Len(t, se.errors, 1) + assert.Len(t, se.Errors(), 1) // Test adding nil error (should not be added) se.Add(nil) - assert.Len(t, se.errors, 1) + assert.Len(t, se.Errors(), 1) } func TestSpecError_Errors(t *testing.T) { - se := &SpecError{} + se := &errs.SpecError{} // Test empty errors errs := se.Errors() @@ -41,7 +42,7 @@ func TestSpecError_Errors(t *testing.T) { } func TestSpecError_Error(t *testing.T) { - se := &SpecError{} + se := &errs.SpecError{} // Test empty error message msg := se.Error() @@ -61,7 +62,7 @@ func TestSpecError_Error(t *testing.T) { } func TestSpecError_HasErrors(t *testing.T) { - se := &SpecError{} + se := &errs.SpecError{} // Test with no errors assert.False(t, se.HasErrors()) @@ -72,16 +73,16 @@ func TestSpecError_HasErrors(t *testing.T) { } func TestSpecError_ConcurrentAccess(t *testing.T) { - se := &SpecError{} + se := &errs.SpecError{} var wg sync.WaitGroup // Test concurrent adds for i := 0; i < 100; i++ { wg.Add(1) - go func(i int) { + go func() { defer wg.Done() se.Add(errors.New("error")) - }(i) + }() } wg.Wait() diff --git a/internal/mapper/openapi3.go b/internal/mapper/openapi3.go index 766ca7f..2cf897a 100644 --- a/internal/mapper/openapi3.go +++ b/internal/mapper/openapi3.go @@ -142,7 +142,10 @@ func OAS3APIKey(scheme *openapi.SecurityScheme, apiKey *openapi.SecuritySchemeAP } } -func OAS3HTTPBearer(securityScheme *openapi.SecuritySchemeHTTPBearer, description *string) *openapi3.HTTPSecurityScheme { +func OAS3HTTPBearer( + securityScheme *openapi.SecuritySchemeHTTPBearer, + description *string, +) *openapi3.HTTPSecurityScheme { if securityScheme == nil { return nil } @@ -153,7 +156,10 @@ func OAS3HTTPBearer(securityScheme *openapi.SecuritySchemeHTTPBearer, descriptio } } -func OAS3OAuth2SecurityScheme(oauth2 *openapi.SecuritySchemeOAuth2, description *string) *openapi3.OAuth2SecurityScheme { +func OAS3OAuth2SecurityScheme( + oauth2 *openapi.SecuritySchemeOAuth2, + description *string, +) *openapi3.OAuth2SecurityScheme { if oauth2 == nil { return nil } diff --git a/internal/mapper/openapi31.go b/internal/mapper/openapi31.go index 1000eff..2a3ec09 100644 --- a/internal/mapper/openapi31.go +++ b/internal/mapper/openapi31.go @@ -193,7 +193,9 @@ func OAS31OauthFlowsPassword(flows *openapi.OAuthFlowsPassword) *openapi31.Oauth } } -func OAS31OauthFlowsClientCredentials(flows *openapi.OAuthFlowsClientCredentials) *openapi31.OauthFlowsDefsClientCredentials { +func OAS31OauthFlowsClientCredentials( + flows *openapi.OAuthFlowsClientCredentials, +) *openapi31.OauthFlowsDefsClientCredentials { if flows == nil { return nil } @@ -204,7 +206,9 @@ func OAS31OauthFlowsClientCredentials(flows *openapi.OAuthFlowsClientCredentials } } -func OAS31OauthFlowsAuthorizationCode(flows *openapi.OAuthFlowsAuthorizationCode) *openapi31.OauthFlowsDefsAuthorizationCode { +func OAS31OauthFlowsAuthorizationCode( + flows *openapi.OAuthFlowsAuthorizationCode, +) *openapi31.OauthFlowsDefsAuthorizationCode { if flows == nil { return nil } diff --git a/jsonschema.go b/jsonschema.go index ea91313..8d0fb02 100644 --- a/jsonschema.go +++ b/jsonschema.go @@ -46,15 +46,18 @@ func getJSONSchemaOpts(cfg *openapi.ReflectorConfig, logger *debuglog.Logger) [] logger.Printf("set custom intercept property function") } if cfg.InterceptSchemaFunc != nil { - opts = append(opts, jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (stop bool, err error) { - stop, err = cfg.InterceptSchemaFunc(openapi.InterceptSchemaParams{ - Context: params.Context, - Value: params.Value, - Schema: params.Schema, - Processed: params.Processed, - }) - return stop, err - })) + opts = append( + opts, + jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (bool, error) { + stop, err := cfg.InterceptSchemaFunc(openapi.InterceptSchemaParams{ + Context: params.Context, + Value: params.Value, + Schema: params.Schema, + Processed: params.Processed, + }) + return stop, err + }), + ) logger.Printf("set custom intercept schema function") } diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..bb307bf --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,30 @@ +# Lefthook configuration for Go project + +pre-commit: + parallel: true + commands: + fmt: + glob: "*.go" + run: gofmt -w {staged_files} && git add {staged_files} + + vet: + glob: "*.go" + run: go vet ./... + + lint: + glob: "*.go" + run: golangci-lint run --fix + + mod-tidy: + glob: "go.{mod,sum}" + run: go mod tidy + +commit-msg: + commands: + check-message: + run: | + if ! grep -qE "^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .+" {1}; then + echo "Commit message must follow conventional commits format" + echo "Example: feat: add new feature" + exit 1 + fi \ No newline at end of file diff --git a/operation.go b/operation.go index 4575459..d33067c 100644 --- a/operation.go +++ b/operation.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/oaswrap/spec/internal/debuglog" + specopenapi "github.com/oaswrap/spec/openapi" "github.com/oaswrap/spec/option" "github.com/swaggest/openapi-go" ) @@ -66,46 +67,58 @@ func (oc *operationContextImpl) build() openapi.OperationContext { } for _, req := range cfg.Requests { - value := fmt.Sprintf("%T", req.Structure) - opts := []openapi.ContentOption{} - if req.Description != "" { - value += fmt.Sprintf(" (%s)", req.Description) - opts = append(opts, func(cu *openapi.ContentUnit) { - cu.Description = req.Description - }) - } - if req.ContentType != "" { - value += fmt.Sprintf(" (Content-Type: %s)", req.ContentType) - opts = append(opts, openapi.WithContentType(req.ContentType)) - } + opts, value := oc.buildRequestOpts(req) oc.op.AddReqStructure(req.Structure, opts...) logger.LogOp(method, path, "add request", value) } for _, resp := range cfg.Responses { - value := fmt.Sprintf("%T (HTTP %d)", resp.Structure, resp.HTTPStatus) - opts := []openapi.ContentOption{ - openapi.WithHTTPStatus(resp.HTTPStatus), - } - if resp.IsDefault { - opts = append(opts, func(cu *openapi.ContentUnit) { - cu.IsDefault = true - }) - value += " (default)" - } - if resp.Description != "" { - value += fmt.Sprintf(" (%s)", resp.Description) - opts = append(opts, func(cu *openapi.ContentUnit) { - cu.Description = resp.Description - }) - } - if resp.ContentType != "" { - value += fmt.Sprintf(" (Content-Type: %s)", resp.ContentType) - opts = append(opts, openapi.WithContentType(resp.ContentType)) - } + opts, value := oc.buildResponseOpts(resp) oc.op.AddRespStructure(resp.Structure, opts...) logger.LogOp(method, path, "add response", value) } return oc.op } + +func (oc *operationContextImpl) buildRequestOpts(req *specopenapi.ContentUnit) ([]openapi.ContentOption, string) { + log := fmt.Sprintf("%T", req.Structure) + var opts []openapi.ContentOption + if req.Description != "" { + opts = append(opts, func(cu *openapi.ContentUnit) { + cu.Description = req.Description + }) + log += fmt.Sprintf(" (%s)", req.Description) + } + if req.ContentType != "" { + opts = append(opts, openapi.WithContentType(req.ContentType)) + log += fmt.Sprintf(" (Content-Type: %s)", req.ContentType) + } + return opts, log +} + +func (oc *operationContextImpl) buildResponseOpts(resp *specopenapi.ContentUnit) ([]openapi.ContentOption, string) { + log := fmt.Sprintf("%T", resp.Structure) + var opts []openapi.ContentOption + if resp.IsDefault { + opts = append(opts, func(cu *openapi.ContentUnit) { + cu.IsDefault = true + }) + log += " (default)" + } + if resp.HTTPStatus != 0 { + opts = append(opts, openapi.WithHTTPStatus(resp.HTTPStatus)) + log += fmt.Sprintf(" (HTTP %d)", resp.HTTPStatus) + } + if resp.Description != "" { + opts = append(opts, func(cu *openapi.ContentUnit) { + cu.Description = resp.Description + }) + log += fmt.Sprintf(" (%s)", resp.Description) + } + if resp.ContentType != "" { + opts = append(opts, openapi.WithContentType(resp.ContentType)) + log += fmt.Sprintf(" (Content-Type: %s)", resp.ContentType) + } + return opts, log +} diff --git a/option/openapi.go b/option/openapi.go index ae496eb..ecd6cba 100644 --- a/option/openapi.go +++ b/option/openapi.go @@ -1,7 +1,7 @@ package option import ( - "log" + "log" //nolint:depguard // Use standard log package for simplicity. "github.com/oaswrap/spec-ui/config" "github.com/oaswrap/spec/openapi" @@ -128,17 +128,18 @@ func WithSecurity(name string, opts ...SecurityOption) OpenAPIOption { c.SecuritySchemes = make(map[string]*openapi.SecurityScheme) } - if securityConfig.APIKey != nil { + switch { + case securityConfig.APIKey != nil: c.SecuritySchemes[name] = &openapi.SecurityScheme{ Description: securityConfig.Description, APIKey: securityConfig.APIKey, } - } else if securityConfig.HTTPBearer != nil { + case securityConfig.HTTPBearer != nil: c.SecuritySchemes[name] = &openapi.SecurityScheme{ Description: securityConfig.Description, HTTPBearer: securityConfig.HTTPBearer, } - } else if securityConfig.Oauth2 != nil { + case securityConfig.Oauth2 != nil: c.SecuritySchemes[name] = &openapi.SecurityScheme{ Description: securityConfig.Description, OAuth2: securityConfig.Oauth2, @@ -182,7 +183,7 @@ func WithDocsPath(path string) OpenAPIOption { // WithSpecPath sets the path for the OpenAPI specification. // // This is the path where the OpenAPI specification will be served. -// The default is "/docs/openapi.yaml" +// The default is "/docs/openapi.yaml". func WithSpecPath(path string) OpenAPIOption { return func(c *openapi.Config) { c.SpecPath = path @@ -309,4 +310,4 @@ func WithPathParser(parser openapi.PathParser) OpenAPIOption { type noopLogger struct{} -func (l noopLogger) Printf(format string, v ...any) {} +func (l noopLogger) Printf(_ string, _ ...any) {} diff --git a/option/openapi_test.go b/option/openapi_test.go index 72eda0e..f0ad87a 100644 --- a/option/openapi_test.go +++ b/option/openapi_test.go @@ -792,7 +792,7 @@ func TestWithPathParser(t *testing.T) { assert.NotNil(t, config.PathParser) } -// mockPathParser is a test implementation of openapi.PathParser +// mockPathParser is a test implementation of openapi.PathParser. type mockPathParser struct{} func (m *mockPathParser) Parse(path string) (string, error) { diff --git a/option/reflector_test.go b/option/reflector_test.go index a0eb0d8..d7a6827 100644 --- a/option/reflector_test.go +++ b/option/reflector_test.go @@ -7,6 +7,7 @@ import ( "github.com/oaswrap/spec/openapi" "github.com/oaswrap/spec/option" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/swaggest/jsonschema-go" ) @@ -45,7 +46,7 @@ func TestStripDefNamePrefix(t *testing.T) { func TestInterceptDefNameFunc(t *testing.T) { config := &openapi.ReflectorConfig{} - mockFunc := func(t reflect.Type, defaultDefName string) string { + mockFunc := func(_ reflect.Type, _ string) string { return "CustomName" } opt := option.InterceptDefNameFunc(mockFunc) @@ -56,7 +57,7 @@ func TestInterceptDefNameFunc(t *testing.T) { func TestInterceptPropFunc(t *testing.T) { config := &openapi.ReflectorConfig{} - mockFunc := func(params openapi.InterceptPropParams) error { + mockFunc := func(_ openapi.InterceptPropParams) error { return nil } opt := option.InterceptPropFunc(mockFunc) @@ -83,13 +84,13 @@ func TestRequiredPropByValidateTag(t *testing.T) { Processed: true, } err := config.InterceptPropFunc(params) - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, params.ParentSchema.Required, "Field1") } func TestInterceptSchemaFunc(t *testing.T) { config := &openapi.ReflectorConfig{} - mockFunc := func(params openapi.InterceptSchemaParams) (stop bool, err error) { + mockFunc := func(_ openapi.InterceptSchemaParams) (bool, error) { return false, nil } opt := option.InterceptSchemaFunc(mockFunc) diff --git a/pkg/dto/pet.go b/pkg/dto/pet.go index 00b69c7..fd9653e 100644 --- a/pkg/dto/pet.go +++ b/pkg/dto/pet.go @@ -9,7 +9,7 @@ type Pet struct { ID int `json:"id"` Name string `json:"name"` Type string `json:"type"` - Status string `json:"status" enum:"available,pending,sold"` + Status string `json:"status" enum:"available,pending,sold"` Category Category `json:"category"` Tags []Tag `json:"tags"` PhotoURLs []string `json:"photoUrls"` @@ -27,19 +27,19 @@ type Category struct { type UpdatePetWithFormRequest struct { ID int `path:"petId" required:"true"` - Name string `formData:"name" required:"true"` - Status string `formData:"status" enum:"available,pending,sold"` + Name string ` required:"true" formData:"name"` + Status string ` formData:"status" enum:"available,pending,sold"` } type UploadImageRequest struct { ID int64 `params:"petId" path:"petId"` - AdditionalMetaData string `query:"additionalMetadata"` - _ *multipart.File `contentType:"application/octet-stream"` + AdditionalMetaData string ` query:"additionalMetadata"` + _ *multipart.File ` contentType:"application/octet-stream"` } type DeletePetRequest struct { ID int `path:"petId" required:"true"` - ApiKey string `header:"api_key"` + APIKey string ` header:"api_key"` } type Order struct { @@ -47,7 +47,7 @@ type Order struct { PetID int `json:"petId"` Quantity int `json:"quantity"` ShipDate time.Time `json:"shipDate"` - Status string `json:"status" enum:"placed,approved,delivered"` + Status string `json:"status" enum:"placed,approved,delivered"` Complete bool `json:"complete"` } @@ -62,7 +62,7 @@ type PetUser struct { UserStatus int `json:"userStatus" enum:"0,1,2"` } -type ApiResponse struct { +type APIResponse struct { Message string `json:"message"` Type string `json:"type"` Code int `json:"code"` diff --git a/pkg/parser/colon_param_parser_test.go b/pkg/parser/colon_param_parser_test.go index ba3b2a1..9508d77 100644 --- a/pkg/parser/colon_param_parser_test.go +++ b/pkg/parser/colon_param_parser_test.go @@ -5,6 +5,7 @@ import ( "github.com/oaswrap/spec/pkg/parser" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewColonParamParser(t *testing.T) { @@ -70,7 +71,7 @@ func TestColonParamParser_Parse(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result, err := parser.Parse(tt.input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, tt.expected, result) }) } diff --git a/pkg/util/util.go b/pkg/util/util.go index 2700b0e..c33e480 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -1,4 +1,4 @@ -package util +package util //nolint:revive // Utility functions import ( "path" diff --git a/reflector.go b/reflector.go index b99e11f..b0b1c1a 100644 --- a/reflector.go +++ b/reflector.go @@ -5,7 +5,7 @@ import ( "regexp" "github.com/oaswrap/spec/internal/debuglog" - "github.com/oaswrap/spec/internal/errors" + "github.com/oaswrap/spec/internal/errs" "github.com/oaswrap/spec/openapi" "github.com/oaswrap/spec/option" ) @@ -30,15 +30,15 @@ func newReflector(cfg *openapi.Config) reflector { type invalidReflector struct { spec *noopSpec - errors *errors.SpecError + errors *errs.SpecError } func newInvalidReflector(err error) reflector { - errors := &errors.SpecError{} - errors.Add(err) + e := &errs.SpecError{} + e.Add(err) return &invalidReflector{ - errors: errors, + errors: e, spec: &noopSpec{}, } } @@ -49,7 +49,7 @@ func (r *invalidReflector) Spec() spec { return r.spec } -func (r *invalidReflector) Add(method, path string, opts ...option.OperationOption) {} +func (r *invalidReflector) Add(_, _ string, _ ...option.OperationOption) {} func (r *invalidReflector) Validate() error { if r.errors.HasErrors() { diff --git a/reflector3.go b/reflector3.go index ac3b72f..7080999 100644 --- a/reflector3.go +++ b/reflector3.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/oaswrap/spec/internal/debuglog" - "github.com/oaswrap/spec/internal/errors" + "github.com/oaswrap/spec/internal/errs" "github.com/oaswrap/spec/internal/mapper" "github.com/oaswrap/spec/openapi" "github.com/oaswrap/spec/option" @@ -15,7 +15,7 @@ import ( type reflector3 struct { reflector *openapi3.Reflector logger *debuglog.Logger - errors *errors.SpecError + errors *errs.SpecError pathParser openapi.PathParser } @@ -102,7 +102,7 @@ func newReflector3(cfg *openapi.Config, logger *debuglog.Logger) reflector { return &reflector3{ reflector: reflector, logger: logger, - errors: &errors.SpecError{}, + errors: &errs.SpecError{}, pathParser: cfg.PathParser, } } @@ -130,7 +130,7 @@ func (r *reflector3) Add(method, path string, opts ...option.OperationOption) { method = strings.ToUpper(method) - if err := r.addOperation(op); err != nil { + if err = r.addOperation(op); err != nil { r.logger.LogOp(method, path, "add operation", "failed") r.errors.Add(err) return diff --git a/reflector31.go b/reflector31.go index a8cfa56..5c2d587 100644 --- a/reflector31.go +++ b/reflector31.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/oaswrap/spec/internal/debuglog" - "github.com/oaswrap/spec/internal/errors" + "github.com/oaswrap/spec/internal/errs" "github.com/oaswrap/spec/internal/mapper" "github.com/oaswrap/spec/openapi" "github.com/oaswrap/spec/option" @@ -16,7 +16,7 @@ type reflector31 struct { reflector *openapi31.Reflector logger *debuglog.Logger pathParser openapi.PathParser - errors *errors.SpecError + errors *errs.SpecError } func newReflector31(cfg *openapi.Config, logger *debuglog.Logger) reflector { @@ -99,7 +99,7 @@ func newReflector31(cfg *openapi.Config, logger *debuglog.Logger) reflector { return &reflector31{ reflector: reflector, logger: logger, - errors: &errors.SpecError{}, + errors: &errs.SpecError{}, pathParser: cfg.PathParser, } } @@ -123,7 +123,7 @@ func (r *reflector31) Add(method, path string, opts ...option.OperationOption) { method = strings.ToUpper(method) - if err := r.addOperation(op); err != nil { + if err = r.addOperation(op); err != nil { r.logger.LogOp(method, path, "add operation", "failed") r.errors.Add(err) return diff --git a/router.go b/router.go index 166a428..d7b9377 100644 --- a/router.go +++ b/router.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "os" + "slices" "strings" "sync" @@ -171,7 +172,7 @@ func (g *generator) MarshalJSON() ([]byte, error) { } var buffer bytes.Buffer - if err := json.Indent(&buffer, schema, "", " "); err != nil { + if err = json.Indent(&buffer, schema, "", " "); err != nil { return nil, fmt.Errorf("failed to indent OpenAPI JSON schema: %w", err) } @@ -181,8 +182,9 @@ func (g *generator) MarshalJSON() ([]byte, error) { // GenerateSchema generates the OpenAPI schema in the specified format (JSON or YAML). func (g *generator) GenerateSchema(formats ...string) ([]byte, error) { format := util.Optional("yaml", formats...) - if format != "json" && format != "yaml" && format != "yml" { - return nil, fmt.Errorf("unsupported format: %s, expected 'json', 'yaml', or 'yml'", format) + supportedFormats := []string{"json", "yaml", "yml"} + if !slices.Contains(supportedFormats, format) { + return nil, fmt.Errorf("unsupported format: %s, expected one of %v", format, supportedFormats) } if format == "yaml" || format == "yml" { @@ -225,31 +227,13 @@ func (g *generator) buildOnce() { func (g *generator) build() []*route { var routes []*route for _, r := range g.routes { - var opts []option.OperationOption - if r.method == "" || r.path == "" { continue // Skip incomplete routes } - if len(g.opts) > 0 { - cfg := &option.GroupConfig{} - for _, opt := range g.opts { - opt(cfg) - } - if cfg.Hide { - continue - } - if cfg.Deprecated { - opts = append(opts, option.Deprecated(true)) - } - if len(cfg.Tags) > 0 { - opts = append(opts, option.Tags(cfg.Tags...)) - } - if len(cfg.Security) > 0 { - for _, sec := range cfg.Security { - opts = append(opts, option.Security(sec.Name, sec.Scopes...)) - } - } + opts, ok := g.buildRouteGroupOpts() + if !ok { + continue } if len(r.opts) > 0 { r.opts = append(r.opts, opts...) @@ -264,6 +248,31 @@ func (g *generator) build() []*route { return routes } +func (g *generator) buildRouteGroupOpts() ([]option.OperationOption, bool) { + var opts []option.OperationOption + if len(g.opts) > 0 { + cfg := &option.GroupConfig{} + for _, opt := range g.opts { + opt(cfg) + } + if cfg.Hide { + return nil, false + } + if cfg.Deprecated { + opts = append(opts, option.Deprecated(true)) + } + if len(cfg.Tags) > 0 { + opts = append(opts, option.Tags(cfg.Tags...)) + } + if len(cfg.Security) > 0 { + for _, sec := range cfg.Security { + opts = append(opts, option.Security(sec.Name, sec.Scopes...)) + } + } + } + return opts, true +} + type route struct { prefix string // Path prefix for the route method string diff --git a/router_test.go b/router_test.go index 5d95ea2..7141ba9 100644 --- a/router_test.go +++ b/router_test.go @@ -21,6 +21,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") type AllBasicDataTypes struct { @@ -62,7 +63,7 @@ type AllBasicDataTypesPointers struct { } type LoginRequest struct { - Username string `json:"username" example:"john_doe" validate:"required"` + Username string `json:"username" example:"john_doe" validate:"required"` Password string `json:"password" example:"password123" validate:"required"` } @@ -155,13 +156,43 @@ func TestRouter(t *testing.T) { ID int `path:"id" validate:"required"` } r.Get("/user", option.OperationID("getUser"), option.Summary("Get User")) - r.Post("/user", option.OperationID("createUser"), option.Summary("Create User"), option.Response(201, new(string), option.ContentType("plain/text"))) - r.Put("/user/{id}", option.OperationID("updateUser"), option.Summary("Update User"), option.Request(new(UserDetailRequest))) - r.Patch("/user/{id}", option.OperationID("patchUser"), option.Summary("Patch User"), option.Request(new(UserDetailRequest))) - r.Delete("/user/{id}", option.OperationID("deleteUser"), option.Summary("Delete User"), option.Request(new(UserDetailRequest))) - r.Head("/user/{id}", option.OperationID("headUser"), option.Summary("Head User"), option.Request(new(UserDetailRequest))) + r.Post( + "/user", + option.OperationID("createUser"), + option.Summary("Create User"), + option.Response(201, new(string), option.ContentType("plain/text")), + ) + r.Put( + "/user/{id}", + option.OperationID("updateUser"), + option.Summary("Update User"), + option.Request(new(UserDetailRequest)), + ) + r.Patch( + "/user/{id}", + option.OperationID("patchUser"), + option.Summary("Patch User"), + option.Request(new(UserDetailRequest)), + ) + r.Delete( + "/user/{id}", + option.OperationID("deleteUser"), + option.Summary("Delete User"), + option.Request(new(UserDetailRequest)), + ) + r.Head( + "/user/{id}", + option.OperationID("headUser"), + option.Summary("Head User"), + option.Request(new(UserDetailRequest)), + ) r.Options("/user", option.OperationID("optionsUser"), option.Summary("Options User")) - r.Trace("/user/{id}", option.OperationID("traceUser"), option.Summary("Trace User"), option.Request(new(UserDetailRequest))) + r.Trace( + "/user/{id}", + option.OperationID("traceUser"), + option.Summary("Trace User"), + option.Request(new(UserDetailRequest)), + ) }, }, { @@ -275,19 +306,25 @@ func TestRouter(t *testing.T) { option.Request(new(dto.Pet)), option.Response(201, new(dto.Pet)), ) - pet.Get("/findByStatus", + pet.Get( + "/findByStatus", option.OperationID("findPetsByStatus"), option.Summary("Find pets by status"), - option.Description("Finds Pets by status. Multiple status values can be provided with comma separated strings."), + option.Description( + "Finds Pets by status. Multiple status values can be provided with comma separated strings.", + ), option.Request(new(struct { Status string `query:"status" enum:"available,pending,sold"` })), option.Response(200, new([]dto.Pet)), ) - pet.Get("/findByTags", + pet.Get( + "/findByTags", option.OperationID("findPetsByTags"), option.Summary("Find pets by tags"), - option.Description("Finds Pets by tags. Multiple tags can be provided with comma separated strings."), + option.Description( + "Finds Pets by tags. Multiple tags can be provided with comma separated strings.", + ), option.Request(new(struct { Tags []string `query:"tags"` })), @@ -298,7 +335,7 @@ func TestRouter(t *testing.T) { option.Summary("Upload an image for a pet"), option.Description("Uploads an image for a pet."), option.Request(new(dto.UploadImageRequest)), - option.Response(200, new(dto.ApiResponse)), + option.Response(200, new(dto.APIResponse)), ) pet.Get("/{petId}", option.OperationID("getPetById"), @@ -385,8 +422,9 @@ func TestRouter(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -451,14 +489,14 @@ func TestRouter(t *testing.T) { option.RootRef(), option.RootNullable(), option.StripDefNamePrefix("Test", "Mock"), - option.InterceptDefNameFunc(func(t reflect.Type, defaultDefName string) string { + option.InterceptDefNameFunc(func(_ reflect.Type, defaultDefName string) string { return defaultDefName + "_Custom" }), - option.InterceptPropFunc(func(params openapi.InterceptPropParams) error { + option.InterceptPropFunc(func(_ openapi.InterceptPropParams) error { return nil }), option.RequiredPropByValidateTag(), - option.InterceptSchemaFunc(func(params openapi.InterceptSchemaParams) (stop bool, err error) { + option.InterceptSchemaFunc(func(_ openapi.InterceptSchemaParams) (bool, error) { return false, nil }), option.TypeMapping(NullString{}, new(string)), @@ -674,10 +712,10 @@ func TestRouter(t *testing.T) { } if tt.shouldError { - assert.Error(t, r.Validate(), "Expected router to fail validation") + require.Error(t, r.Validate(), "Expected router to fail validation") continue } - assert.NoError(t, r.Validate(), "Router validation failed") + require.NoError(t, r.Validate(), "Router validation failed") schema, err := r.GenerateSchema("yaml") require.NoError(t, err) @@ -758,15 +796,15 @@ func TestRouter_GenerateSchema(t *testing.T) { schema, err := r.GenerateSchema(tt.formats...) if tt.expectError { - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, err.Error(), tt.errorMsg) assert.Nil(t, schema) return } - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, schema) - assert.Greater(t, len(schema), 0, "Schema should not be empty") + assert.NotEmpty(t, schema) // Verify format-specific content if len(tt.formats) == 0 || tt.formats[0] == "yaml" { @@ -849,7 +887,7 @@ func TestRouter_WriteSchemaTo(t *testing.T) { return } - assert.NoError(t, err) + require.NoError(t, err) // Verify file was created assert.FileExists(t, fullPath) @@ -857,7 +895,7 @@ func TestRouter_WriteSchemaTo(t *testing.T) { // Read and verify file content content, err := os.ReadFile(fullPath) require.NoError(t, err) - assert.Greater(t, len(content), 0, "File should not be empty") + assert.NotEmpty(t, content) if tt.expectJSON { // Verify JSON format From d8f4c3a325fdf6320e55e2d5fad1115092faa41e Mon Sep 17 00:00:00 2001 From: Ahmad Faiz Kamaludin Date: Fri, 17 Oct 2025 07:19:00 +0700 Subject: [PATCH 3/6] fix: github action issue --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 344dd45..569dee0 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,9 @@ YELLOW := \033[1;33m BLUE := \033[0;34m NC := \033[0m # No Color +GOLANGCI_LINT_VERSION := v2.3.1 +GOTESTSUM_VERSION := v1.12.3 + # Ensure all targets are marked as phony to avoid conflicts with filenames. .PHONY: test test-adapter test-update testcov testcov-html .PHONY: tidy sync lint check tidy-all @@ -118,8 +121,8 @@ check: sync tidy lint test ## Run all local development checks install-tools: ## Install development tools @echo "$(BLUE)📦 Installing development tools...$(NC)" - @go install gotest.tools/gotestsum@latest - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + @go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION) + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) @echo "$(GREEN)✅ Tools installed successfully!$(NC)" list-adapters: ## List available adapters From 1bbb4af0274cd776d24d5bf16f1943fb7fa23bf1 Mon Sep 17 00:00:00 2001 From: Ahmad Faiz Kamaludin Date: Fri, 17 Oct 2025 07:23:40 +0700 Subject: [PATCH 4/6] fix: install tools command and remove gosec at action --- .github/workflows/ci.yml | 27 ++------------------------- Makefile | 3 ++- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d06d93..86a5253 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - go-version: ['1.23', '1.24'] + go-version: ['1.23', '1.24', '1.25'] steps: - name: 📥 Checkout @@ -96,32 +96,13 @@ jobs: fail_ci_if_error: false verbose: true - # ======================================== - # Security Scan - # ======================================== - security: - name: 🔒 Security Scan - runs-on: ubuntu-latest - timeout-minutes: 10 - needs: quality - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) - - steps: - - name: 📥 Checkout - uses: actions/checkout@v4 - - - name: Run Gosec Security Scanner - uses: securego/gosec@master - with: - args: './...' - # ======================================== # Final Status Check # ======================================== ci-success: name: ✅ CI Success runs-on: ubuntu-latest - needs: [quality, test, security] + needs: [quality, test] if: always() steps: @@ -135,8 +116,4 @@ jobs: echo "Tests failed" exit 1 fi - if [[ "${{ needs.security.result }}" != "success" && "${{ needs.security.result }}" != "skipped" ]]; then - echo "Security scan failed" - exit 1 - fi echo "All CI checks passed! 🎉" \ No newline at end of file diff --git a/Makefile b/Makefile index 569dee0..6681f3d 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ YELLOW := \033[1;33m BLUE := \033[0;34m NC := \033[0m # No Color +# Tool versions GOLANGCI_LINT_VERSION := v2.3.1 GOTESTSUM_VERSION := v1.12.3 @@ -122,7 +123,7 @@ check: sync tidy lint test ## Run all local development checks install-tools: ## Install development tools @echo "$(BLUE)📦 Installing development tools...$(NC)" @go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION) - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) + @go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) @echo "$(GREEN)✅ Tools installed successfully!$(NC)" list-adapters: ## List available adapters From 89d5cab313df768dbf949963901b7029eab67ac3 Mon Sep 17 00:00:00 2001 From: Ahmad Faiz Kamaludin Date: Fri, 17 Oct 2025 08:01:54 +0700 Subject: [PATCH 5/6] fix: linter issue at adapter --- .golangci.yml | 11 --- Makefile | 3 +- adapter/chiopenapi/examples/basic/go.mod | 3 +- adapter/chiopenapi/examples/basic/go.sum | 10 +-- adapter/chiopenapi/go.mod | 6 +- adapter/chiopenapi/go.sum | 16 +++-- adapter/chiopenapi/router_test.go | 37 ++++++---- adapter/echoopenapi/examples/basic/go.mod | 3 +- adapter/echoopenapi/examples/basic/go.sum | 10 +-- adapter/echoopenapi/go.mod | 6 +- adapter/echoopenapi/go.sum | 16 +++-- adapter/echoopenapi/router.go | 4 +- adapter/echoopenapi/router_test.go | 28 +++++--- adapter/fiberopenapi/examples/basic/go.mod | 11 +-- adapter/fiberopenapi/examples/basic/go.sum | 18 ++--- adapter/fiberopenapi/go.mod | 14 ++-- adapter/fiberopenapi/go.sum | 26 ++++--- adapter/fiberopenapi/router_test.go | 53 ++++++++++----- adapter/ginopenapi/examples/basic/go.mod | 15 ++-- adapter/ginopenapi/examples/basic/go.sum | 22 +++--- adapter/ginopenapi/go.mod | 18 +++-- adapter/ginopenapi/go.sum | 32 +++++---- adapter/ginopenapi/router_test.go | 68 ++++++++++++------- adapter/httpopenapi/examples/basic/go.mod | 3 +- adapter/httpopenapi/examples/basic/go.sum | 10 +-- adapter/httpopenapi/go.mod | 6 +- adapter/httpopenapi/go.sum | 16 +++-- adapter/httpopenapi/internal/parser/parser.go | 14 ++-- .../internal/parser/parser_test.go | 5 +- adapter/httpopenapi/router_test.go | 36 +++++----- .../httprouteropenapi/examples/basic/go.mod | 3 +- .../httprouteropenapi/examples/basic/go.sum | 10 +-- adapter/httprouteropenapi/go.mod | 6 +- adapter/httprouteropenapi/go.sum | 16 +++-- adapter/httprouteropenapi/router.go | 12 ++-- adapter/httprouteropenapi/router_test.go | 24 ++++--- adapter/muxopenapi/examples/basic/go.mod | 3 +- adapter/muxopenapi/examples/basic/go.sum | 10 +-- adapter/muxopenapi/go.mod | 6 +- adapter/muxopenapi/go.sum | 16 +++-- adapter/muxopenapi/router.go | 7 +- adapter/muxopenapi/router_test.go | 34 +++++----- examples/basic/go.mod | 5 +- examples/basic/go.sum | 10 +-- examples/petstore/go.mod | 5 +- examples/petstore/go.sum | 10 +-- go.mod | 2 + go.sum | 8 ++- lefthook.yml | 4 +- 49 files changed, 417 insertions(+), 294 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7daf9fe..6129c8d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -61,7 +61,6 @@ linters: - goconst # finds repeated strings that could be replaced by a constant - gocritic # provides diagnostics that check for bugs, performance and style issues - gocyclo # computes and checks the cyclomatic complexity of functions - - godoclint # checks Golang's documentation practice - godot # checks if comments end in a period - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - goprintffuncname # checks that printf-like functions are named with f at the end @@ -70,7 +69,6 @@ linters: - iface # checks the incorrect use of interfaces, helping developers avoid interface pollution - ineffassign # detects when assignments to existing variables are not used - intrange # finds places where for loops could make use of an integer range - - iotamixing # checks if iotas are being used in const blocks with other non-iota declarations - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) - makezero # finds slice declarations with non-zero initial length - mirror # reports wrong mirror patterns of bytes/strings usage @@ -103,7 +101,6 @@ linters: - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes - unconvert # removes unnecessary type conversions - unparam # reports unused function parameters - - unqueryvet # detects SELECT * in SQL queries and SQL builders, encouraging explicit column selection - unused # checks for unused constants, variables, functions and types - usestdlibvars # detects the possibility to use variables/constants from the Go standard library - usetesting # reports uses of functions with replacement inside the testing package @@ -301,14 +298,6 @@ linters: # Default: true skipRecvDeref: false - godoclint: - # List of rules to enable in addition to the default set. - # Default: empty - enable: - # Assert no unused link in godocs. - # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#no-unused-link - - no-unused-link - govet: # Enable all analyzers. # Default: false diff --git a/Makefile b/Makefile index 6681f3d..0807147 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,8 @@ lint: ## Run linting @echo "$(GREEN)✅ Core linting passed$(NC)" @for a in $(ADAPTERS); do \ echo "$(BLUE)🔍 Linting adapter/$$a...$(NC)"; \ - (cd "adapter/$$a" && golangci-lint run) || (echo "$(RED)❌ Adapter $$a linting failed$(NC)" && exit 1); \ + golangci-lint run ./adapter/$$a/... || \ + (echo "$(RED)❌ Adapter $$a linting failed$(NC)" && exit 1); \ done @echo "$(GREEN)🎉 All linting passed!$(NC)" diff --git a/adapter/chiopenapi/examples/basic/go.mod b/adapter/chiopenapi/examples/basic/go.mod index 5f18c4b..7d08500 100644 --- a/adapter/chiopenapi/examples/basic/go.mod +++ b/adapter/chiopenapi/examples/basic/go.mod @@ -9,9 +9,10 @@ require ( ) require ( + github.com/kr/text v0.1.0 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/adapter/chiopenapi/examples/basic/go.sum b/adapter/chiopenapi/examples/basic/go.sum index 2574881..babe887 100644 --- a/adapter/chiopenapi/examples/basic/go.sum +++ b/adapter/chiopenapi/examples/basic/go.sum @@ -10,6 +10,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -18,22 +20,20 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/chiopenapi/go.mod b/adapter/chiopenapi/go.mod index 86cf653..2eb03ad 100644 --- a/adapter/chiopenapi/go.mod +++ b/adapter/chiopenapi/go.mod @@ -6,16 +6,18 @@ require ( github.com/go-chi/chi/v5 v5.2.2 github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.7.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/chiopenapi/go.sum b/adapter/chiopenapi/go.sum index 2574881..a0d956f 100644 --- a/adapter/chiopenapi/go.sum +++ b/adapter/chiopenapi/go.sum @@ -10,6 +10,11 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -18,22 +23,23 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/chiopenapi/router_test.go b/adapter/chiopenapi/router_test.go index a3ffedf..cccab72 100644 --- a/adapter/chiopenapi/router_test.go +++ b/adapter/chiopenapi/router_test.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") func TestRouter_Spec(t *testing.T) { @@ -207,8 +208,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -251,11 +253,11 @@ func TestRouter_Spec(t *testing.T) { if tt.shouldErr { err := r.Validate() - assert.Error(t, err, "expected error for invalid OpenAPI configuration") + require.Error(t, err, "expected error for invalid OpenAPI configuration") return } err := r.Validate() - assert.NoError(t, err, "failed to validate OpenAPI configuration") + require.NoError(t, err, "failed to validate OpenAPI configuration") // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -277,7 +279,7 @@ func TestRouter_Spec(t *testing.T) { } } -func pingHandler(w http.ResponseWriter, r *http.Request) { +func pingHandler(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(map[string]string{"message": "pong"}) } @@ -342,7 +344,7 @@ func TestRouter_Single(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rr := httptest.NewRecorder() c.ServeHTTP(rr, req) @@ -366,7 +368,7 @@ func TestRouter_Single(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - req := httptest.NewRequest("CONNECT", "/ping", nil) + req := httptest.NewRequest(http.MethodConnect, "/ping", nil) rr := httptest.NewRecorder() c.ServeHTTP(rr, req) @@ -386,7 +388,7 @@ func TestRouter_Single(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rr := httptest.NewRecorder() c.ServeHTTP(rr, req) @@ -401,7 +403,7 @@ func TestRouter_Single(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rr := httptest.NewRecorder() c.ServeHTTP(rr, req) @@ -422,7 +424,7 @@ func TestRouter_Single(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - req := httptest.NewRequest("GET", "/sub/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/sub/ping", nil) rr := httptest.NewRecorder() c.ServeHTTP(rr, req) @@ -445,7 +447,7 @@ func TestRouter_Group(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rr := httptest.NewRecorder() c.ServeHTTP(rr, req) @@ -454,7 +456,12 @@ func TestRouter_Group(t *testing.T) { schema, err := r.GenerateSchema() require.NoError(t, err, "failed to generate OpenAPI schema") assert.Contains(t, string(schema), "getPing", "expected OpenAPI schema to contain operation ID getPing") - assert.Contains(t, string(schema), "Ping the server with Group", "expected OpenAPI schema to contain summary for getPing") + assert.Contains( + t, + string(schema), + "Ping the server with Group", + "expected OpenAPI schema to contain summary for getPing", + ) assert.Contains(t, string(schema), "deprecated", "expected OpenAPI schema to contain deprecated flag for getPing") } @@ -474,7 +481,7 @@ func TestRouter_Middleware(t *testing.T) { r.Get("/ping", pingHandler) }) - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rec := httptest.NewRecorder() c.ServeHTTP(rec, req) assert.True(t, called, "expected middleware to be called") @@ -493,7 +500,7 @@ func TestRouter_Middleware(t *testing.T) { r := chiopenapi.NewRouter(c) r.With(middleware).Get("/ping", pingHandler) - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rec := httptest.NewRecorder() c.ServeHTTP(rec, req) assert.True(t, called, "expected middleware to be called") @@ -505,7 +512,7 @@ func TestRouter_Middleware(t *testing.T) { func TestRouter_NotFound(t *testing.T) { c := chi.NewRouter() r := chiopenapi.NewRouter(c) - r.NotFound(func(w http.ResponseWriter, r *http.Request) { + r.NotFound(func(w http.ResponseWriter, _ *http.Request) { http.Error(w, "Not Found", http.StatusNotFound) }) @@ -528,7 +535,7 @@ func TestRouter_MethodNotAllowed(t *testing.T) { option.Summary("Ping the server"), option.Description("This endpoint is used to check if the server is running."), ) - r.MethodNotAllowed(func(w http.ResponseWriter, r *http.Request) { + r.MethodNotAllowed(func(w http.ResponseWriter, _ *http.Request) { http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) }) diff --git a/adapter/echoopenapi/examples/basic/go.mod b/adapter/echoopenapi/examples/basic/go.mod index 4ccb8e2..2307752 100644 --- a/adapter/echoopenapi/examples/basic/go.mod +++ b/adapter/echoopenapi/examples/basic/go.mod @@ -9,12 +9,13 @@ require ( ) require ( + github.com/kr/text v0.1.0 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect diff --git a/adapter/echoopenapi/examples/basic/go.sum b/adapter/echoopenapi/examples/basic/go.sum index fd2d12d..345874e 100644 --- a/adapter/echoopenapi/examples/basic/go.sum +++ b/adapter/echoopenapi/examples/basic/go.sum @@ -8,6 +8,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= @@ -24,14 +26,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -51,8 +51,8 @@ golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/echoopenapi/go.mod b/adapter/echoopenapi/go.mod index a1cb3cc..6a13dcf 100644 --- a/adapter/echoopenapi/go.mod +++ b/adapter/echoopenapi/go.mod @@ -6,18 +6,19 @@ require ( github.com/labstack/echo/v4 v4.13.4 github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.7.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect @@ -25,6 +26,7 @@ require ( golang.org/x/net v0.40.0 // indirect golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.25.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/echoopenapi/go.sum b/adapter/echoopenapi/go.sum index fd2d12d..4ac8f45 100644 --- a/adapter/echoopenapi/go.sum +++ b/adapter/echoopenapi/go.sum @@ -8,6 +8,11 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= @@ -24,14 +29,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -51,8 +56,9 @@ golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/echoopenapi/router.go b/adapter/echoopenapi/router.go index 3c827d1..f5faa50 100644 --- a/adapter/echoopenapi/router.go +++ b/adapter/echoopenapi/router.go @@ -20,14 +20,14 @@ type router struct { // NewRouter creates a new OpenAPI router with the provided Echo instance and options. // -// It initializes the OpenAPI configuration and sets up the necessary routes for serving +// It initializes the OpenAPI configuration and sets up the necessary routes for serving. func NewRouter(e *echo.Echo, opts ...option.OpenAPIOption) Generator { return NewGenerator(e, opts...) } // NewGenerator creates a new OpenAPI generator with the provided Echo instance and options. // -// It initializes the OpenAPI configuration and sets up the necessary routes for serving +// It initializes the OpenAPI configuration and sets up the necessary routes for serving. func NewGenerator(e *echo.Echo, opts ...option.OpenAPIOption) Generator { defaultOpts := []option.OpenAPIOption{ option.WithTitle(constant.DefaultTitle), diff --git a/adapter/echoopenapi/router_test.go b/adapter/echoopenapi/router_test.go index 6a827cc..e98161d 100644 --- a/adapter/echoopenapi/router_test.go +++ b/adapter/echoopenapi/router_test.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") type HelloRequest struct { @@ -73,6 +74,7 @@ type ErrorResponse struct { type ValidationResponse struct { ErrorResponse + Errors []struct { Field string `json:"field"` Message string `json:"message"` @@ -271,8 +273,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -298,10 +301,10 @@ func TestRouter_Spec(t *testing.T) { err := r.Validate() if tt.shouldErr { - assert.Error(t, err, "Expected error for test: %s", tt.name) + require.Error(t, err, "Expected error for test: %s", tt.name) return } - assert.NoError(t, err, "Expected no error for test: %s", tt.name) + require.NoError(t, err, "Expected no error for test: %s", tt.name) // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -371,16 +374,21 @@ func TestRouter_Single(t *testing.T) { // Verify the OpenAPI schema if tt.method == "CONNECT" { schema, err := r.MarshalYAML() - assert.NoError(t, err, "Expected no error while generating OpenAPI schema") + require.NoError(t, err, "Expected no error while generating OpenAPI schema") assert.NotEmpty(t, schema, "Expected OpenAPI schema to be generated") assert.NotContains(t, string(schema), fmt.Sprintf("operationId: hello%s", tt.method)) return } schema, err := r.MarshalYAML() - assert.NoError(t, err, "Expected no error while generating OpenAPI schema") + require.NoError(t, err, "Expected no error while generating OpenAPI schema") assert.NotEmpty(t, schema, "Expected OpenAPI schema to be generated") assert.Contains(t, string(schema), fmt.Sprintf("operationId: hello%s", tt.method)) - assert.Contains(t, string(schema), "summary: Hello Handler", "Expected OpenAPI schema to contain the summary") + assert.Contains( + t, + string(schema), + "summary: Hello Handler", + "Expected OpenAPI schema to contain the summary", + ) }) } } @@ -565,13 +573,13 @@ func TestGenerator_WriteSchemaTo(t *testing.T) { // Write the OpenAPI schema to a file tempFile := t.TempDir() + "/openapi.yaml" err := r.WriteSchemaTo(tempFile) - assert.NoError(t, err, "Expected no error while writing OpenAPI schema to file") + require.NoError(t, err, "Expected no error while writing OpenAPI schema to file") // Verify the file exists and is not empty info, err := os.Stat(tempFile) - assert.NoError(t, err, "Expected no error while checking file stats") + require.NoError(t, err, "Expected no error while checking file stats") assert.False(t, info.IsDir(), "Expected file to not be a directory") - assert.Greater(t, info.Size(), int64(0), "Expected file size to be greater than 0") + assert.Positive(t, info.Size(), "Expected file size to be greater than 0") } func TestGenerator_MarshalJSON(t *testing.T) { @@ -593,7 +601,7 @@ func TestGenerator_MarshalJSON(t *testing.T) { // Marshal the OpenAPI schema to JSON schema, err := r.MarshalJSON() - assert.NoError(t, err, "Expected no error while marshaling OpenAPI schema to JSON") + require.NoError(t, err, "Expected no error while marshaling OpenAPI schema to JSON") assert.NotEmpty(t, schema, "Expected OpenAPI schema JSON to not be empty") } diff --git a/adapter/fiberopenapi/examples/basic/go.mod b/adapter/fiberopenapi/examples/basic/go.mod index c27aa88..a7447bf 100644 --- a/adapter/fiberopenapi/examples/basic/go.mod +++ b/adapter/fiberopenapi/examples/basic/go.mod @@ -1,6 +1,8 @@ module github.com/oaswrap/spec/adapter/fiberopenapi/examples/basic -go 1.21 +go 1.23.0 + +toolchain go1.23.12 require ( github.com/gofiber/fiber/v2 v2.52.9 @@ -12,18 +14,19 @@ require ( github.com/andybalholm/brotli v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.17.9 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/kr/text v0.1.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.28.0 // indirect + golang.org/x/sys v0.33.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/adapter/fiberopenapi/examples/basic/go.sum b/adapter/fiberopenapi/examples/basic/go.sum index 254c025..6412514 100644 --- a/adapter/fiberopenapi/examples/basic/go.sum +++ b/adapter/fiberopenapi/examples/basic/go.sum @@ -16,9 +16,9 @@ github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= @@ -33,14 +33,12 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -53,12 +51,10 @@ github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCO github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/fiberopenapi/go.mod b/adapter/fiberopenapi/go.mod index 533a689..4d3703e 100644 --- a/adapter/fiberopenapi/go.mod +++ b/adapter/fiberopenapi/go.mod @@ -1,12 +1,14 @@ module github.com/oaswrap/spec/adapter/fiberopenapi -go 1.21 +go 1.23.0 + +toolchain go1.23.12 require ( github.com/gofiber/fiber/v2 v2.52.9 github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( @@ -15,18 +17,20 @@ require ( github.com/google/go-cmp v0.7.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.17.9 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/kr/pretty v0.1.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.28.0 // indirect + golang.org/x/sys v0.33.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/fiberopenapi/go.sum b/adapter/fiberopenapi/go.sum index 254c025..26e31c4 100644 --- a/adapter/fiberopenapi/go.sum +++ b/adapter/fiberopenapi/go.sum @@ -16,9 +16,13 @@ github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= @@ -33,14 +37,14 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -53,12 +57,12 @@ github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCO github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/fiberopenapi/router_test.go b/adapter/fiberopenapi/router_test.go index cedc243..e887817 100644 --- a/adapter/fiberopenapi/router_test.go +++ b/adapter/fiberopenapi/router_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") func PingHandler(c *fiber.Ctx) error { @@ -212,8 +213,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -262,11 +264,11 @@ func TestRouter_Spec(t *testing.T) { if tt.shouldErr { err := r.Validate() - assert.Error(t, err, "expected error for invalid OpenAPI configuration") + require.Error(t, err, "expected error for invalid OpenAPI configuration") return } err := r.Validate() - assert.NoError(t, err, "failed to validate OpenAPI configuration") + require.NoError(t, err, "failed to validate OpenAPI configuration") // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -329,7 +331,8 @@ func TestRouter_Single(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for %s request", tt.method) if tt.method != "HEAD" { - body, err := io.ReadAll(res.Body) + var body []byte + body, err = io.ReadAll(res.Body) require.NoError(t, err, "failed to read response body for %s request", tt.method) assert.Equal(t, "pong", string(body), "expected response body to be 'pong' for %s request", tt.method) } @@ -342,7 +345,13 @@ func TestRouter_Single(t *testing.T) { assert.NotEmpty(t, schema, "expected non-empty OpenAPI schema for %s request", tt.method) // Check if the route is registered in the OpenAPI schema - assert.Contains(t, string(schema), "operationId: ping", "expected operationId 'ping' in OpenAPI schema for %s request", tt.method) + assert.Contains( + t, + string(schema), + "operationId: ping", + "expected operationId 'ping' in OpenAPI schema for %s request", + tt.method, + ) }) } @@ -350,7 +359,7 @@ func TestRouter_Single(t *testing.T) { app := fiber.New() r := fiberopenapi.NewRouter(app) r.Static("/static", "./testdata", fiber.Static{}) - req, _ := http.NewRequest("GET", "/static/petstore.yaml", nil) + req, _ := http.NewRequest(http.MethodGet, "/static/petstore.yaml", nil) res, err := app.Test(req, -1) require.NoError(t, err, "failed to test static file request") assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for static file request") @@ -373,7 +382,7 @@ func TestRouter_Group(t *testing.T) { option.Summary("Ping Endpoint"), ) - req, _ := http.NewRequest("GET", "/api/ping", nil) + req, _ := http.NewRequest(http.MethodGet, "/api/ping", nil) res, err := app.Test(req, -1) require.NoError(t, err, "failed to test group route") assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for group route") @@ -395,7 +404,7 @@ func TestRouter_Group(t *testing.T) { ) }) - req, _ := http.NewRequest("GET", "/api/ping", nil) + req, _ := http.NewRequest(http.MethodGet, "/api/ping", nil) res, err := app.Test(req, -1) require.NoError(t, err, "failed to test route") assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for route") @@ -420,7 +429,7 @@ func TestRouter_Middleware(t *testing.T) { return c.SendString("pong") }) - req, _ := http.NewRequest("GET", "/ping", nil) + req, _ := http.NewRequest(http.MethodGet, "/ping", nil) res, err := app.Test(req, -1) require.NoError(t, err, "failed to test middleware route") assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for middleware route") @@ -437,17 +446,22 @@ func TestGenerator_Docs(t *testing.T) { ) t.Run("should serve docs", func(t *testing.T) { - req, _ := http.NewRequest("GET", "/docs", nil) + req, _ := http.NewRequest(http.MethodGet, "/docs", nil) res, err := app.Test(req, -1) require.NoError(t, err, "failed to test docs route") assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for docs route") body, err := io.ReadAll(res.Body) require.NoError(t, err, "failed to read response body for docs route") - assert.Contains(t, string(body), "Fiber OpenAPI", "expected response body to contain 'Fiber OpenAPI' for docs route") + assert.Contains( + t, + string(body), + "Fiber OpenAPI", + "expected response body to contain 'Fiber OpenAPI' for docs route", + ) }) t.Run("should serve OpenAPI YAML", func(t *testing.T) { - req, _ := http.NewRequest("GET", "/docs/openapi.yaml", nil) + req, _ := http.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) res, err := app.Test(req, -1) require.NoError(t, err, "failed to test OpenAPI YAML route") assert.Equal(t, http.StatusOK, res.StatusCode, "expected status OK for OpenAPI YAML route") @@ -455,7 +469,12 @@ func TestGenerator_Docs(t *testing.T) { body, err := io.ReadAll(res.Body) require.NoError(t, err, "failed to read response body for OpenAPI YAML route") assert.NotEmpty(t, body, "expected non-empty response body for OpenAPI YAML route") - assert.Contains(t, string(body), "openapi: 3.0.3", "expected OpenAPI version in response body for OpenAPI YAML route") + assert.Contains( + t, + string(body), + "openapi: 3.0.3", + "expected OpenAPI version in response body for OpenAPI YAML route", + ) }) } @@ -471,14 +490,14 @@ func TestGenerator_DisableDocs(t *testing.T) { ) t.Run("should not register docs route", func(t *testing.T) { - reqDocs, _ := http.NewRequest("GET", "/docs", nil) + reqDocs, _ := http.NewRequest(http.MethodGet, "/docs", nil) resDocs, err := app.Test(reqDocs, -1) require.NoError(t, err, "failed to test docs route") assert.Equal(t, http.StatusNotFound, resDocs.StatusCode, "expected status Not Found for docs route") _ = resDocs.Body.Close() }) t.Run("should not register openapi.yaml route", func(t *testing.T) { - reqOpenAPI, _ := http.NewRequest("GET", "/docs/openapi.yaml", nil) + reqOpenAPI, _ := http.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) resOpenAPI, err := app.Test(reqOpenAPI, -1) require.NoError(t, err, "failed to test OpenAPI YAML route") assert.Equal(t, http.StatusNotFound, resOpenAPI.StatusCode, "expected status Not Found for OpenAPI YAML route") @@ -502,10 +521,10 @@ func TestGenerator_WriteSchemaTo(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - tempFile, err := os.CreateTemp("", "openapi-schema-*.yaml") + tempFile, err := os.CreateTemp(t.TempDir(), "openapi-schema-*.yaml") require.NoError(t, err, "failed to create temporary file for OpenAPI schema") defer func() { - err := os.Remove(tempFile.Name()) + err = os.Remove(tempFile.Name()) require.NoError(t, err, "failed to remove temporary file") }() diff --git a/adapter/ginopenapi/examples/basic/go.mod b/adapter/ginopenapi/examples/basic/go.mod index 22d2c20..05cd6e5 100644 --- a/adapter/ginopenapi/examples/basic/go.mod +++ b/adapter/ginopenapi/examples/basic/go.mod @@ -1,6 +1,8 @@ module github.com/oaswrap/spec/adapter/ginopenapi/examples/basic -go 1.21 +go 1.23.0 + +toolchain go1.23.12 require ( github.com/gin-gonic/gin v1.10.1 @@ -21,6 +23,7 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/kr/text v0.1.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -28,15 +31,15 @@ require ( github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/crypto v0.38.0 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect google.golang.org/protobuf v1.34.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/adapter/ginopenapi/examples/basic/go.sum b/adapter/ginopenapi/examples/basic/go.sum index e4fe7ca..d322f79 100644 --- a/adapter/ginopenapi/examples/basic/go.sum +++ b/adapter/ginopenapi/examples/basic/go.sum @@ -40,6 +40,8 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -70,14 +72,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= @@ -91,20 +91,16 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/adapter/ginopenapi/go.mod b/adapter/ginopenapi/go.mod index 6d52040..773c9bc 100644 --- a/adapter/ginopenapi/go.mod +++ b/adapter/ginopenapi/go.mod @@ -1,12 +1,14 @@ module github.com/oaswrap/spec/adapter/ginopenapi -go 1.21 +go 1.23.0 + +toolchain go1.23.12 require ( github.com/gin-gonic/gin v1.10.1 github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( @@ -24,6 +26,7 @@ require ( github.com/google/go-cmp v0.7.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -31,16 +34,17 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/crypto v0.38.0 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/ginopenapi/go.sum b/adapter/ginopenapi/go.sum index e4fe7ca..681906a 100644 --- a/adapter/ginopenapi/go.sum +++ b/adapter/ginopenapi/go.sum @@ -40,6 +40,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -70,14 +75,14 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= @@ -91,20 +96,21 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/adapter/ginopenapi/router_test.go b/adapter/ginopenapi/router_test.go index e9d309b..5845202 100644 --- a/adapter/ginopenapi/router_test.go +++ b/adapter/ginopenapi/router_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") func TestRouter_Spec(t *testing.T) { @@ -210,8 +211,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -260,11 +262,11 @@ func TestRouter_Spec(t *testing.T) { if tt.shouldErr { err := r.Validate() - assert.Error(t, err, "expected error for invalid OpenAPI configuration") + require.Error(t, err, "expected error for invalid OpenAPI configuration") return } err := r.Validate() - assert.NoError(t, err, "failed to validate OpenAPI configuration") + require.NoError(t, err, "failed to validate OpenAPI configuration") // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -329,7 +331,13 @@ func TestRouter_Single(t *testing.T) { app.ServeHTTP(rec, req) assert.Equal(t, http.StatusOK, rec.Code, "expected status code 200 for %s", tt.method) - assert.Equal(t, `{"message":"pong"}`, rec.Body.String(), "expected response body to be 'pong' for %s", tt.method) + assert.JSONEq( + t, + `{"message":"pong"}`, + rec.Body.String(), + "expected response body to be 'pong' for %s", + tt.method, + ) schema, err := r.GenerateSchema() require.NoError(t, err, "failed to generate OpenAPI schema for %s", tt.method) @@ -344,7 +352,7 @@ func TestRouter_Single(t *testing.T) { fileName := "hello.txt" fileContent := []byte("Hello, static!") err := os.WriteFile(filepath.Join(tmpDir, fileName), fileContent, 0644) - assert.NoError(t, err) + require.NoError(t, err) // Setup Gin gin.SetMode(gin.TestMode) @@ -354,7 +362,7 @@ func TestRouter_Single(t *testing.T) { // Create test server w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/static/"+fileName, nil) + req, _ := http.NewRequest(http.MethodGet, "/static/"+fileName, nil) g.ServeHTTP(w, req) // Assertions @@ -370,7 +378,7 @@ func TestRouter_Single(t *testing.T) { fileName := "test.txt" content := []byte("Hello from StaticFS!") err := os.WriteFile(filepath.Join(tmpDir, fileName), content, 0644) - assert.NoError(t, err) + require.NoError(t, err) // Setup Gin gin.SetMode(gin.TestMode) @@ -382,7 +390,7 @@ func TestRouter_Single(t *testing.T) { // Make request w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/assets/"+fileName, nil) + req, _ := http.NewRequest(http.MethodGet, "/assets/"+fileName, nil) g.ServeHTTP(w, req) // Assert @@ -391,7 +399,7 @@ func TestRouter_Single(t *testing.T) { }) t.Run("StaticFile", func(t *testing.T) { // Create temp file - tmpFile, err := os.CreateTemp("", "static-file-*.txt") + tmpFile, err := os.CreateTemp(t.TempDir(), "static-file-*.txt") require.NoError(t, err) defer func() { _ = os.Remove(tmpFile.Name()) @@ -410,7 +418,7 @@ func TestRouter_Single(t *testing.T) { // Create test server w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/static-file", nil) + req, _ := http.NewRequest(http.MethodGet, "/static-file", nil) g.ServeHTTP(w, req) // Assertions @@ -424,7 +432,7 @@ func TestRouter_Single(t *testing.T) { content := []byte("This is served by StaticFileFS!") err := os.WriteFile(filepath.Join(tmpDir, fileName), content, 0644) - assert.NoError(t, err) + require.NoError(t, err) g := gin.New() r := ginopenapi.NewRouter(g) @@ -434,7 +442,7 @@ func TestRouter_Single(t *testing.T) { // Make request w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/myfile", nil) + req, _ := http.NewRequest(http.MethodGet, "/myfile", nil) g.ServeHTTP(w, req) assert.Equal(t, http.StatusOK, w.Code) @@ -467,12 +475,12 @@ func TestRouter_Group(t *testing.T) { assert.NotNil(t, group, "expected group to be created") - req, _ := http.NewRequest("GET", "/api/ping", nil) + req, _ := http.NewRequest(http.MethodGet, "/api/ping", nil) rec := httptest.NewRecorder() app.ServeHTTP(rec, req) assert.Equal(t, http.StatusOK, rec.Code, "expected status code 200 for /api/ping") - assert.Equal(t, `{"message":"pong"}`, rec.Body.String(), "expected response body to be 'pong' for /api/ping") + assert.JSONEq(t, `{"message":"pong"}`, rec.Body.String(), "expected response body to be 'pong' for /api/ping") schema, err := r.GenerateSchema() require.NoError(t, err, "failed to generate OpenAPI schema for /api/ping") @@ -497,11 +505,11 @@ func TestRouter_Middleware(t *testing.T) { option.OperationID("testHandler"), ) - req := httptest.NewRequest("GET", "/test", nil) + req := httptest.NewRequest(http.MethodGet, "/test", nil) rec := httptest.NewRecorder() app.ServeHTTP(rec, req) assert.Equal(t, http.StatusOK, rec.Code, "expected status code 200 for /test") - assert.Equal(t, `{"message":"test"}`, rec.Body.String(), "expected response body to be 'test'") + assert.JSONEq(t, `{"message":"test"}`, rec.Body.String(), "expected response body to be 'test'") assert.True(t, called, "expected middleware to be called") }) } @@ -526,11 +534,11 @@ func TestGenerator_Docs(t *testing.T) { // Validate the router err := r.Validate() - assert.NoError(t, err, "expected no error when validating router") + require.NoError(t, err, "expected no error when validating router") // Test the OpenAPI documentation endpoint t.Run("should serve docs", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs", nil) + req := httptest.NewRequest(http.MethodGet, "/docs", nil) rec := httptest.NewRecorder() app.ServeHTTP(rec, req) @@ -538,13 +546,18 @@ func TestGenerator_Docs(t *testing.T) { assert.Contains(t, rec.Body.String(), "Gin OpenAPI", "expected API documentation in response body") }) t.Run("should serve OpenAPI YAML", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs/openapi.yaml", nil) + req := httptest.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) rec := httptest.NewRecorder() app.ServeHTTP(rec, req) assert.Equal(t, http.StatusOK, rec.Code, "expected status code 200 for /docs/openapi.yaml") assert.NotEmpty(t, rec.Body.String(), "expected non-empty OpenAPI YAML response") - assert.Contains(t, rec.Header().Get("Content-Type"), "application/x-yaml", "expected Content-Type to be application/x-yaml") + assert.Contains( + t, + rec.Header().Get("Content-Type"), + "application/x-yaml", + "expected Content-Type to be application/x-yaml", + ) assert.Contains(t, rec.Body.String(), "openapi: 3.0.3", "expected OpenAPI version in response body") }) } @@ -561,16 +574,21 @@ func TestGenerator_DisableDocs(t *testing.T) { }) t.Run("should not register docs routes", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs", nil) + req := httptest.NewRequest(http.MethodGet, "/docs", nil) rec := httptest.NewRecorder() app.ServeHTTP(rec, req) assert.Equal(t, http.StatusNotFound, rec.Code, "expected status code 404 for /docs when OpenAPI is disabled") }) t.Run("should not register OpenAPI YAML route", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs/openapi.yaml", nil) + req := httptest.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) rec := httptest.NewRecorder() app.ServeHTTP(rec, req) - assert.Equal(t, http.StatusNotFound, rec.Code, "expected status code 404 for /docs/openapi.yaml when OpenAPI is disabled") + assert.Equal( + t, + http.StatusNotFound, + rec.Code, + "expected status code 404 for /docs/openapi.yaml when OpenAPI is disabled", + ) }) } @@ -586,10 +604,10 @@ func TestGenerator_WriteSchemaTo(t *testing.T) { err := r.Validate() require.NoError(t, err, "failed to validate OpenAPI configuration") - tempFile, err := os.CreateTemp("", "openapi-schema-*.yaml") + tempFile, err := os.CreateTemp(t.TempDir(), "openapi-schema-*.yaml") require.NoError(t, err, "failed to create temporary file for OpenAPI schema") defer func() { - err := os.Remove(tempFile.Name()) + err = os.Remove(tempFile.Name()) require.NoError(t, err, "failed to remove temporary file") }() diff --git a/adapter/httpopenapi/examples/basic/go.mod b/adapter/httpopenapi/examples/basic/go.mod index 8eb9d79..564cd21 100644 --- a/adapter/httpopenapi/examples/basic/go.mod +++ b/adapter/httpopenapi/examples/basic/go.mod @@ -8,9 +8,10 @@ require ( ) require ( + github.com/kr/text v0.1.0 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/adapter/httpopenapi/examples/basic/go.sum b/adapter/httpopenapi/examples/basic/go.sum index 42503aa..f9e569d 100644 --- a/adapter/httpopenapi/examples/basic/go.sum +++ b/adapter/httpopenapi/examples/basic/go.sum @@ -8,6 +8,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -16,22 +18,20 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/httpopenapi/go.mod b/adapter/httpopenapi/go.mod index 8f187ac..096d048 100644 --- a/adapter/httpopenapi/go.mod +++ b/adapter/httpopenapi/go.mod @@ -5,16 +5,18 @@ go 1.22 require ( github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.7.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/httpopenapi/go.sum b/adapter/httpopenapi/go.sum index 42503aa..54864bc 100644 --- a/adapter/httpopenapi/go.sum +++ b/adapter/httpopenapi/go.sum @@ -8,6 +8,11 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -16,22 +21,23 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/httpopenapi/internal/parser/parser.go b/adapter/httpopenapi/internal/parser/parser.go index 34ed3a0..e0bb893 100644 --- a/adapter/httpopenapi/internal/parser/parser.go +++ b/adapter/httpopenapi/internal/parser/parser.go @@ -1,7 +1,7 @@ package parser import ( - "fmt" + "errors" "net" "net/http" "strings" @@ -13,10 +13,16 @@ type RoutePattern struct { Path string } +var ( + ErrInvalidRoutePattern = errors.New("invalid route pattern") +) + +const TotalParts = 2 + func ParseRoutePattern(s string) (*RoutePattern, error) { rp := &RoutePattern{} - parts := strings.SplitN(s, " ", 2) + parts := strings.SplitN(s, " ", TotalParts) if len(parts) == 2 && isHTTPMethod(parts[0]) { rp.Method = parts[0] @@ -39,7 +45,7 @@ func ParseRoutePattern(s string) (*RoutePattern, error) { } if strings.Contains(rp.Host, " ") { - return nil, fmt.Errorf("invalid host: contains space") + return nil, ErrInvalidRoutePattern } // Handle host:port @@ -50,7 +56,7 @@ func ParseRoutePattern(s string) (*RoutePattern, error) { // Strict host check if hostPart != "localhost" && !strings.Contains(hostPart, ".") { - return nil, fmt.Errorf("invalid host: %q must contain '.' or be 'localhost'", hostPart) + return nil, ErrInvalidRoutePattern } return rp, nil diff --git a/adapter/httpopenapi/internal/parser/parser_test.go b/adapter/httpopenapi/internal/parser/parser_test.go index 51d7c42..1f9ed5d 100644 --- a/adapter/httpopenapi/internal/parser/parser_test.go +++ b/adapter/httpopenapi/internal/parser/parser_test.go @@ -5,6 +5,7 @@ import ( "github.com/oaswrap/spec/adapter/httpopenapi/internal/parser" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestParseRoutePattern(t *testing.T) { @@ -128,10 +129,10 @@ func TestParseRoutePattern(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := parser.ParseRoutePattern(tt.input) if tt.wantErr { - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, got) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, tt.want.Method, got.Method) assert.Equal(t, tt.want.Host, got.Host) assert.Equal(t, tt.want.Path, got.Path) diff --git a/adapter/httpopenapi/router_test.go b/adapter/httpopenapi/router_test.go index 0bbcb40..e84c0bd 100644 --- a/adapter/httpopenapi/router_test.go +++ b/adapter/httpopenapi/router_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") func TestRouter_Spec(t *testing.T) { @@ -208,8 +209,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -251,11 +253,11 @@ func TestRouter_Spec(t *testing.T) { if tt.shouldErr { err := r.Validate() - assert.Error(t, err, "expected error for invalid OpenAPI configuration") + require.Error(t, err, "expected error for invalid OpenAPI configuration") return } err := r.Validate() - assert.NoError(t, err, "failed to validate OpenAPI configuration") + require.NoError(t, err, "failed to validate OpenAPI configuration") // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -277,7 +279,7 @@ func TestRouter_Spec(t *testing.T) { } } -func pingHandler(w http.ResponseWriter, r *http.Request) { +func pingHandler(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(map[string]string{"message": "pong"}) } @@ -290,7 +292,7 @@ func TestRouter_Handle(t *testing.T) { option.OperationID("pingHandler"), ) - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -308,7 +310,7 @@ func TestRouter_Handle(t *testing.T) { option.OperationID("pingHandler"), ) - req := httptest.NewRequest("CONNECT", "/ping", nil) + req := httptest.NewRequest(http.MethodConnect, "/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -329,7 +331,7 @@ func TestRouter_HandleFunc(t *testing.T) { option.OperationID("pingHandler"), ) - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -347,7 +349,7 @@ func TestRouter_HandleFunc(t *testing.T) { option.OperationID("pingHandler"), ) - req := httptest.NewRequest("CONNECT", "/ping", nil) + req := httptest.NewRequest(http.MethodConnect, "/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -372,7 +374,7 @@ func TestRouter_Group(t *testing.T) { option.OperationID("pingHandler"), ) - req := httptest.NewRequest("GET", "/api/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/api/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -400,7 +402,7 @@ func TestRouter_Group(t *testing.T) { option.OperationID("pingHandler"), ) - req := httptest.NewRequest("GET", "/api/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/api/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -422,7 +424,7 @@ func TestRouter_Group(t *testing.T) { ) }) - req := httptest.NewRequest("GET", "/api/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/api/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -449,7 +451,7 @@ func TestRouter_Group(t *testing.T) { ) }, middleware) - req := httptest.NewRequest("GET", "/api/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/api/ping", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -473,7 +475,7 @@ func TestGenerator_Docs(t *testing.T) { // Test the OpenAPI documentation endpoint t.Run("should serve docs", func(t *testing.T) { - docsReq := httptest.NewRequest("GET", "/docs", nil) + docsReq := httptest.NewRequest(http.MethodGet, "/docs", nil) docsRec := httptest.NewRecorder() mux.ServeHTTP(docsRec, docsReq) @@ -481,7 +483,7 @@ func TestGenerator_Docs(t *testing.T) { assert.Contains(t, docsRec.Body.String(), "HTTP OpenAPI") }) t.Run("should serve docs file", func(t *testing.T) { - docsFileReq := httptest.NewRequest("GET", "/docs/openapi.yaml", nil) + docsFileReq := httptest.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) docsFileRec := httptest.NewRecorder() mux.ServeHTTP(docsFileRec, docsFileReq) @@ -502,14 +504,14 @@ func TestGenerator_DisableDocs(t *testing.T) { // Test that docs are not served when disabled t.Run("should not serve docs when disabled", func(t *testing.T) { - docsReq := httptest.NewRequest("GET", "/docs", nil) + docsReq := httptest.NewRequest(http.MethodGet, "/docs", nil) docsRec := httptest.NewRecorder() mux.ServeHTTP(docsRec, docsReq) assert.Equal(t, http.StatusNotFound, docsRec.Code, "expected 404 when docs are disabled") }) t.Run("should not serve docs file when disabled", func(t *testing.T) { - docsFileReq := httptest.NewRequest("GET", "/docs/openapi.yaml", nil) + docsFileReq := httptest.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) docsFileRec := httptest.NewRecorder() mux.ServeHTTP(docsFileRec, docsFileReq) @@ -555,7 +557,7 @@ func TestGenerator_WriteSchemaTo(t *testing.T) { option.OperationID("pingHandler"), ) - tempFile, err := os.CreateTemp("", "openapi-schema-*.yaml") + tempFile, err := os.CreateTemp(t.TempDir(), "openapi-schema-*.yaml") require.NoError(t, err, "failed to create temporary file") defer func() { _ = os.Remove(tempFile.Name()) diff --git a/adapter/httprouteropenapi/examples/basic/go.mod b/adapter/httprouteropenapi/examples/basic/go.mod index d505350..4ba147a 100644 --- a/adapter/httprouteropenapi/examples/basic/go.mod +++ b/adapter/httprouteropenapi/examples/basic/go.mod @@ -9,9 +9,10 @@ require ( ) require ( + github.com/kr/text v0.1.0 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/adapter/httprouteropenapi/examples/basic/go.sum b/adapter/httprouteropenapi/examples/basic/go.sum index 9e54877..5356427 100644 --- a/adapter/httprouteropenapi/examples/basic/go.sum +++ b/adapter/httprouteropenapi/examples/basic/go.sum @@ -10,6 +10,8 @@ github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -18,22 +20,20 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/httprouteropenapi/go.mod b/adapter/httprouteropenapi/go.mod index bd74bc5..18b35a5 100644 --- a/adapter/httprouteropenapi/go.mod +++ b/adapter/httprouteropenapi/go.mod @@ -6,16 +6,18 @@ require ( github.com/julienschmidt/httprouter v1.3.0 github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.7.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/httprouteropenapi/go.sum b/adapter/httprouteropenapi/go.sum index 9e54877..2c8bc4e 100644 --- a/adapter/httprouteropenapi/go.sum +++ b/adapter/httprouteropenapi/go.sum @@ -10,6 +10,11 @@ github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -18,22 +23,23 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/httprouteropenapi/router.go b/adapter/httprouteropenapi/router.go index 0414733..fcc06ca 100644 --- a/adapter/httprouteropenapi/router.go +++ b/adapter/httprouteropenapi/router.go @@ -58,17 +58,17 @@ type router struct { gen spec.Generator } -func (sr *router) wrapHandler(h httprouter.Handle) httprouter.Handle { - return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { +func (r *router) wrapHandler(h httprouter.Handle) httprouter.Handle { + return func(w http.ResponseWriter, rr *http.Request, ps httprouter.Params) { handlerFunc := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { h(w, r, ps) }) handler := http.Handler(handlerFunc) - for i := len(sr.middlewares) - 1; i >= 0; i-- { - m := sr.middlewares[i] + for i := len(r.middlewares) - 1; i >= 0; i-- { + m := r.middlewares[i] handler = m(handler) } - handler.ServeHTTP(w, r) + handler.ServeHTTP(w, rr) } } @@ -109,7 +109,7 @@ func (r *router) Handler(method, path string, handler http.Handler) Route { } func (r *router) HandlerFunc(method, path string, handlerFunc http.HandlerFunc) Route { - return r.Handler(method, path, http.HandlerFunc(handlerFunc)) + return r.Handler(method, path, handlerFunc) } func (r *router) ServeHTTP(w http.ResponseWriter, req *http.Request) { diff --git a/adapter/httprouteropenapi/router_test.go b/adapter/httprouteropenapi/router_test.go index 7dc5f3f..654b833 100644 --- a/adapter/httprouteropenapi/router_test.go +++ b/adapter/httprouteropenapi/router_test.go @@ -19,9 +19,10 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") -func DummyHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { +func DummyHandler(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) { w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(map[string]string{"message": "Hello, World!"}) } @@ -214,8 +215,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -264,11 +266,11 @@ func TestRouter_Spec(t *testing.T) { if tt.shouldErr { err := r.Validate() - assert.Error(t, err, "expected error for invalid OpenAPI configuration") + require.Error(t, err, "expected error for invalid OpenAPI configuration") return } err := r.Validate() - assert.NoError(t, err, "failed to validate OpenAPI configuration") + require.NoError(t, err, "failed to validate OpenAPI configuration") // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -292,7 +294,7 @@ func TestRouter_Spec(t *testing.T) { type SingleRouteFunc func(path string, handle httprouter.Handle) httprouteropenapi.Route -func PingHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { +func PingHandler(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) { w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(map[string]string{"message": "pong"}) } @@ -376,7 +378,7 @@ func TestRouter_SingleRoute(t *testing.T) { assert.JSONEq(t, `{"message":"pong"}`, rec.Body.String(), "response body should match") schema, err := r.GenerateSchema() - assert.NoError(t, err, "failed to generate OpenAPI schema") + require.NoError(t, err, "failed to generate OpenAPI schema") assert.NotEmpty(t, schema, "OpenAPI schema should not be empty") assert.Contains(t, string(schema), "summary: Ping the server", "OpenAPI schema should contain the summary") }) @@ -404,7 +406,7 @@ func TestRouter_Group(t *testing.T) { api := r.Group("/api/v1", middleware1, middleware2).With( option.GroupTags("apiv1"), ) - dummyHandler := func(w http.ResponseWriter, r *http.Request) { + dummyHandler := func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(map[string]string{"message": "pong"}) } @@ -438,7 +440,7 @@ func TestRouter_Group(t *testing.T) { }, logs, "middleware logs should match") schema, err := r.GenerateSchema() - assert.NoError(t, err, "failed to generate OpenAPI schema") + require.NoError(t, err, "failed to generate OpenAPI schema") assert.NotEmpty(t, schema, "OpenAPI schema should not be empty") assert.Contains(t, string(schema), "apiv1", "OpenAPI schema should contain the group tags") @@ -523,7 +525,7 @@ func TestGenerator_MarshalYAML(t *testing.T) { ) schema, err := r.MarshalYAML() - assert.NoError(t, err, "failed to marshal OpenAPI schema to YAML") + require.NoError(t, err, "failed to marshal OpenAPI schema to YAML") assert.NotEmpty(t, schema, "YAML schema should not be empty") assert.Contains(t, string(schema), "summary: Ping the server", "YAML schema should contain the summary") } @@ -541,7 +543,7 @@ func TestGenerator_MarshalJSON(t *testing.T) { ) schema, err := r.MarshalJSON() - assert.NoError(t, err, "failed to marshal OpenAPI schema to JSON") + require.NoError(t, err, "failed to marshal OpenAPI schema to JSON") assert.NotEmpty(t, schema, "JSON schema should not be empty") assert.Contains(t, string(schema), `"summary": "Ping the server"`, "JSON schema should contain the summary") } @@ -561,6 +563,6 @@ func TestGenerator_WriteSchemaTo(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "openapi.yaml") err := r.WriteSchemaTo(path) - assert.NoError(t, err, "failed to write OpenAPI schema to directory") + require.NoError(t, err, "failed to write OpenAPI schema to directory") assert.FileExists(t, path, "openapi.yaml should be created") } diff --git a/adapter/muxopenapi/examples/basic/go.mod b/adapter/muxopenapi/examples/basic/go.mod index 89cd584..0f5f9a8 100644 --- a/adapter/muxopenapi/examples/basic/go.mod +++ b/adapter/muxopenapi/examples/basic/go.mod @@ -9,9 +9,10 @@ require ( ) require ( + github.com/kr/text v0.1.0 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/adapter/muxopenapi/examples/basic/go.sum b/adapter/muxopenapi/examples/basic/go.sum index e66dc23..643efe9 100644 --- a/adapter/muxopenapi/examples/basic/go.sum +++ b/adapter/muxopenapi/examples/basic/go.sum @@ -10,6 +10,8 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -18,22 +20,20 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/muxopenapi/go.mod b/adapter/muxopenapi/go.mod index ca59b81..b9ffeda 100644 --- a/adapter/muxopenapi/go.mod +++ b/adapter/muxopenapi/go.mod @@ -6,16 +6,18 @@ require ( github.com/gorilla/mux v1.8.1 github.com/oaswrap/spec v0.3.3 github.com/oaswrap/spec-ui v0.1.4 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.7.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/adapter/muxopenapi/go.sum b/adapter/muxopenapi/go.sum index e66dc23..8eb2dd3 100644 --- a/adapter/muxopenapi/go.sum +++ b/adapter/muxopenapi/go.sum @@ -10,6 +10,11 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/oaswrap/spec v0.3.3 h1:ezFH6wflfTrDUo7sxk6iRi+dWWbkdzqRW8xXw139oVw= github.com/oaswrap/spec v0.3.3/go.mod h1:cQiboTAf466DfgKGbFe0wCA14wXSBfhPcGMM0/zN1V8= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= @@ -18,22 +23,23 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/adapter/muxopenapi/router.go b/adapter/muxopenapi/router.go index 36f7f83..b5ac47a 100644 --- a/adapter/muxopenapi/router.go +++ b/adapter/muxopenapi/router.go @@ -1,7 +1,6 @@ package muxopenapi import ( - "fmt" "net/http" "github.com/gorilla/mux" @@ -22,14 +21,14 @@ var _ Generator = (*router)(nil) // NewRouter creates a new OpenAPI router with the provided mux.Router instance and options. // -// It initializes the OpenAPI configuration and sets up the necessary routes for serving +// It initializes the OpenAPI configuration and sets up the necessary routes for serving. func NewRouter(mux *mux.Router, opts ...option.OpenAPIOption) Generator { return NewGenerator(mux, opts...) } // NewGenerator creates a new OpenAPI router with the provided mux.Router instance and options. // -// It initializes the OpenAPI configuration and sets up the necessary routes for serving +// It initializes the OpenAPI configuration and sets up the necessary routes for serving. func NewGenerator(mux *mux.Router, opts ...option.OpenAPIOption) Generator { defaultOpts := []option.OpenAPIOption{ option.WithTitle(constant.DefaultTitle), @@ -52,8 +51,6 @@ func NewGenerator(mux *mux.Router, opts ...option.OpenAPIOption) Generator { handler := specui.NewHandler(mapper.SpecUIOpts(gen)...) - fmt.Println(cfg.SpecPath) - mux.Handle(cfg.DocsPath, handler.Docs()).Methods(http.MethodGet) mux.Handle(cfg.SpecPath, handler.Spec()).Methods(http.MethodGet) diff --git a/adapter/muxopenapi/router_test.go b/adapter/muxopenapi/router_test.go index fbb4cf9..037d533 100644 --- a/adapter/muxopenapi/router_test.go +++ b/adapter/muxopenapi/router_test.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/require" ) +//nolint:gochecknoglobals // test flag for golden file updates var update = flag.Bool("update", false, "update golden files") func TestRouter_Spec(t *testing.T) { @@ -210,8 +211,9 @@ func TestRouter_Spec(t *testing.T) { option.Summary("Update an existing user"), option.Description("Update the details of an existing user."), option.Request(new(struct { - Username string `path:"username" required:"true"` dto.PetUser + + Username string `path:"username" required:"true"` })), option.Response(200, new(dto.PetUser)), option.Response(404, nil), @@ -253,11 +255,11 @@ func TestRouter_Spec(t *testing.T) { if tt.shouldErr { err := r.Validate() - assert.Error(t, err, "expected error for invalid OpenAPI configuration") + require.Error(t, err, "expected error for invalid OpenAPI configuration") return } err := r.Validate() - assert.NoError(t, err, "failed to validate OpenAPI configuration") + require.NoError(t, err, "failed to validate OpenAPI configuration") // Test the OpenAPI schema generation schema, err := r.GenerateSchema() @@ -279,7 +281,7 @@ func TestRouter_Spec(t *testing.T) { } } -func PingHandler(w http.ResponseWriter, r *http.Request) { +func PingHandler(w http.ResponseWriter, _ *http.Request) { _ = json.NewEncoder(w).Encode(map[string]string{"message": "pong"}) } @@ -298,7 +300,7 @@ func TestRouter_HandleFunc(t *testing.T) { assert.NotNil(t, r.GetRoute("ping")) assert.NotNil(t, route.GetHandler()) assert.Equal(t, "ping", route.GetName()) - assert.Nil(t, route.GetError()) + require.NoError(t, route.GetError()) // Test the /ping endpoint req := httptest.NewRequest(method, "/ping", nil) @@ -338,7 +340,7 @@ func TestRouter_Handle(t *testing.T) { assert.NotNil(t, r.GetRoute("ping")) assert.NotNil(t, route.GetHandler()) assert.Equal(t, "ping", route.GetName()) - assert.Nil(t, route.GetError()) + require.NoError(t, route.GetError()) // Test the /ping endpoint req := httptest.NewRequest(method, "/ping", nil) @@ -371,7 +373,7 @@ func TestRouter_Queries(t *testing.T) { option.Summary("Ping endpoint"), ) t.Run("when match should return 200", func(t *testing.T) { - req := httptest.NewRequest("GET", "/ping?foo=bar", nil) + req := httptest.NewRequest(http.MethodGet, "/ping?foo=bar", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -379,7 +381,7 @@ func TestRouter_Queries(t *testing.T) { assert.JSONEq(t, `{"message": "pong"}`, rec.Body.String()) }) t.Run("when not match should return 404", func(t *testing.T) { - req := httptest.NewRequest("GET", "/ping?foo=baz", nil) + req := httptest.NewRequest(http.MethodGet, "/ping?foo=baz", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -396,7 +398,7 @@ func TestRouter_Headers(t *testing.T) { ) t.Run("when match should return 200", func(t *testing.T) { - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) req.Header.Set("X-Foo", "bar") rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -405,7 +407,7 @@ func TestRouter_Headers(t *testing.T) { assert.JSONEq(t, `{"message": "pong"}`, rec.Body.String()) }) t.Run("when not match should return 404", func(t *testing.T) { - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) req.Header.Set("X-Foo", "baz") rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -424,7 +426,7 @@ func TestRouter_Subrouter(t *testing.T) { ) // Test the /api/ping endpoint - req := httptest.NewRequest("GET", "/api/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/api/ping", nil) rr := httptest.NewRecorder() mux.ServeHTTP(rr, req) @@ -455,7 +457,7 @@ func TestRouter_Middleware(t *testing.T) { option.Summary("Ping endpoint"), ) - req := httptest.NewRequest("GET", "/ping", nil) + req := httptest.NewRequest(http.MethodGet, "/ping", nil) rec := httptest.NewRecorder() r.ServeHTTP(rec, req) @@ -474,7 +476,7 @@ func TestGenerator_Docs(t *testing.T) { ) t.Run("should serve docs", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs", nil) + req := httptest.NewRequest(http.MethodGet, "/docs", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -482,7 +484,7 @@ func TestGenerator_Docs(t *testing.T) { assert.Contains(t, rec.Body.String(), "Mux OpenAPI") }) t.Run("should serve docs/openapi.yaml", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs/openapi.yaml", nil) + req := httptest.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -500,7 +502,7 @@ func TestGenerator_DisableDocs(t *testing.T) { ) t.Run("should not serve docs", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs", nil) + req := httptest.NewRequest(http.MethodGet, "/docs", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) @@ -508,7 +510,7 @@ func TestGenerator_DisableDocs(t *testing.T) { }) t.Run("should not serve docs/openapi.yaml", func(t *testing.T) { - req := httptest.NewRequest("GET", "/docs/openapi.yaml", nil) + req := httptest.NewRequest(http.MethodGet, "/docs/openapi.yaml", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) diff --git a/examples/basic/go.mod b/examples/basic/go.mod index 82b7929..0184887 100644 --- a/examples/basic/go.mod +++ b/examples/basic/go.mod @@ -2,12 +2,13 @@ module github.com/oaswrap/spec/examples/basic go 1.21 -require github.com/oaswrap/spec v0.3.2 +require github.com/oaswrap/spec v0.3.3 require ( + github.com/kr/text v0.1.0 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/examples/basic/go.sum b/examples/basic/go.sum index 2964851..61baae4 100644 --- a/examples/basic/go.sum +++ b/examples/basic/go.sum @@ -8,28 +8,28 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= github.com/oaswrap/spec-ui v0.1.4/go.mod h1:D8EnD6zbYJ3q65wdltw6QHXfw+nut5XwSSA1xtlSEQQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/petstore/go.mod b/examples/petstore/go.mod index 45ce45b..0bdcefe 100644 --- a/examples/petstore/go.mod +++ b/examples/petstore/go.mod @@ -2,12 +2,13 @@ module github.com/oaswrap/spec/examples/petstore go 1.21 -require github.com/oaswrap/spec v0.3.2 +require github.com/oaswrap/spec v0.3.3 require ( + github.com/kr/text v0.1.0 // indirect github.com/oaswrap/spec-ui v0.1.4 // indirect github.com/swaggest/jsonschema-go v0.3.78 // indirect - github.com/swaggest/openapi-go v0.2.59 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect github.com/swaggest/refl v1.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/examples/petstore/go.sum b/examples/petstore/go.sum index 2964851..61baae4 100644 --- a/examples/petstore/go.sum +++ b/examples/petstore/go.sum @@ -8,28 +8,28 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= github.com/oaswrap/spec-ui v0.1.4/go.mod h1:D8EnD6zbYJ3q65wdltw6QHXfw+nut5XwSSA1xtlSEQQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw= github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g= -github.com/swaggest/openapi-go v0.2.59 h1:9cUlCrSxbWn/Qn78IxitrhB5kaev0hOROfTxwywYLC0= -github.com/swaggest/openapi-go v0.2.59/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/go.mod b/go.mod index dcc7eb7..2fad21d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,9 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggest/refl v1.4.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 2ddf1d2..ba4ec98 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,11 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +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/oaswrap/spec-ui v0.1.4 h1:XM2Z/ZS2Su90EtDSVuOHGr2+DLpVc2933mxkn6F4aeU= github.com/oaswrap/spec-ui v0.1.4/go.mod h1:D8EnD6zbYJ3q65wdltw6QHXfw+nut5XwSSA1xtlSEQQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -28,8 +33,9 @@ github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCO github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -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-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/lefthook.yml b/lefthook.yml index bb307bf..fc7686c 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -13,11 +13,11 @@ pre-commit: lint: glob: "*.go" - run: golangci-lint run --fix + run: make lint mod-tidy: glob: "go.{mod,sum}" - run: go mod tidy + run: make tidy commit-msg: commands: From 3e616a5c9baa86d7a7be2982f5a2882f9754bb4e Mon Sep 17 00:00:00 2001 From: Ahmad Faiz Kamaludin Date: Fri, 17 Oct 2025 08:10:38 +0700 Subject: [PATCH 6/6] fix: failed unit test --- adapter/chiopenapi/testdata/petstore.yaml | 5 +++-- adapter/echoopenapi/testdata/petstore.yaml | 5 +++-- adapter/fiberopenapi/testdata/petstore.yaml | 5 +++-- adapter/ginopenapi/testdata/petstore.yaml | 5 +++-- adapter/httpopenapi/testdata/petstore.yaml | 5 +++-- adapter/httprouteropenapi/testdata/petstore.yaml | 5 +++-- adapter/muxopenapi/testdata/petstore.yaml | 5 +++-- router.go | 6 +++++- router_test.go | 6 +++--- testdata/basic_data_types_3.yaml | 5 +++++ testdata/petstore_3.yaml | 5 +++-- testdata/petstore_31.yaml | 4 ++-- 12 files changed, 39 insertions(+), 22 deletions(-) diff --git a/adapter/chiopenapi/testdata/petstore.yaml b/adapter/chiopenapi/testdata/petstore.yaml index 411bd4f..3bc4dfa 100644 --- a/adapter/chiopenapi/testdata/petstore.yaml +++ b/adapter/chiopenapi/testdata/petstore.yaml @@ -157,6 +157,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -168,7 +169,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -414,7 +415,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/adapter/echoopenapi/testdata/petstore.yaml b/adapter/echoopenapi/testdata/petstore.yaml index 2fe8cd1..90f0e1f 100644 --- a/adapter/echoopenapi/testdata/petstore.yaml +++ b/adapter/echoopenapi/testdata/petstore.yaml @@ -157,6 +157,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -168,7 +169,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -414,7 +415,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/adapter/fiberopenapi/testdata/petstore.yaml b/adapter/fiberopenapi/testdata/petstore.yaml index 411bd4f..3bc4dfa 100644 --- a/adapter/fiberopenapi/testdata/petstore.yaml +++ b/adapter/fiberopenapi/testdata/petstore.yaml @@ -157,6 +157,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -168,7 +169,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -414,7 +415,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/adapter/ginopenapi/testdata/petstore.yaml b/adapter/ginopenapi/testdata/petstore.yaml index 411bd4f..3bc4dfa 100644 --- a/adapter/ginopenapi/testdata/petstore.yaml +++ b/adapter/ginopenapi/testdata/petstore.yaml @@ -157,6 +157,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -168,7 +169,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -414,7 +415,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/adapter/httpopenapi/testdata/petstore.yaml b/adapter/httpopenapi/testdata/petstore.yaml index 411bd4f..3bc4dfa 100644 --- a/adapter/httpopenapi/testdata/petstore.yaml +++ b/adapter/httpopenapi/testdata/petstore.yaml @@ -157,6 +157,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -168,7 +169,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -414,7 +415,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/adapter/httprouteropenapi/testdata/petstore.yaml b/adapter/httprouteropenapi/testdata/petstore.yaml index 015abf0..dd71794 100644 --- a/adapter/httprouteropenapi/testdata/petstore.yaml +++ b/adapter/httprouteropenapi/testdata/petstore.yaml @@ -134,6 +134,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -145,7 +146,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -415,7 +416,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/adapter/muxopenapi/testdata/petstore.yaml b/adapter/muxopenapi/testdata/petstore.yaml index 7f749f2..53d5ef8 100644 --- a/adapter/muxopenapi/testdata/petstore.yaml +++ b/adapter/muxopenapi/testdata/petstore.yaml @@ -129,6 +129,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -140,7 +141,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -410,7 +411,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/router.go b/router.go index d7b9377..fd0be9e 100644 --- a/router.go +++ b/router.go @@ -184,7 +184,11 @@ func (g *generator) GenerateSchema(formats ...string) ([]byte, error) { format := util.Optional("yaml", formats...) supportedFormats := []string{"json", "yaml", "yml"} if !slices.Contains(supportedFormats, format) { - return nil, fmt.Errorf("unsupported format: %s, expected one of %v", format, supportedFormats) + return nil, fmt.Errorf( + "unsupported format: %s, expected one of %s", + format, + strings.Join(supportedFormats, ", "), + ) } if format == "yaml" || format == "yml" { diff --git a/router_test.go b/router_test.go index 7141ba9..efca0b5 100644 --- a/router_test.go +++ b/router_test.go @@ -762,19 +762,19 @@ func TestRouter_GenerateSchema(t *testing.T) { name: "Unsupported format", formats: []string{"xml"}, expectError: true, - errorMsg: "unsupported format: xml, expected 'json', 'yaml', or 'yml'", + errorMsg: "unsupported format: xml, expected one of json, yaml, yml", }, { name: "Empty string format", formats: []string{""}, expectError: true, - errorMsg: "unsupported format: , expected 'json', 'yaml', or 'yml'", + errorMsg: "unsupported format: , expected one of json, yaml, yml", }, { name: "Invalid format", formats: []string{"invalid"}, expectError: true, - errorMsg: "unsupported format: invalid, expected 'json', 'yaml', or 'yml'", + errorMsg: "unsupported format: invalid, expected one of json, yaml, ym", }, } diff --git a/testdata/basic_data_types_3.yaml b/testdata/basic_data_types_3.yaml index d760a90..57b39ca 100644 --- a/testdata/basic_data_types_3.yaml +++ b/testdata/basic_data_types_3.yaml @@ -31,8 +31,10 @@ components: minimum: 0 type: integer float32: + format: float type: number float64: + format: double type: number int: type: integer @@ -41,10 +43,13 @@ components: int16: type: integer int32: + format: int32 type: integer int64: + format: int64 type: integer rune: + format: int32 type: integer string: type: string diff --git a/testdata/petstore_3.yaml b/testdata/petstore_3.yaml index f5c3395..ce9dfcb 100644 --- a/testdata/petstore_3.yaml +++ b/testdata/petstore_3.yaml @@ -157,6 +157,7 @@ paths: name: petId required: true schema: + format: int64 type: integer requestBody: content: @@ -168,7 +169,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -414,7 +415,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer diff --git a/testdata/petstore_31.yaml b/testdata/petstore_31.yaml index 321d19d..5fb8c2a 100644 --- a/testdata/petstore_31.yaml +++ b/testdata/petstore_31.yaml @@ -153,7 +153,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DtoApiResponse' + $ref: '#/components/schemas/DtoAPIResponse' description: OK security: - petstore_auth: @@ -406,7 +406,7 @@ paths: - user components: schemas: - DtoApiResponse: + DtoAPIResponse: properties: code: type: integer