Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Support for minContains and maxContains
- Incorrectly escaped backslashes in regex in generated code HOT 9
- Integer property with default 0 is incorrectly nullable HOT 3
- Validation of nested composition causes fatal error
- Access to undeclared property `_propertyValidationState` on simple templates HOT 3
- Incorrect native parameter type on nullable setters in mutable models HOT 5
- Crash on `"type": ["object"]` on object properties
- Inconsistency of generated code when using different methods to declare nullable structures HOT 1
- uuid string type support HOT 1
- No nested schema for composed property HOT 5
- Support number property key HOT 3
- Constructor with explicit argument HOT 1
- Add validateOption to FilterInterface
- ...PropertyProxy::getProperty(): Return value must be of type ...PropertyInterface, null returned in HOT 4
- Stable version HOT 1
- Filter for a property inside a Composition inside an array is not executed
- Error when generating classes with FedEx OpenAPI schema HOT 4
- Serialization Bug: Including Null Properties in JSON Output instead of Excluding Them HOT 1
- Creation of dynamic property for composed item validators on properties
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-json-schema-model-generator.