You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Request related
As part of the powerful and wide support in multiple languages in the unit definition, I think it can be cool to standardize the way how unit is represented in the API spec, and how it will be exposed/loaded.
Implementing in all UnitsNet-based libraries a similar API DTO to load/expose and the same JSON schema standard of how the unit is represented, will give the benefits of:
Work with UnitsNet across various technologies transparently without any kind of manual conversions.
Standart way how to represent units in API schemas.
Clear OpenAPI specification (and automatically in case the spec is generated from the code object declarations)
Human readable unit representation in the API schema, and easy to work with anyway.
See also haimkastner/unitsnet-js#29 for real-world, probably common use-case between C# backend and TypeScript frontend.
// Create a Length unit objectconstlength=Length.FromMeters(100.01);// Obtain the DTO object, represented by the default unit - meterconstlengthDto: LengthDto=length.toDto();// {"value":100.01,"unit":"Meter"}// Obtain Length object from lengthDtoconstnewLength: Length=Length.FromDto(lengthDto);
# Create a Length unit objectlength=Length.from_meters(100.01)
# Obtain the DTO object as json, represented by the default unit - meterlength_dto_json=length.to_dto_json() # {"value":100.01,"unit":"Meter"}# Load JSON to DTO, and loadlength_from_dto=Length.from_dto_json(length_dto_json)
Describe alternatives you've considered
To do it manually.
Is your feature request related to a problem? Please describe.
Request related
As part of the powerful and wide support in multiple languages in the unit definition, I think it can be cool to standardize the way how unit is represented in the API spec, and how it will be exposed/loaded.
Implementing in all UnitsNet-based libraries a similar API DTO to load/expose and the same JSON schema standard of how the unit is represented, will give the benefits of:
See also haimkastner/unitsnet-js#29 for real-world, probably common use-case between C# backend and TypeScript frontend.
Currently, sterilizing is supported in the library, but not as a common, standard, unit dedicated and easy-to-use API.
Describe the solution you'd like
The JSON standart DTO will look like this:
As part of the full JSON API payload something like:
See an OpenAPI unitsnet-openapi-spec example schema.
A basic and naive prototype of how it will be in C#
A similar implementation I have created for the JS package haimkastner/unitsnet-js#32 & haimkastner/unitsnet-py#18
TypeScript usage (docs)
Similar for the Python package (docs):
Describe alternatives you've considered
To do it manually.
Additional context
See an example of the Python Length implementation of the DTO class and the unit API example
The text was updated successfully, but these errors were encountered: