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

Showcase generic usecases in examples #47

Closed vearutop closed 2 years ago

github-actions[bot] commented 2 years ago

Lines Of Code

Language Files Lines Code Comments Blanks Complexity Bytes
Go 93 (+16) 6903 (+880) 5005 (+634) 467 (+60) 1431 (+186) 874 (+42) 165.5K (+23.1K)
Go (test) 39 (+6) 3808 (+314) 2915 (+217) 124 (+35) 769 (+62) 107 (+12) 106.5K (+10.1K)
JSON 2 (+1) 948 (+476) 948 (+476) 0 0 0 40K (+20.1K)
gitignore 2 (+1) 6 (+1) 6 (+1) 0 0 0 69B (+16B)
github-actions[bot] commented 2 years ago

API Changes

# summary
Inferred base version: v0.2.13
Suggested version: v0.3.0
github-actions[bot] commented 2 years ago

Unit Test Coverage

total: (statements) 82.1%

Coverage diff with base branch ```diff 50c50,51 < github.com/swaggest/rest/nethttp/handler.go ServeHTTP 84.2% --- > github.com/swaggest/rest/nethttp/handler.go decodeRequest 71.4% > github.com/swaggest/rest/nethttp/handler.go ServeHTTP 87.5% ```
codecov[bot] commented 2 years ago

Codecov Report

Merging #47 (f38aaad) into master (9a406b5) will decrease coverage by 0.42%. The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
- Coverage   74.44%   74.02%   -0.43%     
==========================================
  Files          26       26              
  Lines        1573     1536      -37     
==========================================
- Hits         1171     1137      -34     
+ Misses        251      248       -3     
  Partials      151      151              
Flag Coverage Δ
unittests 74.02% <60.00%> (-0.43%) :arrow_down:

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

Impacted Files Coverage Δ
nethttp/handler.go 86.36% <60.00%> (-0.06%) :arrow_down:
request/decoder.go 71.42% <0.00%> (-5.72%) :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 9a406b5...f38aaad. Read the comment docs.

github-actions[bot] commented 2 years ago

Benchmark Result

Benchmark diff with base branch ``` name old time/op new time/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 1.59µs ± 1% 1.57µs ± 3% ~ (p=0.111 n=4+5) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 838ns ± 3% 823ns ± 2% ~ (p=0.222 n=5+5) DecoderFunc_Decode-2 2.42µs ± 3% 2.39µs ± 1% ~ (p=0.151 n=5+5) Decoder_Decode_json-2 27.8µs ± 2% 27.3µs ± 2% ~ (p=0.056 n=5+5) Decoder_Decode_queryObject-2 5.74µs ± 1% 5.65µs ± 2% ~ (p=0.056 n=5+5) Decoder_Decode_jsonParam-2 2.06µs ± 1% 2.05µs ± 0% ~ (p=0.421 n=5+5) DecoderFactory_SetDecoderFunc-2 1.95µs ± 4% 1.95µs ± 0% ~ (p=0.151 n=5+5) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 13.7µs ± 1% 13.9µs ± 1% +1.62% (p=0.008 n=5+5) Middleware_control-2 3.84µs ± 3% 3.85µs ± 1% ~ (p=0.548 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.46kB ± 0% 2.46kB ± 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 736B ± 0% 736B ± 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.16kB ± 3% 1.14kB ± 1% ~ (p=0.286 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 172 ± 0% 172 ± 0% ~ (all equal) Decoder_Decode_queryObject-2 36.0 ± 0% 36.0 ± 0% ~ (all equal) Decoder_Decode_jsonParam-2 13.0 ± 0% 13.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) ```
Benchmark result ``` name time/op pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 1.57µs ± 3% pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 823ns ± 2% DecoderFunc_Decode-2 2.39µs ± 1% Decoder_Decode_json-2 27.3µs ± 2% Decoder_Decode_queryObject-2 5.65µs ± 2% Decoder_Decode_jsonParam-2 2.05µs ± 0% DecoderFactory_SetDecoderFunc-2 1.95µs ± 0% pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 13.9µs ± 1% Middleware_control-2 3.85µs ± 1% name alloc/op pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 2.46kB ± 0% pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 440B ± 0% DecoderFunc_Decode-2 1.51kB ± 0% Decoder_Decode_json-2 12.3kB ± 0% Decoder_Decode_queryObject-2 2.00kB ± 0% Decoder_Decode_jsonParam-2 736B ± 0% DecoderFactory_SetDecoderFunc-2 1.02kB ± 0% pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 1.14kB ± 1% Middleware_control-2 11.2kB ± 0% name allocs/op pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 8.00 ± 0% pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 4.00 ± 0% DecoderFunc_Decode-2 12.0 ± 0% Decoder_Decode_json-2 172 ± 0% Decoder_Decode_queryObject-2 36.0 ± 0% Decoder_Decode_jsonParam-2 13.0 ± 0% DecoderFactory_SetDecoderFunc-2 16.0 ± 0% pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 11.0 ± 0% Middleware_control-2 9.00 ± 0% ```
github-actions[bot] commented 2 years ago

