GithubHelp home page GithubHelp logo

Comments (3)

mgreca avatar mgreca commented on August 24, 2024 2

@jdpnielsen thanks, it works! but I still consider it an issue, so I'll keep it open until we have a response.

from json-schema-yup-transform.

jdpnielsen avatar jdpnielsen commented on August 24, 2024

I believe you need to do the following:

const schema = {
  properties: {
    name: {
      type: "string",
      format: "email"
    }
  }
};

const config = {
  errors: {
    name: {
      string: "Custom Email Error!",
      format: {
        email: "Testing other way 2"
      }
    }
  }
};

See https://github.com/ritchieanesco/json-schema-yup-transform/blob/master/test/yup/configErrors.string.test.ts#L343-L364

@ritchieanesco I mentioned this issue here: #34 (comment)

from json-schema-yup-transform.

ritchieanesco avatar ritchieanesco commented on August 24, 2024

Thanks for raising this issue. Error messages for formatting have been changed so the format type property is no longer required in the configuration. You can find examples of these in the unit tests:

it("should show configuration error when value does not match date-time format", () => {
const schema: JSONSchema7DefinitionExtended = {
type: "object",
$schema: "http://json-schema.org/draft-07/schema#",
$id: "test",
title: "Test",
properties: {
date: {
type: "string",
format: "date-time"
}
}
};
const config = {
errors: {
date: {
format: "Value does not match date time format"
}
}
};
const yupschema = convertToYup(schema, config) as Yup.ObjectSchema;
let errorMessage;
try {
errorMessage = yupschema.validateSync({ date: "Test" });
} catch (e) {
errorMessage = e.errors[0];
}
expect(errorMessage).toBe(config.errors.date.format);
});

This change is currently available in 1.6.6-beta.1.

I'll be looking shortly to implement @jdpnielsen idea to make the messaging more flexible.

from json-schema-yup-transform.

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.