-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d996fda
commit 484c033
Showing
18 changed files
with
348 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package dnsv1 | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// This code was automatically generated by github.com/mittwald/api-client-go-builder. | ||
// DO NOT EDIT. | ||
|
||
//This data type was generated from the following JSON schema: | ||
// oneOf: | ||
// - {"$ref": "#/components/schemas/de.mittwald.v1.dns.RecordUnset"} | ||
// - {"$ref": "#/components/schemas/de.mittwald.v1.dns.RecordCAAComponent"} | ||
|
||
type RecordCAA struct { | ||
AlternativeRecordUnset *RecordUnset | ||
AlternativeRecordCAAComponent *RecordCAAComponent | ||
} | ||
|
||
func (a *RecordCAA) MarshalJSON() ([]byte, error) { | ||
if a.AlternativeRecordUnset != nil { | ||
return json.Marshal(a.AlternativeRecordUnset) | ||
} | ||
if a.AlternativeRecordCAAComponent != nil { | ||
return json.Marshal(a.AlternativeRecordCAAComponent) | ||
} | ||
return []byte("null"), nil | ||
} | ||
|
||
func (a *RecordCAA) UnmarshalJSON(input []byte) error { | ||
reader := bytes.NewReader(input) | ||
decodedAtLeastOnce := false | ||
dec := json.NewDecoder(reader) | ||
dec.DisallowUnknownFields() | ||
|
||
reader.Reset(input) | ||
var alternativeRecordUnset RecordUnset | ||
if err := dec.Decode(&alternativeRecordUnset); err == nil { | ||
//subtype: *generator.ReferenceType | ||
if vErr := alternativeRecordUnset.Validate(); vErr == nil { | ||
a.AlternativeRecordUnset = &alternativeRecordUnset | ||
decodedAtLeastOnce = true | ||
} | ||
} | ||
|
||
reader.Reset(input) | ||
var alternativeRecordCAAComponent RecordCAAComponent | ||
if err := dec.Decode(&alternativeRecordCAAComponent); err == nil { | ||
//subtype: *generator.ReferenceType | ||
if vErr := alternativeRecordCAAComponent.Validate(); vErr == nil { | ||
a.AlternativeRecordCAAComponent = &alternativeRecordCAAComponent | ||
decodedAtLeastOnce = true | ||
} | ||
} | ||
|
||
if !decodedAtLeastOnce { | ||
return fmt.Errorf("could not unmarshal into any alternative for type %T", a) | ||
} | ||
return nil | ||
} | ||
|
||
func (a *RecordCAA) Validate() error { | ||
if a.AlternativeRecordUnset != nil { | ||
return a.AlternativeRecordUnset.Validate() | ||
} | ||
if a.AlternativeRecordCAAComponent != nil { | ||
return a.AlternativeRecordCAAComponent.Validate() | ||
} | ||
return errors.New("no alternative set") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dnsv1_test | ||
|
||
// This code was automatically generated by github.com/mittwald/api-client-go-builder. | ||
// DO NOT EDIT. | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/mittwald/api-client-go/mittwaldv2/generated/schemas/dnsv1" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("RecordCAA", func() { | ||
When("unmarshaling from JSON", func() { | ||
It("should unmarshal into AlternativeRecordUnset", func() { | ||
exampleJSON := []byte("{}") | ||
|
||
sut := dnsv1.RecordCAA{} | ||
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed()) | ||
Expect(sut.Validate()).To(Succeed()) | ||
Expect(sut.AlternativeRecordUnset).NotTo(BeNil()) | ||
}) | ||
It("should unmarshal into AlternativeRecordCAAComponent", func() { | ||
exampleJSON := []byte("{\"records\":[{\"flags\":42,\"tag\":\"issue\",\"value\":\"string\"}],\"settings\":{\"ttl\":{\"seconds\":42}}}") | ||
|
||
sut := dnsv1.RecordCAA{} | ||
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed()) | ||
Expect(sut.Validate()).To(Succeed()) | ||
Expect(sut.AlternativeRecordCAAComponent).NotTo(BeNil()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.