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

fix: rule required options #1000

Merged
merged 8 commits into from
Jun 10, 2021
Merged

fix: rule required options #1000

merged 8 commits into from
Jun 10, 2021

Conversation

stone-jin
Copy link
Member

@stone-jin stone-jin commented Apr 20, 2021

修改1:

it('check with check with options', () => {
    class WorldDTO {
      @Rule(RuleType.number().max(20))
      age: number;
    }

    class UserDTO {
      @Rule(RuleType.number().max(10))
      age: number;

      @Rule(WorldDTO, {required: false})
      world?: WorldDTO;
    }

    class Hello {
      @Validate()
      school(a, data: UserDTO) {
        return data;
      }
    }
    const user = {
      age: 10
    };
    const result = new Hello().school(1, user);
    assert.deepEqual(result, user);
  });

支持world是非必须的情况

修改2:

it('check with check allowUnknown', () => {
    class UserDTO {
      @Rule(RuleType.number().max(10))
      age: number;

      world: string;
    }

    class Hello {
      @Validate()
      school(a, data: UserDTO) {
        return data;
      }
    }
    const user = {
      age: 10,
      world: '123'
    };
    const result = new Hello().school(1, user);
    assert.deepEqual(result, user);
  });

原先多填了world参数,会报world不能填的情况。

@gitpod-io
Copy link

gitpod-io bot commented Apr 20, 2021

@codecov-commenter
Copy link

codecov-commenter commented Apr 20, 2021

Codecov Report

Merging #1000 (6bbf0d7) into 2.x (53d85a9) will increase coverage by 0.42%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              2.x    #1000      +/-   ##
==========================================
+ Coverage   85.75%   86.17%   +0.42%     
==========================================
  Files         213      221       +8     
  Lines        8190     9743    +1553     
  Branches     1600     2035     +435     
==========================================
+ Hits         7023     8396    +1373     
- Misses       1120     1285     +165     
- Partials       47       62      +15     
Impacted Files Coverage Δ
packages/decorator/src/annotation/rule.ts 100.00% <100.00%> (ø)
packages/prometheus/src/configuration.ts 77.04% <0.00%> (-22.96%) ⬇️
packages/logger/src/container.ts 45.54% <0.00%> (-4.46%) ⬇️
packages/core/src/service/configService.ts 95.12% <0.00%> (-2.29%) ⬇️
packages/web-koa/src/framework.ts 73.75% <0.00%> (-1.25%) ⬇️
packages/web-express/src/framework.ts 71.55% <0.00%> (-1.18%) ⬇️
packages/socketio/src/framework.ts 87.71% <0.00%> (-1.17%) ⬇️
packages/faas/src/framework.ts 75.15% <0.00%> (-0.95%) ⬇️
packages/core/src/baseFramework.ts 94.29% <0.00%> (-0.86%) ⬇️
...ckages-serverless/runtime-engine/src/lib/parser.ts 95.00% <0.00%> (-0.66%) ⬇️
... and 45 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53d85a9...6bbf0d7. Read the comment docs.

@czy88840616 czy88840616 changed the title Fix/rule required options fix: rule required options Apr 20, 2021
@czy88840616 czy88840616 added the type: question / discussion This issue or pull request need be discussion label Apr 21, 2021
@gitpod-io
Copy link

gitpod-io bot commented May 20, 2021

@czy88840616 czy88840616 merged commit d76e9f7 into 2.x Jun 10, 2021
@czy88840616 czy88840616 deleted the fix/rule-required-options branch June 10, 2021 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question / discussion This issue or pull request need be discussion
Development

Successfully merging this pull request may close these issues.

3 participants