Skip to content

Mixed array of custom type #101

@matte0080

Description

@matte0080
export class ActivityEventVisibilityRequest {
  @IsNumber({
    maxDecimalPlaces: 0,
  })
  @IsDefined()
  version: number;

  @ValidateNested({ each: true })
  @Type(() => ActivityEvent, {
    keepDiscriminatorProperty: true,
    discriminator: {
      property: 'name',
      subTypes: [
        { value: ActivityEventVisibility, name: EActivityType.VISIBILITY },
        { value: ActivityEventCiccio, name: EActivityType.TEST },
      ],
    },
  })

  @JSONSchema({
    type: 'array',
    items: {
      anyOf: [
        {
          $ref: '#/components/schemas/ActivityEventCiccio',
        },
        { $ref: '#/components/schemas/ActivityEventVisibility' },
      ],
    },
  })
  events: ActivityEvent[];
}

ActivityEventVisibility e ActivityEventCiccio are subclass of ActivityEvent. In OpenApi doc i see this.

Screenshot 2023-02-07 alle 13 38 27

What i need to do for see ActivityEventVisibility e ActivityEventCiccio in events: ActivityEvent[]; type? Actually i see ActivityEvent in schema space and in example area.

In debug i see this. I think it is wrong.
Screenshot 2023-02-07 alle 13 42 25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions