From 2a9adb3aa485ddf610e805a300a122b03cc494c8 Mon Sep 17 00:00:00 2001 From: Tyler Mairose Date: Fri, 18 Oct 2024 14:04:59 -0400 Subject: [PATCH 1/2] Temporary Fix for Workgroups created and modified times missing seconds in the API response --- api_beta/model_workgroup_dto.go | 53 +++++++++++++++++---- sdk-resources/postscript.js | 83 +++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 10 deletions(-) diff --git a/api_beta/model_workgroup_dto.go b/api_beta/model_workgroup_dto.go index ebeb2f2fc..075b54307 100644 --- a/api_beta/model_workgroup_dto.go +++ b/api_beta/model_workgroup_dto.go @@ -31,8 +31,8 @@ type WorkgroupDto struct { MemberCount *int64 `json:"memberCount,omitempty"` // Number of connections in the governance group. ConnectionCount *int64 `json:"connectionCount,omitempty"` - Created *time.Time `json:"created,omitempty"` - Modified *time.Time `json:"modified,omitempty"` + Created *SailPointTime `json:"created,omitempty"` + Modified *SailPointTime `json:"modified,omitempty"` AdditionalProperties map[string]interface{} } @@ -248,9 +248,9 @@ func (o *WorkgroupDto) SetConnectionCount(v int64) { } // GetCreated returns the Created field value if set, zero value otherwise. -func (o *WorkgroupDto) GetCreated() time.Time { +func (o *WorkgroupDto) GetCreated() SailPointTime { if o == nil || IsNil(o.Created) { - var ret time.Time + var ret SailPointTime return ret } return *o.Created @@ -258,7 +258,7 @@ func (o *WorkgroupDto) GetCreated() time.Time { // GetCreatedOk returns a tuple with the Created field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *WorkgroupDto) GetCreatedOk() (*time.Time, bool) { +func (o *WorkgroupDto) GetCreatedOk() (*SailPointTime, bool) { if o == nil || IsNil(o.Created) { return nil, false } @@ -275,14 +275,14 @@ func (o *WorkgroupDto) HasCreated() bool { } // SetCreated gets a reference to the given time.Time and assigns it to the Created field. -func (o *WorkgroupDto) SetCreated(v time.Time) { +func (o *WorkgroupDto) SetCreated(v SailPointTime) { o.Created = &v } // GetModified returns the Modified field value if set, zero value otherwise. -func (o *WorkgroupDto) GetModified() time.Time { +func (o *WorkgroupDto) GetModified() SailPointTime { if o == nil || IsNil(o.Modified) { - var ret time.Time + var ret SailPointTime return ret } return *o.Modified @@ -290,7 +290,7 @@ func (o *WorkgroupDto) GetModified() time.Time { // GetModifiedOk returns a tuple with the Modified field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *WorkgroupDto) GetModifiedOk() (*time.Time, bool) { +func (o *WorkgroupDto) GetModifiedOk() (*SailPointTime, bool) { if o == nil || IsNil(o.Modified) { return nil, false } @@ -307,7 +307,7 @@ func (o *WorkgroupDto) HasModified() bool { } // SetModified gets a reference to the given time.Time and assigns it to the Modified field. -func (o *WorkgroupDto) SetModified(v time.Time) { +func (o *WorkgroupDto) SetModified(v SailPointTime) { o.Modified = &v } @@ -353,6 +353,39 @@ func (o WorkgroupDto) ToMap() (map[string]interface{}, error) { return toSerialize, nil } +type SailPointTime struct { + time.Time +} + +func (m *SailPointTime) UnmarshalJSON(data []byte) error { + if string(data) == "null" || string(data) == `""` { + return nil; + } + + // Strip the quotes from the data + str := string(data); + str = str[1 : len(str)-1]; + + // Try parsing with seconds first + formats := []string{ + time.RFC3339, // Format with seconds (e.g., "2012-04-23T18:25:43Z") + "2006-01-02T15:04Z", // Format without seconds (e.g., "2012-04-23T18:25Z") + "2006-01-02T15:04:05.999999999", // Optional milliseconds and nanoseconds + } + + var err error; + for _, format := range formats { + var t time.Time; + t, err = time.Parse(format, str); + if err == nil { + *m = SailPointTime{t}; + return nil; + } + } + + return nil; +} + func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) { varWorkgroupDto := _WorkgroupDto{} diff --git a/sdk-resources/postscript.js b/sdk-resources/postscript.js index 925861476..97549a4d3 100644 --- a/sdk-resources/postscript.js +++ b/sdk-resources/postscript.js @@ -172,6 +172,89 @@ const fixFiles = function (myArray) { rawDataArra = fileOut.slice(); fileOut = []; } + + if (file.includes("model_workgroup_dto.go")) { + + const sailPointTimeCode = `type SailPointTime struct { + time.Time +} + +func (m *SailPointTime) UnmarshalJSON(data []byte) error { + if string(data) == "null" || string(data) == \`""\` { + return nil; + } + + // Strip the quotes from the data + str := string(data); + str = str[1 : len(str)-1]; + + // Try parsing with seconds first + formats := []string{ + time.RFC3339, // Format with seconds (e.g., "2012-04-23T18:25:43Z") + "2006-01-02T15:04Z", // Format without seconds (e.g., "2012-04-23T18:25Z") + "2006-01-02T15:04:05.999999999", // Optional milliseconds and nanoseconds + } + + var err error; + for _, format := range formats { + var t time.Time; + t, err = time.Parse(format, str); + if err == nil { + *m = SailPointTime{t}; + return nil; + } + } + + return nil; +} + +func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {`; + + + for (const line of rawDataArra) { + if (line.includes('Created *time.Time `json:"created,omitempty"`')) { + fileOut.push(line.replace('Created *time.Time `json:"created,omitempty"`', 'Created *SailPointTime `json:"created,omitempty"`')); + madeChange = true; + } else if (line.includes('Modified *time.Time `json:"modified,omitempty"`')) { + fileOut.push(line.replace('Modified *time.Time `json:"modified,omitempty"`', 'Modified *SailPointTime `json:"modified,omitempty"`')); + madeChange = true; + } else if (line.includes('func (o *WorkgroupDto) GetCreated() time.Time {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) GetCreated() time.Time {', 'func (o *WorkgroupDto) GetCreated() SailPointTime {')); + madeChange = true; + } else if (line.includes('func (o *WorkgroupDto) GetCreatedOk() (*time.Time, bool) {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) GetCreatedOk() (*time.Time, bool) {', 'func (o *WorkgroupDto) GetCreatedOk() (*SailPointTime, bool) {')); + madeChange = true; + } else if (line.includes('func (o *WorkgroupDto) GetModified() time.Time {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) GetModified() time.Time {', 'func (o *WorkgroupDto) GetModified() SailPointTime {')); + madeChange = true; + } else if (line.includes('var ret time.Time')) { + fileOut.push(line.replace('var ret time.Time', 'var ret SailPointTime')); + madeChange = true; + } else if (line.includes('func (o *WorkgroupDto) GetModifiedOk() (*time.Time, bool) {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) GetModifiedOk() (*time.Time, bool) {', 'func (o *WorkgroupDto) GetModifiedOk() (*SailPointTime, bool) {')); + madeChange = true; + } else if (line.includes('func (o *WorkgroupDto) SetModified(v time.Time) {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) SetModified(v time.Time) {', 'func (o *WorkgroupDto) SetModified(v SailPointTime) {')); + madeChange = true; + } else if (line.includes('func (o *WorkgroupDto) SetCreated(v time.Time) {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) SetCreated(v time.Time) {', 'func (o *WorkgroupDto) SetCreated(v SailPointTime) {')); + madeChange = true; + }else if (line.includes('func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {')) { + fileOut.push(line.replace('func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {', sailPointTimeCode)); + madeChange = true; + } else if (line.includes('')) { + fileOut.push(line.replace('', '')); + madeChange = true; + } + + else { + fileOut.push(line); + } + } + + rawDataArra = fileOut.slice(); + fileOut = []; + } if (madeChange) { fixCheck += 1; From 78dfa90091d4fc7ebd86b2be815564578b21a91b Mon Sep 17 00:00:00 2001 From: Tyler Mairose Date: Fri, 18 Oct 2024 14:07:56 -0400 Subject: [PATCH 2/2] Remove extra check --- sdk-resources/postscript.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sdk-resources/postscript.js b/sdk-resources/postscript.js index 97549a4d3..fe3fa6346 100644 --- a/sdk-resources/postscript.js +++ b/sdk-resources/postscript.js @@ -239,15 +239,10 @@ func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {`; } else if (line.includes('func (o *WorkgroupDto) SetCreated(v time.Time) {')) { fileOut.push(line.replace('func (o *WorkgroupDto) SetCreated(v time.Time) {', 'func (o *WorkgroupDto) SetCreated(v SailPointTime) {')); madeChange = true; - }else if (line.includes('func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {')) { + } else if (line.includes('func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {')) { fileOut.push(line.replace('func (o *WorkgroupDto) UnmarshalJSON(data []byte) (err error) {', sailPointTimeCode)); madeChange = true; - } else if (line.includes('')) { - fileOut.push(line.replace('', '')); - madeChange = true; - } - - else { + } else { fileOut.push(line); } }