Skip to content

Commit

Permalink
New updates to generated code (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
octokitbot authored Oct 10, 2024
1 parent 33ef26a commit 7ea85c4
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 41 deletions.
4 changes: 4 additions & 0 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func NewApiClient(optionFuncs ...ClientOptionFunc) (*Client, error) {
return nil, fmt.Errorf("failed to create transport from GitHub App: %v", err)
}

if options.BaseURL != "" {
appTransport.BaseURL = options.BaseURL
}

netHttpClient.Transport = appTransport
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/client_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package pkg

import (
"context"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

abs "github.com/microsoft/kiota-abstractions-go"
"github.com/octokit/go-sdk-enterprise-server/pkg/github/installation"
"github.com/octokit/go-sdk-enterprise-server/pkg/headers"
)

Expand Down Expand Up @@ -91,6 +97,49 @@ func TestNewApiClientAppAuthHappyPath(t *testing.T) {
}
}

func TestNewApiClientAppAuthBaseUrl(t *testing.T) {
tmpfile, err := os.CreateTemp("", pemFileName)
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())

if _, err := tmpfile.Write(key); err != nil {
t.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
t.Fatal(err)
}

expectedCall := false
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.Path, "/app/installations") {
expectedCall = true
}
}))

client, err := NewApiClient(
WithGitHubAppAuthentication(tmpfile.Name(), clientID, installationID),
WithBaseUrl(server.URL),
)
if err != nil {
t.Fatalf("error creating client: %v", err)
}
if client == nil {
t.Fatalf("client is nil")
}
queryParams := &installation.RepositoriesRequestBuilderGetQueryParameters{}
requestConfig := &abs.RequestConfiguration[installation.RepositoriesRequestBuilderGetQueryParameters]{
QueryParameters: queryParams,
}

// trigger a refresh of the installation token to the expected url
_, _ = client.Installation().Repositories().Get(context.Background(), requestConfig)
if !expectedCall {
t.Errorf("installation token endpoint not called")
}
}

func TestNewApiClientAppAuthErrorGettingKeyFromFile(t *testing.T) {
client, err := NewApiClient(WithGitHubAppAuthentication("pem/file/does/not/exist.pem", clientID, installationID))
if err == nil {
Expand Down
152 changes: 111 additions & 41 deletions pkg/github/models/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (
type Users struct {
// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
additionalData map[string]any
// Whether this email address is the primary address.
primary *bool
// The type of email address.
typeEscaped *string
// The email address.
value *string
// The fragment property
fragment *string
// The matches property
matches []Users_matchesable
// The object_type property
object_type *string
// The object_url property
object_url *string
// The property property
property *string
}
// NewUsers instantiates a new Users and sets the default values.
func NewUsers()(*Users) {
Expand All @@ -35,69 +39,123 @@ func (m *Users) GetAdditionalData()(map[string]any) {
// returns a map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(error) when successful
func (m *Users) GetFieldDeserializers()(map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(error)) {
res := make(map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(error))
res["primary"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetBoolValue()
res["fragment"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetFragment(val)
}
return nil
}
res["matches"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetCollectionOfObjectValues(CreateUsers_matchesFromDiscriminatorValue)
if err != nil {
return err
}
if val != nil {
res := make([]Users_matchesable, len(val))
for i, v := range val {
if v != nil {
res[i] = v.(Users_matchesable)
}
}
m.SetMatches(res)
}
return nil
}
res["object_type"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetPrimary(val)
m.SetObjectType(val)
}
return nil
}
res["type"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
res["object_url"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetTypeEscaped(val)
m.SetObjectUrl(val)
}
return nil
}
res["value"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
res["property"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetValue(val)
m.SetProperty(val)
}
return nil
}
return res
}
// GetPrimary gets the primary property value. Whether this email address is the primary address.
// returns a *bool when successful
func (m *Users) GetPrimary()(*bool) {
return m.primary
// GetFragment gets the fragment property value. The fragment property
// returns a *string when successful
func (m *Users) GetFragment()(*string) {
return m.fragment
}
// GetMatches gets the matches property value. The matches property
// returns a []Users_matchesable when successful
func (m *Users) GetMatches()([]Users_matchesable) {
return m.matches
}
// GetObjectType gets the object_type property value. The object_type property
// returns a *string when successful
func (m *Users) GetObjectType()(*string) {
return m.object_type
}
// GetTypeEscaped gets the type property value. The type of email address.
// GetObjectUrl gets the object_url property value. The object_url property
// returns a *string when successful
func (m *Users) GetTypeEscaped()(*string) {
return m.typeEscaped
func (m *Users) GetObjectUrl()(*string) {
return m.object_url
}
// GetValue gets the value property value. The email address.
// GetProperty gets the property property value. The property property
// returns a *string when successful
func (m *Users) GetValue()(*string) {
return m.value
func (m *Users) GetProperty()(*string) {
return m.property
}
// Serialize serializes information the current object
func (m *Users) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.SerializationWriter)(error) {
{
err := writer.WriteBoolValue("primary", m.GetPrimary())
err := writer.WriteStringValue("fragment", m.GetFragment())
if err != nil {
return err
}
}
if m.GetMatches() != nil {
cast := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, len(m.GetMatches()))
for i, v := range m.GetMatches() {
if v != nil {
cast[i] = v.(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable)
}
}
err := writer.WriteCollectionOfObjectValues("matches", cast)
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("object_type", m.GetObjectType())
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("type", m.GetTypeEscaped())
err := writer.WriteStringValue("object_url", m.GetObjectUrl())
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("value", m.GetValue())
err := writer.WriteStringValue("property", m.GetProperty())
if err != nil {
return err
}
Expand All @@ -114,25 +172,37 @@ func (m *Users) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0e6c010c4
func (m *Users) SetAdditionalData(value map[string]any)() {
m.additionalData = value
}
// SetPrimary sets the primary property value. Whether this email address is the primary address.
func (m *Users) SetPrimary(value *bool)() {
m.primary = value
// SetFragment sets the fragment property value. The fragment property
func (m *Users) SetFragment(value *string)() {
m.fragment = value
}
// SetMatches sets the matches property value. The matches property
func (m *Users) SetMatches(value []Users_matchesable)() {
m.matches = value
}
// SetObjectType sets the object_type property value. The object_type property
func (m *Users) SetObjectType(value *string)() {
m.object_type = value
}
// SetTypeEscaped sets the type property value. The type of email address.
func (m *Users) SetTypeEscaped(value *string)() {
m.typeEscaped = value
// SetObjectUrl sets the object_url property value. The object_url property
func (m *Users) SetObjectUrl(value *string)() {
m.object_url = value
}
// SetValue sets the value property value. The email address.
func (m *Users) SetValue(value *string)() {
m.value = value
// SetProperty sets the property property value. The property property
func (m *Users) SetProperty(value *string)() {
m.property = value
}
type Usersable interface {
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.AdditionalDataHolder
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable
GetPrimary()(*bool)
GetTypeEscaped()(*string)
GetValue()(*string)
SetPrimary(value *bool)()
SetTypeEscaped(value *string)()
SetValue(value *string)()
GetFragment()(*string)
GetMatches()([]Users_matchesable)
GetObjectType()(*string)
GetObjectUrl()(*string)
GetProperty()(*string)
SetFragment(value *string)()
SetMatches(value []Users_matchesable)()
SetObjectType(value *string)()
SetObjectUrl(value *string)()
SetProperty(value *string)()
}
Loading

0 comments on commit 7ea85c4

Please sign in to comment.