Skip to content

Commit 0c797f4

Browse files
committed
wip
Signed-off-by: Pierre Fenoll <[email protected]>
1 parent be86de1 commit 0c797f4

12 files changed

+167
-723
lines changed

README.md

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -156,41 +156,3 @@ func xmlBodyDecoder(body []byte) (interface{}, error) {
156156
// Decode body to a primitive, []inteface{}, or map[string]interface{}.
157157
}
158158
```
159-
160-
## Custom function for check uniqueness of JSON array
161-
162-
By defaut, the library check unique items by below predefined function
163-
164-
```go
165-
func isSliceOfUniqueItems(xs []interface{}) bool {
166-
s := len(xs)
167-
m := make(map[string]struct{}, s)
168-
for _, x := range xs {
169-
// The input slice is coverted from a JSON string, there shall
170-
// have no error when covert it back.
171-
key, _ := json.Marshal(&x)
172-
m[string(key)] = struct{}{}
173-
}
174-
return s == len(m)
175-
}
176-
```
177-
178-
In the predefined function using `json.Marshal` to generate a string can
179-
be used as a map key which is to support check the uniqueness of an array
180-
when the array items are JSON objects or JSON arraies. You can register
181-
you own function according to your input data to get better performance:
182-
183-
```go
184-
func main() {
185-
// ...
186-
187-
// Register a customized function used to check uniqueness of array.
188-
openapi3.RegisterArrayUniqueItemsChecker(arrayUniqueItemsChecker)
189-
190-
// ... other validate codes
191-
}
192-
193-
func arrayUniqueItemsChecker(items []interface{}) bool {
194-
// Check the uniqueness of the input slice(array in JSON)
195-
}
196-
```

0 commit comments

Comments
 (0)