microsoft / typespec

https://typespec.io/
MIT License
4.1k stars 194 forks source link

Encoding numeric as string #3856

Closed lmazuel closed 1 month ago

lmazuel commented 1 month ago

Proposed changed signature for decorator

extern dec encode(
  target: Scalar | ModelProperty,
  encoding: string | EnumMember,
  encodedAs?: Scalar
);
extern dec encode2(target: Scalar | ModelProperty, encodedAs: Scalar);
extern dec encode2(
  target: Scalar | ModelProperty,
  encodingOrEncodedAs: string | EnumMember | Scalar,
  encodedAs?: Scalar
);

And then you can call

@encode(string) val: int64

restrict this overload format to only numeric scalar types and string as the encodeAs

Changes:

timotheeguerin commented 1 month ago

Would also be good to decide if string is the right key.

MaryGao commented 1 month ago

Similar issue with https://github.com/microsoft/typespec/issues/2762