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 28, 2025
1 parent dc27c7c commit d996fda
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
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 {
AlternativeAuthenticateOKResponse *AuthenticateOKResponse
AlternativeAuthenticateAcceptedResponse *AuthenticateAcceptedResponse
AlternativeAuthenticateOKResponse *AuthenticateOKResponse
}

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

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

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
}
}

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
}
}
Expand All @@ -61,11 +61,11 @@ func (a *AuthenticateResponse) UnmarshalJSON(input []byte) error {
}

func (a *AuthenticateResponse) Validate() error {
if a.AlternativeAuthenticateOKResponse != nil {
return a.AlternativeAuthenticateOKResponse.Validate()
}
if a.AlternativeAuthenticateAcceptedResponse != nil {
return a.AlternativeAuthenticateAcceptedResponse.Validate()
}
if a.AlternativeAuthenticateOKResponse != nil {
return a.AlternativeAuthenticateOKResponse.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 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())
})
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())
})
})
})
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 {
AlternativeChangePasswordOKResponse *ChangePasswordOKResponse
AlternativeChangePasswordAcceptedResponse *any
AlternativeChangePasswordOKResponse *ChangePasswordOKResponse
}

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

Expand All @@ -34,6 +34,13 @@ 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 @@ -44,26 +51,19 @@ 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 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())
})
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())
})
})
})

0 comments on commit d996fda

Please sign in to comment.