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

Object schema without #160

Merged
merged 3 commits into from
Jan 10, 2022
Merged

Object schema without #160

merged 3 commits into from
Jan 10, 2022

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
This pull request was closed.
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