Examples Benchmark Result

Benchmark diff with base branch ``` name old time/op new time/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 39.6µs ± 6% 35.7µs ± 9% ~ (p=0.056 n=5+5) _directGzipHead-2 38.2µs ± 9% 34.6µs ± 5% -9.47% (p=0.016 n=5+5) _noDirectGzip-2 170µs ± 1% 156µs ± 2% -8.08% (p=0.008 n=5+5) _directGzip_decode-2 569µs ± 8% 584µs ± 8% ~ (p=1.000 n=5+5) _noDirectGzip_decode-2 162µs ± 5% 153µs ± 2% ~ (p=0.095 n=5+5) _jsonBody-2 65.6µs ± 5% 65.1µs ± 6% ~ (p=1.000 n=5+5) _jsonBodyValidation-2 74.3µs ± 5% 68.2µs ± 2% -8.16% (p=0.008 n=5+5) _outputHeaders-2 37.3µs ± 2% 35.5µs ± 6% ~ (p=0.095 n=5+5) _validation-2 69.1µs ± 7% 68.4µs ± 5% ~ (p=1.000 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 43.1µs ± 4% 46.0µs ± 5% +6.72% (p=0.008 n=5+5) _ok-2 43.4µs ± 4% 46.9µs ±10% +7.95% (p=0.032 n=5+5) _invalidBody-2 61.2µs ± 4% 64.0µs ± 3% ~ (p=0.056 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 25.3k ± 6% 28.1k ± 9% ~ (p=0.056 n=5+5) _directGzipHead-2 26.2k ± 8% 28.9k ± 5% +10.31% (p=0.016 n=5+5) _noDirectGzip-2 5.89k ± 1% 6.41k ± 2% +8.80% (p=0.008 n=5+5) _directGzip_decode-2 1.77k ± 8% 1.72k ± 9% ~ (p=1.000 n=5+5) _noDirectGzip_decode-2 6.18k ± 5% 6.52k ± 2% ~ (p=0.095 n=5+5) _jsonBody-2 15.2k ± 5% 15.4k ± 6% ~ (p=1.000 n=5+5) _jsonBodyValidation-2 13.5k ± 5% 14.7k ± 2% +8.83% (p=0.008 n=5+5) _outputHeaders-2 26.8k ± 2% 28.2k ± 6% ~ (p=0.095 n=5+5) _validation-2 14.5k ± 7% 14.6k ± 5% ~ (p=1.000 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 23.2k ± 4% 21.7k ± 5% -6.28% (p=0.008 n=5+5) _ok-2 23.0k ± 4% 21.4k ±10% -7.12% (p=0.032 n=5+5) _invalidBody-2 16.3k ± 4% 15.6k ± 3% ~ (p=0.056 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.87kB ± 0% 3.87kB ± 0% -0.12% (p=0.024 n=5+5) _directGzipHead-2 3.87kB ± 0% 3.86kB ± 0% ~ (p=0.571 n=5+5) _noDirectGzip-2 6.37kB ±18% 6.40kB ±22% ~ (p=1.000 n=5+5) _directGzip_decode-2 403kB ± 0% 403kB ± 0% ~ (p=0.548 n=5+5) _noDirectGzip_decode-2 5.38kB ± 9% 5.22kB ± 5% ~ (p=1.000 n=5+5) _jsonBody-2 13.2kB ± 0% 13.2kB ± 0% ~ (p=0.651 n=5+5) _jsonBodyValidation-2 18.2kB ± 0% 18.2kB ± 0% ~ (p=0.087 n=5+5) _outputHeaders-2 3.65kB ± 0% 3.64kB ± 0% ~ (p=0.270 n=5+5) _validation-2 16.2kB ± 0% 16.2kB ± 0% ~ (p=0.810 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 4.82kB ± 0% 4.82kB ± 0% ~ (p=0.238 n=5+5) _ok-2 4.73kB ± 0% 4.73kB ± 0% ~ (p=0.171 n=4+4) _invalidBody-2 8.73kB ± 4% 8.74kB ± 4% ~ (p=1.000 n=5+5) 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% 48.0 ± 4% ~ (p=1.000 n=5+5) _directGzip_decode-2 497 ± 0% 498 ± 0% ~ (p=1.000 n=5+5) _noDirectGzip_decode-2 48.0 ± 0% 48.0 ± 0% ~ (all equal) _jsonBody-2 124 ± 0% 124 ± 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 99.0 ± 0% 99.8 ± 2% ~ (p=0.556 n=4+5) ```