From f1ce0ab6d08cc01b1d62ca38a45459e63f7663c7 Mon Sep 17 00:00:00 2001 From: Jeremy Wharton Date: Wed, 15 Nov 2023 01:37:10 -0600 Subject: [PATCH] private/apigen/example: use hardcoded time This change makes the example API definition use a hardcoded timestamp rather than the current time so that files aren't unnecessarily changed each time the API code is generated. Change-Id: I72e4ec98d29345b9f16ca2ca38a91e593f83ea87 --- private/apigen/example/client-api-mock.gen.ts | 8 ++++---- private/apigen/example/gen.go | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/private/apigen/example/client-api-mock.gen.ts b/private/apigen/example/client-api-mock.gen.ts index 49b283d65..93ea4791f 100644 --- a/private/apigen/example/client-api-mock.gen.ts +++ b/private/apigen/example/client-api-mock.gen.ts @@ -91,7 +91,7 @@ export class DocumentsHttpApiV0 { throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); } - return JSON.parse('[{"id":"00000000-0000-0000-0000-000000000000","path":"/workspace/notes.md","date":"0001-01-01T00:00:00Z","metadata":{"owner":"Storj","tags":[["category","general"]]},"last_retrievals":[{"user":"Storj","when":"2023-11-03T15:41:14.288101181+01:00"}]}]') as DocsGetResponse; + return JSON.parse('[{"id":"00000000-0000-0000-0000-000000000000","path":"/workspace/notes.md","date":"0001-01-01T00:00:00Z","metadata":{"owner":"Storj","tags":[["category","general"]]},"last_retrievals":[{"user":"Storj","when":"2001-02-03T03:05:06.000000007Z"}]}]') as DocsGetResponse; } public async getOne(path: string): Promise { @@ -99,7 +99,7 @@ export class DocumentsHttpApiV0 { throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); } - return JSON.parse('{"id":"00000000-0000-0000-0000-000000000000","date":"2023-11-02T16:41:14.288104016+01:00","pathParam":"ID","body":"## Notes","version":{"date":"2023-11-03T16:11:14.288104112+01:00","number":1}}') as Document; + return JSON.parse('{"id":"00000000-0000-0000-0000-000000000000","date":"2001-02-02T04:05:06.000000007Z","pathParam":"ID","body":"## Notes","version":{"date":"2001-02-03T03:35:06.000000007Z","number":1}}') as Document; } public async getTag(path: string, tagName: string): Promise { @@ -115,7 +115,7 @@ export class DocumentsHttpApiV0 { throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); } - return JSON.parse('[{"date":"2023-10-19T17:41:14.288106868+02:00","number":1},{"date":"2023-11-03T11:41:14.288106932+01:00","number":2}]') as Version[]; + return JSON.parse('[{"date":"2001-01-19T04:05:06.000000007Z","number":1},{"date":"2001-02-02T23:05:06.000000007Z","number":2}]') as Version[]; } public async updateContent(request: DocsUpdateContentRequest, path: string, id: UUID, date: Time): Promise { @@ -123,7 +123,7 @@ export class DocumentsHttpApiV0 { throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); } - return JSON.parse('{"id":"00000000-0000-0000-0000-000000000000","date":"2023-11-03T16:41:14.288108437+01:00","pathParam":"ID","body":"## Notes\n### General"}') as DocsUpdateContentResponse; + return JSON.parse('{"id":"00000000-0000-0000-0000-000000000000","date":"2001-02-03T04:05:06.000000007Z","pathParam":"ID","body":"## Notes\n### General"}') as DocsUpdateContentResponse; } } diff --git a/private/apigen/example/gen.go b/private/apigen/example/gen.go index 0ad68135d..4bf21ece5 100644 --- a/private/apigen/example/gen.go +++ b/private/apigen/example/gen.go @@ -20,6 +20,8 @@ func main() { g := a.Group("Documents", "docs") + now := time.Date(2001, 02, 03, 04, 05, 06, 07, time.UTC) + g.Get("/", &apigen.Endpoint{ Name: "Get Documents", Description: "Get the paths to all the documents under the specified paths", @@ -56,7 +58,7 @@ func main() { When time.Time `json:"when"` }{{ User: "Storj", - When: time.Now().Add(-time.Hour), + When: now.Add(-time.Hour), }}, }}, }) @@ -72,11 +74,11 @@ func main() { }, ResponseMock: myapi.Document{ ID: uuid.UUID{}, - Date: time.Now().Add(-24 * time.Hour), + Date: now.Add(-24 * time.Hour), PathParam: "ID", Body: "## Notes", Version: myapi.Version{ - Date: time.Now().Add(-30 * time.Minute), + Date: now.Add(-30 * time.Minute), Number: 1, }, }, @@ -105,8 +107,8 @@ func main() { apigen.NewParam("path", ""), }, ResponseMock: []myapi.Version{ - {Date: time.Now().Add(-360 * time.Hour), Number: 1}, - {Date: time.Now().Add(-5 * time.Hour), Number: 2}, + {Date: now.Add(-360 * time.Hour), Number: 1}, + {Date: now.Add(-5 * time.Hour), Number: 2}, }, }) @@ -138,7 +140,7 @@ func main() { Body string `json:"body"` }{ ID: uuid.UUID{}, - Date: time.Now(), + Date: now, PathParam: "ID", Body: "## Notes\n### General", },