Skip to content

Object schema without#160

Merged
aboutlo merged 3 commits intofastify:masterfrom
victortosts:object-schema-without
Jan 10, 2022
Merged

Object schema without#160
aboutlo merged 3 commits intofastify:masterfrom
victortosts:object-schema-without

Conversation

@victortosts
Copy link
Contributor

This pull request adds 'without' method to ObjectSchema;

Sometimes when you have a large Fluent Schema becomes difficult to reuse it selecting only some of its properties. It makes more sense to reuse by removing properties you don't want to keep.

Example:

const S = require('fluent-json-schema')
const personSchema = S.object()
  .prop('id', S.string().format('uuid'))
  .prop('name', S.string())
  .prop('age', S.number())
  .prop('gender', S.string())
  .prop(
            'address',
            S.object()
              .prop('city', S.string())
              .prop('street', S.string())
              .prop('zipCode', S.string())
          )
  .prop('profession', S.string())
  .prop('createdAt', S.string().format('time'))
  .prop('updatedAt', S.string().format('time'))

// looks better
const bodySchema = personSchema.without(['createdAt', 'updatedAt'])

// then this
const bodySchema = personSchema.only(['id', 'name', 'age', 'gender', 'address', 'profession'])

image

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1669904525

  • 0 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 99.57%

Totals Coverage Status
Change from base Build 1555567555: 0.002%
Covered Lines: 423
Relevant Lines: 423

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jan 8, 2022

Pull Request Test Coverage Report for Build 1669904525

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 99.57%

Totals Coverage Status
Change from base Build 1555567555: 0.002%
Covered Lines: 423
Relevant Lines: 423

💛 - Coveralls

@aboutlo aboutlo merged commit 88f72dd into fastify:master Jan 10, 2022
@aboutlo
Copy link
Collaborator

aboutlo commented Jan 10, 2022

tks @victortostes-hotmart for this!

@victortosts victortosts deleted the object-schema-without branch January 10, 2022 22:51
@coveralls
Copy link

coveralls commented Nov 30, 2024

Pull Request Test Coverage Report for Build 1669904525

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 99.57%

Totals Coverage Status
Change from base Build 1555567555: 0.002%
Covered Lines: 423
Relevant Lines: 423

💛 - Coveralls

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.

4 participants