Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom validator generate invalid output #91

Open
exejutable opened this issue Sep 13, 2021 · 0 comments
Open

Custom validator generate invalid output #91

exejutable opened this issue Sep 13, 2021 · 0 comments

Comments

@exejutable
Copy link

A custom decorator breaks the generation of the spec

export function IsResourceExist(resourceManager: any, key?: string) {
  return function resourceExist(object: Object, propertyName: string) {
    registerDecorator({
      name: 'IsResourceExist',
      target: object.constructor,
      propertyName,
      validator: {
        async validate(value: any): Promise<boolean> {
          let exist = true;

          if (value) {
            let manager: find = Container.get(resourceManager);
           
            await manager.find(new Pagination({ [key || 'id']: value }));
          
          }

          return exist;
        },
      }
    });
  };
}

class Example {
  @IsNumber({}, { each: true })
  @IsArray()
  @JSONSchema({
    description: 'Payment gateways ID',
    example: [1, 2],
  })
  @IsResourceExist(PaymentGatewayManager)
  payment_gateways: number[]

}

this returns in the yaml

   Example :
      properties:
        payment_gateways:
          $ref: '#/components/schemas/Array'
          items:
            type: number
          type: array
          description: Payment gateways ID
          example:
            - 1
            - 2

If i remove the custom decorator, the documentation is generated as spected

   Example :
      properties:
        payment_gateways:
          items:
            type: number
          type: array
          description: Payment gateways ID
          example:
            - 1
            - 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant