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
This commit is contained in:
Jeremy Wharton 2023-11-15 01:37:10 -06:00 committed by Jeremy Wharton
parent 2ed05314fc
commit f1ce0ab6d0
2 changed files with 12 additions and 10 deletions

View File

@ -91,7 +91,7 @@ export class DocumentsHttpApiV0 {
throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); 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<Document> { public async getOne(path: string): Promise<Document> {
@ -99,7 +99,7 @@ export class DocumentsHttpApiV0 {
throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); 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<string[]> { public async getTag(path: string, tagName: string): Promise<string[]> {
@ -115,7 +115,7 @@ export class DocumentsHttpApiV0 {
throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); 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<DocsUpdateContentResponse> { public async updateContent(request: DocsUpdateContentRequest, path: string, id: UUID, date: Time): Promise<DocsUpdateContentResponse> {
@ -123,7 +123,7 @@ export class DocumentsHttpApiV0 {
throw new APIError('mock error message: ' + this.respStatusCode, this.respStatusCode); 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;
} }
} }

View File

@ -20,6 +20,8 @@ func main() {
g := a.Group("Documents", "docs") g := a.Group("Documents", "docs")
now := time.Date(2001, 02, 03, 04, 05, 06, 07, time.UTC)
g.Get("/", &apigen.Endpoint{ g.Get("/", &apigen.Endpoint{
Name: "Get Documents", Name: "Get Documents",
Description: "Get the paths to all the documents under the specified paths", Description: "Get the paths to all the documents under the specified paths",
@ -56,7 +58,7 @@ func main() {
When time.Time `json:"when"` When time.Time `json:"when"`
}{{ }{{
User: "Storj", User: "Storj",
When: time.Now().Add(-time.Hour), When: now.Add(-time.Hour),
}}, }},
}}, }},
}) })
@ -72,11 +74,11 @@ func main() {
}, },
ResponseMock: myapi.Document{ ResponseMock: myapi.Document{
ID: uuid.UUID{}, ID: uuid.UUID{},
Date: time.Now().Add(-24 * time.Hour), Date: now.Add(-24 * time.Hour),
PathParam: "ID", PathParam: "ID",
Body: "## Notes", Body: "## Notes",
Version: myapi.Version{ Version: myapi.Version{
Date: time.Now().Add(-30 * time.Minute), Date: now.Add(-30 * time.Minute),
Number: 1, Number: 1,
}, },
}, },
@ -105,8 +107,8 @@ func main() {
apigen.NewParam("path", ""), apigen.NewParam("path", ""),
}, },
ResponseMock: []myapi.Version{ ResponseMock: []myapi.Version{
{Date: time.Now().Add(-360 * time.Hour), Number: 1}, {Date: now.Add(-360 * time.Hour), Number: 1},
{Date: time.Now().Add(-5 * time.Hour), Number: 2}, {Date: now.Add(-5 * time.Hour), Number: 2},
}, },
}) })
@ -138,7 +140,7 @@ func main() {
Body string `json:"body"` Body string `json:"body"`
}{ }{
ID: uuid.UUID{}, ID: uuid.UUID{},
Date: time.Now(), Date: now,
PathParam: "ID", PathParam: "ID",
Body: "## Notes\n### General", Body: "## Notes\n### General",
}, },