debian-forge-composer/vendor/github.com/getkin/kin-openapi/jsoninfo/marshal_ref.go
Ondřej Budai 2241a8d9ed go: vendor the oapi-codegen cmd
See the comment in tools.go, I cannot fully explain what's happening here.
Somehow, Go 1.14 wants to use the vendored version of oapi-codegen but
without this file, oapi-codegen isn't vendored so the generation fails.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-02-01 15:32:58 +01:00

30 lines
583 B
Go

package jsoninfo
import (
"encoding/json"
)
func MarshalRef(value string, otherwise interface{}) ([]byte, error) {
if len(value) > 0 {
return json.Marshal(&refProps{
Ref: value,
})
}
return json.Marshal(otherwise)
}
func UnmarshalRef(data []byte, destRef *string, destOtherwise interface{}) error {
refProps := &refProps{}
if err := json.Unmarshal(data, refProps); err == nil {
ref := refProps.Ref
if len(ref) > 0 {
*destRef = ref
return nil
}
}
return json.Unmarshal(data, destOtherwise)
}
type refProps struct {
Ref string `json:"$ref,omitempty"`
}