dynamicItemAttributes.jsonl
Schema
_key
(required): integer
Range: 47297 .. 85698-
attributeIDs
(required): array of object_key
(required): integer
Range: 6 .. 2347highIsGood
: integer
Range: 0 .. 1max
(required): number
Range: 0.875 .. 3min
(required): number
Range: 0.55 .. 1.4
-
inputOutputMapping
(required): array of objectapplicableTypes
(required): array of integer
Type:integer
Range: 377 .. 88721resultingType
(required): integer
Range: 47408 .. 84445
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var dynamicItemAttribute = DynamicItemAttribute.FromJson(jsonString);
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class DynamicItemAttribute
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("attributeIDs")]
public AttributeId[] AttributeIDs { get; set; }
[JsonProperty("inputOutputMapping")]
public InputOutputMapping[] InputOutputMapping { get; set; }
}
public partial class AttributeId
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("highIsGood", NullValueHandling = NullValueHandling.Ignore)]
public long? HighIsGood { get; set; }
[JsonProperty("max")]
[JsonConverter(typeof(PurpleMinMaxValueCheckConverter))]
public double Max { get; set; }
[JsonProperty("min")]
[JsonConverter(typeof(FluffyMinMaxValueCheckConverter))]
public double Min { get; set; }
}
public partial class InputOutputMapping
{
[JsonProperty("applicableTypes")]
public long[] ApplicableTypes { get; set; }
[JsonProperty("resultingType")]
public long ResultingType { get; set; }
}
public partial class DynamicItemAttribute
{
public static DynamicItemAttribute FromJson(string json) => JsonConvert.DeserializeObject<DynamicItemAttribute>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this DynamicItemAttribute 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 >= 0.875 && value <= 3)
{
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 >= 0.875 && value <= 3)
{
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 >= 0.55 && value <= 1.4)
{
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 >= 0.55 && value <= 1.4)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly FluffyMinMaxValueCheckConverter Singleton = new FluffyMinMaxValueCheckConverter();
}
}
// 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:
//
// dynamicItemAttribute, err := UnmarshalDynamicItemAttribute(bytes)
// bytes, err = dynamicItemAttribute.Marshal()
package model
import "encoding/json"
func UnmarshalDynamicItemAttribute(data []byte) (DynamicItemAttribute, error) {
var r DynamicItemAttribute
err := json.Unmarshal(data, &r)
return r, err
}
func (r *DynamicItemAttribute) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type DynamicItemAttribute struct {
Key int64 `json:"_key"`
AttributeIDs []AttributeID `json:"attributeIDs"`
InputOutputMapping []InputOutputMapping `json:"inputOutputMapping"`
}
type AttributeID struct {
Key int64 `json:"_key"`
HighIsGood *int64 `json:"highIsGood,omitempty"`
Max float64 `json:"max"`
Min float64 `json:"min"`
}
type InputOutputMapping struct {
ApplicableTypes []int64 `json:"applicableTypes"`
ResultingType int64 `json:"resultingType"`
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"_key": {
"type": "integer",
"minimum": 47297,
"maximum": 85698
},
"attributeIDs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"_key": {
"type": "integer",
"minimum": 6,
"maximum": 2347
},
"highIsGood": {
"type": "integer",
"minimum": 0,
"maximum": 1
},
"max": {
"type": "number",
"minimum": 0.875,
"maximum": 3.0
},
"min": {
"type": "number",
"minimum": 0.55,
"maximum": 1.4
}
},
"required": [
"_key",
"max",
"min"
]
},
"minItems": 2,
"maxItems": 8
},
"inputOutputMapping": {
"type": "array",
"items": {
"type": "object",
"properties": {
"applicableTypes": {
"type": "array",
"items": {
"type": "integer",
"minimum": 377,
"maximum": 88721
},
"minItems": 2,
"maxItems": 44
},
"resultingType": {
"type": "integer",
"minimum": 47408,
"maximum": 84445
}
},
"required": [
"applicableTypes",
"resultingType"
]
},
"minItems": 1,
"maxItems": 1
}
},
"required": [
"_key",
"attributeIDs",
"inputOutputMapping"
]
}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val dynamicItemAttribute = json.parse(DynamicItemAttribute.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class DynamicItemAttribute (
@SerialName("_key")
val key: Long,
val attributeIDs: List<AttributeId>,
val inputOutputMapping: List<InputOutputMapping>
)
@Serializable
data class AttributeId (
@SerialName("_key")
val key: Long,
val highIsGood: Long? = null,
val max: Double,
val min: Double
)
@Serializable
data class InputOutputMapping (
val applicableTypes: List<Long>,
val resultingType: Long
)
<?php
// This is a autogenerated file:DynamicItemAttribute
class DynamicItemAttribute {
private int $key; // json:_key Required
private array $attributeIDs; // json:attributeIDs Required
private array $inputOutputMapping; // json:inputOutputMapping Required
/**
* @param int $key
* @param array $attributeIDs
* @param array $inputOutputMapping
*/
public function __construct(int $key, array $attributeIDs, array $inputOutputMapping) {
$this->key = $key;
$this->attributeIDs = $attributeIDs;
$this->inputOutputMapping = $inputOutputMapping;
}
/**
* @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 (DynamicItemAttribute::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this DynamicItemAttribute::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:DynamicItemAttribute::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (DynamicItemAttribute::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey DynamicItemAttribute::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param array $value
* @throws Exception
* @return array
*/
public static function fromAttributeIDs(array $value): array {
return array_map(function ($value) {
return AttributeId::from($value); /*class*/
}, $value);
}
/**
* @throws Exception
* @return array
*/
public function toAttributeIDs(): array {
if (DynamicItemAttribute::validateAttributeIDs($this->attributeIDs)) {
return array_map(function ($value) {
return $value->to(); /*class*/
}, $this->attributeIDs);
}
throw new Exception('never get to this DynamicItemAttribute::attributeIDs');
}
/**
* @param array
* @return bool
* @throws Exception
*/
public static function validateAttributeIDs(array $value): bool {
if (!is_array($value)) {
throw new Exception("Attribute Error:DynamicItemAttribute::attributeIDs");
}
array_walk($value, function($value_v) {
$value_v->validate();
});
return true;
}
/**
* @throws Exception
* @return array
*/
public function getAttributeIDs(): array {
if (DynamicItemAttribute::validateAttributeIDs($this->attributeIDs)) {
return $this->attributeIDs;
}
throw new Exception('never get to getAttributeIDs DynamicItemAttribute::attributeIDs');
}
/**
* @return array
*/
public static function sampleAttributeIDs(): array {
return array(
AttributeId::sample() /*32:*/
); /* 32:attributeIDs*/
}
/**
* @param array $value
* @throws Exception
* @return array
*/
public static function fromInputOutputMapping(array $value): array {
return array_map(function ($value) {
return InputOutputMapping::from($value); /*class*/
}, $value);
}
/**
* @throws Exception
* @return array
*/
public function toInputOutputMapping(): array {
if (DynamicItemAttribute::validateInputOutputMapping($this->inputOutputMapping)) {
return array_map(function ($value) {
return $value->to(); /*class*/
}, $this->inputOutputMapping);
}
throw new Exception('never get to this DynamicItemAttribute::inputOutputMapping');
}
/**
* @param array
* @return bool
* @throws Exception
*/
public static function validateInputOutputMapping(array $value): bool {
if (!is_array($value)) {
throw new Exception("Attribute Error:DynamicItemAttribute::inputOutputMapping");
}
array_walk($value, function($value_v) {
$value_v->validate();
});
return true;
}
/**
* @throws Exception
* @return array
*/
public function getInputOutputMapping(): array {
if (DynamicItemAttribute::validateInputOutputMapping($this->inputOutputMapping)) {
return $this->inputOutputMapping;
}
throw new Exception('never get to getInputOutputMapping DynamicItemAttribute::inputOutputMapping');
}
/**
* @return array
*/
public static function sampleInputOutputMapping(): array {
return array(
InputOutputMapping::sample() /*33:*/
); /* 33:inputOutputMapping*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return DynamicItemAttribute::validateKey($this->key)
|| DynamicItemAttribute::validateAttributeIDs($this->attributeIDs)
|| DynamicItemAttribute::validateInputOutputMapping($this->inputOutputMapping);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'attributeIDs'} = $this->toAttributeIDs();
$out->{'inputOutputMapping'} = $this->toInputOutputMapping();
return $out;
}
/**
* @param stdClass $obj
* @return DynamicItemAttribute
* @throws Exception
*/
public static function from(stdClass $obj): DynamicItemAttribute {
return new DynamicItemAttribute(
DynamicItemAttribute::fromKey($obj->{'_key'})
,DynamicItemAttribute::fromAttributeIDs($obj->{'attributeIDs'})
,DynamicItemAttribute::fromInputOutputMapping($obj->{'inputOutputMapping'})
);
}
/**
* @return DynamicItemAttribute
*/
public static function sample(): DynamicItemAttribute {
return new DynamicItemAttribute(
DynamicItemAttribute::sampleKey()
,DynamicItemAttribute::sampleAttributeIDs()
,DynamicItemAttribute::sampleInputOutputMapping()
);
}
}
// This is a autogenerated file:AttributeId
class AttributeId {
private int $key; // json:_key Required
private ?int $highIsGood; // json:highIsGood Optional
private float $max; // json:max Required
private float $min; // json:min Required
/**
* @param int $key
* @param int|null $highIsGood
* @param float $max
* @param float $min
*/
public function __construct(int $key, ?int $highIsGood, float $max, float $min) {
$this->key = $key;
$this->highIsGood = $highIsGood;
$this->max = $max;
$this->min = $min;
}
/**
* @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 (AttributeId::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this AttributeId::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:AttributeId::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (AttributeId::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey AttributeId::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param ?int $value
* @throws Exception
* @return ?int
*/
public static function fromHighIsGood(?int $value): ?int {
if (!is_null($value)) {
return $value; /*int*/
} else {
return null;
}
}
/**
* @throws Exception
* @return ?int
*/
public function toHighIsGood(): ?int {
if (AttributeId::validateHighIsGood($this->highIsGood)) {
if (!is_null($this->highIsGood)) {
return $this->highIsGood; /*int*/
} else {
return null;
}
}
throw new Exception('never get to this AttributeId::highIsGood');
}
/**
* @param int|null
* @return bool
* @throws Exception
*/
public static function validateHighIsGood(?int $value): bool {
if (!is_null($value)) {
if (!is_integer($value)) {
throw new Exception("Attribute Error:AttributeId::highIsGood");
}
}
return true;
}
/**
* @throws Exception
* @return ?int
*/
public function getHighIsGood(): ?int {
if (AttributeId::validateHighIsGood($this->highIsGood)) {
return $this->highIsGood;
}
throw new Exception('never get to getHighIsGood AttributeId::highIsGood');
}
/**
* @return ?int
*/
public static function sampleHighIsGood(): ?int {
return 32; /*32:highIsGood*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromMax(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toMax(): float {
if (AttributeId::validateMax($this->max)) {
return $this->max; /*float*/
}
throw new Exception('never get to this AttributeId::max');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateMax(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:AttributeId::max");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getMax(): float {
if (AttributeId::validateMax($this->max)) {
return $this->max;
}
throw new Exception('never get to getMax AttributeId::max');
}
/**
* @return float
*/
public static function sampleMax(): float {
return 33.033; /*33:max*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromMin(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toMin(): float {
if (AttributeId::validateMin($this->min)) {
return $this->min; /*float*/
}
throw new Exception('never get to this AttributeId::min');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateMin(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:AttributeId::min");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getMin(): float {
if (AttributeId::validateMin($this->min)) {
return $this->min;
}
throw new Exception('never get to getMin AttributeId::min');
}
/**
* @return float
*/
public static function sampleMin(): float {
return 34.034; /*34:min*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return AttributeId::validateKey($this->key)
|| AttributeId::validateHighIsGood($this->highIsGood)
|| AttributeId::validateMax($this->max)
|| AttributeId::validateMin($this->min);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'highIsGood'} = $this->toHighIsGood();
$out->{'max'} = $this->toMax();
$out->{'min'} = $this->toMin();
return $out;
}
/**
* @param stdClass $obj
* @return AttributeId
* @throws Exception
*/
public static function from(stdClass $obj): AttributeId {
return new AttributeId(
AttributeId::fromKey($obj->{'_key'})
,AttributeId::fromHighIsGood($obj->{'highIsGood'})
,AttributeId::fromMax($obj->{'max'})
,AttributeId::fromMin($obj->{'min'})
);
}
/**
* @return AttributeId
*/
public static function sample(): AttributeId {
return new AttributeId(
AttributeId::sampleKey()
,AttributeId::sampleHighIsGood()
,AttributeId::sampleMax()
,AttributeId::sampleMin()
);
}
}
// This is a autogenerated file:InputOutputMapping
class InputOutputMapping {
private array $applicableTypes; // json:applicableTypes Required
private int $resultingType; // json:resultingType Required
/**
* @param array $applicableTypes
* @param int $resultingType
*/
public function __construct(array $applicableTypes, int $resultingType) {
$this->applicableTypes = $applicableTypes;
$this->resultingType = $resultingType;
}
/**
* @param array $value
* @throws Exception
* @return array
*/
public static function fromApplicableTypes(array $value): array {
return array_map(function ($value) {
return $value; /*int*/
}, $value);
}
/**
* @throws Exception
* @return array
*/
public function toApplicableTypes(): array {
if (InputOutputMapping::validateApplicableTypes($this->applicableTypes)) {
return array_map(function ($value) {
return $value; /*int*/
}, $this->applicableTypes);
}
throw new Exception('never get to this InputOutputMapping::applicableTypes');
}
/**
* @param array
* @return bool
* @throws Exception
*/
public static function validateApplicableTypes(array $value): bool {
if (!is_array($value)) {
throw new Exception("Attribute Error:InputOutputMapping::applicableTypes");
}
array_walk($value, function($value_v) {
if (!is_integer($value_v)) {
throw new Exception("Attribute Error:InputOutputMapping::applicableTypes");
}
});
return true;
}
/**
* @throws Exception
* @return array
*/
public function getApplicableTypes(): array {
if (InputOutputMapping::validateApplicableTypes($this->applicableTypes)) {
return $this->applicableTypes;
}
throw new Exception('never get to getApplicableTypes InputOutputMapping::applicableTypes');
}
/**
* @return array
*/
public static function sampleApplicableTypes(): array {
return array(
31 /*31:*/
); /* 31:applicableTypes*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromResultingType(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toResultingType(): int {
if (InputOutputMapping::validateResultingType($this->resultingType)) {
return $this->resultingType; /*int*/
}
throw new Exception('never get to this InputOutputMapping::resultingType');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateResultingType(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:InputOutputMapping::resultingType");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getResultingType(): int {
if (InputOutputMapping::validateResultingType($this->resultingType)) {
return $this->resultingType;
}
throw new Exception('never get to getResultingType InputOutputMapping::resultingType');
}
/**
* @return int
*/
public static function sampleResultingType(): int {
return 32; /*32:resultingType*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return InputOutputMapping::validateApplicableTypes($this->applicableTypes)
|| InputOutputMapping::validateResultingType($this->resultingType);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'applicableTypes'} = $this->toApplicableTypes();
$out->{'resultingType'} = $this->toResultingType();
return $out;
}
/**
* @param stdClass $obj
* @return InputOutputMapping
* @throws Exception
*/
public static function from(stdClass $obj): InputOutputMapping {
return new InputOutputMapping(
InputOutputMapping::fromApplicableTypes($obj->{'applicableTypes'})
,InputOutputMapping::fromResultingType($obj->{'resultingType'})
);
}
/**
* @return InputOutputMapping
*/
public static function sample(): InputOutputMapping {
return new InputOutputMapping(
InputOutputMapping::sampleApplicableTypes()
,InputOutputMapping::sampleResultingType()
);
}
}
from typing import Optional, Any, List, TypeVar, Callable, Type, cast
T = TypeVar("T")
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_none(x: Any) -> Any:
assert x is None
return x
def from_union(fs, x):
for f in fs:
try:
return f(x)
except:
pass
assert False
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 from_list(f: Callable[[Any], T], x: Any) -> List[T]:
assert isinstance(x, list)
return [f(y) for y in x]
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
class AttributeID:
key: int
high_is_good: Optional[int]
max: float
min: float
def __init__(self, key: int, high_is_good: Optional[int], max: float, min: float) -> None:
self.key = key
self.high_is_good = high_is_good
self.max = max
self.min = min
@staticmethod
def from_dict(obj: Any) -> 'AttributeID':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
high_is_good = from_union([from_int, from_none], obj.get("highIsGood"))
max = from_float(obj.get("max"))
min = from_float(obj.get("min"))
return AttributeID(key, high_is_good, max, min)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
if self.high_is_good is not None:
result["highIsGood"] = from_union([from_int, from_none], self.high_is_good)
result["max"] = to_float(self.max)
result["min"] = to_float(self.min)
return result
class InputOutputMapping:
applicable_types: List[int]
resulting_type: int
def __init__(self, applicable_types: List[int], resulting_type: int) -> None:
self.applicable_types = applicable_types
self.resulting_type = resulting_type
@staticmethod
def from_dict(obj: Any) -> 'InputOutputMapping':
assert isinstance(obj, dict)
applicable_types = from_list(from_int, obj.get("applicableTypes"))
resulting_type = from_int(obj.get("resultingType"))
return InputOutputMapping(applicable_types, resulting_type)
def to_dict(self) -> dict:
result: dict = {}
result["applicableTypes"] = from_list(from_int, self.applicable_types)
result["resultingType"] = from_int(self.resulting_type)
return result
class DynamicItemAttribute:
key: int
attribute_i_ds: List[AttributeID]
input_output_mapping: List[InputOutputMapping]
def __init__(self, key: int, attribute_i_ds: List[AttributeID], input_output_mapping: List[InputOutputMapping]) -> None:
self.key = key
self.attribute_i_ds = attribute_i_ds
self.input_output_mapping = input_output_mapping
@staticmethod
def from_dict(obj: Any) -> 'DynamicItemAttribute':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
attribute_i_ds = from_list(AttributeID.from_dict, obj.get("attributeIDs"))
input_output_mapping = from_list(InputOutputMapping.from_dict, obj.get("inputOutputMapping"))
return DynamicItemAttribute(key, attribute_i_ds, input_output_mapping)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["attributeIDs"] = from_list(lambda x: to_class(AttributeID, x), self.attribute_i_ds)
result["inputOutputMapping"] = from_list(lambda x: to_class(InputOutputMapping, x), self.input_output_mapping)
return result
def dynamic_item_attribute_from_dict(s: Any) -> DynamicItemAttribute:
return DynamicItemAttribute.from_dict(s)
def dynamic_item_attribute_to_dict(x: DynamicItemAttribute) -> Any:
return to_class(DynamicItemAttribute, x)
// To parse this data:
//
// import { Convert, DynamicItemAttribute } from "./file";
//
// const dynamicItemAttribute = Convert.toDynamicItemAttribute(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface DynamicItemAttribute {
_key: number;
attributeIDs: AttributeId[];
inputOutputMapping: InputOutputMapping[];
[property: string]: any;
}
export interface AttributeId {
_key: number;
highIsGood?: number;
max: number;
min: number;
[property: string]: any;
}
export interface InputOutputMapping {
applicableTypes: number[];
resultingType: 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 toDynamicItemAttribute(json: string): DynamicItemAttribute {
return cast(JSON.parse(json), r("DynamicItemAttribute"));
}
public static dynamicItemAttributeToJson(value: DynamicItemAttribute): string {
return JSON.stringify(uncast(value, r("DynamicItemAttribute")), 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 = {
"DynamicItemAttribute": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "attributeIDs", js: "attributeIDs", typ: a(r("AttributeId")) },
{ json: "inputOutputMapping", js: "inputOutputMapping", typ: a(r("InputOutputMapping")) },
], "any"),
"AttributeId": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "highIsGood", js: "highIsGood", typ: u(undefined, 0) },
{ json: "max", js: "max", typ: 3.14 },
{ json: "min", js: "min", typ: 3.14 },
], "any"),
"InputOutputMapping": o([
{ json: "applicableTypes", js: "applicableTypes", typ: a(0) },
{ json: "resultingType", js: "resultingType", typ: 0 },
], "any"),
};