| 1 |
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package openapi_vocabulary |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
|
| 9 |
"golang.org/x/text/message" |
| 10 |
) |
| 11 |
|
| 12 |
// OpenAPIKeywordError represents an error with an OpenAPI-specific keyword |
| 13 |
type OpenAPIKeywordError struct { |
| 14 |
Keyword string |
| 15 |
Message string |
| 16 |
} |
| 17 |
|
| 18 |
func (e *OpenAPIKeywordError) Error() string { |
| 19 |
return fmt.Sprintf("OpenAPI keyword '%s': %s", e.Keyword, e.Message) |
| 20 |
} |
| 21 |
|
| 22 |
// DiscriminatorPropertyMissingError represents an error when discriminator property is missing |
| 23 |
type DiscriminatorPropertyMissingError struct { |
| 24 |
PropertyName string |
| 25 |
} |
| 26 |
|
| 27 |
func (e *DiscriminatorPropertyMissingError) KeywordPath() []string { |
| 28 |
return []string{"discriminator"} |
| 29 |
} |
| 30 |
|
| 31 |
func (e *DiscriminatorPropertyMissingError) LocalizedString(printer *message.Printer) string { |
| 32 |
return fmt.Sprintf("discriminator property '%s' is missing", e.PropertyName) |
| 33 |
} |
| 34 |
|
| 35 |
func (e *DiscriminatorPropertyMissingError) Error() string { |
| 36 |
return fmt.Sprintf("discriminator property '%s' is missing", e.PropertyName) |
| 37 |
} |
| 38 |
|
| 39 |
// CoercionError represents an error during scalar type coercion |
| 40 |
type CoercionError struct { |
| 41 |
SourceType string |
| 42 |
TargetType string |
| 43 |
Value string |
| 44 |
Message string |
| 45 |
} |
| 46 |
|
| 47 |
func (e *CoercionError) KeywordPath() []string { |
| 48 |
return []string{"type"} |
| 49 |
} |
| 50 |
|
| 51 |
func (e *CoercionError) LocalizedString(printer *message.Printer) string { |
| 52 |
return fmt.Sprintf("cannot coerce %s '%s' to %s: %s", e.SourceType, e.Value, e.TargetType, e.Message) |
| 53 |
} |
| 54 |
|
| 55 |
func (e *CoercionError) Error() string { |
| 56 |
return fmt.Sprintf("cannot coerce %s '%s' to %s: %s", e.SourceType, e.Value, e.TargetType, e.Message) |
| 57 |
} |