samchon / typia

Super-fast/easy runtime validations and serializations through transformation

Home Page:https://typia.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Protobuff serialization/deserialization - Array enums should be supported as they are in .proto

ShanonJackson opened this issue Β· comments

πŸ“ Summary

Write a short summary of the bug in here.

  • Typia Version: @latest
  • Expected behavior: Enum arrays supported in typia.
  • Actual behavior: Enum arrays not supported in typia.

Write detailed description in here.

Given the follow .proto type.

message MovieReleaseTypeCriteria {
  enum MovieReleaseType {
    WIDE_THEATRICAL_RELEASE = 0;
    LIMITED_THEATRICAL_RELEASE = 1;
    HOME_ENTERTAINMENT_STREAMING_ONLY_RELEASE = 2;
  }
  repeated MovieReleaseType releaseTypes = 1;
}

The generated Typescript code models this type correctly.

  enum MovieReleaseType {
    WIDE_THEATRICAL_RELEASE = 0,
    LIMITED_THEATRICAL_RELEASE = 1,
    HOME_ENTERTAINMENT_STREAMING_ONLY_RELEASE = 2,
  }

interface IMovie {
  release: Array<MovieReleaseType>
}
typia.protobuf.encode<IMovie>({
  release: [MovieReleaseType.WIDE_THEATRICAL_RELEASE]
})

Trying to produce serialize/deserialize this type with typia results in the following error:

"does not support union type in array"

This can be fixed by creating separate models for typia AND the .proto representation; I want my enums to work application side so I create a separate type with release: Array<number>. However the ideal behavior is that when Typia discovers an Array of a single type union (all strings or all numbers or a string enum or number enum) then it should simplify the resolution to follow Array or Array semantics.

Without this it makes Typia significantly harder to use because it's purpose is to avoid double declaration, However to use .proto I need to declare multiple types to get typia working properly.

⏯ Playground Link

https://typia.io/playground

Visit above playground and write code occuring the bug.

After that, copy and paste link address of that.

Example Link

> https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDOAzKERwERIqp4DcAUGcAHYwCmUGqAxrXAJICytIARvXAG8ycEXAD0AKglxhouNIACGaCFTwAruuAATGXPli9onQC44AZxhRqAc3KyRk6Q5GLlUVfG6pgAGyOiEoYu3n5mltZUdhRyTi7ycAqErFo08Yog1KDquABMAAzpibQAHky+6ubAAG60HKgl2bgAjPmF+kEuqDa0ZlQ5fFDkcmCoULQ0Zpzcg3AAPnD9vr7DokwAFn7a41RTXLz0ANoAuuQAvhRiYgC0t9dkV+wAyg83d2SEaAB0TONqtGxzAAeaYHKAAPgAFABKchAA

πŸ’» Code occuring the bug

import typia, { tags } from "typia";

  enum MovieReleaseType {
    WIDE_THEATRICAL_RELEASE = 0,
    LIMITED_THEATRICAL_RELEASE = 1,
    HOME_ENTERTAINMENT_STREAMING_ONLY_RELEASE = 2,
  }

interface IMovie {
  release: Array<MovieReleaseType>
}

typia.protobuf.encode<IMovie>({
  release: [MovieReleaseType.WIDE_THEATRICAL_RELEASE]
})

I have missed the enum array type.

Will fix it at tommorow. Thanks fot reporting.

Upgrade to v5.5.4, then be fixed.

@samchon absolute legend what a turnaround.

Have some more proto related tickets so will create them here. I'm building a gRPC client for node as hopefully a better successor to grpc-js and planning on utilizing typia.