swaggest / jsonschema-go

JSON Schema mapping for Go
https://pkg.go.dev/github.com/swaggest/jsonschema-go
MIT License
123 stars 14 forks source link

Make a deep copy of Schema in Exposer to avoid ptr sharing #63

Closed vearutop closed 1 year ago

vearutop commented 1 year ago

Fixes https://github.com/swaggest/rest/issues/99.

Due to pointer sharing in mapped schema, one field could add nullability and poison schema of another field originating from same mapped schema.

github-actions[bot] commented 1 year ago

Lines Of Code

Language Files Lines Code Comments Blanks Complexity Bytes
Go 6 1873 (+13) 1271 (+9) 216 (+1) 386 (+3) 497 (+4) 45.3K (+343B)
Go (test) 11 2456 (+29) 1765 (+22) 265 426 (+7) 45 61.5K (+675B)
YAML 6 485 (+3) 408 (+3) 36 41 0 15.9K (+53B)
github-actions[bot] commented 1 year ago

Go API Changes

# summary
Inferred base version: v0.3.42
Suggested version: v0.3.43
github-actions[bot] commented 1 year ago

Unit Test Coverage

total: (statements) 78.2% changed lines: (statements) 77.8%, coverage is less than 90.0%, consider testing the changes more thoroughly

Coverage of changed lines | File | Function | Coverage | |----------------|------------|----------| | Total | | 77.8% | | helper.go | | 71.4% | | helper.go:75 | JSONSchema | 82.6% | | reflect.go | | 100.0% | | reflect.go:335 | reflect | 100.0% |
Coverage diff with base branch | File | Function | Base Coverage | Current Coverage | |---------------------------------------------|------------|---------------|------------------| | Total | | 78.3% | 78.2% (-0.1%) | | github.com/swaggest/jsonschema-go/helper.go | JSONSchema | 100.0% | 71.4% (-28.6%) |
codecov[bot] commented 1 year ago

Codecov Report

Merging #63 (f780d79) into master (7e5b606) will decrease coverage by 0.22%. The diff coverage is 55.55%.

@@            Coverage Diff             @@
##           master      #63      +/-   ##
==========================================
- Coverage   72.43%   72.21%   -0.23%     
==========================================
  Files           6        6              
  Lines        1034     1040       +6     
==========================================
+ Hits          749      751       +2     
- Misses        217      219       +2     
- Partials       68       70       +2     
Flag Coverage Δ
unittests 72.21% <55.55%> (-0.23%) :arrow_down:

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

Impacted Files Coverage Δ
helper.go 83.96% <42.85%> (-3.04%) :arrow_down:
reflect.go 80.91% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

github-actions[bot] commented 1 year ago

Benchmark Result

Benchmark diff with base branch ``` name old time/op new time/op delta Schema_UnmarshalJSON_raw-2 73.9µs ± 1% 74.2µs ± 3% ~ (p=0.841 n=5+5) Schema_UnmarshalJSON-2 602µs ± 0% 603µs ± 1% ~ (p=0.413 n=4+5) Schema_MarshalJSON_raw-2 70.0µs ± 1% 70.5µs ± 1% ~ (p=0.056 n=5+5) Schema_MarshalJSON-2 238µs ± 1% 237µs ± 1% ~ (p=0.151 n=5+5) name old alloc/op new alloc/op delta Schema_UnmarshalJSON_raw-2 31.7kB ± 0% 31.7kB ± 0% ~ (p=0.667 n=5+5) Schema_UnmarshalJSON-2 184kB ± 0% 184kB ± 0% ~ (all equal) Schema_MarshalJSON_raw-2 21.9kB ± 0% 21.9kB ± 0% ~ (p=1.000 n=5+5) Schema_MarshalJSON-2 55.3kB ± 0% 55.3kB ± 0% ~ (p=0.286 n=5+5) name old allocs/op new allocs/op delta Schema_UnmarshalJSON_raw-2 457 ± 0% 457 ± 0% ~ (all equal) Schema_UnmarshalJSON-2 2.00k ± 0% 2.00k ± 0% ~ (all equal) Schema_MarshalJSON_raw-2 484 ± 0% 484 ± 0% ~ (all equal) Schema_MarshalJSON-2 477 ± 0% 477 ± 0% ~ (all equal) ```
Benchmark result ``` name time/op Schema_UnmarshalJSON_raw-2 74.2µs ± 3% Schema_UnmarshalJSON-2 603µs ± 1% Schema_MarshalJSON_raw-2 70.5µs ± 1% Schema_MarshalJSON-2 237µs ± 1% name alloc/op Schema_UnmarshalJSON_raw-2 31.7kB ± 0% Schema_UnmarshalJSON-2 184kB ± 0% Schema_MarshalJSON_raw-2 21.9kB ± 0% Schema_MarshalJSON-2 55.3kB ± 0% name allocs/op Schema_UnmarshalJSON_raw-2 457 ± 0% Schema_UnmarshalJSON-2 2.00k ± 0% Schema_MarshalJSON_raw-2 484 ± 0% Schema_MarshalJSON-2 477 ± 0% ```