swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
362 stars 17 forks source link

Allow custom response structures and statuses in security middlewares #26

Closed vearutop closed 3 years ago

github-actions[bot] commented 3 years ago

Unit Test Coverage

total: (statements) 81.1%

Coverage diff with base branch ```diff 45c45 < github.com/swaggest/rest/nethttp/handler.go NewHandler 100.0% --- > github.com/swaggest/rest/nethttp/handler.go NewHandler 80.0% 60c60 < github.com/swaggest/rest/nethttp/openapi.go HTTPBasicSecurityMiddleware 100.0% --- > github.com/swaggest/rest/nethttp/openapi.go HTTPBasicSecurityMiddleware 88.9% 62a63 > github.com/swaggest/rest/nethttp/openapi.go SecurityResponse 100.0% 74c75 < github.com/swaggest/rest/openapi/collector.go Collect 72.0% --- > github.com/swaggest/rest/openapi/collector.go Collect 70.4% ```
codecov[bot] commented 3 years ago

Codecov Report

Merging #26 (b343997) into master (1beaa1a) will decrease coverage by 0.06%. The diff coverage is 69.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
- Coverage   73.41%   73.34%   -0.07%     
==========================================
  Files          26       26              
  Lines        1482     1497      +15     
==========================================
+ Hits         1088     1098      +10     
- Misses        249      252       +3     
- Partials      145      147       +2     
Flag Coverage Δ
unittests 73.34% <69.56%> (-0.07%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
nethttp/handler.go 86.84% <0.00%> (-2.35%) :arrow_down:
openapi/collector.go 64.62% <33.33%> (-0.62%) :arrow_down:
nethttp/openapi.go 92.95% <93.33%> (-0.38%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1beaa1a...b343997. Read the comment docs.

github-actions[bot] commented 3 years ago

Benchmark Result

Benchmark diff with base branch ``` Using vendor name old time/op new time/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 1.71µs ± 2% 1.61µs ± 1% -6.01% (p=0.016 n=5+4) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 962ns ± 3% 893ns ± 0% -7.18% (p=0.016 n=5+4) DecoderFunc_Decode-2 2.60µs ± 1% 2.48µs ± 1% -4.49% (p=0.008 n=5+5) Decoder_Decode_json-2 29.7µs ± 1% 28.2µs ± 1% -4.74% (p=0.008 n=5+5) Decoder_Decode_queryObject-2 6.93µs ± 1% 6.65µs ± 1% -3.92% (p=0.008 n=5+5) Decoder_Decode_jsonParam-2 2.34µs ± 1% 2.29µs ± 2% -2.09% (p=0.032 n=5+5) DecoderFactory_SetDecoderFunc-2 2.17µs ± 1% 2.08µs ± 2% -4.34% (p=0.008 n=5+5) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 16.7µs ± 1% 16.4µs ± 2% ~ (p=0.095 n=5+5) Middleware_control-2 4.11µs ± 4% 3.84µs ± 1% -6.46% (p=0.008 n=5+5) name old alloc/op new alloc/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 2.50kB ± 0% 2.50kB ± 0% ~ (all equal) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 440B ± 0% 440B ± 0% ~ (all equal) DecoderFunc_Decode-2 1.51kB ± 0% 1.51kB ± 0% ~ (all equal) Decoder_Decode_json-2 12.3kB ± 0% 12.3kB ± 0% ~ (all equal) Decoder_Decode_queryObject-2 2.00kB ± 0% 2.00kB ± 0% ~ (all equal) Decoder_Decode_jsonParam-2 720B ± 0% 720B ± 0% ~ (all equal) DecoderFactory_SetDecoderFunc-2 1.02kB ± 0% 1.02kB ± 0% ~ (all equal) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 1.12kB ± 2% 1.12kB ± 3% ~ (p=0.365 n=5+5) Middleware_control-2 11.2kB ± 0% 11.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 8.00 ± 0% 8.00 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 4.00 ± 0% 4.00 ± 0% ~ (all equal) DecoderFunc_Decode-2 12.0 ± 0% 12.0 ± 0% ~ (all equal) Decoder_Decode_json-2 169 ± 0% 169 ± 0% ~ (all equal) Decoder_Decode_queryObject-2 36.0 ± 0% 36.0 ± 0% ~ (all equal) Decoder_Decode_jsonParam-2 12.0 ± 0% 12.0 ± 0% ~ (all equal) DecoderFactory_SetDecoderFunc-2 16.0 ± 0% 16.0 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 11.0 ± 0% 11.0 ± 0% ~ (all equal) Middleware_control-2 9.00 ± 0% 9.00 ± 0% ~ (all equal) ```

Examples Benchmark Result

Benchmark diff with base branch ``` Using vendor name old time/op new time/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 26.5µs ± 3% 25.2µs ± 0% -4.85% (p=0.008 n=5+5) _directGzipHead-2 26.5µs ± 2% 25.4µs ± 3% -4.22% (p=0.016 n=5+5) _noDirectGzip-2 148µs ± 2% 146µs ± 1% -1.69% (p=0.032 n=5+5) _directGzip_decode-2 551µs ± 1% 533µs ± 1% -3.42% (p=0.008 n=5+5) _noDirectGzip_decode-2 149µs ± 1% 146µs ± 3% ~ (p=0.222 n=5+5) _jsonBody-2 48.1µs ± 2% 45.6µs ± 2% -5.09% (p=0.008 n=5+5) _jsonBodyValidation-2 57.3µs ± 2% 52.9µs ± 1% -7.64% (p=0.008 n=5+5) _outputHeaders-2 25.7µs ± 1% 24.4µs ± 1% -5.16% (p=0.008 n=5+5) _validation-2 51.6µs ± 1% 49.0µs ± 3% -5.04% (p=0.008 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 29.6µs ± 1% 28.7µs ± 1% -3.12% (p=0.008 n=5+5) _ok-2 31.0µs ± 1% 30.1µs ± 2% -2.77% (p=0.008 n=5+5) _invalidBody-2 45.7µs ± 1% 44.8µs ± 3% ~ (p=0.222 n=5+5) name old B:rcvd/op new B:rcvd/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 639 ± 0% 639 ± 0% ~ (all equal) _directGzipHead-2 183 ± 0% 183 ± 0% ~ (all equal) _noDirectGzip-2 1.04k ± 0% 1.04k ± 0% ~ (all equal) _directGzip_decode-2 639 ± 0% 639 ± 0% ~ (all equal) _noDirectGzip_decode-2 1.04k ± 0% 1.04k ± 0% ~ (all equal) _jsonBody-2 208 ± 0% 208 ± 0% ~ (all equal) _jsonBodyValidation-2 194 ± 0% 194 ± 0% ~ (all equal) _outputHeaders-2 155 ± 0% 155 ± 0% ~ (all equal) _validation-2 177 ± 0% 177 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 337 ± 0% 337 ± 0% ~ (all equal) _ok-2 359 ± 0% 359 ± 0% ~ (all equal) _invalidBody-2 435 ± 0% 435 ± 0% ~ (all equal) name old B:sent/op new B:sent/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 103 ± 0% 103 ± 0% ~ (all equal) _directGzipHead-2 104 ± 0% 104 ± 0% ~ (all equal) _noDirectGzip-2 117 ± 0% 117 ± 0% ~ (all equal) _directGzip_decode-2 116 ± 0% 116 ± 0% ~ (all equal) _noDirectGzip_decode-2 130 ± 0% 130 ± 0% ~ (all equal) _jsonBody-2 188 ± 0% 188 ± 0% ~ (all equal) _jsonBodyValidation-2 192 ± 0% 192 ± 0% ~ (all equal) _outputHeaders-2 77.0 ± 0% 77.0 ± 0% ~ (all equal) _validation-2 170 ± 0% 170 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 74.0 ± 0% 74.0 ± 0% ~ (all equal) _ok-2 74.0 ± 0% 74.0 ± 0% ~ (all equal) _invalidBody-2 137 ± 0% 137 ± 0% ~ (all equal) name old rps new rps delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 37.8k ± 3% 39.7k ± 0% +5.06% (p=0.008 n=5+5) _directGzipHead-2 37.7k ± 2% 39.4k ± 3% +4.42% (p=0.016 n=5+5) _noDirectGzip-2 6.76k ± 2% 6.87k ± 1% +1.70% (p=0.032 n=5+5) _directGzip_decode-2 1.81k ± 1% 1.88k ± 1% +3.54% (p=0.008 n=5+5) _noDirectGzip_decode-2 6.71k ± 1% 6.87k ± 3% ~ (p=0.222 n=5+5) _jsonBody-2 20.8k ± 2% 21.9k ± 2% +5.34% (p=0.008 n=5+5) _jsonBodyValidation-2 17.5k ± 2% 18.9k ± 1% +8.27% (p=0.008 n=5+5) _outputHeaders-2 38.9k ± 1% 41.0k ± 1% +5.44% (p=0.008 n=5+5) _validation-2 19.4k ± 1% 20.4k ± 2% +5.32% (p=0.008 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 33.7k ± 1% 34.8k ± 1% +3.22% (p=0.008 n=5+5) _ok-2 32.3k ± 1% 33.2k ± 2% +2.85% (p=0.008 n=5+5) _invalidBody-2 21.9k ± 1% 22.3k ± 3% ~ (p=0.222 n=5+5) name old alloc/op new alloc/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 3.86kB ± 0% 3.86kB ± 0% ~ (p=0.587 n=5+5) _directGzipHead-2 3.86kB ± 0% 3.86kB ± 0% ~ (p=1.000 n=5+4) _noDirectGzip-2 6.35kB ±19% 6.10kB ±21% ~ (p=0.421 n=5+5) _directGzip_decode-2 402kB ± 0% 402kB ± 0% ~ (p=0.794 n=5+5) _noDirectGzip_decode-2 5.13kB ± 2% 5.23kB ± 5% ~ (p=0.548 n=5+5) _jsonBody-2 11.7kB ± 0% 11.7kB ± 0% ~ (p=0.786 n=5+5) _jsonBodyValidation-2 18.2kB ± 0% 18.2kB ± 0% ~ (p=0.198 n=5+5) _outputHeaders-2 3.64kB ± 0% 3.63kB ± 0% ~ (p=0.095 n=5+4) _validation-2 16.2kB ± 0% 16.2kB ± 0% ~ (p=0.516 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 4.81kB ± 0% 4.81kB ± 0% ~ (p=0.206 n=4+5) _ok-2 4.72kB ± 0% 4.72kB ± 0% ~ (p=0.400 n=4+4) _invalidBody-2 8.58kB ± 0% 8.58kB ± 0% ~ (p=1.000 n=4+4) name old allocs/op new allocs/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 40.0 ± 0% 40.0 ± 0% ~ (all equal) _directGzipHead-2 40.0 ± 0% 40.0 ± 0% ~ (all equal) _noDirectGzip-2 47.8 ± 4% 47.6 ± 3% ~ (p=1.000 n=5+5) _directGzip_decode-2 497 ± 0% 497 ± 0% ~ (all equal) _noDirectGzip_decode-2 48.0 ± 0% 48.0 ± 0% ~ (all equal) _jsonBody-2 103 ± 0% 103 ± 0% ~ (all equal) _jsonBodyValidation-2 144 ± 0% 144 ± 0% ~ (all equal) _outputHeaders-2 35.0 ± 0% 35.0 ± 0% ~ (all equal) _validation-2 131 ± 0% 131 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 52.0 ± 0% 52.0 ± 0% ~ (all equal) _ok-2 48.0 ± 0% 48.0 ± 0% ~ (all equal) _invalidBody-2 98.0 ± 0% 98.0 ± 0% ~ (all equal) ```