From 6840f5d4809b0eda87cc67447798ee6bc7805cb8 Mon Sep 17 00:00:00 2001 From: cp20 <47262658+cp-20@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:02:08 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=99=E3=83=B3=E3=83=81=E3=83=9E=E3=83=BC?= =?UTF-8?q?=E3=82=AF=E5=91=A8=E3=82=8A=E3=81=AE=20OpenAPI=20=E3=82=92?= =?UTF-8?q?=E6=94=B9=E5=96=84=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/api/openapi.ts | 96 +- client/src/mock/handlers.ts | 15 +- openapi/openapi.yml | 103 +- server/handler/openapi/oas_json_gen.go | 2823 +++++++++++++----- server/handler/openapi/oas_parameters_gen.go | 6 + server/handler/openapi/oas_schemas_gen.go | 1325 +++++--- server/handler/openapi/oas_validators_gen.go | 385 ++- 7 files changed, 3574 insertions(+), 1179 deletions(-) diff --git a/client/src/api/openapi.ts b/client/src/api/openapi.ts index 1e6fc1d..e6b34f5 100644 --- a/client/src/api/openapi.ts +++ b/client/src/api/openapi.ts @@ -113,7 +113,7 @@ export interface paths { } /** * チーム一覧取得 - * @description チーム一覧を取得します + * @description チーム一覧を取得します (0件の場合も200で空配列が返ります) */ get: operations['getTeams'] put?: never @@ -162,7 +162,7 @@ export interface paths { } /** * インスタンス一覧取得 - * @description チームに所属しているインスタンス一覧を取得します + * @description チームに所属しているインスタンス一覧を取得します (0件の場合も200で空配列が返ります) */ get: operations['getTeamInstances'] put?: never @@ -210,7 +210,7 @@ export interface paths { } /** * インスタンス一覧取得 - * @description 全インスタンス一覧を取得します + * @description 全インスタンス一覧を取得します (0件の場合も200で空配列が返ります) */ get: operations['getInstances'] put?: never @@ -230,7 +230,7 @@ export interface paths { } /** * ベンチマーク一覧取得 - * @description 全チームのベンチマーク一覧を取得します + * @description 全チームのベンチマーク一覧を取得します (0件の場合も200で空配列が返ります) */ get: operations['getBenchmarks'] put?: never @@ -256,6 +256,7 @@ export interface paths { * ベンチマーク待ち行列取得 * @description ベンチマーク待ちのキューを取得します。 * createdAtの昇順になっており、現在実行中のベンチマークと、実行待ちのベンチマークが含まれます。 + * 0件の場合も200で空配列が返ります。 * */ get: operations['getBenchmarkQueue'] @@ -276,7 +277,7 @@ export interface paths { } /** * チームのベンチマーク一覧取得 - * @description チームのベンチマーク一覧を取得します + * @description チームのベンチマーク一覧を取得します (0件の場合も200で空配列が返ります) */ get: operations['getTeamBenchmarks'] put?: never @@ -338,7 +339,7 @@ export interface paths { } /** * 全てのスコア取得 - * @description 全てのベンチマークのスコアをチームごとに取得します + * @description 全てのベンチマークのスコアをチームごとに取得します (0件の場合も200で空配列が返ります) */ get: operations['getScores'] put?: never @@ -360,6 +361,7 @@ export interface paths { * ランキング取得 * @description ベンチマークのスコアランキングを取得します。1位から順に並んでいます。 * 同じスコアの場合は、ベンチマーク実行日時(createdAt)が早い順に並べます。 + * 0件の場合も200で空配列が返ります * */ get: operations['getRanking'] @@ -542,41 +544,28 @@ export interface components { */ Score: number /** @description ベンチマーク */ - Benchmark: { - id: components['schemas']['BenchmarkId'] - instanceId: components['schemas']['InstanceId'] - teamId: components['schemas']['TeamId'] - userId: components['schemas']['UserId'] - status: components['schemas']['BenchmarkStatus'] - score?: components['schemas']['Score'] - createdAt: components['schemas']['CreatedAt'] - startedAt?: components['schemas']['StartedAt'] - finishedAt?: components['schemas']['FinishedAt'] - } + BenchmarkListItem: + | components['schemas']['WaitingBenchmark'] + | components['schemas']['RunningBenchmark'] + | components['schemas']['FinishedBenchmark'] /** @description ベンチマーク結果 */ - BenchmarkResult: { - id: components['schemas']['BenchmarkId'] - instanceId: components['schemas']['InstanceId'] - teamId: components['schemas']['TeamId'] - userId: components['schemas']['UserId'] - status: components['schemas']['BenchmarkStatus'] + Benchmark: ( + | components['schemas']['WaitingBenchmark'] + | components['schemas']['RunningBenchmark'] + | components['schemas']['FinishedBenchmark'] + ) & { /** * @description ベンチマークの競技者用ログ(標準出力) * @example log */ log: string - score: components['schemas']['Score'] - createdAt: components['schemas']['CreatedAt'] - startedAt: components['schemas']['StartedAt'] - finishedAt: components['schemas']['FinishedAt'] } /** @description Adminが見ることができるベンチマーク結果 */ - BenchmarkAdminResult: { - id: components['schemas']['BenchmarkId'] - instanceId: components['schemas']['InstanceId'] - teamId: components['schemas']['TeamId'] - userId: components['schemas']['UserId'] - status: components['schemas']['BenchmarkStatus'] + BenchmarkAdminResult: ( + | components['schemas']['WaitingBenchmark'] + | components['schemas']['RunningBenchmark'] + | components['schemas']['FinishedBenchmark'] + ) & { /** * @description ベンチマークの競技者用ログ(標準出力) * @example log @@ -587,6 +576,37 @@ export interface components { * @example admin log */ adminLog: string + } + /** @description status=waiting のベンチマーク結果 */ + WaitingBenchmark: { + id: components['schemas']['BenchmarkId'] + instanceId: components['schemas']['InstanceId'] + teamId: components['schemas']['TeamId'] + userId: components['schemas']['UserId'] + /** @enum {string} */ + status: 'waiting' + createdAt: components['schemas']['CreatedAt'] + } + /** @description status=running のベンチマーク結果 */ + RunningBenchmark: { + id: components['schemas']['BenchmarkId'] + instanceId: components['schemas']['InstanceId'] + teamId: components['schemas']['TeamId'] + userId: components['schemas']['UserId'] + /** @enum {string} */ + status: 'running' + score: components['schemas']['Score'] + createdAt: components['schemas']['CreatedAt'] + startedAt: components['schemas']['StartedAt'] + } + /** @description status=finished のベンチマーク結果 */ + FinishedBenchmark: { + id: components['schemas']['BenchmarkId'] + instanceId: components['schemas']['InstanceId'] + teamId: components['schemas']['TeamId'] + userId: components['schemas']['UserId'] + /** @enum {string} */ + status: 'finished' score: components['schemas']['Score'] createdAt: components['schemas']['CreatedAt'] startedAt: components['schemas']['StartedAt'] @@ -1138,7 +1158,7 @@ export interface operations { [name: string]: unknown } content: { - 'application/json': components['schemas']['Benchmark'][] + 'application/json': components['schemas']['BenchmarkListItem'][] } } 401: components['responses']['Unauthorized'] @@ -1161,7 +1181,7 @@ export interface operations { [name: string]: unknown } content: { - 'application/json': components['schemas']['Benchmark'] + 'application/json': components['schemas']['BenchmarkListItem'] } } /** @description インスタンスが存在しない、チームに所属していない、すでにそのチームのベンチマークがキューに入っているなど */ @@ -1193,7 +1213,7 @@ export interface operations { [name: string]: unknown } content: { - 'application/json': components['schemas']['Benchmark'][] + 'application/json': components['schemas']['BenchmarkListItem'][] } } 401: components['responses']['Unauthorized'] @@ -1221,7 +1241,7 @@ export interface operations { [name: string]: unknown } content: { - 'application/json': components['schemas']['Benchmark'][] + 'application/json': components['schemas']['BenchmarkListItem'][] } } 401: components['responses']['Unauthorized'] @@ -1250,7 +1270,7 @@ export interface operations { [name: string]: unknown } content: { - 'application/json': components['schemas']['BenchmarkResult'] + 'application/json': components['schemas']['Benchmark'] } } 401: components['responses']['Unauthorized'] diff --git a/client/src/mock/handlers.ts b/client/src/mock/handlers.ts index 625610a..2e6d358 100644 --- a/client/src/mock/handlers.ts +++ b/client/src/mock/handlers.ts @@ -118,6 +118,7 @@ const benchmarks: paths['/benchmarks']['get']['responses']['200']['content']['ap status: 'running', createdAt: '2025-01-01T02:00:00Z', startedAt: '2025-01-01T02:00:01Z', + score: 0, }, { id: '01943f69-3aec-7702-8d1e-8642d9c5b47b', @@ -224,11 +225,12 @@ export const handlers = [ teams.map((team) => ({ teamId: team.id, scores: benchmarks - .filter((b) => b.teamId === team.id && b.status === 'finished') + .filter((b) => b.teamId === team.id) + .filter((b) => b.status === 'finished') .map((b) => ({ benchmarkId: b.id, teamId: team.id, - score: b.score!, + score: b.score, createdAt: b.createdAt, })), })) @@ -237,8 +239,8 @@ export const handlers = [ }), http.get(`${apiBaseUrl}/scores/ranking`, () => { const sortFn = ( - a: components['schemas']['Benchmark'], - b: components['schemas']['Benchmark'], + a: components['schemas']['FinishedBenchmark'], + b: components['schemas']['FinishedBenchmark'], ) => { // スコアの降順 if (a.score! < b.score!) return 1 @@ -252,14 +254,15 @@ export const handlers = [ .map( (team) => benchmarks - .filter((b) => b.teamId === team.id && b.status === 'finished') + .filter((b) => b.teamId === team.id) + .filter((b) => b.status === 'finished') .sort(sortFn)[0], ) .sort(sortFn) .map((b, i) => ({ rank: i + 1, teamId: b.teamId, - score: b.score!, + score: b.score, createdAt: b.createdAt, })) diff --git a/openapi/openapi.yml b/openapi/openapi.yml index 17fcc51..44ce5f0 100644 --- a/openapi/openapi.yml +++ b/openapi/openapi.yml @@ -414,7 +414,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/Benchmark" + $ref: "#/components/schemas/BenchmarkListItem" 400: description: "インスタンスが存在しない、チームに所属していない、すでにそのチームのベンチマークがキューに入っているなど" content: @@ -445,7 +445,7 @@ paths: schema: type: "array" items: - $ref: "#/components/schemas/Benchmark" + $ref: "#/components/schemas/BenchmarkListItem" 401: $ref: "#/components/responses/Unauthorized" 403: @@ -472,7 +472,7 @@ paths: schema: type: "array" items: - $ref: "#/components/schemas/Benchmark" + $ref: "#/components/schemas/BenchmarkListItem" 401: $ref: "#/components/responses/Unauthorized" 500: @@ -498,7 +498,7 @@ paths: schema: type: "array" items: - $ref: "#/components/schemas/Benchmark" + $ref: "#/components/schemas/BenchmarkListItem" 401: $ref: "#/components/responses/Unauthorized" 403: @@ -526,7 +526,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/BenchmarkResult" + $ref: "#/components/schemas/Benchmark" 401: $ref: "#/components/responses/Unauthorized" 403: @@ -962,9 +962,60 @@ components: example: 100 description: "ベンチマークのスコア" - Benchmark: + BenchmarkListItem: type: "object" description: "ベンチマーク" + discriminator: + propertyName: status + oneOf: + - $ref: "#/components/schemas/WaitingBenchmark" + - $ref: "#/components/schemas/RunningBenchmark" + - $ref: "#/components/schemas/FinishedBenchmark" + + Benchmark: + type: "object" + description: "ベンチマーク結果" + allOf: + - discriminator: + propertyName: status + oneOf: + - $ref: "#/components/schemas/WaitingBenchmark" + - $ref: "#/components/schemas/RunningBenchmark" + - $ref: "#/components/schemas/FinishedBenchmark" + - properties: + log: + type: "string" + example: "log" + description: "ベンチマークの競技者用ログ(標準出力)" + required: + - log + + BenchmarkAdminResult: + type: "object" + description: "Adminが見ることができるベンチマーク結果" + allOf: + - discriminator: + propertyName: status + oneOf: + - $ref: "#/components/schemas/WaitingBenchmark" + - $ref: "#/components/schemas/RunningBenchmark" + - $ref: "#/components/schemas/FinishedBenchmark" + - properties: + log: + type: "string" + example: "log" + description: "ベンチマークの競技者用ログ(標準出力)" + adminLog: + type: "string" + example: "admin log" + description: "ベンチマークの管理者用ログ(標準エラー出力)" + required: + - log + - adminLog + + WaitingBenchmark: + type: "object" + description: "status=waiting のベンチマーク結果" properties: id: $ref: "#/components/schemas/BenchmarkId" @@ -975,15 +1026,11 @@ components: userId: $ref: "#/components/schemas/UserId" status: - $ref: "#/components/schemas/BenchmarkStatus" - score: - $ref: "#/components/schemas/Score" + type: "string" + enum: + - "waiting" createdAt: $ref: "#/components/schemas/CreatedAt" - startedAt: - $ref: "#/components/schemas/StartedAt" - finishedAt: - $ref: "#/components/schemas/FinishedAt" required: - id - instanceId @@ -992,9 +1039,9 @@ components: - status - createdAt - BenchmarkResult: + RunningBenchmark: type: "object" - description: "ベンチマーク結果" + description: "status=running のベンチマーク結果" properties: id: $ref: "#/components/schemas/BenchmarkId" @@ -1005,34 +1052,28 @@ components: userId: $ref: "#/components/schemas/UserId" status: - $ref: "#/components/schemas/BenchmarkStatus" - log: type: "string" - example: "log" - description: "ベンチマークの競技者用ログ(標準出力)" + enum: + - "running" score: $ref: "#/components/schemas/Score" createdAt: $ref: "#/components/schemas/CreatedAt" startedAt: $ref: "#/components/schemas/StartedAt" - finishedAt: - $ref: "#/components/schemas/FinishedAt" required: - id - instanceId - teamId - userId - status - - log - score - createdAt - startedAt - - finishedAt - BenchmarkAdminResult: + FinishedBenchmark: type: "object" - description: "Adminが見ることができるベンチマーク結果" + description: "status=finished のベンチマーク結果" properties: id: $ref: "#/components/schemas/BenchmarkId" @@ -1043,15 +1084,9 @@ components: userId: $ref: "#/components/schemas/UserId" status: - $ref: "#/components/schemas/BenchmarkStatus" - log: - type: "string" - example: "log" - description: "ベンチマークの競技者用ログ(標準出力)" - adminLog: type: "string" - example: "admin log" - description: "ベンチマークの管理者用ログ(標準エラー出力)" + enum: + - "finished" score: $ref: "#/components/schemas/Score" createdAt: @@ -1066,8 +1101,6 @@ components: - teamId - userId - status - - log - - adminLog - score - createdAt - startedAt diff --git a/server/handler/openapi/oas_json_gen.go b/server/handler/openapi/oas_json_gen.go index 130a911..15abc04 100644 --- a/server/handler/openapi/oas_json_gen.go +++ b/server/handler/openapi/oas_json_gen.go @@ -16,101 +16,62 @@ import ( ) // Encode implements json.Marshaler. -func (s *Benchmark) Encode(e *jx.Encoder) { +func (s *BenchScore) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. -func (s *Benchmark) encodeFields(e *jx.Encoder) { +func (s *BenchScore) encodeFields(e *jx.Encoder) { { - e.FieldStart("id") - s.ID.Encode(e) - } - { - e.FieldStart("instanceId") - s.InstanceId.Encode(e) + if s.BenchmarkId.Set { + e.FieldStart("benchmarkId") + s.BenchmarkId.Encode(e) + } } { e.FieldStart("teamId") s.TeamId.Encode(e) } { - e.FieldStart("userId") - s.UserId.Encode(e) - } - { - e.FieldStart("status") - s.Status.Encode(e) - } - { - if s.Score.Set { - e.FieldStart("score") - s.Score.Encode(e) - } + e.FieldStart("score") + s.Score.Encode(e) } { e.FieldStart("createdAt") s.CreatedAt.Encode(e) } - { - if s.StartedAt.Set { - e.FieldStart("startedAt") - s.StartedAt.Encode(e) - } - } - { - if s.FinishedAt.Set { - e.FieldStart("finishedAt") - s.FinishedAt.Encode(e) - } - } } -var jsonFieldsNameOfBenchmark = [9]string{ - 0: "id", - 1: "instanceId", - 2: "teamId", - 3: "userId", - 4: "status", - 5: "score", - 6: "createdAt", - 7: "startedAt", - 8: "finishedAt", +var jsonFieldsNameOfBenchScore = [4]string{ + 0: "benchmarkId", + 1: "teamId", + 2: "score", + 3: "createdAt", } -// Decode decodes Benchmark from json. -func (s *Benchmark) Decode(d *jx.Decoder) error { +// Decode decodes BenchScore from json. +func (s *BenchScore) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode Benchmark to nil") + return errors.New("invalid: unable to decode BenchScore to nil") } - var requiredBitSet [2]uint8 + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { - case "id": - requiredBitSet[0] |= 1 << 0 - if err := func() error { - if err := s.ID.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"id\"") - } - case "instanceId": - requiredBitSet[0] |= 1 << 1 + case "benchmarkId": if err := func() error { - if err := s.InstanceId.Decode(d); err != nil { + s.BenchmarkId.Reset() + if err := s.BenchmarkId.Decode(d); err != nil { return err } return nil }(); err != nil { - return errors.Wrap(err, "decode field \"instanceId\"") + return errors.Wrap(err, "decode field \"benchmarkId\"") } case "teamId": - requiredBitSet[0] |= 1 << 2 + requiredBitSet[0] |= 1 << 1 if err := func() error { if err := s.TeamId.Decode(d); err != nil { return err @@ -119,29 +80,9 @@ func (s *Benchmark) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"teamId\"") } - case "userId": - requiredBitSet[0] |= 1 << 3 - if err := func() error { - if err := s.UserId.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"userId\"") - } - case "status": - requiredBitSet[0] |= 1 << 4 - if err := func() error { - if err := s.Status.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"status\"") - } case "score": + requiredBitSet[0] |= 1 << 2 if err := func() error { - s.Score.Reset() if err := s.Score.Decode(d); err != nil { return err } @@ -150,7 +91,7 @@ func (s *Benchmark) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"score\"") } case "createdAt": - requiredBitSet[0] |= 1 << 6 + requiredBitSet[0] |= 1 << 3 if err := func() error { if err := s.CreatedAt.Decode(d); err != nil { return err @@ -159,38 +100,17 @@ func (s *Benchmark) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"createdAt\"") } - case "startedAt": - if err := func() error { - s.StartedAt.Reset() - if err := s.StartedAt.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"startedAt\"") - } - case "finishedAt": - if err := func() error { - s.FinishedAt.Reset() - if err := s.FinishedAt.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"finishedAt\"") - } default: return d.Skip() } return nil }); err != nil { - return errors.Wrap(err, "decode Benchmark") + return errors.Wrap(err, "decode BenchScore") } // Validate required fields. var failures []validate.FieldError - for i, mask := range [2]uint8{ - 0b01011111, - 0b00000000, + for i, mask := range [1]uint8{ + 0b00001110, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -202,8 +122,8 @@ func (s *Benchmark) Decode(d *jx.Decoder) error { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string - if fieldIdx < len(jsonFieldsNameOfBenchmark) { - name = jsonFieldsNameOfBenchmark[fieldIdx] + if fieldIdx < len(jsonFieldsNameOfBenchScore) { + name = jsonFieldsNameOfBenchScore[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } @@ -224,282 +144,787 @@ func (s *Benchmark) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s *Benchmark) MarshalJSON() ([]byte, error) { +func (s *BenchScore) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *Benchmark) UnmarshalJSON(data []byte) error { +func (s *BenchScore) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode implements json.Marshaler. -func (s *BenchmarkAdminResult) Encode(e *jx.Encoder) { +// Encode encodes Benchmark as json. +func (s Benchmark) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields encodes fields. -func (s *BenchmarkAdminResult) encodeFields(e *jx.Encoder) { - { - e.FieldStart("id") - s.ID.Encode(e) +func (s Benchmark) encodeFields(e *jx.Encoder) { + switch s.Type { + case FinishedBenchmarkBenchmark: + e.FieldStart("status") + e.Str("FinishedBenchmark") + { + s := s.FinishedBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) + } + { + e.FieldStart("finishedAt") + s.FinishedAt.Encode(e) + } + } + case RunningBenchmarkBenchmark: + e.FieldStart("status") + e.Str("RunningBenchmark") + { + s := s.RunningBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) + } + } + case WaitingBenchmarkBenchmark: + e.FieldStart("status") + e.Str("WaitingBenchmark") + { + s := s.WaitingBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + } } - { - e.FieldStart("instanceId") - s.InstanceId.Encode(e) +} + +// Decode decodes Benchmark from json. +func (s *Benchmark) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Benchmark to nil") } - { - e.FieldStart("teamId") - s.TeamId.Encode(e) + // Sum type discriminator. + if typ := d.Next(); typ != jx.Object { + return errors.Errorf("unexpected json type %q", typ) } - { - e.FieldStart("userId") - s.UserId.Encode(e) + + var found bool + if err := d.Capture(func(d *jx.Decoder) error { + return d.ObjBytes(func(d *jx.Decoder, key []byte) error { + if found { + return d.Skip() + } + switch string(key) { + case "status": + typ, err := d.Str() + if err != nil { + return err + } + switch typ { + case "FinishedBenchmark": + s.Type = FinishedBenchmarkBenchmark + found = true + case "RunningBenchmark": + s.Type = RunningBenchmarkBenchmark + found = true + case "WaitingBenchmark": + s.Type = WaitingBenchmarkBenchmark + found = true + default: + return errors.Errorf("unknown type %s", typ) + } + return nil + } + return d.Skip() + }) + }); err != nil { + return errors.Wrap(err, "capture") } - { + if !found { + return errors.New("unable to detect sum type variant") + } + switch s.Type { + case WaitingBenchmarkBenchmark: + if err := s.WaitingBenchmark.Decode(d); err != nil { + return err + } + case RunningBenchmarkBenchmark: + if err := s.RunningBenchmark.Decode(d); err != nil { + return err + } + case FinishedBenchmarkBenchmark: + if err := s.FinishedBenchmark.Decode(d); err != nil { + return err + } + default: + return errors.Errorf("inferred invalid type: %s", s.Type) + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s Benchmark) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Benchmark) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes BenchmarkAdminResult as json. +func (s BenchmarkAdminResult) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +func (s BenchmarkAdminResult) encodeFields(e *jx.Encoder) { + switch s.Type { + case FinishedBenchmarkBenchmarkAdminResult: e.FieldStart("status") - s.Status.Encode(e) + e.Str("FinishedBenchmark") + { + s := s.FinishedBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) + } + { + e.FieldStart("finishedAt") + s.FinishedAt.Encode(e) + } + } + case RunningBenchmarkBenchmarkAdminResult: + e.FieldStart("status") + e.Str("RunningBenchmark") + { + s := s.RunningBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) + } + } + case WaitingBenchmarkBenchmarkAdminResult: + e.FieldStart("status") + e.Str("WaitingBenchmark") + { + s := s.WaitingBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + } } - { - e.FieldStart("log") - e.Str(s.Log) +} + +// Decode decodes BenchmarkAdminResult from json. +func (s *BenchmarkAdminResult) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode BenchmarkAdminResult to nil") } - { - e.FieldStart("adminLog") - e.Str(s.AdminLog) + // Sum type discriminator. + if typ := d.Next(); typ != jx.Object { + return errors.Errorf("unexpected json type %q", typ) } - { - e.FieldStart("score") - s.Score.Encode(e) + + var found bool + if err := d.Capture(func(d *jx.Decoder) error { + return d.ObjBytes(func(d *jx.Decoder, key []byte) error { + if found { + return d.Skip() + } + switch string(key) { + case "status": + typ, err := d.Str() + if err != nil { + return err + } + switch typ { + case "FinishedBenchmark": + s.Type = FinishedBenchmarkBenchmarkAdminResult + found = true + case "RunningBenchmark": + s.Type = RunningBenchmarkBenchmarkAdminResult + found = true + case "WaitingBenchmark": + s.Type = WaitingBenchmarkBenchmarkAdminResult + found = true + default: + return errors.Errorf("unknown type %s", typ) + } + return nil + } + return d.Skip() + }) + }); err != nil { + return errors.Wrap(err, "capture") } - { - e.FieldStart("createdAt") - s.CreatedAt.Encode(e) + if !found { + return errors.New("unable to detect sum type variant") } - { - e.FieldStart("startedAt") - s.StartedAt.Encode(e) + switch s.Type { + case WaitingBenchmarkBenchmarkAdminResult: + if err := s.WaitingBenchmark.Decode(d); err != nil { + return err + } + case RunningBenchmarkBenchmarkAdminResult: + if err := s.RunningBenchmark.Decode(d); err != nil { + return err + } + case FinishedBenchmarkBenchmarkAdminResult: + if err := s.FinishedBenchmark.Decode(d); err != nil { + return err + } + default: + return errors.Errorf("inferred invalid type: %s", s.Type) } - { - e.FieldStart("finishedAt") - s.FinishedAt.Encode(e) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s BenchmarkAdminResult) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *BenchmarkAdminResult) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes BenchmarkId as json. +func (s BenchmarkId) Encode(e *jx.Encoder) { + unwrapped := uuid.UUID(s) + + json.EncodeUUID(e, unwrapped) +} + +// Decode decodes BenchmarkId from json. +func (s *BenchmarkId) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode BenchmarkId to nil") + } + var unwrapped uuid.UUID + if err := func() error { + v, err := json.DecodeUUID(d) + unwrapped = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") } + *s = BenchmarkId(unwrapped) + return nil } -var jsonFieldsNameOfBenchmarkAdminResult = [11]string{ - 0: "id", - 1: "instanceId", - 2: "teamId", - 3: "userId", - 4: "status", - 5: "log", - 6: "adminLog", - 7: "score", - 8: "createdAt", - 9: "startedAt", - 10: "finishedAt", +// MarshalJSON implements stdjson.Marshaler. +func (s BenchmarkId) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil } -// Decode decodes BenchmarkAdminResult from json. -func (s *BenchmarkAdminResult) Decode(d *jx.Decoder) error { +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *BenchmarkId) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *BenchmarkListItem) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *BenchmarkListItem) encodeFields(e *jx.Encoder) { + s.OneOf.encodeFields(e) +} + +var jsonFieldsNameOfBenchmarkListItem = [0]string{} + +// Decode decodes BenchmarkListItem from json. +func (s *BenchmarkListItem) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode BenchmarkAdminResult to nil") + return errors.New("invalid: unable to decode BenchmarkListItem to nil") + } + if err := d.Capture(func(d *jx.Decoder) error { + return s.OneOf.Decode(d) + }); err != nil { + return errors.Wrap(err, "decode field OneOf") } - var requiredBitSet [2]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { - case "id": - requiredBitSet[0] |= 1 << 0 - if err := func() error { - if err := s.ID.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"id\"") + default: + return d.Skip() + } + }); err != nil { + return errors.Wrap(err, "decode BenchmarkListItem") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *BenchmarkListItem) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *BenchmarkListItem) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes BenchmarkListItemSum as json. +func (s BenchmarkListItemSum) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +func (s BenchmarkListItemSum) encodeFields(e *jx.Encoder) { + switch s.Type { + case FinishedBenchmarkBenchmarkListItemSum: + e.FieldStart("status") + e.Str("FinishedBenchmark") + { + s := s.FinishedBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) } - case "instanceId": - requiredBitSet[0] |= 1 << 1 - if err := func() error { - if err := s.InstanceId.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"instanceId\"") + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) } - case "teamId": - requiredBitSet[0] |= 1 << 2 - if err := func() error { - if err := s.TeamId.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"teamId\"") + { + e.FieldStart("teamId") + s.TeamId.Encode(e) } - case "userId": - requiredBitSet[0] |= 1 << 3 - if err := func() error { - if err := s.UserId.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"userId\"") + { + e.FieldStart("userId") + s.UserId.Encode(e) } - case "status": - requiredBitSet[0] |= 1 << 4 - if err := func() error { - if err := s.Status.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"status\"") + { + e.FieldStart("score") + s.Score.Encode(e) } - case "log": - requiredBitSet[0] |= 1 << 5 - if err := func() error { - v, err := d.Str() - s.Log = string(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"log\"") + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) } - case "adminLog": - requiredBitSet[0] |= 1 << 6 - if err := func() error { - v, err := d.Str() - s.AdminLog = string(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"adminLog\"") + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) } - case "score": - requiredBitSet[0] |= 1 << 7 - if err := func() error { - if err := s.Score.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"score\"") + { + e.FieldStart("finishedAt") + s.FinishedAt.Encode(e) } - case "createdAt": - requiredBitSet[1] |= 1 << 0 - if err := func() error { - if err := s.CreatedAt.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"createdAt\"") + } + case RunningBenchmarkBenchmarkListItemSum: + e.FieldStart("status") + e.Str("RunningBenchmark") + { + s := s.RunningBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) } - case "startedAt": - requiredBitSet[1] |= 1 << 1 - if err := func() error { - if err := s.StartedAt.Decode(d); err != nil { + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) + } + } + case WaitingBenchmarkBenchmarkListItemSum: + e.FieldStart("status") + e.Str("WaitingBenchmark") + { + s := s.WaitingBenchmark + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + } + } +} + +// Decode decodes BenchmarkListItemSum from json. +func (s *BenchmarkListItemSum) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode BenchmarkListItemSum to nil") + } + // Sum type discriminator. + if typ := d.Next(); typ != jx.Object { + return errors.Errorf("unexpected json type %q", typ) + } + + var found bool + if err := d.Capture(func(d *jx.Decoder) error { + return d.ObjBytes(func(d *jx.Decoder, key []byte) error { + if found { + return d.Skip() + } + switch string(key) { + case "status": + typ, err := d.Str() + if err != nil { return err } + switch typ { + case "FinishedBenchmark": + s.Type = FinishedBenchmarkBenchmarkListItemSum + found = true + case "RunningBenchmark": + s.Type = RunningBenchmarkBenchmarkListItemSum + found = true + case "WaitingBenchmark": + s.Type = WaitingBenchmarkBenchmarkListItemSum + found = true + default: + return errors.Errorf("unknown type %s", typ) + } return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"startedAt\"") } - case "finishedAt": - requiredBitSet[1] |= 1 << 2 + return d.Skip() + }) + }); err != nil { + return errors.Wrap(err, "capture") + } + if !found { + return errors.New("unable to detect sum type variant") + } + switch s.Type { + case WaitingBenchmarkBenchmarkListItemSum: + if err := s.WaitingBenchmark.Decode(d); err != nil { + return err + } + case RunningBenchmarkBenchmarkListItemSum: + if err := s.RunningBenchmark.Decode(d); err != nil { + return err + } + case FinishedBenchmarkBenchmarkListItemSum: + if err := s.FinishedBenchmark.Decode(d); err != nil { + return err + } + default: + return errors.Errorf("inferred invalid type: %s", s.Type) + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s BenchmarkListItemSum) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *BenchmarkListItemSum) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes CreatedAt as json. +func (s CreatedAt) Encode(e *jx.Encoder) { + unwrapped := time.Time(s) + + json.EncodeDateTime(e, unwrapped) +} + +// Decode decodes CreatedAt from json. +func (s *CreatedAt) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CreatedAt to nil") + } + var unwrapped time.Time + if err := func() error { + v, err := json.DecodeDateTime(d) + unwrapped = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = CreatedAt(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s CreatedAt) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CreatedAt) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *ErrorBadRequest) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *ErrorBadRequest) encodeFields(e *jx.Encoder) { + { + if s.Message.Set { + e.FieldStart("message") + s.Message.Encode(e) + } + } +} + +var jsonFieldsNameOfErrorBadRequest = [1]string{ + 0: "message", +} + +// Decode decodes ErrorBadRequest from json. +func (s *ErrorBadRequest) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ErrorBadRequest to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "message": if err := func() error { - if err := s.FinishedAt.Decode(d); err != nil { + s.Message.Reset() + if err := s.Message.Decode(d); err != nil { return err } return nil }(); err != nil { - return errors.Wrap(err, "decode field \"finishedAt\"") + return errors.Wrap(err, "decode field \"message\"") } default: return d.Skip() } return nil }); err != nil { - return errors.Wrap(err, "decode BenchmarkAdminResult") - } - // Validate required fields. - var failures []validate.FieldError - for i, mask := range [2]uint8{ - 0b11111111, - 0b00000111, - } { - if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { - // Mask only required fields and check equality to mask using XOR. - // - // If XOR result is not zero, result is not equal to expected, so some fields are missed. - // Bits of fields which would be set are actually bits of missed fields. - missed := bits.OnesCount8(result) - for bitN := 0; bitN < missed; bitN++ { - bitIdx := bits.TrailingZeros8(result) - fieldIdx := i*8 + bitIdx - var name string - if fieldIdx < len(jsonFieldsNameOfBenchmarkAdminResult) { - name = jsonFieldsNameOfBenchmarkAdminResult[fieldIdx] - } else { - name = strconv.Itoa(fieldIdx) - } - failures = append(failures, validate.FieldError{ - Name: name, - Error: validate.ErrFieldRequired, - }) - // Reset bit. - result &^= 1 << bitIdx - } - } - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} + return errors.Wrap(err, "decode ErrorBadRequest") } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s *BenchmarkAdminResult) MarshalJSON() ([]byte, error) { +func (s *ErrorBadRequest) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *BenchmarkAdminResult) UnmarshalJSON(data []byte) error { +func (s *ErrorBadRequest) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes BenchmarkId as json. -func (s BenchmarkId) Encode(e *jx.Encoder) { - unwrapped := uuid.UUID(s) +// Encode encodes FinishedAt as json. +func (s FinishedAt) Encode(e *jx.Encoder) { + unwrapped := time.Time(s) - json.EncodeUUID(e, unwrapped) + json.EncodeDateTime(e, unwrapped) } -// Decode decodes BenchmarkId from json. -func (s *BenchmarkId) Decode(d *jx.Decoder) error { +// Decode decodes FinishedAt from json. +func (s *FinishedAt) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode BenchmarkId to nil") + return errors.New("invalid: unable to decode FinishedAt to nil") } - var unwrapped uuid.UUID + var unwrapped time.Time if err := func() error { - v, err := json.DecodeUUID(d) + v, err := json.DecodeDateTime(d) unwrapped = v if err != nil { return err @@ -508,32 +933,32 @@ func (s *BenchmarkId) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "alias") } - *s = BenchmarkId(unwrapped) + *s = FinishedAt(unwrapped) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s BenchmarkId) MarshalJSON() ([]byte, error) { +func (s FinishedAt) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *BenchmarkId) UnmarshalJSON(data []byte) error { +func (s *FinishedAt) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. -func (s *BenchmarkResult) Encode(e *jx.Encoder) { +func (s *FinishedBenchmark) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. -func (s *BenchmarkResult) encodeFields(e *jx.Encoder) { +func (s *FinishedBenchmark) encodeFields(e *jx.Encoder) { { e.FieldStart("id") s.ID.Encode(e) @@ -554,10 +979,6 @@ func (s *BenchmarkResult) encodeFields(e *jx.Encoder) { e.FieldStart("status") s.Status.Encode(e) } - { - e.FieldStart("log") - e.Str(s.Log) - } { e.FieldStart("score") s.Score.Encode(e) @@ -576,23 +997,22 @@ func (s *BenchmarkResult) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfBenchmarkResult = [10]string{ +var jsonFieldsNameOfFinishedBenchmark = [9]string{ 0: "id", 1: "instanceId", 2: "teamId", 3: "userId", 4: "status", - 5: "log", - 6: "score", - 7: "createdAt", - 8: "startedAt", - 9: "finishedAt", + 5: "score", + 6: "createdAt", + 7: "startedAt", + 8: "finishedAt", } -// Decode decodes BenchmarkResult from json. -func (s *BenchmarkResult) Decode(d *jx.Decoder) error { +// Decode decodes FinishedBenchmark from json. +func (s *FinishedBenchmark) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode BenchmarkResult to nil") + return errors.New("invalid: unable to decode FinishedBenchmark to nil") } var requiredBitSet [2]uint8 @@ -648,20 +1068,8 @@ func (s *BenchmarkResult) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"status\"") } - case "log": - requiredBitSet[0] |= 1 << 5 - if err := func() error { - v, err := d.Str() - s.Log = string(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"log\"") - } case "score": - requiredBitSet[0] |= 1 << 6 + requiredBitSet[0] |= 1 << 5 if err := func() error { if err := s.Score.Decode(d); err != nil { return err @@ -671,7 +1079,7 @@ func (s *BenchmarkResult) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"score\"") } case "createdAt": - requiredBitSet[0] |= 1 << 7 + requiredBitSet[0] |= 1 << 6 if err := func() error { if err := s.CreatedAt.Decode(d); err != nil { return err @@ -681,7 +1089,7 @@ func (s *BenchmarkResult) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"createdAt\"") } case "startedAt": - requiredBitSet[1] |= 1 << 0 + requiredBitSet[0] |= 1 << 7 if err := func() error { if err := s.StartedAt.Decode(d); err != nil { return err @@ -691,7 +1099,7 @@ func (s *BenchmarkResult) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"startedAt\"") } case "finishedAt": - requiredBitSet[1] |= 1 << 1 + requiredBitSet[1] |= 1 << 0 if err := func() error { if err := s.FinishedAt.Decode(d); err != nil { return err @@ -705,13 +1113,13 @@ func (s *BenchmarkResult) Decode(d *jx.Decoder) error { } return nil }); err != nil { - return errors.Wrap(err, "decode BenchmarkResult") + return errors.Wrap(err, "decode FinishedBenchmark") } // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ 0b11111111, - 0b00000011, + 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -722,222 +1130,75 @@ func (s *BenchmarkResult) Decode(d *jx.Decoder) error { for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx - var name string - if fieldIdx < len(jsonFieldsNameOfBenchmarkResult) { - name = jsonFieldsNameOfBenchmarkResult[fieldIdx] - } else { - name = strconv.Itoa(fieldIdx) - } - failures = append(failures, validate.FieldError{ - Name: name, - Error: validate.ErrFieldRequired, - }) - // Reset bit. - result &^= 1 << bitIdx - } - } - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *BenchmarkResult) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *BenchmarkResult) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes BenchmarkStatus as json. -func (s BenchmarkStatus) Encode(e *jx.Encoder) { - e.Str(string(s)) -} - -// Decode decodes BenchmarkStatus from json. -func (s *BenchmarkStatus) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode BenchmarkStatus to nil") - } - v, err := d.StrBytes() - if err != nil { - return err - } - // Try to use constant string. - switch BenchmarkStatus(v) { - case BenchmarkStatusWaiting: - *s = BenchmarkStatusWaiting - case BenchmarkStatusRunning: - *s = BenchmarkStatusRunning - case BenchmarkStatusFinished: - *s = BenchmarkStatusFinished - default: - *s = BenchmarkStatus(v) - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s BenchmarkStatus) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *BenchmarkStatus) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes CreatedAt as json. -func (s CreatedAt) Encode(e *jx.Encoder) { - unwrapped := time.Time(s) - - json.EncodeDateTime(e, unwrapped) -} - -// Decode decodes CreatedAt from json. -func (s *CreatedAt) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode CreatedAt to nil") - } - var unwrapped time.Time - if err := func() error { - v, err := json.DecodeDateTime(d) - unwrapped = v - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = CreatedAt(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s CreatedAt) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *CreatedAt) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode implements json.Marshaler. -func (s *ErrorBadRequest) Encode(e *jx.Encoder) { - e.ObjStart() - s.encodeFields(e) - e.ObjEnd() -} - -// encodeFields encodes fields. -func (s *ErrorBadRequest) encodeFields(e *jx.Encoder) { - { - if s.Message.Set { - e.FieldStart("message") - s.Message.Encode(e) - } - } -} - -var jsonFieldsNameOfErrorBadRequest = [1]string{ - 0: "message", -} - -// Decode decodes ErrorBadRequest from json. -func (s *ErrorBadRequest) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode ErrorBadRequest to nil") - } - - if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - switch string(k) { - case "message": - if err := func() error { - s.Message.Reset() - if err := s.Message.Decode(d); err != nil { - return err + var name string + if fieldIdx < len(jsonFieldsNameOfFinishedBenchmark) { + name = jsonFieldsNameOfFinishedBenchmark[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"message\"") + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx } - default: - return d.Skip() } - return nil - }); err != nil { - return errors.Wrap(err, "decode ErrorBadRequest") + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s *ErrorBadRequest) MarshalJSON() ([]byte, error) { +func (s *FinishedBenchmark) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *ErrorBadRequest) UnmarshalJSON(data []byte) error { +func (s *FinishedBenchmark) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes FinishedAt as json. -func (s FinishedAt) Encode(e *jx.Encoder) { - unwrapped := time.Time(s) - - json.EncodeDateTime(e, unwrapped) +// Encode encodes FinishedBenchmarkStatus as json. +func (s FinishedBenchmarkStatus) Encode(e *jx.Encoder) { + e.Str(string(s)) } -// Decode decodes FinishedAt from json. -func (s *FinishedAt) Decode(d *jx.Decoder) error { +// Decode decodes FinishedBenchmarkStatus from json. +func (s *FinishedBenchmarkStatus) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode FinishedAt to nil") + return errors.New("invalid: unable to decode FinishedBenchmarkStatus to nil") } - var unwrapped time.Time - if err := func() error { - v, err := json.DecodeDateTime(d) - unwrapped = v - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") + v, err := d.StrBytes() + if err != nil { + return err } - *s = FinishedAt(unwrapped) + // Try to use constant string. + switch FinishedBenchmarkStatus(v) { + case FinishedBenchmarkStatusFinished: + *s = FinishedBenchmarkStatusFinished + default: + *s = FinishedBenchmarkStatus(v) + } + return nil } // MarshalJSON implements stdjson.Marshaler. -func (s FinishedAt) MarshalJSON() ([]byte, error) { +func (s FinishedBenchmarkStatus) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *FinishedAt) UnmarshalJSON(data []byte) error { +func (s *FinishedBenchmarkStatus) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -1007,7 +1268,7 @@ func (s *Forbidden) UnmarshalJSON(data []byte) error { // Encode encodes GetBenchmarkQueueOKApplicationJSON as json. func (s GetBenchmarkQueueOKApplicationJSON) Encode(e *jx.Encoder) { - unwrapped := []Benchmark(s) + unwrapped := []BenchmarkListItem(s) e.ArrStart() for _, elem := range unwrapped { @@ -1021,11 +1282,11 @@ func (s *GetBenchmarkQueueOKApplicationJSON) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode GetBenchmarkQueueOKApplicationJSON to nil") } - var unwrapped []Benchmark + var unwrapped []BenchmarkListItem if err := func() error { - unwrapped = make([]Benchmark, 0) + unwrapped = make([]BenchmarkListItem, 0) if err := d.Arr(func(d *jx.Decoder) error { - var elem Benchmark + var elem BenchmarkListItem if err := elem.Decode(d); err != nil { return err } @@ -1057,7 +1318,7 @@ func (s *GetBenchmarkQueueOKApplicationJSON) UnmarshalJSON(data []byte) error { // Encode encodes GetBenchmarksOKApplicationJSON as json. func (s GetBenchmarksOKApplicationJSON) Encode(e *jx.Encoder) { - unwrapped := []Benchmark(s) + unwrapped := []BenchmarkListItem(s) e.ArrStart() for _, elem := range unwrapped { @@ -1071,11 +1332,11 @@ func (s *GetBenchmarksOKApplicationJSON) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode GetBenchmarksOKApplicationJSON to nil") } - var unwrapped []Benchmark + var unwrapped []BenchmarkListItem if err := func() error { - unwrapped = make([]Benchmark, 0) + unwrapped = make([]BenchmarkListItem, 0) if err := d.Arr(func(d *jx.Decoder) error { - var elem Benchmark + var elem BenchmarkListItem if err := elem.Decode(d); err != nil { return err } @@ -1105,6 +1366,69 @@ func (s *GetBenchmarksOKApplicationJSON) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *GetDocsOK) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *GetDocsOK) encodeFields(e *jx.Encoder) { + { + if s.Body.Set { + e.FieldStart("body") + s.Body.Encode(e) + } + } +} + +var jsonFieldsNameOfGetDocsOK = [1]string{ + 0: "body", +} + +// Decode decodes GetDocsOK from json. +func (s *GetDocsOK) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode GetDocsOK to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "body": + if err := func() error { + s.Body.Reset() + if err := s.Body.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"body\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode GetDocsOK") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *GetDocsOK) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *GetDocsOK) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes GetInstancesOKApplicationJSON as json. func (s GetInstancesOKApplicationJSON) Encode(e *jx.Encoder) { unwrapped := []Instance(s) @@ -1218,9 +1542,109 @@ func (s *GetOauth2CallbackBadRequest) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes GetRankingOKApplicationJSON as json. +func (s GetRankingOKApplicationJSON) Encode(e *jx.Encoder) { + unwrapped := []RankingItem(s) + + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() +} + +// Decode decodes GetRankingOKApplicationJSON from json. +func (s *GetRankingOKApplicationJSON) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode GetRankingOKApplicationJSON to nil") + } + var unwrapped []RankingItem + if err := func() error { + unwrapped = make([]RankingItem, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem RankingItem + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = GetRankingOKApplicationJSON(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s GetRankingOKApplicationJSON) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *GetRankingOKApplicationJSON) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes GetScoresOKApplicationJSON as json. +func (s GetScoresOKApplicationJSON) Encode(e *jx.Encoder) { + unwrapped := []TeamScores(s) + + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() +} + +// Decode decodes GetScoresOKApplicationJSON from json. +func (s *GetScoresOKApplicationJSON) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode GetScoresOKApplicationJSON to nil") + } + var unwrapped []TeamScores + if err := func() error { + unwrapped = make([]TeamScores, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem TeamScores + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = GetScoresOKApplicationJSON(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s GetScoresOKApplicationJSON) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *GetScoresOKApplicationJSON) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes GetTeamBenchmarksOKApplicationJSON as json. func (s GetTeamBenchmarksOKApplicationJSON) Encode(e *jx.Encoder) { - unwrapped := []Benchmark(s) + unwrapped := []BenchmarkListItem(s) e.ArrStart() for _, elem := range unwrapped { @@ -1234,11 +1658,11 @@ func (s *GetTeamBenchmarksOKApplicationJSON) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode GetTeamBenchmarksOKApplicationJSON to nil") } - var unwrapped []Benchmark + var unwrapped []BenchmarkListItem if err := func() error { - unwrapped = make([]Benchmark, 0) + unwrapped = make([]BenchmarkListItem, 0) if err := d.Arr(func(d *jx.Decoder) error { - var elem Benchmark + var elem BenchmarkListItem if err := elem.Decode(d); err != nil { return err } @@ -1418,6 +1842,46 @@ func (s *GetUsersOKApplicationJSON) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes GitHubId as json. +func (s GitHubId) Encode(e *jx.Encoder) { + unwrapped := string(s) + + e.Str(unwrapped) +} + +// Decode decodes GitHubId from json. +func (s *GitHubId) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode GitHubId to nil") + } + var unwrapped string + if err := func() error { + v, err := d.Str() + unwrapped = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = GitHubId(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s GitHubId) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *GitHubId) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes IPAddress as json. func (s IPAddress) Encode(e *jx.Encoder) { unwrapped := string(s) @@ -1686,6 +2150,46 @@ func (s *InstanceId) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes InstanceOperation as json. +func (s InstanceOperation) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes InstanceOperation from json. +func (s *InstanceOperation) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode InstanceOperation to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch InstanceOperation(v) { + case InstanceOperationStart: + *s = InstanceOperationStart + case InstanceOperationStop: + *s = InstanceOperationStop + default: + *s = InstanceOperation(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s InstanceOperation) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *InstanceOperation) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes InstanceStatus as json. func (s InstanceStatus) Encode(e *jx.Encoder) { e.Str(string(s)) @@ -1771,22 +2275,62 @@ func (s *InternalServerError) Decode(d *jx.Decoder) error { return d.Skip() } return nil - }); err != nil { - return errors.Wrap(err, "decode InternalServerError") + }); err != nil { + return errors.Wrap(err, "decode InternalServerError") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *InternalServerError) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *InternalServerError) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes MarkdownDocument as json. +func (s MarkdownDocument) Encode(e *jx.Encoder) { + unwrapped := string(s) + + e.Str(unwrapped) +} + +// Decode decodes MarkdownDocument from json. +func (s *MarkdownDocument) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MarkdownDocument to nil") + } + var unwrapped string + if err := func() error { + v, err := d.Str() + unwrapped = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") } - + *s = MarkdownDocument(unwrapped) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s *InternalServerError) MarshalJSON() ([]byte, error) { +func (s MarkdownDocument) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *InternalServerError) UnmarshalJSON(data []byte) error { +func (s *MarkdownDocument) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -1854,18 +2398,18 @@ func (s *NotFound) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes FinishedAt as json. -func (o OptFinishedAt) Encode(e *jx.Encoder) { +// Encode encodes BenchmarkId as json. +func (o OptBenchmarkId) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } -// Decode decodes FinishedAt from json. -func (o *OptFinishedAt) Decode(d *jx.Decoder) error { +// Decode decodes BenchmarkId from json. +func (o *OptBenchmarkId) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptFinishedAt to nil") + return errors.New("invalid: unable to decode OptBenchmarkId to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { @@ -1875,30 +2419,63 @@ func (o *OptFinishedAt) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptFinishedAt) MarshalJSON() ([]byte, error) { +func (s OptBenchmarkId) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptFinishedAt) UnmarshalJSON(data []byte) error { +func (s *OptBenchmarkId) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes InstanceStatus as json. -func (o OptInstanceStatus) Encode(e *jx.Encoder) { +// Encode encodes CreatedAt as json. +func (o OptCreatedAt) Encode(e *jx.Encoder) { if !o.Set { return } - e.Str(string(o.Value)) + o.Value.Encode(e) } -// Decode decodes InstanceStatus from json. -func (o *OptInstanceStatus) Decode(d *jx.Decoder) error { +// Decode decodes CreatedAt from json. +func (o *OptCreatedAt) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptCreatedAt to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptCreatedAt) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptCreatedAt) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes MarkdownDocument as json. +func (o OptMarkdownDocument) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes MarkdownDocument from json. +func (o *OptMarkdownDocument) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptInstanceStatus to nil") + return errors.New("invalid: unable to decode OptMarkdownDocument to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { @@ -1908,14 +2485,14 @@ func (o *OptInstanceStatus) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptInstanceStatus) MarshalJSON() ([]byte, error) { +func (s OptMarkdownDocument) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptInstanceStatus) UnmarshalJSON(data []byte) error { +func (s *OptMarkdownDocument) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -2019,51 +2596,53 @@ func (s *OptPostTeamReq) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes Score as json. -func (o OptScore) Encode(e *jx.Encoder) { +// Encode encodes string as json. +func (o OptString) Encode(e *jx.Encoder) { if !o.Set { return } - o.Value.Encode(e) + e.Str(string(o.Value)) } -// Decode decodes Score from json. -func (o *OptScore) Decode(d *jx.Decoder) error { +// Decode decodes string from json. +func (o *OptString) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptScore to nil") + return errors.New("invalid: unable to decode OptString to nil") } o.Set = true - if err := o.Value.Decode(d); err != nil { + v, err := d.Str() + if err != nil { return err } + o.Value = string(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptScore) MarshalJSON() ([]byte, error) { +func (s OptString) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptScore) UnmarshalJSON(data []byte) error { +func (s *OptString) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes StartedAt as json. -func (o OptStartedAt) Encode(e *jx.Encoder) { +// Encode encodes TeamId as json. +func (o OptTeamId) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } -// Decode decodes StartedAt from json. -func (o *OptStartedAt) Decode(d *jx.Decoder) error { +// Decode decodes TeamId from json. +func (o *OptTeamId) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptStartedAt to nil") + return errors.New("invalid: unable to decode OptTeamId to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { @@ -2073,115 +2652,204 @@ func (o *OptStartedAt) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptStartedAt) MarshalJSON() ([]byte, error) { +func (s OptTeamId) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptStartedAt) UnmarshalJSON(data []byte) error { +func (s *OptTeamId) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes string as json. -func (o OptString) Encode(e *jx.Encoder) { +// Encode encodes TeamName as json. +func (o OptTeamName) Encode(e *jx.Encoder) { if !o.Set { return } - e.Str(string(o.Value)) + o.Value.Encode(e) } -// Decode decodes string from json. -func (o *OptString) Decode(d *jx.Decoder) error { +// Decode decodes TeamName from json. +func (o *OptTeamName) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptString to nil") + return errors.New("invalid: unable to decode OptTeamName to nil") } o.Set = true - v, err := d.Str() - if err != nil { + if err := o.Value.Decode(d); err != nil { return err } - o.Value = string(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptString) MarshalJSON() ([]byte, error) { +func (s OptTeamName) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptString) UnmarshalJSON(data []byte) error { +func (s *OptTeamName) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes TeamId as json. -func (o OptTeamId) Encode(e *jx.Encoder) { - if !o.Set { - return +// Encode implements json.Marshaler. +func (s *PatchDocsOK) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *PatchDocsOK) encodeFields(e *jx.Encoder) { + { + if s.Body.Set { + e.FieldStart("body") + s.Body.Encode(e) + } } - o.Value.Encode(e) } -// Decode decodes TeamId from json. -func (o *OptTeamId) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptTeamId to nil") +var jsonFieldsNameOfPatchDocsOK = [1]string{ + 0: "body", +} + +// Decode decodes PatchDocsOK from json. +func (s *PatchDocsOK) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode PatchDocsOK to nil") } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "body": + if err := func() error { + s.Body.Reset() + if err := s.Body.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"body\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode PatchDocsOK") } + return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptTeamId) MarshalJSON() ([]byte, error) { +func (s *PatchDocsOK) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptTeamId) UnmarshalJSON(data []byte) error { +func (s *PatchDocsOK) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes TeamName as json. -func (o OptTeamName) Encode(e *jx.Encoder) { - if !o.Set { - return +// Encode implements json.Marshaler. +func (s *PatchDocsReq) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *PatchDocsReq) encodeFields(e *jx.Encoder) { + { + e.FieldStart("body") + s.Body.Encode(e) } - o.Value.Encode(e) } -// Decode decodes TeamName from json. -func (o *OptTeamName) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptTeamName to nil") +var jsonFieldsNameOfPatchDocsReq = [1]string{ + 0: "body", +} + +// Decode decodes PatchDocsReq from json. +func (s *PatchDocsReq) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode PatchDocsReq to nil") } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "body": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Body.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"body\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode PatchDocsReq") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfPatchDocsReq) { + name = jsonFieldsNameOfPatchDocsReq[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} } + return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptTeamName) MarshalJSON() ([]byte, error) { +func (s *PatchDocsReq) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptTeamName) UnmarshalJSON(data []byte) error { +func (s *PatchDocsReq) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -2196,15 +2864,13 @@ func (s *PatchTeamInstanceReq) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *PatchTeamInstanceReq) encodeFields(e *jx.Encoder) { { - if s.Status.Set { - e.FieldStart("status") - s.Status.Encode(e) - } + e.FieldStart("operation") + s.Operation.Encode(e) } } var jsonFieldsNameOfPatchTeamInstanceReq = [1]string{ - 0: "status", + 0: "operation", } // Decode decodes PatchTeamInstanceReq from json. @@ -2212,18 +2878,19 @@ func (s *PatchTeamInstanceReq) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode PatchTeamInstanceReq to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { - case "status": + case "operation": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Status.Reset() - if err := s.Status.Decode(d); err != nil { + if err := s.Operation.Decode(d); err != nil { return err } return nil }(); err != nil { - return errors.Wrap(err, "decode field \"status\"") + return errors.Wrap(err, "decode field \"operation\"") } default: return d.Skip() @@ -2232,6 +2899,38 @@ func (s *PatchTeamInstanceReq) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode PatchTeamInstanceReq") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfPatchTeamInstanceReq) { + name = jsonFieldsNameOfPatchTeamInstanceReq[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -2265,10 +2964,20 @@ func (s *PatchTeamReq) encodeFields(e *jx.Encoder) { } } { - if s.Members != nil { - e.FieldStart("members") + if s.Members != nil { + e.FieldStart("members") + e.ArrStart() + for _, elem := range s.Members { + elem.Encode(e) + } + e.ArrEnd() + } + } + { + if s.GithubIds != nil { + e.FieldStart("githubIds") e.ArrStart() - for _, elem := range s.Members { + for _, elem := range s.GithubIds { elem.Encode(e) } e.ArrEnd() @@ -2276,9 +2985,10 @@ func (s *PatchTeamReq) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfPatchTeamReq = [2]string{ +var jsonFieldsNameOfPatchTeamReq = [3]string{ 0: "name", 1: "members", + 2: "githubIds", } // Decode decodes PatchTeamReq from json. @@ -2316,6 +3026,23 @@ func (s *PatchTeamReq) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"members\"") } + case "githubIds": + if err := func() error { + s.GithubIds = make([]GitHubId, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem GitHubId + if err := elem.Decode(d); err != nil { + return err + } + s.GithubIds = append(s.GithubIds, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"githubIds\"") + } default: return d.Skip() } @@ -2473,106 +3200,448 @@ func (s *PostOauth2LogoutBadRequest) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"message\"") } - default: - return d.Skip() + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode PostOauth2LogoutBadRequest") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *PostOauth2LogoutBadRequest) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *PostOauth2LogoutBadRequest) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *PostTeamReq) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *PostTeamReq) encodeFields(e *jx.Encoder) { + { + e.FieldStart("name") + s.Name.Encode(e) + } + { + e.FieldStart("members") + e.ArrStart() + for _, elem := range s.Members { + elem.Encode(e) + } + e.ArrEnd() + } +} + +var jsonFieldsNameOfPostTeamReq = [2]string{ + 0: "name", + 1: "members", +} + +// Decode decodes PostTeamReq from json. +func (s *PostTeamReq) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode PostTeamReq to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "name": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Name.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"name\"") + } + case "members": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + s.Members = make([]UserId, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem UserId + if err := elem.Decode(d); err != nil { + return err + } + s.Members = append(s.Members, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"members\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode PostTeamReq") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfPostTeamReq) { + name = jsonFieldsNameOfPostTeamReq[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *PostTeamReq) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *PostTeamReq) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *RankingItem) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *RankingItem) encodeFields(e *jx.Encoder) { + { + e.FieldStart("rank") + e.Int(s.Rank) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + if s.CreatedAt.Set { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + } +} + +var jsonFieldsNameOfRankingItem = [4]string{ + 0: "rank", + 1: "teamId", + 2: "score", + 3: "createdAt", +} + +// Decode decodes RankingItem from json. +func (s *RankingItem) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode RankingItem to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "rank": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.Rank = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rank\"") + } + case "teamId": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + if err := s.TeamId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"teamId\"") + } + case "score": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + if err := s.Score.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"score\"") + } + case "createdAt": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"createdAt\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode RankingItem") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfRankingItem) { + name = jsonFieldsNameOfRankingItem[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } } - return nil - }); err != nil { - return errors.Wrap(err, "decode PostOauth2LogoutBadRequest") + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s *PostOauth2LogoutBadRequest) MarshalJSON() ([]byte, error) { +func (s *RankingItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *PostOauth2LogoutBadRequest) UnmarshalJSON(data []byte) error { +func (s *RankingItem) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. -func (s *PostTeamReq) Encode(e *jx.Encoder) { +func (s *RunningBenchmark) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. -func (s *PostTeamReq) encodeFields(e *jx.Encoder) { +func (s *RunningBenchmark) encodeFields(e *jx.Encoder) { { - e.FieldStart("name") - s.Name.Encode(e) + e.FieldStart("id") + s.ID.Encode(e) } { - e.FieldStart("members") - e.ArrStart() - for _, elem := range s.Members { - elem.Encode(e) - } - e.ArrEnd() + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("status") + s.Status.Encode(e) + } + { + e.FieldStart("score") + s.Score.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } + { + e.FieldStart("startedAt") + s.StartedAt.Encode(e) } } -var jsonFieldsNameOfPostTeamReq = [2]string{ - 0: "name", - 1: "members", +var jsonFieldsNameOfRunningBenchmark = [8]string{ + 0: "id", + 1: "instanceId", + 2: "teamId", + 3: "userId", + 4: "status", + 5: "score", + 6: "createdAt", + 7: "startedAt", } -// Decode decodes PostTeamReq from json. -func (s *PostTeamReq) Decode(d *jx.Decoder) error { +// Decode decodes RunningBenchmark from json. +func (s *RunningBenchmark) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode PostTeamReq to nil") + return errors.New("invalid: unable to decode RunningBenchmark to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { - case "name": + case "id": requiredBitSet[0] |= 1 << 0 if err := func() error { - if err := s.Name.Decode(d); err != nil { + if err := s.ID.Decode(d); err != nil { return err } return nil }(); err != nil { - return errors.Wrap(err, "decode field \"name\"") + return errors.Wrap(err, "decode field \"id\"") } - case "members": + case "instanceId": requiredBitSet[0] |= 1 << 1 if err := func() error { - s.Members = make([]UserId, 0) - if err := d.Arr(func(d *jx.Decoder) error { - var elem UserId - if err := elem.Decode(d); err != nil { - return err - } - s.Members = append(s.Members, elem) - return nil - }); err != nil { + if err := s.InstanceId.Decode(d); err != nil { return err } return nil }(); err != nil { - return errors.Wrap(err, "decode field \"members\"") + return errors.Wrap(err, "decode field \"instanceId\"") + } + case "teamId": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + if err := s.TeamId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"teamId\"") + } + case "userId": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + if err := s.UserId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"userId\"") + } + case "status": + requiredBitSet[0] |= 1 << 4 + if err := func() error { + if err := s.Status.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"status\"") + } + case "score": + requiredBitSet[0] |= 1 << 5 + if err := func() error { + if err := s.Score.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"score\"") + } + case "createdAt": + requiredBitSet[0] |= 1 << 6 + if err := func() error { + if err := s.CreatedAt.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"createdAt\"") + } + case "startedAt": + requiredBitSet[0] |= 1 << 7 + if err := func() error { + if err := s.StartedAt.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"startedAt\"") } default: return d.Skip() } return nil }); err != nil { - return errors.Wrap(err, "decode PostTeamReq") + return errors.Wrap(err, "decode RunningBenchmark") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ - 0b00000011, + 0b11111111, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -2584,8 +3653,8 @@ func (s *PostTeamReq) Decode(d *jx.Decoder) error { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string - if fieldIdx < len(jsonFieldsNameOfPostTeamReq) { - name = jsonFieldsNameOfPostTeamReq[fieldIdx] + if fieldIdx < len(jsonFieldsNameOfRunningBenchmark) { + name = jsonFieldsNameOfRunningBenchmark[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } @@ -2606,14 +3675,52 @@ func (s *PostTeamReq) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s *PostTeamReq) MarshalJSON() ([]byte, error) { +func (s *RunningBenchmark) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *PostTeamReq) UnmarshalJSON(data []byte) error { +func (s *RunningBenchmark) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes RunningBenchmarkStatus as json. +func (s RunningBenchmarkStatus) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes RunningBenchmarkStatus from json. +func (s *RunningBenchmarkStatus) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode RunningBenchmarkStatus to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch RunningBenchmarkStatus(v) { + case RunningBenchmarkStatusRunning: + *s = RunningBenchmarkStatusRunning + default: + *s = RunningBenchmarkStatus(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s RunningBenchmarkStatus) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *RunningBenchmarkStatus) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -2723,17 +3830,28 @@ func (s *Team) encodeFields(e *jx.Encoder) { } e.ArrEnd() } + { + if s.GithubIds != nil { + e.FieldStart("githubIds") + e.ArrStart() + for _, elem := range s.GithubIds { + elem.Encode(e) + } + e.ArrEnd() + } + } { e.FieldStart("createdAt") json.EncodeDateTime(e, s.CreatedAt) } } -var jsonFieldsNameOfTeam = [4]string{ +var jsonFieldsNameOfTeam = [5]string{ 0: "id", 1: "name", 2: "members", - 3: "createdAt", + 3: "githubIds", + 4: "createdAt", } // Decode decodes Team from json. @@ -2783,8 +3901,25 @@ func (s *Team) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"members\"") } + case "githubIds": + if err := func() error { + s.GithubIds = make([]GitHubId, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem GitHubId + if err := elem.Decode(d); err != nil { + return err + } + s.GithubIds = append(s.GithubIds, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"githubIds\"") + } case "createdAt": - requiredBitSet[0] |= 1 << 3 + requiredBitSet[0] |= 1 << 4 if err := func() error { v, err := json.DecodeDateTime(d) s.CreatedAt = v @@ -2805,7 +3940,7 @@ func (s *Team) Decode(d *jx.Decoder) error { // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ - 0b00001111, + 0b00010111, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -2901,32 +4036,153 @@ func (s TeamName) Encode(e *jx.Encoder) { // Decode decodes TeamName from json. func (s *TeamName) Decode(d *jx.Decoder) error { if s == nil { - return errors.New("invalid: unable to decode TeamName to nil") + return errors.New("invalid: unable to decode TeamName to nil") + } + var unwrapped string + if err := func() error { + v, err := d.Str() + unwrapped = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = TeamName(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s TeamName) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *TeamName) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *TeamScores) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *TeamScores) encodeFields(e *jx.Encoder) { + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("scores") + e.ArrStart() + for _, elem := range s.Scores { + elem.Encode(e) + } + e.ArrEnd() + } +} + +var jsonFieldsNameOfTeamScores = [2]string{ + 0: "teamId", + 1: "scores", +} + +// Decode decodes TeamScores from json. +func (s *TeamScores) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode TeamScores to nil") } - var unwrapped string - if err := func() error { - v, err := d.Str() - unwrapped = string(v) - if err != nil { - return err + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "teamId": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.TeamId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"teamId\"") + } + case "scores": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + s.Scores = make([]BenchScore, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem BenchScore + if err := elem.Decode(d); err != nil { + return err + } + s.Scores = append(s.Scores, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"scores\"") + } + default: + return d.Skip() } return nil - }(); err != nil { - return errors.Wrap(err, "alias") + }); err != nil { + return errors.Wrap(err, "decode TeamScores") } - *s = TeamName(unwrapped) + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfTeamScores) { + name = jsonFieldsNameOfTeamScores[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil } // MarshalJSON implements stdjson.Marshaler. -func (s TeamName) MarshalJSON() ([]byte, error) { +func (s *TeamScores) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *TeamName) UnmarshalJSON(data []byte) error { +func (s *TeamScores) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -3216,3 +4472,210 @@ func (s *UserName) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } + +// Encode implements json.Marshaler. +func (s *WaitingBenchmark) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *WaitingBenchmark) encodeFields(e *jx.Encoder) { + { + e.FieldStart("id") + s.ID.Encode(e) + } + { + e.FieldStart("instanceId") + s.InstanceId.Encode(e) + } + { + e.FieldStart("teamId") + s.TeamId.Encode(e) + } + { + e.FieldStart("userId") + s.UserId.Encode(e) + } + { + e.FieldStart("status") + s.Status.Encode(e) + } + { + e.FieldStart("createdAt") + s.CreatedAt.Encode(e) + } +} + +var jsonFieldsNameOfWaitingBenchmark = [6]string{ + 0: "id", + 1: "instanceId", + 2: "teamId", + 3: "userId", + 4: "status", + 5: "createdAt", +} + +// Decode decodes WaitingBenchmark from json. +func (s *WaitingBenchmark) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode WaitingBenchmark to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.ID.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "instanceId": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + if err := s.InstanceId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"instanceId\"") + } + case "teamId": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + if err := s.TeamId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"teamId\"") + } + case "userId": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + if err := s.UserId.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"userId\"") + } + case "status": + requiredBitSet[0] |= 1 << 4 + if err := func() error { + if err := s.Status.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"status\"") + } + case "createdAt": + requiredBitSet[0] |= 1 << 5 + if err := func() error { + if err := s.CreatedAt.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"createdAt\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode WaitingBenchmark") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00111111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfWaitingBenchmark) { + name = jsonFieldsNameOfWaitingBenchmark[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *WaitingBenchmark) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *WaitingBenchmark) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes WaitingBenchmarkStatus as json. +func (s WaitingBenchmarkStatus) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes WaitingBenchmarkStatus from json. +func (s *WaitingBenchmarkStatus) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode WaitingBenchmarkStatus to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch WaitingBenchmarkStatus(v) { + case WaitingBenchmarkStatusWaiting: + *s = WaitingBenchmarkStatusWaiting + default: + *s = WaitingBenchmarkStatus(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s WaitingBenchmarkStatus) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *WaitingBenchmarkStatus) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} diff --git a/server/handler/openapi/oas_parameters_gen.go b/server/handler/openapi/oas_parameters_gen.go index 5886ed9..2e5dc41 100644 --- a/server/handler/openapi/oas_parameters_gen.go +++ b/server/handler/openapi/oas_parameters_gen.go @@ -34,6 +34,12 @@ type GetOauth2CallbackParams struct { Code string } +// GetRankingParams is parameters of getRanking operation. +type GetRankingParams struct { + // ランキングにどのスコアを使用するか。latestは最新のスコア、highestは最高スコアを使用する. + OrderBy RankingOrderBy +} + // GetTeamParams is parameters of getTeam operation. type GetTeamParams struct { // チームID. diff --git a/server/handler/openapi/oas_schemas_gen.go b/server/handler/openapi/oas_schemas_gen.go index 09e8130..9a74d2c 100644 --- a/server/handler/openapi/oas_schemas_gen.go +++ b/server/handler/openapi/oas_schemas_gen.go @@ -24,362 +24,365 @@ func (s *AdminAuth) SetAPIKey(val string) { s.APIKey = val } -// ベンチマーク. -// Ref: #/components/schemas/Benchmark -type Benchmark struct { - ID BenchmarkId `json:"id"` - InstanceId InstanceId `json:"instanceId"` - TeamId TeamId `json:"teamId"` - UserId UserId `json:"userId"` - Status BenchmarkStatus `json:"status"` - Score OptScore `json:"score"` - CreatedAt CreatedAt `json:"createdAt"` - StartedAt OptStartedAt `json:"startedAt"` - FinishedAt OptFinishedAt `json:"finishedAt"` +// ベンチマークのスコア. +// Ref: #/components/schemas/BenchScore +type BenchScore struct { + BenchmarkId OptBenchmarkId `json:"benchmarkId"` + TeamId TeamId `json:"teamId"` + Score Score `json:"score"` + CreatedAt CreatedAt `json:"createdAt"` } -// GetID returns the value of ID. -func (s *Benchmark) GetID() BenchmarkId { - return s.ID -} - -// GetInstanceId returns the value of InstanceId. -func (s *Benchmark) GetInstanceId() InstanceId { - return s.InstanceId +// GetBenchmarkId returns the value of BenchmarkId. +func (s *BenchScore) GetBenchmarkId() OptBenchmarkId { + return s.BenchmarkId } // GetTeamId returns the value of TeamId. -func (s *Benchmark) GetTeamId() TeamId { +func (s *BenchScore) GetTeamId() TeamId { return s.TeamId } -// GetUserId returns the value of UserId. -func (s *Benchmark) GetUserId() UserId { - return s.UserId -} - -// GetStatus returns the value of Status. -func (s *Benchmark) GetStatus() BenchmarkStatus { - return s.Status -} - // GetScore returns the value of Score. -func (s *Benchmark) GetScore() OptScore { +func (s *BenchScore) GetScore() Score { return s.Score } // GetCreatedAt returns the value of CreatedAt. -func (s *Benchmark) GetCreatedAt() CreatedAt { +func (s *BenchScore) GetCreatedAt() CreatedAt { return s.CreatedAt } -// GetStartedAt returns the value of StartedAt. -func (s *Benchmark) GetStartedAt() OptStartedAt { - return s.StartedAt -} - -// GetFinishedAt returns the value of FinishedAt. -func (s *Benchmark) GetFinishedAt() OptFinishedAt { - return s.FinishedAt -} - -// SetID sets the value of ID. -func (s *Benchmark) SetID(val BenchmarkId) { - s.ID = val -} - -// SetInstanceId sets the value of InstanceId. -func (s *Benchmark) SetInstanceId(val InstanceId) { - s.InstanceId = val +// SetBenchmarkId sets the value of BenchmarkId. +func (s *BenchScore) SetBenchmarkId(val OptBenchmarkId) { + s.BenchmarkId = val } // SetTeamId sets the value of TeamId. -func (s *Benchmark) SetTeamId(val TeamId) { +func (s *BenchScore) SetTeamId(val TeamId) { s.TeamId = val } -// SetUserId sets the value of UserId. -func (s *Benchmark) SetUserId(val UserId) { - s.UserId = val -} - -// SetStatus sets the value of Status. -func (s *Benchmark) SetStatus(val BenchmarkStatus) { - s.Status = val -} - // SetScore sets the value of Score. -func (s *Benchmark) SetScore(val OptScore) { +func (s *BenchScore) SetScore(val Score) { s.Score = val } // SetCreatedAt sets the value of CreatedAt. -func (s *Benchmark) SetCreatedAt(val CreatedAt) { +func (s *BenchScore) SetCreatedAt(val CreatedAt) { s.CreatedAt = val } -// SetStartedAt sets the value of StartedAt. -func (s *Benchmark) SetStartedAt(val OptStartedAt) { - s.StartedAt = val +// Merged schema. +// Ref: #/components/schemas/Benchmark +// Benchmark represents sum type. +type Benchmark struct { + Type BenchmarkType // switch on this field + WaitingBenchmark WaitingBenchmark + RunningBenchmark RunningBenchmark + FinishedBenchmark FinishedBenchmark } -// SetFinishedAt sets the value of FinishedAt. -func (s *Benchmark) SetFinishedAt(val OptFinishedAt) { - s.FinishedAt = val -} +// BenchmarkType is oneOf type of Benchmark. +type BenchmarkType string -func (*Benchmark) postBenchmarkRes() {} +// Possible values for BenchmarkType. +const ( + WaitingBenchmarkBenchmark BenchmarkType = "WaitingBenchmark" + RunningBenchmarkBenchmark BenchmarkType = "RunningBenchmark" + FinishedBenchmarkBenchmark BenchmarkType = "FinishedBenchmark" +) -// Adminが見ることができるベンチマーク結果. -// Ref: #/components/schemas/BenchmarkAdminResult -type BenchmarkAdminResult struct { - ID BenchmarkId `json:"id"` - InstanceId InstanceId `json:"instanceId"` - TeamId TeamId `json:"teamId"` - UserId UserId `json:"userId"` - Status BenchmarkStatus `json:"status"` - // ベンチマークの競技者用ログ(標準出力). - Log string `json:"log"` - // ベンチマークの管理者用ログ(標準エラー出力). - AdminLog string `json:"adminLog"` - Score Score `json:"score"` - CreatedAt CreatedAt `json:"createdAt"` - StartedAt StartedAt `json:"startedAt"` - FinishedAt FinishedAt `json:"finishedAt"` -} +// IsWaitingBenchmark reports whether Benchmark is WaitingBenchmark. +func (s Benchmark) IsWaitingBenchmark() bool { return s.Type == WaitingBenchmarkBenchmark } -// GetID returns the value of ID. -func (s *BenchmarkAdminResult) GetID() BenchmarkId { - return s.ID +// IsRunningBenchmark reports whether Benchmark is RunningBenchmark. +func (s Benchmark) IsRunningBenchmark() bool { return s.Type == RunningBenchmarkBenchmark } + +// IsFinishedBenchmark reports whether Benchmark is FinishedBenchmark. +func (s Benchmark) IsFinishedBenchmark() bool { return s.Type == FinishedBenchmarkBenchmark } + +// SetWaitingBenchmark sets Benchmark to WaitingBenchmark. +func (s *Benchmark) SetWaitingBenchmark(v WaitingBenchmark) { + s.Type = WaitingBenchmarkBenchmark + s.WaitingBenchmark = v } -// GetInstanceId returns the value of InstanceId. -func (s *BenchmarkAdminResult) GetInstanceId() InstanceId { - return s.InstanceId +// GetWaitingBenchmark returns WaitingBenchmark and true boolean if Benchmark is WaitingBenchmark. +func (s Benchmark) GetWaitingBenchmark() (v WaitingBenchmark, ok bool) { + if !s.IsWaitingBenchmark() { + return v, false + } + return s.WaitingBenchmark, true } -// GetTeamId returns the value of TeamId. -func (s *BenchmarkAdminResult) GetTeamId() TeamId { - return s.TeamId +// NewWaitingBenchmarkBenchmark returns new Benchmark from WaitingBenchmark. +func NewWaitingBenchmarkBenchmark(v WaitingBenchmark) Benchmark { + var s Benchmark + s.SetWaitingBenchmark(v) + return s } -// GetUserId returns the value of UserId. -func (s *BenchmarkAdminResult) GetUserId() UserId { - return s.UserId +// SetRunningBenchmark sets Benchmark to RunningBenchmark. +func (s *Benchmark) SetRunningBenchmark(v RunningBenchmark) { + s.Type = RunningBenchmarkBenchmark + s.RunningBenchmark = v } -// GetStatus returns the value of Status. -func (s *BenchmarkAdminResult) GetStatus() BenchmarkStatus { - return s.Status +// GetRunningBenchmark returns RunningBenchmark and true boolean if Benchmark is RunningBenchmark. +func (s Benchmark) GetRunningBenchmark() (v RunningBenchmark, ok bool) { + if !s.IsRunningBenchmark() { + return v, false + } + return s.RunningBenchmark, true } -// GetLog returns the value of Log. -func (s *BenchmarkAdminResult) GetLog() string { - return s.Log +// NewRunningBenchmarkBenchmark returns new Benchmark from RunningBenchmark. +func NewRunningBenchmarkBenchmark(v RunningBenchmark) Benchmark { + var s Benchmark + s.SetRunningBenchmark(v) + return s } -// GetAdminLog returns the value of AdminLog. -func (s *BenchmarkAdminResult) GetAdminLog() string { - return s.AdminLog +// SetFinishedBenchmark sets Benchmark to FinishedBenchmark. +func (s *Benchmark) SetFinishedBenchmark(v FinishedBenchmark) { + s.Type = FinishedBenchmarkBenchmark + s.FinishedBenchmark = v } -// GetScore returns the value of Score. -func (s *BenchmarkAdminResult) GetScore() Score { - return s.Score +// GetFinishedBenchmark returns FinishedBenchmark and true boolean if Benchmark is FinishedBenchmark. +func (s Benchmark) GetFinishedBenchmark() (v FinishedBenchmark, ok bool) { + if !s.IsFinishedBenchmark() { + return v, false + } + return s.FinishedBenchmark, true } -// GetCreatedAt returns the value of CreatedAt. -func (s *BenchmarkAdminResult) GetCreatedAt() CreatedAt { - return s.CreatedAt +// NewFinishedBenchmarkBenchmark returns new Benchmark from FinishedBenchmark. +func NewFinishedBenchmarkBenchmark(v FinishedBenchmark) Benchmark { + var s Benchmark + s.SetFinishedBenchmark(v) + return s } -// GetStartedAt returns the value of StartedAt. -func (s *BenchmarkAdminResult) GetStartedAt() StartedAt { - return s.StartedAt +func (*Benchmark) getTeamBenchmarkResultRes() {} + +// Merged schema. +// Ref: #/components/schemas/BenchmarkAdminResult +// BenchmarkAdminResult represents sum type. +type BenchmarkAdminResult struct { + Type BenchmarkAdminResultType // switch on this field + WaitingBenchmark WaitingBenchmark + RunningBenchmark RunningBenchmark + FinishedBenchmark FinishedBenchmark } -// GetFinishedAt returns the value of FinishedAt. -func (s *BenchmarkAdminResult) GetFinishedAt() FinishedAt { - return s.FinishedAt +// BenchmarkAdminResultType is oneOf type of BenchmarkAdminResult. +type BenchmarkAdminResultType string + +// Possible values for BenchmarkAdminResultType. +const ( + WaitingBenchmarkBenchmarkAdminResult BenchmarkAdminResultType = "WaitingBenchmark" + RunningBenchmarkBenchmarkAdminResult BenchmarkAdminResultType = "RunningBenchmark" + FinishedBenchmarkBenchmarkAdminResult BenchmarkAdminResultType = "FinishedBenchmark" +) + +// IsWaitingBenchmark reports whether BenchmarkAdminResult is WaitingBenchmark. +func (s BenchmarkAdminResult) IsWaitingBenchmark() bool { + return s.Type == WaitingBenchmarkBenchmarkAdminResult } -// SetID sets the value of ID. -func (s *BenchmarkAdminResult) SetID(val BenchmarkId) { - s.ID = val +// IsRunningBenchmark reports whether BenchmarkAdminResult is RunningBenchmark. +func (s BenchmarkAdminResult) IsRunningBenchmark() bool { + return s.Type == RunningBenchmarkBenchmarkAdminResult } -// SetInstanceId sets the value of InstanceId. -func (s *BenchmarkAdminResult) SetInstanceId(val InstanceId) { - s.InstanceId = val +// IsFinishedBenchmark reports whether BenchmarkAdminResult is FinishedBenchmark. +func (s BenchmarkAdminResult) IsFinishedBenchmark() bool { + return s.Type == FinishedBenchmarkBenchmarkAdminResult } -// SetTeamId sets the value of TeamId. -func (s *BenchmarkAdminResult) SetTeamId(val TeamId) { - s.TeamId = val +// SetWaitingBenchmark sets BenchmarkAdminResult to WaitingBenchmark. +func (s *BenchmarkAdminResult) SetWaitingBenchmark(v WaitingBenchmark) { + s.Type = WaitingBenchmarkBenchmarkAdminResult + s.WaitingBenchmark = v } -// SetUserId sets the value of UserId. -func (s *BenchmarkAdminResult) SetUserId(val UserId) { - s.UserId = val +// GetWaitingBenchmark returns WaitingBenchmark and true boolean if BenchmarkAdminResult is WaitingBenchmark. +func (s BenchmarkAdminResult) GetWaitingBenchmark() (v WaitingBenchmark, ok bool) { + if !s.IsWaitingBenchmark() { + return v, false + } + return s.WaitingBenchmark, true } -// SetStatus sets the value of Status. -func (s *BenchmarkAdminResult) SetStatus(val BenchmarkStatus) { - s.Status = val +// NewWaitingBenchmarkBenchmarkAdminResult returns new BenchmarkAdminResult from WaitingBenchmark. +func NewWaitingBenchmarkBenchmarkAdminResult(v WaitingBenchmark) BenchmarkAdminResult { + var s BenchmarkAdminResult + s.SetWaitingBenchmark(v) + return s } -// SetLog sets the value of Log. -func (s *BenchmarkAdminResult) SetLog(val string) { - s.Log = val +// SetRunningBenchmark sets BenchmarkAdminResult to RunningBenchmark. +func (s *BenchmarkAdminResult) SetRunningBenchmark(v RunningBenchmark) { + s.Type = RunningBenchmarkBenchmarkAdminResult + s.RunningBenchmark = v } -// SetAdminLog sets the value of AdminLog. -func (s *BenchmarkAdminResult) SetAdminLog(val string) { - s.AdminLog = val +// GetRunningBenchmark returns RunningBenchmark and true boolean if BenchmarkAdminResult is RunningBenchmark. +func (s BenchmarkAdminResult) GetRunningBenchmark() (v RunningBenchmark, ok bool) { + if !s.IsRunningBenchmark() { + return v, false + } + return s.RunningBenchmark, true } -// SetScore sets the value of Score. -func (s *BenchmarkAdminResult) SetScore(val Score) { - s.Score = val +// NewRunningBenchmarkBenchmarkAdminResult returns new BenchmarkAdminResult from RunningBenchmark. +func NewRunningBenchmarkBenchmarkAdminResult(v RunningBenchmark) BenchmarkAdminResult { + var s BenchmarkAdminResult + s.SetRunningBenchmark(v) + return s } -// SetCreatedAt sets the value of CreatedAt. -func (s *BenchmarkAdminResult) SetCreatedAt(val CreatedAt) { - s.CreatedAt = val +// SetFinishedBenchmark sets BenchmarkAdminResult to FinishedBenchmark. +func (s *BenchmarkAdminResult) SetFinishedBenchmark(v FinishedBenchmark) { + s.Type = FinishedBenchmarkBenchmarkAdminResult + s.FinishedBenchmark = v } -// SetStartedAt sets the value of StartedAt. -func (s *BenchmarkAdminResult) SetStartedAt(val StartedAt) { - s.StartedAt = val +// GetFinishedBenchmark returns FinishedBenchmark and true boolean if BenchmarkAdminResult is FinishedBenchmark. +func (s BenchmarkAdminResult) GetFinishedBenchmark() (v FinishedBenchmark, ok bool) { + if !s.IsFinishedBenchmark() { + return v, false + } + return s.FinishedBenchmark, true } -// SetFinishedAt sets the value of FinishedAt. -func (s *BenchmarkAdminResult) SetFinishedAt(val FinishedAt) { - s.FinishedAt = val +// NewFinishedBenchmarkBenchmarkAdminResult returns new BenchmarkAdminResult from FinishedBenchmark. +func NewFinishedBenchmarkBenchmarkAdminResult(v FinishedBenchmark) BenchmarkAdminResult { + var s BenchmarkAdminResult + s.SetFinishedBenchmark(v) + return s } func (*BenchmarkAdminResult) getBenchmarkResultRes() {} type BenchmarkId uuid.UUID -// ベンチマーク結果. -// Ref: #/components/schemas/BenchmarkResult -type BenchmarkResult struct { - ID BenchmarkId `json:"id"` - InstanceId InstanceId `json:"instanceId"` - TeamId TeamId `json:"teamId"` - UserId UserId `json:"userId"` - Status BenchmarkStatus `json:"status"` - // ベンチマークの競技者用ログ(標準出力). - Log string `json:"log"` - Score Score `json:"score"` - CreatedAt CreatedAt `json:"createdAt"` - StartedAt StartedAt `json:"startedAt"` - FinishedAt FinishedAt `json:"finishedAt"` -} - -// GetID returns the value of ID. -func (s *BenchmarkResult) GetID() BenchmarkId { - return s.ID +// ベンチマーク. +// Ref: #/components/schemas/BenchmarkListItem +type BenchmarkListItem struct { + OneOf BenchmarkListItemSum } -// GetInstanceId returns the value of InstanceId. -func (s *BenchmarkResult) GetInstanceId() InstanceId { - return s.InstanceId +// GetOneOf returns the value of OneOf. +func (s *BenchmarkListItem) GetOneOf() BenchmarkListItemSum { + return s.OneOf } -// GetTeamId returns the value of TeamId. -func (s *BenchmarkResult) GetTeamId() TeamId { - return s.TeamId +// SetOneOf sets the value of OneOf. +func (s *BenchmarkListItem) SetOneOf(val BenchmarkListItemSum) { + s.OneOf = val } -// GetUserId returns the value of UserId. -func (s *BenchmarkResult) GetUserId() UserId { - return s.UserId -} +func (*BenchmarkListItem) postBenchmarkRes() {} -// GetStatus returns the value of Status. -func (s *BenchmarkResult) GetStatus() BenchmarkStatus { - return s.Status +// BenchmarkListItemSum represents sum type. +type BenchmarkListItemSum struct { + Type BenchmarkListItemSumType // switch on this field + WaitingBenchmark WaitingBenchmark + RunningBenchmark RunningBenchmark + FinishedBenchmark FinishedBenchmark } -// GetLog returns the value of Log. -func (s *BenchmarkResult) GetLog() string { - return s.Log -} +// BenchmarkListItemSumType is oneOf type of BenchmarkListItemSum. +type BenchmarkListItemSumType string -// GetScore returns the value of Score. -func (s *BenchmarkResult) GetScore() Score { - return s.Score -} - -// GetCreatedAt returns the value of CreatedAt. -func (s *BenchmarkResult) GetCreatedAt() CreatedAt { - return s.CreatedAt -} +// Possible values for BenchmarkListItemSumType. +const ( + WaitingBenchmarkBenchmarkListItemSum BenchmarkListItemSumType = "WaitingBenchmark" + RunningBenchmarkBenchmarkListItemSum BenchmarkListItemSumType = "RunningBenchmark" + FinishedBenchmarkBenchmarkListItemSum BenchmarkListItemSumType = "FinishedBenchmark" +) -// GetStartedAt returns the value of StartedAt. -func (s *BenchmarkResult) GetStartedAt() StartedAt { - return s.StartedAt +// IsWaitingBenchmark reports whether BenchmarkListItemSum is WaitingBenchmark. +func (s BenchmarkListItemSum) IsWaitingBenchmark() bool { + return s.Type == WaitingBenchmarkBenchmarkListItemSum } -// GetFinishedAt returns the value of FinishedAt. -func (s *BenchmarkResult) GetFinishedAt() FinishedAt { - return s.FinishedAt +// IsRunningBenchmark reports whether BenchmarkListItemSum is RunningBenchmark. +func (s BenchmarkListItemSum) IsRunningBenchmark() bool { + return s.Type == RunningBenchmarkBenchmarkListItemSum } -// SetID sets the value of ID. -func (s *BenchmarkResult) SetID(val BenchmarkId) { - s.ID = val +// IsFinishedBenchmark reports whether BenchmarkListItemSum is FinishedBenchmark. +func (s BenchmarkListItemSum) IsFinishedBenchmark() bool { + return s.Type == FinishedBenchmarkBenchmarkListItemSum } -// SetInstanceId sets the value of InstanceId. -func (s *BenchmarkResult) SetInstanceId(val InstanceId) { - s.InstanceId = val +// SetWaitingBenchmark sets BenchmarkListItemSum to WaitingBenchmark. +func (s *BenchmarkListItemSum) SetWaitingBenchmark(v WaitingBenchmark) { + s.Type = WaitingBenchmarkBenchmarkListItemSum + s.WaitingBenchmark = v } -// SetTeamId sets the value of TeamId. -func (s *BenchmarkResult) SetTeamId(val TeamId) { - s.TeamId = val +// GetWaitingBenchmark returns WaitingBenchmark and true boolean if BenchmarkListItemSum is WaitingBenchmark. +func (s BenchmarkListItemSum) GetWaitingBenchmark() (v WaitingBenchmark, ok bool) { + if !s.IsWaitingBenchmark() { + return v, false + } + return s.WaitingBenchmark, true } -// SetUserId sets the value of UserId. -func (s *BenchmarkResult) SetUserId(val UserId) { - s.UserId = val +// NewWaitingBenchmarkBenchmarkListItemSum returns new BenchmarkListItemSum from WaitingBenchmark. +func NewWaitingBenchmarkBenchmarkListItemSum(v WaitingBenchmark) BenchmarkListItemSum { + var s BenchmarkListItemSum + s.SetWaitingBenchmark(v) + return s } -// SetStatus sets the value of Status. -func (s *BenchmarkResult) SetStatus(val BenchmarkStatus) { - s.Status = val +// SetRunningBenchmark sets BenchmarkListItemSum to RunningBenchmark. +func (s *BenchmarkListItemSum) SetRunningBenchmark(v RunningBenchmark) { + s.Type = RunningBenchmarkBenchmarkListItemSum + s.RunningBenchmark = v } -// SetLog sets the value of Log. -func (s *BenchmarkResult) SetLog(val string) { - s.Log = val +// GetRunningBenchmark returns RunningBenchmark and true boolean if BenchmarkListItemSum is RunningBenchmark. +func (s BenchmarkListItemSum) GetRunningBenchmark() (v RunningBenchmark, ok bool) { + if !s.IsRunningBenchmark() { + return v, false + } + return s.RunningBenchmark, true } -// SetScore sets the value of Score. -func (s *BenchmarkResult) SetScore(val Score) { - s.Score = val +// NewRunningBenchmarkBenchmarkListItemSum returns new BenchmarkListItemSum from RunningBenchmark. +func NewRunningBenchmarkBenchmarkListItemSum(v RunningBenchmark) BenchmarkListItemSum { + var s BenchmarkListItemSum + s.SetRunningBenchmark(v) + return s } -// SetCreatedAt sets the value of CreatedAt. -func (s *BenchmarkResult) SetCreatedAt(val CreatedAt) { - s.CreatedAt = val +// SetFinishedBenchmark sets BenchmarkListItemSum to FinishedBenchmark. +func (s *BenchmarkListItemSum) SetFinishedBenchmark(v FinishedBenchmark) { + s.Type = FinishedBenchmarkBenchmarkListItemSum + s.FinishedBenchmark = v } -// SetStartedAt sets the value of StartedAt. -func (s *BenchmarkResult) SetStartedAt(val StartedAt) { - s.StartedAt = val +// GetFinishedBenchmark returns FinishedBenchmark and true boolean if BenchmarkListItemSum is FinishedBenchmark. +func (s BenchmarkListItemSum) GetFinishedBenchmark() (v FinishedBenchmark, ok bool) { + if !s.IsFinishedBenchmark() { + return v, false + } + return s.FinishedBenchmark, true } -// SetFinishedAt sets the value of FinishedAt. -func (s *BenchmarkResult) SetFinishedAt(val FinishedAt) { - s.FinishedAt = val +// NewFinishedBenchmarkBenchmarkListItemSum returns new BenchmarkListItemSum from FinishedBenchmark. +func NewFinishedBenchmarkBenchmarkListItemSum(v FinishedBenchmark) BenchmarkListItemSum { + var s BenchmarkListItemSum + s.SetFinishedBenchmark(v) + return s } -func (*BenchmarkResult) getTeamBenchmarkResultRes() {} - // Ref: #/components/schemas/BenchmarkStatus type BenchmarkStatus string @@ -452,13 +455,153 @@ func (s *ErrorBadRequest) SetMessage(val OptString) { } func (*ErrorBadRequest) createTeamInstanceRes() {} +func (*ErrorBadRequest) patchDocsRes() {} func (*ErrorBadRequest) patchTeamInstanceRes() {} func (*ErrorBadRequest) patchTeamRes() {} func (*ErrorBadRequest) postBenchmarkRes() {} func (*ErrorBadRequest) postTeamRes() {} +func (*ErrorBadRequest) putAdminsRes() {} type FinishedAt time.Time +// Status=finished のベンチマーク結果. +// Ref: #/components/schemas/FinishedBenchmark +type FinishedBenchmark struct { + ID BenchmarkId `json:"id"` + InstanceId InstanceId `json:"instanceId"` + TeamId TeamId `json:"teamId"` + UserId UserId `json:"userId"` + Status FinishedBenchmarkStatus `json:"status"` + Score Score `json:"score"` + CreatedAt CreatedAt `json:"createdAt"` + StartedAt StartedAt `json:"startedAt"` + FinishedAt FinishedAt `json:"finishedAt"` +} + +// GetID returns the value of ID. +func (s *FinishedBenchmark) GetID() BenchmarkId { + return s.ID +} + +// GetInstanceId returns the value of InstanceId. +func (s *FinishedBenchmark) GetInstanceId() InstanceId { + return s.InstanceId +} + +// GetTeamId returns the value of TeamId. +func (s *FinishedBenchmark) GetTeamId() TeamId { + return s.TeamId +} + +// GetUserId returns the value of UserId. +func (s *FinishedBenchmark) GetUserId() UserId { + return s.UserId +} + +// GetStatus returns the value of Status. +func (s *FinishedBenchmark) GetStatus() FinishedBenchmarkStatus { + return s.Status +} + +// GetScore returns the value of Score. +func (s *FinishedBenchmark) GetScore() Score { + return s.Score +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *FinishedBenchmark) GetCreatedAt() CreatedAt { + return s.CreatedAt +} + +// GetStartedAt returns the value of StartedAt. +func (s *FinishedBenchmark) GetStartedAt() StartedAt { + return s.StartedAt +} + +// GetFinishedAt returns the value of FinishedAt. +func (s *FinishedBenchmark) GetFinishedAt() FinishedAt { + return s.FinishedAt +} + +// SetID sets the value of ID. +func (s *FinishedBenchmark) SetID(val BenchmarkId) { + s.ID = val +} + +// SetInstanceId sets the value of InstanceId. +func (s *FinishedBenchmark) SetInstanceId(val InstanceId) { + s.InstanceId = val +} + +// SetTeamId sets the value of TeamId. +func (s *FinishedBenchmark) SetTeamId(val TeamId) { + s.TeamId = val +} + +// SetUserId sets the value of UserId. +func (s *FinishedBenchmark) SetUserId(val UserId) { + s.UserId = val +} + +// SetStatus sets the value of Status. +func (s *FinishedBenchmark) SetStatus(val FinishedBenchmarkStatus) { + s.Status = val +} + +// SetScore sets the value of Score. +func (s *FinishedBenchmark) SetScore(val Score) { + s.Score = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *FinishedBenchmark) SetCreatedAt(val CreatedAt) { + s.CreatedAt = val +} + +// SetStartedAt sets the value of StartedAt. +func (s *FinishedBenchmark) SetStartedAt(val StartedAt) { + s.StartedAt = val +} + +// SetFinishedAt sets the value of FinishedAt. +func (s *FinishedBenchmark) SetFinishedAt(val FinishedAt) { + s.FinishedAt = val +} + +type FinishedBenchmarkStatus string + +const ( + FinishedBenchmarkStatusFinished FinishedBenchmarkStatus = "finished" +) + +// AllValues returns all FinishedBenchmarkStatus values. +func (FinishedBenchmarkStatus) AllValues() []FinishedBenchmarkStatus { + return []FinishedBenchmarkStatus{ + FinishedBenchmarkStatusFinished, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s FinishedBenchmarkStatus) MarshalText() ([]byte, error) { + switch s { + case FinishedBenchmarkStatusFinished: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *FinishedBenchmarkStatus) UnmarshalText(data []byte) error { + switch FinishedBenchmarkStatus(data) { + case FinishedBenchmarkStatusFinished: + *s = FinishedBenchmarkStatusFinished + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + type Forbidden struct { Message OptString `json:"message"` } @@ -481,18 +624,36 @@ func (*Forbidden) getInstancesRes() {} func (*Forbidden) getTeamBenchmarkResultRes() {} func (*Forbidden) getTeamBenchmarksRes() {} func (*Forbidden) getTeamInstancesRes() {} +func (*Forbidden) patchDocsRes() {} func (*Forbidden) patchTeamInstanceRes() {} func (*Forbidden) patchTeamRes() {} func (*Forbidden) postBenchmarkRes() {} +func (*Forbidden) putAdminsRes() {} -type GetBenchmarkQueueOKApplicationJSON []Benchmark +type GetBenchmarkQueueOKApplicationJSON []BenchmarkListItem func (*GetBenchmarkQueueOKApplicationJSON) getBenchmarkQueueRes() {} -type GetBenchmarksOKApplicationJSON []Benchmark +type GetBenchmarksOKApplicationJSON []BenchmarkListItem func (*GetBenchmarksOKApplicationJSON) getBenchmarksRes() {} +type GetDocsOK struct { + Body OptMarkdownDocument `json:"body"` +} + +// GetBody returns the value of Body. +func (s *GetDocsOK) GetBody() OptMarkdownDocument { + return s.Body +} + +// SetBody sets the value of Body. +func (s *GetDocsOK) SetBody(val OptMarkdownDocument) { + s.Body = val +} + +func (*GetDocsOK) getDocsRes() {} + type GetInstancesOKApplicationJSON []Instance func (*GetInstancesOKApplicationJSON) getInstancesRes() {} @@ -547,7 +708,15 @@ func (s *GetOauth2CodeSeeOther) SetLocation(val OptURI) { func (*GetOauth2CodeSeeOther) getOauth2CodeRes() {} -type GetTeamBenchmarksOKApplicationJSON []Benchmark +type GetRankingOKApplicationJSON []RankingItem + +func (*GetRankingOKApplicationJSON) getRankingRes() {} + +type GetScoresOKApplicationJSON []TeamScores + +func (*GetScoresOKApplicationJSON) getScoresRes() {} + +type GetTeamBenchmarksOKApplicationJSON []BenchmarkListItem func (*GetTeamBenchmarksOKApplicationJSON) getTeamBenchmarksRes() {} @@ -563,6 +732,8 @@ type GetUsersOKApplicationJSON []User func (*GetUsersOKApplicationJSON) getUsersRes() {} +type GitHubId string + type IPAddress string // サーバーのインスタンス. @@ -654,6 +825,48 @@ func (*Instance) createTeamInstanceRes() {} type InstanceId uuid.UUID +// Ref: #/components/schemas/InstanceOperation +type InstanceOperation string + +const ( + InstanceOperationStart InstanceOperation = "start" + InstanceOperationStop InstanceOperation = "stop" +) + +// AllValues returns all InstanceOperation values. +func (InstanceOperation) AllValues() []InstanceOperation { + return []InstanceOperation{ + InstanceOperationStart, + InstanceOperationStop, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s InstanceOperation) MarshalText() ([]byte, error) { + switch s { + case InstanceOperationStart: + return []byte(s), nil + case InstanceOperationStop: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *InstanceOperation) UnmarshalText(data []byte) error { + switch InstanceOperation(data) { + case InstanceOperationStart: + *s = InstanceOperationStart + return nil + case InstanceOperationStop: + *s = InstanceOperationStop + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + // Ref: #/components/schemas/InstanceStatus type InstanceStatus string @@ -722,21 +935,28 @@ func (*InternalServerError) deleteTeamInstanceRes() {} func (*InternalServerError) getBenchmarkQueueRes() {} func (*InternalServerError) getBenchmarkResultRes() {} func (*InternalServerError) getBenchmarksRes() {} +func (*InternalServerError) getDocsRes() {} func (*InternalServerError) getInstancesRes() {} func (*InternalServerError) getMeRes() {} func (*InternalServerError) getOauth2CallbackRes() {} func (*InternalServerError) getOauth2CodeRes() {} +func (*InternalServerError) getRankingRes() {} +func (*InternalServerError) getScoresRes() {} func (*InternalServerError) getTeamBenchmarkResultRes() {} func (*InternalServerError) getTeamBenchmarksRes() {} func (*InternalServerError) getTeamInstancesRes() {} func (*InternalServerError) getTeamRes() {} func (*InternalServerError) getTeamsRes() {} func (*InternalServerError) getUsersRes() {} +func (*InternalServerError) patchDocsRes() {} func (*InternalServerError) patchTeamInstanceRes() {} func (*InternalServerError) patchTeamRes() {} func (*InternalServerError) postBenchmarkRes() {} func (*InternalServerError) postOauth2LogoutRes() {} func (*InternalServerError) postTeamRes() {} +func (*InternalServerError) putAdminsRes() {} + +type MarkdownDocument string type NotFound struct { Message OptString `json:"message"` @@ -762,6 +982,52 @@ func (*NotFound) getTeamRes() {} func (*NotFound) patchTeamInstanceRes() {} func (*NotFound) patchTeamRes() {} +// NewOptBenchmarkId returns new OptBenchmarkId with value set to v. +func NewOptBenchmarkId(v BenchmarkId) OptBenchmarkId { + return OptBenchmarkId{ + Value: v, + Set: true, + } +} + +// OptBenchmarkId is optional BenchmarkId. +type OptBenchmarkId struct { + Value BenchmarkId + Set bool +} + +// IsSet returns true if OptBenchmarkId was set. +func (o OptBenchmarkId) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptBenchmarkId) Reset() { + var v BenchmarkId + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptBenchmarkId) SetTo(v BenchmarkId) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptBenchmarkId) Get() (v BenchmarkId, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptBenchmarkId) Or(d BenchmarkId) BenchmarkId { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptBenchmarkStatus returns new OptBenchmarkStatus with value set to v. func NewOptBenchmarkStatus(v BenchmarkStatus) OptBenchmarkStatus { return OptBenchmarkStatus{ @@ -808,38 +1074,38 @@ func (o OptBenchmarkStatus) Or(d BenchmarkStatus) BenchmarkStatus { return d } -// NewOptFinishedAt returns new OptFinishedAt with value set to v. -func NewOptFinishedAt(v FinishedAt) OptFinishedAt { - return OptFinishedAt{ +// NewOptCreatedAt returns new OptCreatedAt with value set to v. +func NewOptCreatedAt(v CreatedAt) OptCreatedAt { + return OptCreatedAt{ Value: v, Set: true, } } -// OptFinishedAt is optional FinishedAt. -type OptFinishedAt struct { - Value FinishedAt +// OptCreatedAt is optional CreatedAt. +type OptCreatedAt struct { + Value CreatedAt Set bool } -// IsSet returns true if OptFinishedAt was set. -func (o OptFinishedAt) IsSet() bool { return o.Set } +// IsSet returns true if OptCreatedAt was set. +func (o OptCreatedAt) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptFinishedAt) Reset() { - var v FinishedAt +func (o *OptCreatedAt) Reset() { + var v CreatedAt o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptFinishedAt) SetTo(v FinishedAt) { +func (o *OptCreatedAt) SetTo(v CreatedAt) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptFinishedAt) Get() (v FinishedAt, ok bool) { +func (o OptCreatedAt) Get() (v CreatedAt, ok bool) { if !o.Set { return v, false } @@ -847,45 +1113,45 @@ func (o OptFinishedAt) Get() (v FinishedAt, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptFinishedAt) Or(d FinishedAt) FinishedAt { +func (o OptCreatedAt) Or(d CreatedAt) CreatedAt { if v, ok := o.Get(); ok { return v } return d } -// NewOptInstanceStatus returns new OptInstanceStatus with value set to v. -func NewOptInstanceStatus(v InstanceStatus) OptInstanceStatus { - return OptInstanceStatus{ +// NewOptMarkdownDocument returns new OptMarkdownDocument with value set to v. +func NewOptMarkdownDocument(v MarkdownDocument) OptMarkdownDocument { + return OptMarkdownDocument{ Value: v, Set: true, } } -// OptInstanceStatus is optional InstanceStatus. -type OptInstanceStatus struct { - Value InstanceStatus +// OptMarkdownDocument is optional MarkdownDocument. +type OptMarkdownDocument struct { + Value MarkdownDocument Set bool } -// IsSet returns true if OptInstanceStatus was set. -func (o OptInstanceStatus) IsSet() bool { return o.Set } +// IsSet returns true if OptMarkdownDocument was set. +func (o OptMarkdownDocument) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptInstanceStatus) Reset() { - var v InstanceStatus +func (o *OptMarkdownDocument) Reset() { + var v MarkdownDocument o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptInstanceStatus) SetTo(v InstanceStatus) { +func (o *OptMarkdownDocument) SetTo(v MarkdownDocument) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptInstanceStatus) Get() (v InstanceStatus, ok bool) { +func (o OptMarkdownDocument) Get() (v MarkdownDocument, ok bool) { if !o.Set { return v, false } @@ -893,7 +1159,7 @@ func (o OptInstanceStatus) Get() (v InstanceStatus, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptInstanceStatus) Or(d InstanceStatus) InstanceStatus { +func (o OptMarkdownDocument) Or(d MarkdownDocument) MarkdownDocument { if v, ok := o.Get(); ok { return v } @@ -1038,98 +1304,6 @@ func (o OptPostTeamReq) Or(d PostTeamReq) PostTeamReq { return d } -// NewOptScore returns new OptScore with value set to v. -func NewOptScore(v Score) OptScore { - return OptScore{ - Value: v, - Set: true, - } -} - -// OptScore is optional Score. -type OptScore struct { - Value Score - Set bool -} - -// IsSet returns true if OptScore was set. -func (o OptScore) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptScore) Reset() { - var v Score - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptScore) SetTo(v Score) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptScore) Get() (v Score, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptScore) Or(d Score) Score { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptStartedAt returns new OptStartedAt with value set to v. -func NewOptStartedAt(v StartedAt) OptStartedAt { - return OptStartedAt{ - Value: v, - Set: true, - } -} - -// OptStartedAt is optional StartedAt. -type OptStartedAt struct { - Value StartedAt - Set bool -} - -// IsSet returns true if OptStartedAt was set. -func (o OptStartedAt) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptStartedAt) Reset() { - var v StartedAt - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptStartedAt) SetTo(v StartedAt) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptStartedAt) Get() (v StartedAt, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptStartedAt) Or(d StartedAt) StartedAt { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptString returns new OptString with value set to v. func NewOptString(v string) OptString { return OptString{ @@ -1314,29 +1488,61 @@ func (o OptURI) Or(d url.URL) url.URL { return d } +type PatchDocsOK struct { + Body OptMarkdownDocument `json:"body"` +} + +// GetBody returns the value of Body. +func (s *PatchDocsOK) GetBody() OptMarkdownDocument { + return s.Body +} + +// SetBody sets the value of Body. +func (s *PatchDocsOK) SetBody(val OptMarkdownDocument) { + s.Body = val +} + +func (*PatchDocsOK) patchDocsRes() {} + +type PatchDocsReq struct { + Body MarkdownDocument `json:"body"` +} + +// GetBody returns the value of Body. +func (s *PatchDocsReq) GetBody() MarkdownDocument { + return s.Body +} + +// SetBody sets the value of Body. +func (s *PatchDocsReq) SetBody(val MarkdownDocument) { + s.Body = val +} + // PatchTeamInstanceOK is response for PatchTeamInstance operation. type PatchTeamInstanceOK struct{} func (*PatchTeamInstanceOK) patchTeamInstanceRes() {} type PatchTeamInstanceReq struct { - Status OptInstanceStatus `json:"status"` + Operation InstanceOperation `json:"operation"` } -// GetStatus returns the value of Status. -func (s *PatchTeamInstanceReq) GetStatus() OptInstanceStatus { - return s.Status +// GetOperation returns the value of Operation. +func (s *PatchTeamInstanceReq) GetOperation() InstanceOperation { + return s.Operation } -// SetStatus sets the value of Status. -func (s *PatchTeamInstanceReq) SetStatus(val OptInstanceStatus) { - s.Status = val +// SetOperation sets the value of Operation. +func (s *PatchTeamInstanceReq) SetOperation(val InstanceOperation) { + s.Operation = val } type PatchTeamReq struct { Name OptTeamName `json:"name"` // チームに所属させる部員のID. Members []UserId `json:"members"` + // チームに所属させる部員のGitHub ID. + GithubIds []GitHubId `json:"githubIds"` } // GetName returns the value of Name. @@ -1349,6 +1555,11 @@ func (s *PatchTeamReq) GetMembers() []UserId { return s.Members } +// GetGithubIds returns the value of GithubIds. +func (s *PatchTeamReq) GetGithubIds() []GitHubId { + return s.GithubIds +} + // SetName sets the value of Name. func (s *PatchTeamReq) SetName(val OptTeamName) { s.Name = val @@ -1359,6 +1570,11 @@ func (s *PatchTeamReq) SetMembers(val []UserId) { s.Members = val } +// SetGithubIds sets the value of GithubIds. +func (s *PatchTeamReq) SetGithubIds(val []GitHubId) { + s.GithubIds = val +} + type PostBenchmarkReq struct { InstanceId InstanceId `json:"instanceId"` } @@ -1420,6 +1636,229 @@ func (s *PostTeamReq) SetMembers(val []UserId) { s.Members = val } +// PutAdminsOK is response for PutAdmins operation. +type PutAdminsOK struct{} + +func (*PutAdminsOK) putAdminsRes() {} + +// ランキングの順位。まだベンチマークを1回も実行していない場合、createdAtはnull. +// Ref: #/components/schemas/RankingItem +type RankingItem struct { + // 順位. + Rank int `json:"rank"` + TeamId TeamId `json:"teamId"` + Score Score `json:"score"` + CreatedAt OptCreatedAt `json:"createdAt"` +} + +// GetRank returns the value of Rank. +func (s *RankingItem) GetRank() int { + return s.Rank +} + +// GetTeamId returns the value of TeamId. +func (s *RankingItem) GetTeamId() TeamId { + return s.TeamId +} + +// GetScore returns the value of Score. +func (s *RankingItem) GetScore() Score { + return s.Score +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *RankingItem) GetCreatedAt() OptCreatedAt { + return s.CreatedAt +} + +// SetRank sets the value of Rank. +func (s *RankingItem) SetRank(val int) { + s.Rank = val +} + +// SetTeamId sets the value of TeamId. +func (s *RankingItem) SetTeamId(val TeamId) { + s.TeamId = val +} + +// SetScore sets the value of Score. +func (s *RankingItem) SetScore(val Score) { + s.Score = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *RankingItem) SetCreatedAt(val OptCreatedAt) { + s.CreatedAt = val +} + +type RankingOrderBy string + +const ( + RankingOrderByLatest RankingOrderBy = "latest" + RankingOrderByHighest RankingOrderBy = "highest" +) + +// AllValues returns all RankingOrderBy values. +func (RankingOrderBy) AllValues() []RankingOrderBy { + return []RankingOrderBy{ + RankingOrderByLatest, + RankingOrderByHighest, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s RankingOrderBy) MarshalText() ([]byte, error) { + switch s { + case RankingOrderByLatest: + return []byte(s), nil + case RankingOrderByHighest: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *RankingOrderBy) UnmarshalText(data []byte) error { + switch RankingOrderBy(data) { + case RankingOrderByLatest: + *s = RankingOrderByLatest + return nil + case RankingOrderByHighest: + *s = RankingOrderByHighest + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +// Status=running のベンチマーク結果. +// Ref: #/components/schemas/RunningBenchmark +type RunningBenchmark struct { + ID BenchmarkId `json:"id"` + InstanceId InstanceId `json:"instanceId"` + TeamId TeamId `json:"teamId"` + UserId UserId `json:"userId"` + Status RunningBenchmarkStatus `json:"status"` + Score Score `json:"score"` + CreatedAt CreatedAt `json:"createdAt"` + StartedAt StartedAt `json:"startedAt"` +} + +// GetID returns the value of ID. +func (s *RunningBenchmark) GetID() BenchmarkId { + return s.ID +} + +// GetInstanceId returns the value of InstanceId. +func (s *RunningBenchmark) GetInstanceId() InstanceId { + return s.InstanceId +} + +// GetTeamId returns the value of TeamId. +func (s *RunningBenchmark) GetTeamId() TeamId { + return s.TeamId +} + +// GetUserId returns the value of UserId. +func (s *RunningBenchmark) GetUserId() UserId { + return s.UserId +} + +// GetStatus returns the value of Status. +func (s *RunningBenchmark) GetStatus() RunningBenchmarkStatus { + return s.Status +} + +// GetScore returns the value of Score. +func (s *RunningBenchmark) GetScore() Score { + return s.Score +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *RunningBenchmark) GetCreatedAt() CreatedAt { + return s.CreatedAt +} + +// GetStartedAt returns the value of StartedAt. +func (s *RunningBenchmark) GetStartedAt() StartedAt { + return s.StartedAt +} + +// SetID sets the value of ID. +func (s *RunningBenchmark) SetID(val BenchmarkId) { + s.ID = val +} + +// SetInstanceId sets the value of InstanceId. +func (s *RunningBenchmark) SetInstanceId(val InstanceId) { + s.InstanceId = val +} + +// SetTeamId sets the value of TeamId. +func (s *RunningBenchmark) SetTeamId(val TeamId) { + s.TeamId = val +} + +// SetUserId sets the value of UserId. +func (s *RunningBenchmark) SetUserId(val UserId) { + s.UserId = val +} + +// SetStatus sets the value of Status. +func (s *RunningBenchmark) SetStatus(val RunningBenchmarkStatus) { + s.Status = val +} + +// SetScore sets the value of Score. +func (s *RunningBenchmark) SetScore(val Score) { + s.Score = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *RunningBenchmark) SetCreatedAt(val CreatedAt) { + s.CreatedAt = val +} + +// SetStartedAt sets the value of StartedAt. +func (s *RunningBenchmark) SetStartedAt(val StartedAt) { + s.StartedAt = val +} + +type RunningBenchmarkStatus string + +const ( + RunningBenchmarkStatusRunning RunningBenchmarkStatus = "running" +) + +// AllValues returns all RunningBenchmarkStatus values. +func (RunningBenchmarkStatus) AllValues() []RunningBenchmarkStatus { + return []RunningBenchmarkStatus{ + RunningBenchmarkStatusRunning, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s RunningBenchmarkStatus) MarshalText() ([]byte, error) { + switch s { + case RunningBenchmarkStatusRunning: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *RunningBenchmarkStatus) UnmarshalText(data []byte) error { + switch RunningBenchmarkStatus(data) { + case RunningBenchmarkStatusRunning: + *s = RunningBenchmarkStatusRunning + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + type Score float64 type StartedAt time.Time @@ -1430,8 +1869,10 @@ type Team struct { ID TeamId `json:"id"` Name TeamName `json:"name"` // チームに所属している部員のID. - Members []UserId `json:"members"` - CreatedAt time.Time `json:"createdAt"` + Members []UserId `json:"members"` + // チームに所属している部員のGitHub ID. + GithubIds []GitHubId `json:"githubIds"` + CreatedAt time.Time `json:"createdAt"` } // GetID returns the value of ID. @@ -1449,6 +1890,11 @@ func (s *Team) GetMembers() []UserId { return s.Members } +// GetGithubIds returns the value of GithubIds. +func (s *Team) GetGithubIds() []GitHubId { + return s.GithubIds +} + // GetCreatedAt returns the value of CreatedAt. func (s *Team) GetCreatedAt() time.Time { return s.CreatedAt @@ -1469,6 +1915,11 @@ func (s *Team) SetMembers(val []UserId) { s.Members = val } +// SetGithubIds sets the value of GithubIds. +func (s *Team) SetGithubIds(val []GitHubId) { + s.GithubIds = val +} + // SetCreatedAt sets the value of CreatedAt. func (s *Team) SetCreatedAt(val time.Time) { s.CreatedAt = val @@ -1496,6 +1947,34 @@ type TeamId uuid.UUID type TeamName string +// チームのスコア一覧。. +// Ref: #/components/schemas/TeamScores +type TeamScores struct { + TeamId TeamId `json:"teamId"` + // CreatedAtの昇順. + Scores []BenchScore `json:"scores"` +} + +// GetTeamId returns the value of TeamId. +func (s *TeamScores) GetTeamId() TeamId { + return s.TeamId +} + +// GetScores returns the value of Scores. +func (s *TeamScores) GetScores() []BenchScore { + return s.Scores +} + +// SetTeamId sets the value of TeamId. +func (s *TeamScores) SetTeamId(val TeamId) { + s.TeamId = val +} + +// SetScores sets the value of Scores. +func (s *TeamScores) SetScores(val []BenchScore) { + s.Scores = val +} + type Unauthorized struct { Message OptString `json:"message"` } @@ -1515,19 +1994,24 @@ func (*Unauthorized) deleteTeamInstanceRes() {} func (*Unauthorized) getBenchmarkQueueRes() {} func (*Unauthorized) getBenchmarkResultRes() {} func (*Unauthorized) getBenchmarksRes() {} +func (*Unauthorized) getDocsRes() {} func (*Unauthorized) getInstancesRes() {} func (*Unauthorized) getMeRes() {} +func (*Unauthorized) getRankingRes() {} +func (*Unauthorized) getScoresRes() {} func (*Unauthorized) getTeamBenchmarkResultRes() {} func (*Unauthorized) getTeamBenchmarksRes() {} func (*Unauthorized) getTeamInstancesRes() {} func (*Unauthorized) getTeamRes() {} func (*Unauthorized) getTeamsRes() {} func (*Unauthorized) getUsersRes() {} +func (*Unauthorized) patchDocsRes() {} func (*Unauthorized) patchTeamInstanceRes() {} func (*Unauthorized) patchTeamRes() {} func (*Unauthorized) postBenchmarkRes() {} func (*Unauthorized) postOauth2LogoutRes() {} func (*Unauthorized) postTeamRes() {} +func (*Unauthorized) putAdminsRes() {} // 部員. // Ref: #/components/schemas/User @@ -1598,3 +2082,108 @@ func (s *UserAuth) SetAPIKey(val string) { type UserId uuid.UUID type UserName string + +// Status=waiting のベンチマーク結果. +// Ref: #/components/schemas/WaitingBenchmark +type WaitingBenchmark struct { + ID BenchmarkId `json:"id"` + InstanceId InstanceId `json:"instanceId"` + TeamId TeamId `json:"teamId"` + UserId UserId `json:"userId"` + Status WaitingBenchmarkStatus `json:"status"` + CreatedAt CreatedAt `json:"createdAt"` +} + +// GetID returns the value of ID. +func (s *WaitingBenchmark) GetID() BenchmarkId { + return s.ID +} + +// GetInstanceId returns the value of InstanceId. +func (s *WaitingBenchmark) GetInstanceId() InstanceId { + return s.InstanceId +} + +// GetTeamId returns the value of TeamId. +func (s *WaitingBenchmark) GetTeamId() TeamId { + return s.TeamId +} + +// GetUserId returns the value of UserId. +func (s *WaitingBenchmark) GetUserId() UserId { + return s.UserId +} + +// GetStatus returns the value of Status. +func (s *WaitingBenchmark) GetStatus() WaitingBenchmarkStatus { + return s.Status +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *WaitingBenchmark) GetCreatedAt() CreatedAt { + return s.CreatedAt +} + +// SetID sets the value of ID. +func (s *WaitingBenchmark) SetID(val BenchmarkId) { + s.ID = val +} + +// SetInstanceId sets the value of InstanceId. +func (s *WaitingBenchmark) SetInstanceId(val InstanceId) { + s.InstanceId = val +} + +// SetTeamId sets the value of TeamId. +func (s *WaitingBenchmark) SetTeamId(val TeamId) { + s.TeamId = val +} + +// SetUserId sets the value of UserId. +func (s *WaitingBenchmark) SetUserId(val UserId) { + s.UserId = val +} + +// SetStatus sets the value of Status. +func (s *WaitingBenchmark) SetStatus(val WaitingBenchmarkStatus) { + s.Status = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *WaitingBenchmark) SetCreatedAt(val CreatedAt) { + s.CreatedAt = val +} + +type WaitingBenchmarkStatus string + +const ( + WaitingBenchmarkStatusWaiting WaitingBenchmarkStatus = "waiting" +) + +// AllValues returns all WaitingBenchmarkStatus values. +func (WaitingBenchmarkStatus) AllValues() []WaitingBenchmarkStatus { + return []WaitingBenchmarkStatus{ + WaitingBenchmarkStatusWaiting, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s WaitingBenchmarkStatus) MarshalText() ([]byte, error) { + switch s { + case WaitingBenchmarkStatusWaiting: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *WaitingBenchmarkStatus) UnmarshalText(data []byte) error { + switch WaitingBenchmarkStatus(data) { + case WaitingBenchmarkStatusWaiting: + *s = WaitingBenchmarkStatusWaiting + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} diff --git a/server/handler/openapi/oas_validators_gen.go b/server/handler/openapi/oas_validators_gen.go index 413d2f2..44e4de8 100644 --- a/server/handler/openapi/oas_validators_gen.go +++ b/server/handler/openapi/oas_validators_gen.go @@ -10,35 +10,17 @@ import ( "github.com/ogen-go/ogen/validate" ) -func (s *Benchmark) Validate() error { +func (s *BenchScore) Validate() error { if s == nil { return validate.ErrNilPointer } var failures []validate.FieldError if err := func() error { - if err := s.Status.Validate(); err != nil { + if err := s.Score.Validate(); err != nil { return err } return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "status", - Error: err, - }) - } - if err := func() error { - if value, ok := s.Score.Get(); ok { - if err := func() error { - if err := value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } - } - return nil }(); err != nil { failures = append(failures, validate.FieldError{ Name: "score", @@ -51,31 +33,64 @@ func (s *Benchmark) Validate() error { return nil } -func (s *BenchmarkAdminResult) Validate() error { - if s == nil { - return validate.ErrNilPointer +func (s Benchmark) Validate() error { + switch s.Type { + case WaitingBenchmarkBenchmark: + if err := s.WaitingBenchmark.Validate(); err != nil { + return err + } + return nil + case RunningBenchmarkBenchmark: + if err := s.RunningBenchmark.Validate(); err != nil { + return err + } + return nil + case FinishedBenchmarkBenchmark: + if err := s.FinishedBenchmark.Validate(); err != nil { + return err + } + return nil + default: + return errors.Errorf("invalid type %q", s.Type) } +} - var failures []validate.FieldError - if err := func() error { - if err := s.Status.Validate(); err != nil { +func (s BenchmarkAdminResult) Validate() error { + switch s.Type { + case WaitingBenchmarkBenchmarkAdminResult: + if err := s.WaitingBenchmark.Validate(); err != nil { return err } return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "status", - Error: err, - }) + case RunningBenchmarkBenchmarkAdminResult: + if err := s.RunningBenchmark.Validate(); err != nil { + return err + } + return nil + case FinishedBenchmarkBenchmarkAdminResult: + if err := s.FinishedBenchmark.Validate(); err != nil { + return err + } + return nil + default: + return errors.Errorf("invalid type %q", s.Type) } +} + +func (s *BenchmarkListItem) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError if err := func() error { - if err := s.Score.Validate(); err != nil { + if err := s.OneOf.Validate(); err != nil { return err } return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "score", + Name: "OneOf", Error: err, }) } @@ -85,7 +100,42 @@ func (s *BenchmarkAdminResult) Validate() error { return nil } -func (s *BenchmarkResult) Validate() error { +func (s BenchmarkListItemSum) Validate() error { + switch s.Type { + case WaitingBenchmarkBenchmarkListItemSum: + if err := s.WaitingBenchmark.Validate(); err != nil { + return err + } + return nil + case RunningBenchmarkBenchmarkListItemSum: + if err := s.RunningBenchmark.Validate(); err != nil { + return err + } + return nil + case FinishedBenchmarkBenchmarkListItemSum: + if err := s.FinishedBenchmark.Validate(); err != nil { + return err + } + return nil + default: + return errors.Errorf("invalid type %q", s.Type) + } +} + +func (s BenchmarkStatus) Validate() error { + switch s { + case "waiting": + return nil + case "running": + return nil + case "finished": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *FinishedBenchmark) Validate() error { if s == nil { return validate.ErrNilPointer } @@ -119,12 +169,8 @@ func (s *BenchmarkResult) Validate() error { return nil } -func (s BenchmarkStatus) Validate() error { +func (s FinishedBenchmarkStatus) Validate() error { switch s { - case "waiting": - return nil - case "running": - return nil case "finished": return nil default: @@ -133,7 +179,7 @@ func (s BenchmarkStatus) Validate() error { } func (s GetBenchmarkQueueOKApplicationJSON) Validate() error { - alias := ([]Benchmark)(s) + alias := ([]BenchmarkListItem)(s) if alias == nil { return errors.New("nil is invalid value") } @@ -158,7 +204,7 @@ func (s GetBenchmarkQueueOKApplicationJSON) Validate() error { } func (s GetBenchmarksOKApplicationJSON) Validate() error { - alias := ([]Benchmark)(s) + alias := ([]BenchmarkListItem)(s) if alias == nil { return errors.New("nil is invalid value") } @@ -207,8 +253,58 @@ func (s GetInstancesOKApplicationJSON) Validate() error { return nil } +func (s GetRankingOKApplicationJSON) Validate() error { + alias := ([]RankingItem)(s) + if alias == nil { + return errors.New("nil is invalid value") + } + var failures []validate.FieldError + for i, elem := range alias { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s GetScoresOKApplicationJSON) Validate() error { + alias := ([]TeamScores)(s) + if alias == nil { + return errors.New("nil is invalid value") + } + var failures []validate.FieldError + for i, elem := range alias { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + func (s GetTeamBenchmarksOKApplicationJSON) Validate() error { - alias := ([]Benchmark)(s) + alias := ([]BenchmarkListItem)(s) if alias == nil { return errors.New("nil is invalid value") } @@ -333,6 +429,17 @@ func (s *Instance) Validate() error { return nil } +func (s InstanceOperation) Validate() error { + switch s { + case "start": + return nil + case "stop": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s InstanceStatus) Validate() error { switch s { case "building": @@ -353,20 +460,13 @@ func (s *PatchTeamInstanceReq) Validate() error { var failures []validate.FieldError if err := func() error { - if value, ok := s.Status.Get(); ok { - if err := func() error { - if err := value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } + if err := s.Operation.Validate(); err != nil { + return err } return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "status", + Name: "operation", Error: err, }) } @@ -398,6 +498,22 @@ func (s *PatchTeamReq) Validate() error { Error: err, }) } + if err := func() error { + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 3, + MaxLengthSet: true, + }).ValidateLength(len(s.GithubIds)); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "githubIds", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } @@ -435,6 +551,83 @@ func (s *PostTeamReq) Validate() error { return nil } +func (s *RankingItem) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Score.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "score", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s RankingOrderBy) Validate() error { + switch s { + case "latest": + return nil + case "highest": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *RunningBenchmark) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Status.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "status", + Error: err, + }) + } + if err := func() error { + if err := s.Score.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "score", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s RunningBenchmarkStatus) Validate() error { + switch s { + case "running": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s Score) Validate() error { alias := (float64)(s) if err := (validate.Float{}).Validate(float64(alias)); err != nil { @@ -468,8 +661,96 @@ func (s *Team) Validate() error { Error: err, }) } + if err := func() error { + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 3, + MaxLengthSet: true, + }).ValidateLength(len(s.GithubIds)); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "githubIds", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *TeamScores) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.Scores == nil { + return errors.New("nil is invalid value") + } + var failures []validate.FieldError + for i, elem := range s.Scores { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "scores", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *WaitingBenchmark) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Status.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "status", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } + +func (s WaitingBenchmarkStatus) Validate() error { + switch s { + case "waiting": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +}