本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.6KB

  1. // Copyright 2015 go-swagger maintainers
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package validate
  15. import (
  16. "github.com/go-openapi/errors"
  17. )
  18. // Error messages related to schema validation and returned as results.
  19. const (
  20. // ArrayDoesNotAllowAdditionalItemsError when an additionalItems construct is not verified by the array values provided.
  21. //
  22. // TODO: should move to package go-openapi/errors
  23. ArrayDoesNotAllowAdditionalItemsError = "array doesn't allow for additional items"
  24. // HasDependencyError indicates that a dependencies construct was not verified
  25. HasDependencyError = "%q has a dependency on %s"
  26. // InvalidSchemaProvidedError indicates that the schema provided to validate a value cannot be properly compiled
  27. InvalidSchemaProvidedError = "Invalid schema provided to SchemaValidator: %v"
  28. // InvalidTypeConversionError indicates that a numerical conversion for the given type could not be carried on
  29. InvalidTypeConversionError = "invalid type conversion in %s: %v "
  30. // MustValidateAtLeastOneSchemaError indicates that in a AnyOf construct, none of the schema constraints specified were verified
  31. MustValidateAtLeastOneSchemaError = "%q must validate at least one schema (anyOf)"
  32. // MustValidateOnlyOneSchemaError indicates that in a OneOf construct, either none of the schema constraints specified were verified, or several were
  33. MustValidateOnlyOneSchemaError = "%q must validate one and only one schema (oneOf). %s"
  34. // MustValidateAllSchemasError indicates that in a AllOf construct, at least one of the schema constraints specified were not verified
  35. //
  36. // TODO: punctuation in message
  37. MustValidateAllSchemasError = "%q must validate all the schemas (allOf)%s"
  38. // MustNotValidateSchemaError indicates that in a Not construct, the schema constraint specified was verified
  39. MustNotValidateSchemaError = "%q must not validate the schema (not)"
  40. )
  41. // Warning messages related to schema validation and returned as results
  42. const ()
  43. func invalidSchemaProvidedMsg(err error) errors.Error {
  44. return errors.New(InternalErrorCode, InvalidSchemaProvidedError, err)
  45. }
  46. func invalidTypeConversionMsg(path string, err error) errors.Error {
  47. return errors.New(errors.CompositeErrorCode, InvalidTypeConversionError, path, err)
  48. }
  49. func mustValidateOnlyOneSchemaMsg(path, additionalMsg string) errors.Error {
  50. return errors.New(errors.CompositeErrorCode, MustValidateOnlyOneSchemaError, path, additionalMsg)
  51. }
  52. func mustValidateAtLeastOneSchemaMsg(path string) errors.Error {
  53. return errors.New(errors.CompositeErrorCode, MustValidateAtLeastOneSchemaError, path)
  54. }
  55. func mustValidateAllSchemasMsg(path, additionalMsg string) errors.Error {
  56. return errors.New(errors.CompositeErrorCode, MustValidateAllSchemasError, path, additionalMsg)
  57. }
  58. func mustNotValidatechemaMsg(path string) errors.Error {
  59. return errors.New(errors.CompositeErrorCode, MustNotValidateSchemaError, path)
  60. }
  61. func hasADependencyMsg(path, depkey string) errors.Error {
  62. return errors.New(errors.CompositeErrorCode, HasDependencyError, path, depkey)
  63. }
  64. func arrayDoesNotAllowAdditionalItemsMsg() errors.Error {
  65. return errors.New(errors.CompositeErrorCode, ArrayDoesNotAllowAdditionalItemsError)
  66. }
上海开阖软件有限公司 沪ICP备12045867号-1