Skip to content

Support Cross-Technologies Unit & API Specifications #31

@haimkastner

Description

@haimkastner

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions