Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #21

Merged
merged 5 commits into from
Jul 2, 2024
Merged

Fix #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
To install the package, use the following command:

```sh
go get github.com/ashbeelghouri/jsonschematics
go get github.com/ashbeelghouri/jsonschematics@latest
```

## Usage
Expand Down Expand Up @@ -404,6 +404,26 @@ If you want to get the single error, you can define the error format like below:
| LIKE | | | |
| MatchRegex | | | |

#### Schema

##### v2@latest
v2 is the lates schema version designed.
below are the required fields listed
```golang
fields <ARRAY> : [{
required <BOOLEAN>
depends_on <ARRAY OF STRINGS> : [] (can be empty)
target_key <STRING>
validators <ARRAY OF OBJ>: [{
name <STRING>
}]
operators <ARRAY OF OBJ>: [{
"name" <STRING>
}],
}]
```


#### Go Version

```go
Expand Down
6 changes: 4 additions & 2 deletions data/v0/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ func (f *Field) Validate(value interface{}, allValidators map[string]validators.
}
for name, constants := range f.Validators {
err.Validator = name
f.logging.DEBUG("Validator: ", name, constants)
if name != "" {
f.logging.DEBUG("Validator", name, constants)
if name == "" {
f.logging.DEBUG("Name of the validator is not given: ", name)
err.Validator = name
err.AddMessage("en", "no validator name given")
return &err
}
if f.IsRequired && value == nil {
err.Validator = "Required"
Expand Down
Empty file removed test-data/api.json
Empty file.
44 changes: 0 additions & 44 deletions test-data/arr-data.json

This file was deleted.

31 changes: 0 additions & 31 deletions test-data/arr-inside-obj-data.json

This file was deleted.

13 changes: 0 additions & 13 deletions test-data/data.json

This file was deleted.

60 changes: 0 additions & 60 deletions test-data/data/direct/v2/example-3.json

This file was deleted.

82 changes: 0 additions & 82 deletions test-data/schema-v1.1.json

This file was deleted.

81 changes: 81 additions & 0 deletions test-data/schema/direct/v0/example-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"version": "0",
"fields": {
"user.profile.name.first": {
"name": "",
"display_name": "",
"required": false,
"depends_on": [],
"description": "",
"validators": {
"IsString": {},
"MaxLengthAllowed": {
"attributes": {
"max": 20
},
"error": "user's first name should have maximum 20 characters",
"l10n": {
"ar": "سي شسيشسشسيش شسيشس شسيضصثضصث قفلربل ٦ع لبلا ثفق"
}
}
},
"operators": [
{
"Capitalize": {}
}
],
"l10n": {
"description": {
"locale": {
"ar": ""
}
}
}
},
"user.profile.name.last": {
"depends_on": [],
"required": false,
"target_key": "user.profile.name.last",
"description": "",
"validators": {
"IsString": {},
"MinLengthAllowed": {
"attributes": {
"min": 10
},
"error": "user's last name should have minimum 10 characters"
}
},
"operators": {
"Capitalize": {}
}
},
"user.profile.age": {
"depends_on": [],
"required": false,
"target_key": "user.profile.age",
"description": "",
"validators": {
"IsNumber": {},
"MaxAllowed": {
"attributes": {
"max": 20
},
"error": "user's age should not be greater than 20"
}
}
},
"user.profile.email": {
"depends_on": [
"user.profile.name.first",
"user.profile.name.last"
],
"target_key": "user.profile.email",
"description": "",
"validators": {
"IsString": {},
"IsEmail": {}
}
}
}
}
Loading