'use strict'; /* Shared response schemas (JSON-schema subset), referenced from route meta as { $ref: 'Name' } and emitted into * openapi.json components. Responses are documentation (and checked by test/api-contract.test.js), not enforced at runtime. */ const int = { type: 'integer' }; const num = { type: 'number' }; const str = { type: 'string' }; const bool = { type: 'boolean' }; const obj = (properties, required) => ({ type: 'object', properties, required: required || Object.keys(properties), additionalProperties: true }); const arr = (items) => ({ type: 'array', items }); const Cost = obj({ fiber: int, hardware: int, capital: int }); const schemas = { Cost, Error: obj({ serverTime: int, error: obj({ code: str, message: str, details: { type: 'object', additionalProperties: true } }) }), World: obj({ id: int, name: str, speed: num, mapRadius: int, seed: int, startAt: int, endAt: { type: ['integer', 'null'] }, status: str, preset: str }), TownSummary: obj({ id: int, name: str, x: int, y: int, isCapital: bool }), Operator: obj({ id: int, name: str, asNumber: int, allianceId: { type: ['integer', 'null'] }, protectionUntil: int, world: { $ref: 'World' }, towns: arr({ $ref: 'TownSummary' }) }), Me: obj({ serverTime: int, user: obj({ id: int, username: str, createdAt: int }), operators: arr({ $ref: 'Operator' }) }), AuthResult: obj({ serverTime: int, token: str, tokenId: int, user: obj({ id: int, username: str }), operators: arr({ $ref: 'Operator' }) }), Token: obj({ id: int, device: str, createdAt: int, lastUsedAt: int, current: bool }), BuildPlan: obj({ ok: bool, code: { type: ['string', 'null'] }, toLevel: int, cost: { $ref: 'Cost' }, durationMs: int, missing: arr(obj({ type: str, level: int, have: int })) }, ['ok', 'code', 'toLevel']), BuildingView: obj({ key: str, type: str, kind: str, level: int, maxLevel: int, next: { $ref: 'BuildPlan' } }), QueueEntry: obj({ id: int, key: str, type: str, toLevel: int, startedAt: int, dueAt: int }), ResourceView: obj({ amount: num, rate: num, cap: num }), Town: obj({ id: int, name: str, x: int, y: int, isCapital: bool, ownerId: int, worldId: int, loyalty: num, footprint: num, footprintPerDay: num, resources: obj({ fiber: { $ref: 'ResourceView' }, hardware: { $ref: 'ResourceView' }, capital: { $ref: 'ResourceView' } }), power: obj({ out: num, draw: num, net: num, buffer: num, bufferCap: num, bufferRate: num, online: bool }), buildings: arr({ $ref: 'BuildingView' }), queue: arr({ $ref: 'QueueEntry' }), queueSlots: int, bonus: obj({ fiber: num, hardware: num, capital: num }), }), TownResponse: obj({ serverTime: int, town: { $ref: 'Town' } }), MapTown: obj({ id: int, name: str, x: int, y: int, isCapital: bool, owner: obj({ id: int, name: str, asNumber: int, allianceId: { type: ['integer', 'null'] }, protected: bool }) }), MapSpecial: obj({ x: int, y: int, type: str, bonus: { type: ['string', 'null'] } }), MapResponse: obj({ serverTime: int, world: { $ref: 'World' }, bounds: obj({ x0: int, x1: int, y0: int, y1: int }), specials: arr({ $ref: 'MapSpecial' }), towns: arr({ $ref: 'MapTown' }) }), BuildResult: obj({ serverTime: int, eventId: int, key: str, type: str, toLevel: int, startedAt: int, dueAt: int, cost: { $ref: 'Cost' } }), Notification: obj({ id: int, type: str, worldId: { type: ['integer', 'null'] }, payload: { type: 'object', additionalProperties: true }, createdAt: int, readAt: { type: ['integer', 'null'] } }), NotificationList: obj({ serverTime: int, items: arr({ $ref: 'Notification' }), next: { type: ['integer', 'null'] } }), Ok: obj({ serverTime: int }), }; module.exports = { schemas, int, num, str, bool, obj, arr };