Code Monkey home page Code Monkey logo

Comments (7)

scaytrase avatar scaytrase commented on May 18, 2024

Also some questions @lezhnev74

if (! isset($this->parentSchema->items)) {

This line should some kind of schema validation step, not data validation. It's rather strange to decline data here if schema is invalid. Probably this should go to cebe/php-openapi instead

if (count($data) && ! (is_array($data) && ArrayHelper::isAssoc($data))) {

counting data befor validating its type is unsafe (especially for php 7.2). why we expecting items in data at all?

from openapi-psr7-validator.

scaytrase avatar scaytrase commented on May 18, 2024

Also schema validation is duplicated here

])->stringType()->assert($type);

and here

throw new Exception("Type '%s' is unexpected", $type);

I hope we can leave second only, it's more obvious

from openapi-psr7-validator.

lezhnev74 avatar lezhnev74 commented on May 18, 2024

Great points!

  1. $this->parentSchema->items.
    Agree, this is too defensive. This should be delegated to the underlying package.
  2. count($data) && ! (is_array($data) && ArrayHelper::isAssoc($data))
    This must make sure that the data is an array, and it has no string keys (which makes it a dictionary in terms of JSON). What would be a better check here? Ah, I jsut saw the PR. This code solves the problem: if (! is_array($data) || ArrayHelper::isAssoc($data)) {...
  3. Also schema validation is duplicated here.
    Agreed. Let's leave just switch statement here. Again, sometimes my code is over defensive.

from openapi-psr7-validator.

scaytrase avatar scaytrase commented on May 18, 2024
  1. everything but counting is ok. counting is unsafe and really not needed. to check vector against array is_array($data) && !ArrayHelper::isAssoc($data) is enough. Counting on non countable would fail in 7.2+

https://php.net/manual/en/migration72.incompatible.php#migration72.incompatible.warn-on-non-countable-types

from openapi-psr7-validator.

scaytrase avatar scaytrase commented on May 18, 2024

For 1 and 3 I can update #21 removing these additional checks

from openapi-psr7-validator.

lezhnev74 avatar lezhnev74 commented on May 18, 2024

Please, go ahead, sounds good!

from openapi-psr7-validator.

scaytrase avatar scaytrase commented on May 18, 2024

Done. Raised one more question in PR

from openapi-psr7-validator.

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.