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

Extend schema fixes #65 #69

Merged
merged 2 commits into from
May 17, 2020
Merged

Extend schema fixes #65 #69

merged 2 commits into from
May 17, 2020

Conversation

aboutlo
Copy link
Collaborator

@aboutlo aboutlo commented May 8, 2020

Better merge strategy. Before, the merge was replacing the array element rather than merging the items.
I decided to block all the method after .extend to avoid incorrect usage.

Wrong but no error raised by FluentSchema

const SCHEMA_BASE = S.object()
  .prop(
    'reason',
    S.string()
      .title('Reason 1')
  )

const base = S.object()
  .extend(SCHEMA_BASE)
  .prop(
    'reason',
    S.string()
      .minLength(1)
  )
  

Correct usage should be:

const extended = S.object()
  .prop(
    'reason',
    S.string()
      .minLength(1)
  )
  .extend(SCHEMA_BASE)

First, the schema is defined with all the props then it extends the base schema.

With the sealed schema after the .extend the only thing that can be done is calling valueOf

I'm unsure if I should mark this as 1.0.2 because it's a bug fix or considering the sealing as breaking change. Feedback welcome.

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@aboutlo
Copy link
Collaborator Author

aboutlo commented May 14, 2020

I'm unsure if I should mark this as 1.0.2 because it's a bug fix or considering the sealing as breaking change. Feedback welcome.

@mcollina and @Eomm any strong opinion?

@mcollina
Copy link
Member

Looks like a bug to me.. how high is the chance of some code breaking because of this change?

@aboutlo
Copy link
Collaborator Author

aboutlo commented May 14, 2020

If you look the bug reported the snippet provided is broken after the upgrade #65.

const NEW_SCHEMA = S.object()
  .extend(SCHEMA_BASE)
  .prop(
    'reason',
    S.string()
      .minLength(1)
  )

.prop is added after .extend

@mcollina
Copy link
Member

Mark it as 1.0.2. I don't think the library is really usable without this fix.

@aboutlo aboutlo merged commit 937eb40 into master May 17, 2020
@aboutlo aboutlo deleted the extend-schema branch May 17, 2020 20:18
@jmav
Copy link

jmav commented May 20, 2020

This does not work with multiple extend, and I think it could fail on some cases users are using.

const SCHEMA_V1 = S.object()
  .prop(
    'reason',
    S.string()
      .minLength(1)
  )
  .extend(SCHEMA_BASE)

const SCHEMA_NEW = S.object()
  .prop(
    'reason',
    S.string()
      .minLength(1)
  )
  .extend(SCHEMA_V1)

@aboutlo
Copy link
Collaborator Author

aboutlo commented May 21, 2020 via email

@jmav
Copy link

jmav commented May 25, 2020

Expected behavior:
Props should be allowed to be extended multiple times.

SCHEMA_V1 should have all definitions defined in SCHEMA_BASE + prop "reason"
SCHEMA_NEW should have all definitions defined in SCHEMA_V1 and in SCHEMA_BASE + change

aboutlo added a commit that referenced this pull request May 28, 2020
@aboutlo aboutlo mentioned this pull request May 28, 2020
3 tasks
aboutlo added a commit that referenced this pull request Jun 2, 2020
* #69 fix multiple extension issue

* #73 fix with better coverage

* Add Github actions
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.

3 participants