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

Add support for simple object pattern in schema #356

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danilvalov
Copy link

Related issues: #351 #352

@danilvalov danilvalov changed the title Add support for simple pattern Add support for simple object pattern in schema Aug 17, 2023
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Patch coverage: 90.00% and project coverage change: -0.22% ⚠️

Comparison is base (94fb293) 98.67% compared to head (ffbe3cb) 98.45%.

❗ Current head ffbe3cb differs from pull request most recent head 78b4d8d. Consider uploading reports for the commit 78b4d8d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #356      +/-   ##
==========================================
- Coverage   98.67%   98.45%   -0.22%     
==========================================
  Files           9        9              
  Lines         529      519      -10     
  Branches      203      199       -4     
==========================================
- Hits          522      511      -11     
- Misses          7        8       +1     
Files Changed Coverage Δ
src/parse.ts 96.92% <90.00%> (-0.49%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mrjono1
Copy link
Owner

mrjono1 commented Aug 17, 2023

Looks good, a few people are going to be happy with this

@@ -65,28 +65,6 @@ export interface TestSchema {
}`);
});

test('`pattern(Joi.string(), Joi.number())`', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if these removed tests are kept? this may cause regression for some people

Copy link
Author

@danilvalov danilvalov Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrjono1
There are the following problems with supporting old tests:

 FAIL  src/__tests__/unknown.ts (11.936 s)
  ● test `Joi.unknown()` › `pattern(Joi.string(), Joi.number())`

    expect(received).toBe(expected) // Object.is equality

    - Expected  - 4
    + Received  + 1

      /**
       * a test schema definition
       */
      export interface TestSchema {
        name?: string;
    -   /**
    -    * Number Property
    -    */
    -   [x: string]: number;
    +   [pattern: string]: number;
      }

      76 |     const result = convertSchema({ sortPropertiesByName: false }, schema);
      77 |     expect(result).not.toBeUndefined;
    > 78 |     expect(result?.content).toBe(`/**
         |                             ^
      79 |  * a test schema definition
      80 |  */
      81 | export interface TestSchema {

      at Object.<anonymous> (src/__tests__/unknown.ts:78:29)

  ● test `Joi.unknown()` › `pattern(Joi.string(), Joi.AnySchema())`

    expect(received).toBe(expected) // Object.is equality

    - Expected  - 1
    + Received  + 1

      /**
       * a test schema definition
       */
      export interface TestSchema {
    -   [x: string]: {
    +   [pattern: string]: {
          id: string;
        }[];
      }

      123 |     const result = convertSchema({}, schema);
      124 |     expect(result).not.toBeUndefined;
    > 125 |     expect(result?.content).toBe(`/**
          |                             ^
      126 |  * a test schema definition
      127 |  */
      128 | export interface TestSchema {

      at Object.<anonymous> (src/__tests__/unknown.ts:125:29)

Patterns change this generation logic and we get a new output schema

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

Successfully merging this pull request may close these issues.

None yet

2 participants