Cysharp / MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
MIT License
3.68k stars 417 forks source link

Can't lunch Swagger if I use Vector2 for the communication #755

Open locus84 opened 2 months ago

locus84 commented 2 months ago
  [MessagePackObject]
  public struct Vector2
  {
      public static readonly Vector2 zero = new Vector2(0, 0);
      public static readonly Vector2 up = new Vector2(0, 1);

      [Key(0)]
      public float x { get; set; }
      [Key(1)]
      public float y { get; set; }

      [SerializationConstructor]
      public Vector2(float x, float y)
      {
          this.x = x;
          this.y = y;
      }

      public static Vector2 right = new Vector2(1f, 0);

      [IgnoreMember, JsonIgnore]
      public Vector2 normalized => new Vector2(this.x / this.magnitude, this.y / this.magnitude); //if I comment out this member, it works
  }

above is part of my Vector2 struct on server. When I use this structure data transfer, everything works fine except swagger.

async UnaryResult<bool> ShipFreeMoved(Vector2 pos);

above is my function signature that breaks swagger.

image image

Imo, it looks like swagger trying to serialize the 'normalized' parameter even it's taged with Ignored/JsonIgnore.