GithubHelp home page GithubHelp logo

Comments (7)

dktapps avatar dktapps commented on July 26, 2024 1

Is there a specific reason why you commit the generated code?

I'm currently experimenting with this library and it seemed like the simplest way to do it right now, because otherwise deploy involves two extra steps (install dev deps, generate code, then install non-dev deps). I haven't settled on how I'm going to use it right now.

The ArrayItemValidator on the other hand currently needs the suffix. You're right, each property is evaluated in a single function so conflicts won't occur. But if a property contains a nested array the validation for the property will contain nested array validators in a single function which will collide and overwrite each others invalid items collection (if the variable names are identical, eg. both use $invalidItems).

I did some experimentation and found that a hash of this seems to be sufficient for nested arrays.

from php-json-schema-model-generator.

dktapps avatar dktapps commented on July 26, 2024

For the ArrayItemValidator case it seems like md5(propertyName) is sufficient. I checked nested arrays and their property names are item of {actualPropertyName}, so this seems fine.

from php-json-schema-model-generator.

wol-soft avatar wol-soft commented on July 26, 2024

I've had a quick view: for the AbstractPropertyProvider I think the uniqid is not necessary, as you already stated in the issue description.

The ArrayItemValidator on the other hand currently needs the suffix. You're right, each property is evaluated in a single function so conflicts won't occur. But if a property contains a nested array the validation for the property will contain nested array validators in a single function which will collide and overwrite each others invalid items collection (if the variable names are identical, eg. both use $invalidItems).

Consequently some kind of 'nested level counter' or something similar would be required to generate a reproducable suffix for the variable names. I'll have a look into it the next days.

For all my usages of the library, I don't commit the generated code (as it's just a duplication in my opinion. All information is already committed in the JSON-files used to generate the classes). I run my generate-script as a build step of the applications (like composer install to not commit the vendor directory). Is there a specific reason why you commit the generated code?

from php-json-schema-model-generator.

wol-soft avatar wol-soft commented on July 26, 2024

I did some experimentation and found that a hash of this seems to be sufficient for nested arrays.

Yes, you are absolutely right. Clean and simple solution. I've added it in 1b7a21a to the master as well as a patch for the AbstractPropertyProvider. You may test it with the latest master version.

Thanks for the hint 😃

from php-json-schema-model-generator.

dktapps avatar dktapps commented on July 26, 2024

Thanks. Only thing that remains (AFAIK) is the ClassNameGenerator, but I solved that with my code using a custom impl that just md5's the contents of the json schema. There's probably a better way to do it though (is there a way to get the full property path in there?).

from php-json-schema-model-generator.

dktapps avatar dktapps commented on July 26, 2024

Is there a specific reason why you commit the generated code?

I just want to mention something in addition to what I said before, which is that as well as making initial install as root project more complicated, codegen on install is not an option if the package may be used as a library, since dev deps won't be available. In that case, the only choices are to either commit the code or to depend on the codegen tool as a non-dev dep, neither of which are ideal. I think committing the code is the lesser evil in this case.

from php-json-schema-model-generator.

wol-soft avatar wol-soft commented on July 26, 2024

Yes, using this library in a library context currently has no proper solution. Maybe it's possible to wrap the generate script into a Composer plugin. I've not yet tested this idea.

from php-json-schema-model-generator.

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.