Comments (10)
Please explain what youve customized. I am currently analyzing quicktype especially for php as well
from quicktype.
At first glance, this looks exactly like what I need as well. I have already started building my own version as well. Things I've noticed or changed: enums (BackedEnum), validations which are currently completely pointless. From/To-Array instead of stdClass, Multiple-Files with namespaces and imports instead of a god-class. Let's go into the details in the new year and then we simply create a pull request.
from quicktype.
@comod here you go if you want to test it yourself > https://github.com/HighLiuk/quicktype
I've added support for a lot of different features ranging through PHP 7.3 (or older) to PHP 8.2 which has far way less boilerplate than previous versions of PHP especially for OOP.
I've added a dozen options as shown in this local version of the web app I've scaffolded to play with it. As you can see from the screenshot, choosing which PHP version to target is an option. This internally guarantees that you cannot opt in for features that are not available for that PHP version (e.g. readonly
attributes are introduced in PHP 8.1. These may be turned off with a flag (defaults to true for simplicity) but are auto-disabled if the PHP version is lower than 8.1)
It is not 100% accurate (I recently noticed a few inconsistencies and so) and I've not run unit tests against it, but if a PR is accepted I would add the required tests.
Also, I've revised how the validation works in order to keep it simpler.
Let me know what do you think about.
Would be nice if a maintainer read this too (perhaps liking the thread would help?)
from quicktype.
I saw that other languages (like Go) have support for output multiple files but I didn't figure out how to implement it.
In PHP this is necessary when you leverage autoloads and if you have to do that manually over several generated classes, it easily becomes messy.
from quicktype.
Hello! You can make a PR and we can review it there.
from quicktype.
i figured out that it needs to remove this line to get it work @HighLiuk:
The generated code looks good so far!
I was able to generate multiple files with some few changes like this:
but i dont know how to add namespaces and imports. should this be inferred by additional properties in the json schema or should this be inferred by the original structure of the json-schema source. i only get fileName as parameter and not the whole filePath. so this is kind of tricky - any ideas?
from quicktype.
Hey there @comod thanks in advance
but i dont know how to add namespaces and imports. should this be inferred by additional properties in the json schema or should this be inferred by the original structure of the json-schema source. i only get fileName as parameter and not the whole filePath. so this is kind of tricky - any ideas?
probably you should look for the property types to get which classes / enums need to be imported at the top of the file.
But a clever option would be to add a "namespace" option to add a namespace on the top of the file. Like --namespace=Glideapps\Quicktype
so for instance class Foo
would have namespace Glideapps\Quicktype;
on top of the file. This way according to PSR-4 you don't even need to add use Glideapps\Quicktype\Foo;
if you add them to the same directory with the same namespace.
from quicktype.
I wasnt clear enough. What i try to achive is multiple files in different folders either according to the source structure (which is already organized in different folders) or to any additional information from the json schema (like a property named "package" or "namespace") if this makes any sense. Maybe this is out of scope and should be done as extra step
from quicktype.
I have now delved even deeper into the subject matter and have a few basic questions for the authors:
- Is there already a concept for namespaces that spread across multiple levels, or are there only "global namespaces", i.e., ultimately a single namespace that is simply appended everywhere?
In the code, for example, I found this:
private _globalForbiddenNamespace: Namespace | undefined;
private _otherForbiddenNamespaces: Map<string, Namespace> | undefined;
private _globalNamespace: Namespace | undefined;
However, I could not understand what this is used for. I believe this has nothing to do with the namespace I mean.
- Is it possible to add and read a custom top-level property to the JSON schema? What would be the places that would need to be adjusted for this?
- I have already tried using a custom
Namer
, but file and class names are inseparably constructed in the code. As a workaround, it would initially suffice to build namespaces based only on the "title" property (e.g.,"title": "myNameSpace/myClassName"
). File and class name, however, refer to the sameName
/Namer
, and I am not sure whether I should use these or whether there is not a better way.
Finding a solution outside is no less challenging, as not only namespaces have to be added, but all references also have to be adjusted. Additionally, the sources would have to be read and mapped, etc. It would simply be more elegant to get a grip on this with this one tool on the spot.
If it is to remain with just the one global namespace, then what @HighLiuk suggested is indeed sufficient.
from quicktype.
Not sure if I understand everything @comod, but I agree that it should be simpler to use QuickType's internal API to easily print on different files.
from quicktype.
Related Issues (20)
- Update Dart Model Generation Command to Support Optional Fields HOT 1
- Change cursor color when JSON format is invalid
- npm install quicktype, err HOT 1
- [Typescript] Top-level array don't get generated HOT 1
- Enum schemas aren't generated if the enumerator list matches
- License for Generated C++ with "Helper" Code
- One TS file from multiple schemas HOT 4
- top level simple type doesnt work
- Directory multiple file input src and multiple file out differences
- no support for definitions
- converting a recursive json schema into a zod type breaks HOT 1
- Golang: Omitempty when field is required by some oneOf variants HOT 7
- const number type throws error HOT 5
- Go - time package is not being imported in certain cases
- Generated Rust code overrides `Option` keyword when array key is `options`
- C# Renderer with `--features just-types` doesn't include required `using`s.
- Need to add a feature to append a suffix to class names, as model classes
- Error: EMFILE: too many open files HOT 1
- Go time import is misplaced in some circumstances. HOT 1
- The Python "to_dict" method fails when generated from JSON schema with properties of type "number" which are assigned an integer value
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 quicktype.