Blame vendor/github.com/getkin/kin-openapi/jsoninfo/marshal_ref.go
|
Packit Service |
3a6627 |
package jsoninfo
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
import (
|
|
Packit Service |
3a6627 |
"encoding/json"
|
|
Packit Service |
3a6627 |
)
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func MarshalRef(value string, otherwise interface{}) ([]byte, error) {
|
|
Packit Service |
3a6627 |
if len(value) > 0 {
|
|
Packit Service |
3a6627 |
return json.Marshal(&refProps{
|
|
Packit Service |
3a6627 |
Ref: value,
|
|
Packit Service |
3a6627 |
})
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
return json.Marshal(otherwise)
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func UnmarshalRef(data []byte, destRef *string, destOtherwise interface{}) error {
|
|
Packit Service |
3a6627 |
refProps := &refProps{}
|
|
Packit Service |
3a6627 |
if err := json.Unmarshal(data, refProps); err == nil {
|
|
Packit Service |
3a6627 |
ref := refProps.Ref
|
|
Packit Service |
3a6627 |
if len(ref) > 0 {
|
|
Packit Service |
3a6627 |
*destRef = ref
|
|
Packit Service |
3a6627 |
return nil
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
return json.Unmarshal(data, destOtherwise)
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
type refProps struct {
|
|
Packit Service |
3a6627 |
Ref string `json:"$ref,omitempty"`
|
|
Packit Service |
3a6627 |
}
|