Coder Social home page Coder Social logo

Enum about schema-to-yup HOT 4 CLOSED

kristianmandrup avatar kristianmandrup commented on August 17, 2024
Enum

from schema-to-yup.

Comments (4)

kristianmandrup avatar kristianmandrup commented on August 17, 2024

I will add a test for it now and see if I can fix it ;)

from schema-to-yup.

kristianmandrup avatar kristianmandrup commented on August 17, 2024

If you look at types/mixed.js you can see it references this.constraints.enum
There are string tests for oneOf and notOneOf. The use of enum should just be an alias.

  oneOf() {
    let value =
      this.constraints.enum || this.constraints.oneOf || this.constraints.anyOf;
    if (this.isNothing(value)) return this;
    value = Array.isArray(value) ? value : [value];
    return this.addConstraint("oneOf", { value, errName: "enum" });
  }

  notOneOf() {
    const { not, notOneOf } = this.constraints;
    let value = notOneOf || (not && (not.enum || not.oneOf));
    value = Array.isArray(value) ? value : [value];
    return this.addConstraint("notOneOf", { value });
  }

As you can see, String just extends Mixed

class YupString extends YupMixed {
  constructor(obj) {
    super(obj);
    this.type = "string";
    this.base = this.yup.string();
  }

  static create(obj) {
    return new YupString(obj);
  }

  convert() {
    // generic constraint building, including oneOf (enum) etc
    super.convert();
    // ... string specific constraint building
  }

  // ...
}

from schema-to-yup.

kristianmandrup avatar kristianmandrup commented on August 17, 2024

Pls check my latest commit to master (better string testing) and debug from there. I see some tests are currently broken. Sorry.

from schema-to-yup.

kristianmandrup avatar kristianmandrup commented on August 17, 2024

Fixed this issue and all string related issues in latest release :)

from schema-to-yup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.