Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
golang-github-go-openapi-errors
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Debian Go Packaging Team
packages
golang-github-go-openapi-errors
Commits
00a6ebee
Unverified
Commit
00a6ebee
authored
4 years ago
by
Ivan Porto Carrero
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #26 from youyuanwu/feature/ReadOnly-Error
Add ReadOnly Error
parents
7f224678
91d424a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
schema.go
+20
-0
20 additions, 0 deletions
schema.go
schema_test.go
+12
-0
12 additions, 0 deletions
schema_test.go
with
32 additions
and
0 deletions
schema.go
+
20
−
0
View file @
00a6ebee
...
...
@@ -25,6 +25,7 @@ const (
typeFailWithData
=
"%s in %s must be of type %s: %q"
typeFailWithError
=
"%s in %s must be of type %s, because: %s"
requiredFail
=
"%s in %s is required"
readOnlyFail
=
"%s in %s is readOnly"
tooLongMessage
=
"%s in %s should be at most %d chars long"
tooShortMessage
=
"%s in %s should be at least %d chars long"
patternFail
=
"%s in %s should match '%s'"
...
...
@@ -41,6 +42,7 @@ const (
typeFailWithDataNoIn
=
"%s must be of type %s: %q"
typeFailWithErrorNoIn
=
"%s must be of type %s, because: %s"
requiredFailNoIn
=
"%s is required"
readOnlyFailNoIn
=
"%s is readOnly"
tooLongMessageNoIn
=
"%s should be at most %d chars long"
tooShortMessageNoIn
=
"%s should be at least %d chars long"
patternFailNoIn
=
"%s should match '%s'"
...
...
@@ -91,6 +93,7 @@ const (
UnallowedPropertyCode
FailedAllPatternPropsCode
MultipleOfMustBePositiveCode
ReadOnlyFailCode
)
// CompositeError is an error that groups several errors together
...
...
@@ -501,6 +504,23 @@ func Required(name, in string, value interface{}) *Validation {
}
}
// ReadOnly error for when a value is present in request
func
ReadOnly
(
name
,
in
string
,
value
interface
{})
*
Validation
{
var
msg
string
if
in
==
""
{
msg
=
fmt
.
Sprintf
(
readOnlyFailNoIn
,
name
)
}
else
{
msg
=
fmt
.
Sprintf
(
readOnlyFail
,
name
,
in
)
}
return
&
Validation
{
code
:
ReadOnlyFailCode
,
Name
:
name
,
In
:
in
,
Value
:
value
,
message
:
msg
,
}
}
// TooLong error for when a string is too long
func
TooLong
(
name
,
in
string
,
max
int64
,
value
interface
{})
*
Validation
{
var
msg
string
...
...
This diff is collapsed.
Click to expand it.
schema_test.go
+
12
−
0
View file @
00a6ebee
...
...
@@ -273,6 +273,18 @@ func TestSchemaErrors(t *testing.T) {
assert
.
Equal
(
t
,
"something is required"
,
err
.
Error
())
assert
.
Equal
(
t
,
nil
,
err
.
Value
)
err
=
ReadOnly
(
"something"
,
"query"
,
nil
)
assert
.
Error
(
t
,
err
)
assert
.
EqualValues
(
t
,
ReadOnlyFailCode
,
err
.
Code
())
assert
.
Equal
(
t
,
"something in query is readOnly"
,
err
.
Error
())
assert
.
Equal
(
t
,
nil
,
err
.
Value
)
err
=
ReadOnly
(
"something"
,
""
,
nil
)
assert
.
Error
(
t
,
err
)
assert
.
EqualValues
(
t
,
ReadOnlyFailCode
,
err
.
Code
())
assert
.
Equal
(
t
,
"something is readOnly"
,
err
.
Error
())
assert
.
Equal
(
t
,
nil
,
err
.
Value
)
err
=
TooLong
(
"something"
,
"query"
,
5
,
"abcdef"
)
assert
.
Error
(
t
,
err
)
assert
.
EqualValues
(
t
,
TooLongFailCode
,
err
.
Code
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment