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 31, 2025
1 parent 3fca606 commit 52abe00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
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())
})
})
})

0 comments on commit 52abe00

Please sign in to comment.