As part of the powerful and wide support in multiple languages in the unit definition, I think it will be a good idea to standardize the way how unit is represented in an API spec, and how it will be exposed/loaded.
The API object should look similar to:
export interface LengthDto {
value: number;
unit: LengthUnits;
}
And this is also how it will be represented in the OpenAPI specification.
The JSON will look like this:
{
"value":100.01,
"unit":"Meter"
}
As part of the full JSON payload something like:
{
"someInfo":"someValue",
"someInfoLength":{
"value":100.01,
"unit":"Meter"
}
}
Any unit class will have an API to expose and load it:
export interface LengthDto {
value: number;
unit: LengthUnits;
}
export class Length {
...
...
public toDto(holdInUnit: LengthUnits = LengthUnits.Meters): LengthDto {
return {
value: this.convert(holdInUnit),
unit: holdInUnit
} ;
}
public static fromDto(dtoLength: LengthDto): Length {
return new Length(dtoLength.value, dtoLength.unit);
}
}
See also #29 for motivation
As part of the powerful and wide support in multiple languages in the unit definition, I think it will be a good idea to standardize the way how unit is represented in an API spec, and how it will be exposed/loaded.
The API object should look similar to:
And this is also how it will be represented in the OpenAPI specification.
The JSON will look like this:
{ "value":100.01, "unit":"Meter" }As part of the full JSON payload something like:
{ "someInfo":"someValue", "someInfoLength":{ "value":100.01, "unit":"Meter" } }Any unit class will have an API to expose and load it:
See also #29 for motivation