Skip to content

Commit

Permalink
chore: update auto-generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
mittwald-machine committed Jan 29, 2025
1 parent d996fda commit 484c033
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
// - {"$ref": "#/components/schemas/de.mittwald.v1.dns.RecordTXTComponent"}
// - {"$ref": "#/components/schemas/de.mittwald.v1.dns.RecordSRVComponent"}
// - {"$ref": "#/components/schemas/de.mittwald.v1.dns.RecordCNAMEComponent"}
// - {"$ref": "#/components/schemas/de.mittwald.v1.dns.RecordCAAComponent"}
// description: UpdateRecordSetRequestBody models the JSON body of a 'dns-update-record-set' request

type UpdateRecordSetRequestBody struct {
Expand All @@ -29,6 +30,7 @@ type UpdateRecordSetRequestBody struct {
AlternativeRecordTXTComponent *dnsv1.RecordTXTComponent
AlternativeRecordSRVComponent *dnsv1.RecordSRVComponent
AlternativeRecordCNAMEComponent *dnsv1.RecordCNAMEComponent
AlternativeRecordCAAComponent *dnsv1.RecordCAAComponent
}

func (a *UpdateRecordSetRequestBody) MarshalJSON() ([]byte, error) {
Expand All @@ -50,6 +52,9 @@ func (a *UpdateRecordSetRequestBody) MarshalJSON() ([]byte, error) {
if a.AlternativeRecordCNAMEComponent != nil {
return json.Marshal(a.AlternativeRecordCNAMEComponent)
}
if a.AlternativeRecordCAAComponent != nil {
return json.Marshal(a.AlternativeRecordCAAComponent)
}
return []byte("null"), nil
}

Expand Down Expand Up @@ -119,6 +124,16 @@ func (a *UpdateRecordSetRequestBody) UnmarshalJSON(input []byte) error {
}
}

reader.Reset(input)
var alternativeRecordCAAComponent dnsv1.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)
}
Expand All @@ -144,5 +159,8 @@ func (a *UpdateRecordSetRequestBody) Validate() error {
if a.AlternativeRecordCNAMEComponent != nil {
return a.AlternativeRecordCNAMEComponent.Validate()
}
if a.AlternativeRecordCAAComponent != nil {
return a.AlternativeRecordCAAComponent.Validate()
}
return errors.New("no alternative set")
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,13 @@ var _ = Describe("UpdateRecordSetRequestBody", func() {
Expect(sut.Validate()).To(Succeed())
Expect(sut.AlternativeRecordCNAMEComponent).NotTo(BeNil())
})
It("should unmarshal into AlternativeRecordCAAComponent", func() {
exampleJSON := []byte("{\"records\":[{\"flags\":42,\"tag\":\"issue\",\"value\":\"string\"}],\"settings\":{\"ttl\":{\"seconds\":42}}}")

sut := domain.UpdateRecordSetRequestBody{}
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed())
Expect(sut.Validate()).To(Succeed())
Expect(sut.AlternativeRecordCAAComponent).NotTo(BeNil())
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "fmt"
// - "txt"
// - "srv"
// - "cname"
// - "caa"

type UpdateRecordSetRequestPathRecordSet string

Expand All @@ -21,9 +22,10 @@ const UpdateRecordSetRequestPathRecordSetMx UpdateRecordSetRequestPathRecordSet
const UpdateRecordSetRequestPathRecordSetTxt UpdateRecordSetRequestPathRecordSet = "txt"
const UpdateRecordSetRequestPathRecordSetSrv UpdateRecordSetRequestPathRecordSet = "srv"
const UpdateRecordSetRequestPathRecordSetCname UpdateRecordSetRequestPathRecordSet = "cname"
const UpdateRecordSetRequestPathRecordSetCaa UpdateRecordSetRequestPathRecordSet = "caa"

func (e UpdateRecordSetRequestPathRecordSet) Validate() error {
if e == UpdateRecordSetRequestPathRecordSetA || e == UpdateRecordSetRequestPathRecordSetMx || e == UpdateRecordSetRequestPathRecordSetTxt || e == UpdateRecordSetRequestPathRecordSetSrv || e == UpdateRecordSetRequestPathRecordSetCname {
if e == UpdateRecordSetRequestPathRecordSetA || e == UpdateRecordSetRequestPathRecordSetMx || e == UpdateRecordSetRequestPathRecordSetTxt || e == UpdateRecordSetRequestPathRecordSetSrv || e == UpdateRecordSetRequestPathRecordSetCname || e == UpdateRecordSetRequestPathRecordSetCaa {
return nil
}
return fmt.Errorf("unexpected value for type %T: %s", e, e)
Expand Down
30 changes: 15 additions & 15 deletions mittwaldv2/generated/clients/user/authenticate_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import (
// null

type AuthenticateResponse struct {
AlternativeAuthenticateAcceptedResponse *AuthenticateAcceptedResponse
AlternativeAuthenticateOKResponse *AuthenticateOKResponse
AlternativeAuthenticateAcceptedResponse *AuthenticateAcceptedResponse
}

func (a *AuthenticateResponse) MarshalJSON() ([]byte, error) {
if a.AlternativeAuthenticateAcceptedResponse != nil {
return json.Marshal(a.AlternativeAuthenticateAcceptedResponse)
}
if a.AlternativeAuthenticateOKResponse != nil {
return json.Marshal(a.AlternativeAuthenticateOKResponse)
}
if a.AlternativeAuthenticateAcceptedResponse != nil {
return json.Marshal(a.AlternativeAuthenticateAcceptedResponse)
}
return []byte("null"), nil
}

Expand All @@ -35,21 +35,21 @@ func (a *AuthenticateResponse) UnmarshalJSON(input []byte) error {
dec.DisallowUnknownFields()

reader.Reset(input)
var alternativeAuthenticateAcceptedResponse AuthenticateAcceptedResponse
if err := dec.Decode(&alternativeAuthenticateAcceptedResponse); err == nil {
var alternativeAuthenticateOKResponse AuthenticateOKResponse
if err := dec.Decode(&alternativeAuthenticateOKResponse); err == nil {
//subtype: *generator.ObjectType
if vErr := alternativeAuthenticateAcceptedResponse.Validate(); vErr == nil {
a.AlternativeAuthenticateAcceptedResponse = &alternativeAuthenticateAcceptedResponse
if vErr := alternativeAuthenticateOKResponse.Validate(); vErr == nil {
a.AlternativeAuthenticateOKResponse = &alternativeAuthenticateOKResponse
decodedAtLeastOnce = true
}
}

reader.Reset(input)
var alternativeAuthenticateOKResponse AuthenticateOKResponse
if err := dec.Decode(&alternativeAuthenticateOKResponse); err == nil {
var alternativeAuthenticateAcceptedResponse AuthenticateAcceptedResponse
if err := dec.Decode(&alternativeAuthenticateAcceptedResponse); err == nil {
//subtype: *generator.ObjectType
if vErr := alternativeAuthenticateOKResponse.Validate(); vErr == nil {
a.AlternativeAuthenticateOKResponse = &alternativeAuthenticateOKResponse
if vErr := alternativeAuthenticateAcceptedResponse.Validate(); vErr == nil {
a.AlternativeAuthenticateAcceptedResponse = &alternativeAuthenticateAcceptedResponse
decodedAtLeastOnce = true
}
}
Expand All @@ -61,11 +61,11 @@ func (a *AuthenticateResponse) UnmarshalJSON(input []byte) error {
}

func (a *AuthenticateResponse) Validate() error {
if a.AlternativeAuthenticateAcceptedResponse != nil {
return a.AlternativeAuthenticateAcceptedResponse.Validate()
}
if a.AlternativeAuthenticateOKResponse != nil {
return a.AlternativeAuthenticateOKResponse.Validate()
}
if a.AlternativeAuthenticateAcceptedResponse != nil {
return a.AlternativeAuthenticateAcceptedResponse.Validate()
}
return errors.New("no alternative set")
}
12 changes: 6 additions & 6 deletions mittwaldv2/generated/clients/user/authenticate_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (

var _ = Describe("AuthenticateResponse", func() {
When("unmarshaling from JSON", func() {
It("should unmarshal into AlternativeAuthenticateAcceptedResponse", func() {
exampleJSON := []byte("{\"name\":\"SecondFactorRequired\"}")
It("should unmarshal into AlternativeAuthenticateOKResponse", func() {
exampleJSON := []byte("{\"expires\":\"2006-01-02T15:04:05Z\",\"refreshToken\":\"string\",\"token\":\"string\"}")

sut := user.AuthenticateResponse{}
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed())
Expect(sut.Validate()).To(Succeed())
Expect(sut.AlternativeAuthenticateAcceptedResponse).NotTo(BeNil())
Expect(sut.AlternativeAuthenticateOKResponse).NotTo(BeNil())
})
It("should unmarshal into AlternativeAuthenticateOKResponse", func() {
exampleJSON := []byte("{\"expires\":\"2006-01-02T15:04:05Z\",\"refreshToken\":\"string\",\"token\":\"string\"}")
It("should unmarshal into AlternativeAuthenticateAcceptedResponse", func() {
exampleJSON := []byte("{\"name\":\"SecondFactorRequired\"}")

sut := user.AuthenticateResponse{}
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed())
Expect(sut.Validate()).To(Succeed())
Expect(sut.AlternativeAuthenticateOKResponse).NotTo(BeNil())
Expect(sut.AlternativeAuthenticateAcceptedResponse).NotTo(BeNil())
})
})
})
28 changes: 14 additions & 14 deletions mittwaldv2/generated/clients/user/changepassword_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import (
// null

type ChangePasswordResponse struct {
AlternativeChangePasswordAcceptedResponse *any
AlternativeChangePasswordOKResponse *ChangePasswordOKResponse
AlternativeChangePasswordAcceptedResponse *any
}

func (a *ChangePasswordResponse) MarshalJSON() ([]byte, error) {
if a.AlternativeChangePasswordAcceptedResponse != nil {
return json.Marshal(a.AlternativeChangePasswordAcceptedResponse)
}
if a.AlternativeChangePasswordOKResponse != nil {
return json.Marshal(a.AlternativeChangePasswordOKResponse)
}
if a.AlternativeChangePasswordAcceptedResponse != nil {
return json.Marshal(a.AlternativeChangePasswordAcceptedResponse)
}
return []byte("null"), nil
}

Expand All @@ -34,13 +34,6 @@ func (a *ChangePasswordResponse) UnmarshalJSON(input []byte) error {
dec := json.NewDecoder(reader)
dec.DisallowUnknownFields()

reader.Reset(input)
var alternativeChangePasswordAcceptedResponse any
if err := dec.Decode(&alternativeChangePasswordAcceptedResponse); err == nil {
a.AlternativeChangePasswordAcceptedResponse = &alternativeChangePasswordAcceptedResponse
decodedAtLeastOnce = true
}

reader.Reset(input)
var alternativeChangePasswordOKResponse ChangePasswordOKResponse
if err := dec.Decode(&alternativeChangePasswordOKResponse); err == nil {
Expand All @@ -51,19 +44,26 @@ func (a *ChangePasswordResponse) UnmarshalJSON(input []byte) error {
}
}

reader.Reset(input)
var alternativeChangePasswordAcceptedResponse any
if err := dec.Decode(&alternativeChangePasswordAcceptedResponse); err == nil {
a.AlternativeChangePasswordAcceptedResponse = &alternativeChangePasswordAcceptedResponse
decodedAtLeastOnce = true
}

if !decodedAtLeastOnce {
return fmt.Errorf("could not unmarshal into any alternative for type %T", a)
}
return nil
}

func (a *ChangePasswordResponse) Validate() error {
if a.AlternativeChangePasswordOKResponse != nil {
return a.AlternativeChangePasswordOKResponse.Validate()
}
// The AlternativeChangePasswordAcceptedResponse subtype does not implement validation, so we consider being non-nil as valid
if a.AlternativeChangePasswordAcceptedResponse != nil {
return nil
}
if a.AlternativeChangePasswordOKResponse != nil {
return a.AlternativeChangePasswordOKResponse.Validate()
}
return errors.New("no alternative set")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (

var _ = Describe("ChangePasswordResponse", func() {
When("unmarshaling from JSON", func() {
It("should unmarshal into AlternativeChangePasswordAcceptedResponse", func() {
exampleJSON := []byte("null")
It("should unmarshal into AlternativeChangePasswordOKResponse", func() {
exampleJSON := []byte("{\"expires\":\"2006-01-02T15:04:05Z\",\"token\":\"string\"}")

sut := user.ChangePasswordResponse{}
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed())
Expect(sut.Validate()).To(Succeed())
Expect(sut.AlternativeChangePasswordAcceptedResponse).NotTo(BeNil())
Expect(sut.AlternativeChangePasswordOKResponse).NotTo(BeNil())
})
It("should unmarshal into AlternativeChangePasswordOKResponse", func() {
exampleJSON := []byte("{\"expires\":\"2006-01-02T15:04:05Z\",\"token\":\"string\"}")
It("should unmarshal into AlternativeChangePasswordAcceptedResponse", func() {
exampleJSON := []byte("null")

sut := user.ChangePasswordResponse{}
Expect(json.Unmarshal(exampleJSON, &sut)).To(Succeed())
Expect(sut.Validate()).To(Succeed())
Expect(sut.AlternativeChangePasswordOKResponse).NotTo(BeNil())
Expect(sut.AlternativeChangePasswordAcceptedResponse).NotTo(BeNil())
})
})
})
73 changes: 73 additions & 0 deletions mittwaldv2/generated/schemas/dnsv1/recordcaa.go
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")
}
33 changes: 33 additions & 0 deletions mittwaldv2/generated/schemas/dnsv1/recordcaa_test.go
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())
})
})
})
Loading

0 comments on commit 484c033

Please sign in to comment.