mapStargates.jsonl
Schema
_key
(required): integer
Range: 50000001 .. 50016569-
destination
(required): objectsolarSystemID
(required): integer
Range: 30000001 .. 30100000stargateID
(required): integer
Range: 50000001 .. 50016569
-
position
(required): objectx
(required): number
Range: -14632731648000 .. 18455964426240y
(required): number
Range: -19609206743040 .. 16239381749760z
(required): number
Range: -19210384957440 .. 19550170030080
-
solarSystemID
(required): integer
Range: 30000001 .. 30100000 typeID
(required): integer
Range: 16 .. 78266
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var mapStargate = MapStargate.FromJson(jsonString);
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class MapStargate
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("destination")]
public Destination Destination { get; set; }
[JsonProperty("position")]
public Position Position { get; set; }
[JsonProperty("solarSystemID")]
public long SolarSystemId { get; set; }
[JsonProperty("typeID")]
public long TypeId { get; set; }
}
public partial class Destination
{
[JsonProperty("solarSystemID")]
public long SolarSystemId { get; set; }
[JsonProperty("stargateID")]
public long StargateId { get; set; }
}
public partial class Position
{
[JsonProperty("x")]
[JsonConverter(typeof(PurpleMinMaxValueCheckConverter))]
public double X { get; set; }
[JsonProperty("y")]
[JsonConverter(typeof(FluffyMinMaxValueCheckConverter))]
public double Y { get; set; }
[JsonProperty("z")]
[JsonConverter(typeof(TentacledMinMaxValueCheckConverter))]
public double Z { get; set; }
}
public partial class MapStargate
{
public static MapStargate FromJson(string json) => JsonConvert.DeserializeObject<MapStargate>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this MapStargate self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class PurpleMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= -14632731648000 && value <= 18455964426240)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= -14632731648000 && value <= 18455964426240)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly PurpleMinMaxValueCheckConverter Singleton = new PurpleMinMaxValueCheckConverter();
}
internal class FluffyMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= -19609206743040 && value <= 16239381749760)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= -19609206743040 && value <= 16239381749760)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly FluffyMinMaxValueCheckConverter Singleton = new FluffyMinMaxValueCheckConverter();
}
internal class TentacledMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= -19210384957440 && value <= 19550170030080)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= -19210384957440 && value <= 19550170030080)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly TentacledMinMaxValueCheckConverter Singleton = new TentacledMinMaxValueCheckConverter();
}
}
// Code generated from JSON Schema using quicktype. DO NOT EDIT.
// To parse and unparse this JSON data, add this code to your project and do:
//
// mapStargate, err := UnmarshalMapStargate(bytes)
// bytes, err = mapStargate.Marshal()
package model
import "encoding/json"
func UnmarshalMapStargate(data []byte) (MapStargate, error) {
var r MapStargate
err := json.Unmarshal(data, &r)
return r, err
}
func (r *MapStargate) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type MapStargate struct {
Key int64 `json:"_key"`
Destination Destination `json:"destination"`
Position Position `json:"position"`
SolarSystemID int64 `json:"solarSystemID"`
TypeID int64 `json:"typeID"`
}
type Destination struct {
SolarSystemID int64 `json:"solarSystemID"`
StargateID int64 `json:"stargateID"`
}
type Position struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"_key": {
"type": "integer",
"minimum": 50000001,
"maximum": 50016569
},
"destination": {
"type": "object",
"properties": {
"solarSystemID": {
"type": "integer",
"minimum": 30000001,
"maximum": 30100000
},
"stargateID": {
"type": "integer",
"minimum": 50000001,
"maximum": 50016569
}
},
"required": [
"solarSystemID",
"stargateID"
]
},
"position": {
"type": "object",
"properties": {
"x": {
"type": "number",
"minimum": -1.4632731648E13,
"maximum": 1.845596442624E13
},
"y": {
"type": "number",
"minimum": -1.960920674304E13,
"maximum": 1.623938174976E13
},
"z": {
"type": "number",
"minimum": -1.921038495744E13,
"maximum": 1.955017003008E13
}
},
"required": [
"x",
"y",
"z"
]
},
"solarSystemID": {
"type": "integer",
"minimum": 30000001,
"maximum": 30100000
},
"typeID": {
"type": "integer",
"minimum": 16,
"maximum": 78266
}
},
"required": [
"_key",
"destination",
"position",
"solarSystemID",
"typeID"
]
}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val mapStargate = json.parse(MapStargate.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class MapStargate (
@SerialName("_key")
val key: Long,
val destination: Destination,
val position: Position,
@SerialName("solarSystemID")
val solarSystemId: Long,
@SerialName("typeID")
val typeId: Long
)
@Serializable
data class Destination (
@SerialName("solarSystemID")
val solarSystemId: Long,
@SerialName("stargateID")
val stargateId: Long
)
@Serializable
data class Position (
val x: Double,
val y: Double,
val z: Double
)
<?php
// This is a autogenerated file:MapStargate
class MapStargate {
private int $key; // json:_key Required
private Destination $destination; // json:destination Required
private Position $position; // json:position Required
private int $solarSystemId; // json:solarSystemID Required
private int $typeId; // json:typeID Required
/**
* @param int $key
* @param Destination $destination
* @param Position $position
* @param int $solarSystemId
* @param int $typeId
*/
public function __construct(int $key, Destination $destination, Position $position, int $solarSystemId, int $typeId) {
$this->key = $key;
$this->destination = $destination;
$this->position = $position;
$this->solarSystemId = $solarSystemId;
$this->typeId = $typeId;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromKey(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toKey(): int {
if (MapStargate::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this MapStargate::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStargate::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (MapStargate::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey MapStargate::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param stdClass $value
* @throws Exception
* @return Destination
*/
public static function fromDestination(stdClass $value): Destination {
return Destination::from($value); /*class*/
}
/**
* @throws Exception
* @return stdClass
*/
public function toDestination(): stdClass {
if (MapStargate::validateDestination($this->destination)) {
return $this->destination->to(); /*class*/
}
throw new Exception('never get to this MapStargate::destination');
}
/**
* @param Destination
* @return bool
* @throws Exception
*/
public static function validateDestination(Destination $value): bool {
$value->validate();
return true;
}
/**
* @throws Exception
* @return Destination
*/
public function getDestination(): Destination {
if (MapStargate::validateDestination($this->destination)) {
return $this->destination;
}
throw new Exception('never get to getDestination MapStargate::destination');
}
/**
* @return Destination
*/
public static function sampleDestination(): Destination {
return Destination::sample(); /*32:destination*/
}
/**
* @param stdClass $value
* @throws Exception
* @return Position
*/
public static function fromPosition(stdClass $value): Position {
return Position::from($value); /*class*/
}
/**
* @throws Exception
* @return stdClass
*/
public function toPosition(): stdClass {
if (MapStargate::validatePosition($this->position)) {
return $this->position->to(); /*class*/
}
throw new Exception('never get to this MapStargate::position');
}
/**
* @param Position
* @return bool
* @throws Exception
*/
public static function validatePosition(Position $value): bool {
$value->validate();
return true;
}
/**
* @throws Exception
* @return Position
*/
public function getPosition(): Position {
if (MapStargate::validatePosition($this->position)) {
return $this->position;
}
throw new Exception('never get to getPosition MapStargate::position');
}
/**
* @return Position
*/
public static function samplePosition(): Position {
return Position::sample(); /*33:position*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromSolarSystemId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toSolarSystemId(): int {
if (MapStargate::validateSolarSystemId($this->solarSystemId)) {
return $this->solarSystemId; /*int*/
}
throw new Exception('never get to this MapStargate::solarSystemId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateSolarSystemId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStargate::solarSystemId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getSolarSystemId(): int {
if (MapStargate::validateSolarSystemId($this->solarSystemId)) {
return $this->solarSystemId;
}
throw new Exception('never get to getSolarSystemId MapStargate::solarSystemId');
}
/**
* @return int
*/
public static function sampleSolarSystemId(): int {
return 34; /*34:solarSystemId*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromTypeId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toTypeId(): int {
if (MapStargate::validateTypeId($this->typeId)) {
return $this->typeId; /*int*/
}
throw new Exception('never get to this MapStargate::typeId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateTypeId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStargate::typeId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getTypeId(): int {
if (MapStargate::validateTypeId($this->typeId)) {
return $this->typeId;
}
throw new Exception('never get to getTypeId MapStargate::typeId');
}
/**
* @return int
*/
public static function sampleTypeId(): int {
return 35; /*35:typeId*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return MapStargate::validateKey($this->key)
|| MapStargate::validateDestination($this->destination)
|| MapStargate::validatePosition($this->position)
|| MapStargate::validateSolarSystemId($this->solarSystemId)
|| MapStargate::validateTypeId($this->typeId);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'destination'} = $this->toDestination();
$out->{'position'} = $this->toPosition();
$out->{'solarSystemID'} = $this->toSolarSystemId();
$out->{'typeID'} = $this->toTypeId();
return $out;
}
/**
* @param stdClass $obj
* @return MapStargate
* @throws Exception
*/
public static function from(stdClass $obj): MapStargate {
return new MapStargate(
MapStargate::fromKey($obj->{'_key'})
,MapStargate::fromDestination($obj->{'destination'})
,MapStargate::fromPosition($obj->{'position'})
,MapStargate::fromSolarSystemId($obj->{'solarSystemID'})
,MapStargate::fromTypeId($obj->{'typeID'})
);
}
/**
* @return MapStargate
*/
public static function sample(): MapStargate {
return new MapStargate(
MapStargate::sampleKey()
,MapStargate::sampleDestination()
,MapStargate::samplePosition()
,MapStargate::sampleSolarSystemId()
,MapStargate::sampleTypeId()
);
}
}
// This is a autogenerated file:Destination
class Destination {
private int $solarSystemId; // json:solarSystemID Required
private int $stargateId; // json:stargateID Required
/**
* @param int $solarSystemId
* @param int $stargateId
*/
public function __construct(int $solarSystemId, int $stargateId) {
$this->solarSystemId = $solarSystemId;
$this->stargateId = $stargateId;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromSolarSystemId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toSolarSystemId(): int {
if (Destination::validateSolarSystemId($this->solarSystemId)) {
return $this->solarSystemId; /*int*/
}
throw new Exception('never get to this Destination::solarSystemId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateSolarSystemId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Destination::solarSystemId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getSolarSystemId(): int {
if (Destination::validateSolarSystemId($this->solarSystemId)) {
return $this->solarSystemId;
}
throw new Exception('never get to getSolarSystemId Destination::solarSystemId');
}
/**
* @return int
*/
public static function sampleSolarSystemId(): int {
return 31; /*31:solarSystemId*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromStargateId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toStargateId(): int {
if (Destination::validateStargateId($this->stargateId)) {
return $this->stargateId; /*int*/
}
throw new Exception('never get to this Destination::stargateId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateStargateId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Destination::stargateId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getStargateId(): int {
if (Destination::validateStargateId($this->stargateId)) {
return $this->stargateId;
}
throw new Exception('never get to getStargateId Destination::stargateId');
}
/**
* @return int
*/
public static function sampleStargateId(): int {
return 32; /*32:stargateId*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Destination::validateSolarSystemId($this->solarSystemId)
|| Destination::validateStargateId($this->stargateId);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'solarSystemID'} = $this->toSolarSystemId();
$out->{'stargateID'} = $this->toStargateId();
return $out;
}
/**
* @param stdClass $obj
* @return Destination
* @throws Exception
*/
public static function from(stdClass $obj): Destination {
return new Destination(
Destination::fromSolarSystemId($obj->{'solarSystemID'})
,Destination::fromStargateId($obj->{'stargateID'})
);
}
/**
* @return Destination
*/
public static function sample(): Destination {
return new Destination(
Destination::sampleSolarSystemId()
,Destination::sampleStargateId()
);
}
}
// This is a autogenerated file:Position
class Position {
private float $x; // json:x Required
private float $y; // json:y Required
private float $z; // json:z Required
/**
* @param float $x
* @param float $y
* @param float $z
*/
public function __construct(float $x, float $y, float $z) {
$this->x = $x;
$this->y = $y;
$this->z = $z;
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromX(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toX(): float {
if (Position::validateX($this->x)) {
return $this->x; /*float*/
}
throw new Exception('never get to this Position::x');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateX(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Position::x");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getX(): float {
if (Position::validateX($this->x)) {
return $this->x;
}
throw new Exception('never get to getX Position::x');
}
/**
* @return float
*/
public static function sampleX(): float {
return 31.031; /*31:x*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromY(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toY(): float {
if (Position::validateY($this->y)) {
return $this->y; /*float*/
}
throw new Exception('never get to this Position::y');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateY(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Position::y");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getY(): float {
if (Position::validateY($this->y)) {
return $this->y;
}
throw new Exception('never get to getY Position::y');
}
/**
* @return float
*/
public static function sampleY(): float {
return 32.032; /*32:y*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromZ(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toZ(): float {
if (Position::validateZ($this->z)) {
return $this->z; /*float*/
}
throw new Exception('never get to this Position::z');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateZ(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Position::z");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getZ(): float {
if (Position::validateZ($this->z)) {
return $this->z;
}
throw new Exception('never get to getZ Position::z');
}
/**
* @return float
*/
public static function sampleZ(): float {
return 33.033; /*33:z*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Position::validateX($this->x)
|| Position::validateY($this->y)
|| Position::validateZ($this->z);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'x'} = $this->toX();
$out->{'y'} = $this->toY();
$out->{'z'} = $this->toZ();
return $out;
}
/**
* @param stdClass $obj
* @return Position
* @throws Exception
*/
public static function from(stdClass $obj): Position {
return new Position(
Position::fromX($obj->{'x'})
,Position::fromY($obj->{'y'})
,Position::fromZ($obj->{'z'})
);
}
/**
* @return Position
*/
public static function sample(): Position {
return new Position(
Position::sampleX()
,Position::sampleY()
,Position::sampleZ()
);
}
}
from typing import Any, TypeVar, Type, cast
T = TypeVar("T")
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_float(x: Any) -> float:
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x)
def to_float(x: Any) -> float:
assert isinstance(x, (int, float))
return x
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
class Destination:
solar_system_id: int
stargate_id: int
def __init__(self, solar_system_id: int, stargate_id: int) -> None:
self.solar_system_id = solar_system_id
self.stargate_id = stargate_id
@staticmethod
def from_dict(obj: Any) -> 'Destination':
assert isinstance(obj, dict)
solar_system_id = from_int(obj.get("solarSystemID"))
stargate_id = from_int(obj.get("stargateID"))
return Destination(solar_system_id, stargate_id)
def to_dict(self) -> dict:
result: dict = {}
result["solarSystemID"] = from_int(self.solar_system_id)
result["stargateID"] = from_int(self.stargate_id)
return result
class Position:
x: float
y: float
z: float
def __init__(self, x: float, y: float, z: float) -> None:
self.x = x
self.y = y
self.z = z
@staticmethod
def from_dict(obj: Any) -> 'Position':
assert isinstance(obj, dict)
x = from_float(obj.get("x"))
y = from_float(obj.get("y"))
z = from_float(obj.get("z"))
return Position(x, y, z)
def to_dict(self) -> dict:
result: dict = {}
result["x"] = to_float(self.x)
result["y"] = to_float(self.y)
result["z"] = to_float(self.z)
return result
class MapStargate:
key: int
destination: Destination
position: Position
solar_system_id: int
type_id: int
def __init__(self, key: int, destination: Destination, position: Position, solar_system_id: int, type_id: int) -> None:
self.key = key
self.destination = destination
self.position = position
self.solar_system_id = solar_system_id
self.type_id = type_id
@staticmethod
def from_dict(obj: Any) -> 'MapStargate':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
destination = Destination.from_dict(obj.get("destination"))
position = Position.from_dict(obj.get("position"))
solar_system_id = from_int(obj.get("solarSystemID"))
type_id = from_int(obj.get("typeID"))
return MapStargate(key, destination, position, solar_system_id, type_id)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["destination"] = to_class(Destination, self.destination)
result["position"] = to_class(Position, self.position)
result["solarSystemID"] = from_int(self.solar_system_id)
result["typeID"] = from_int(self.type_id)
return result
def map_stargate_from_dict(s: Any) -> MapStargate:
return MapStargate.from_dict(s)
def map_stargate_to_dict(x: MapStargate) -> Any:
return to_class(MapStargate, x)
// To parse this data:
//
// import { Convert, MapStargate } from "./file";
//
// const mapStargate = Convert.toMapStargate(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface MapStargate {
_key: number;
destination: Destination;
position: Position;
solarSystemID: number;
typeID: number;
[property: string]: any;
}
export interface Destination {
solarSystemID: number;
stargateID: number;
[property: string]: any;
}
export interface Position {
x: number;
y: number;
z: number;
[property: string]: any;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toMapStargate(json: string): MapStargate {
return cast(JSON.parse(json), r("MapStargate"));
}
public static mapStargateToJson(value: MapStargate): string {
return JSON.stringify(uncast(value, r("MapStargate")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"MapStargate": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "destination", js: "destination", typ: r("Destination") },
{ json: "position", js: "position", typ: r("Position") },
{ json: "solarSystemID", js: "solarSystemID", typ: 0 },
{ json: "typeID", js: "typeID", typ: 0 },
], "any"),
"Destination": o([
{ json: "solarSystemID", js: "solarSystemID", typ: 0 },
{ json: "stargateID", js: "stargateID", typ: 0 },
], "any"),
"Position": o([
{ json: "x", js: "x", typ: 3.14 },
{ json: "y", js: "y", typ: 3.14 },
{ json: "z", js: "z", typ: 3.14 },
], "any"),
};