-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Worth trying to merge? Major additions/changes related to OpenAPI spec generation #22
Open
jlevers
wants to merge
112
commits into
crescat-io:master
Choose a base branch
from
highsidelabs:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* If CodeGenerator is not passed a Config instance, it will look for a file named "generator-config.json" in the current working directory and use that as the config file. * Config::load() loads a JSON config file into a Config instance. If its $path argument is null, it will look for a file named "generator- config.json" in the current working directory.
The NullGenerator class doesn't output anything, so if (for instance) you don't want to generate connectors, you can pass a NullGenerator instance as the connectorGenerator argument of the Generator class.
Most of the functionality in GenerateSdk that writes generated code to disk has been moved to GeneratedCode. This allows us to write code to disk when generating code programmatically, rather than from the command line. All command-line functionality remains the same, and stayed in GenerateSdk.
This makes it possible to extend existing parser classes, and override a subset of their methods.
Previously, there was no way to avoid having namespace suffixes - if a null value was passed, the default value was used. This commit makes it so that passing an explicit null value will disable the resource and request namespace suffixes entirely.
The CodeGenerator and GeneratedCode classes now take a FileHandler implementation as a constructor argument. This allows for user-defined file structure and naming conventions for the generated code.
* Add FileHandler::dtoPath() for specifying the DTO output path * Implement DtoGenerator::generate() * Parse schema types from OpenAPI specification * Create Data\Generator\Schema class for storing parsed schema information
* Create stubbed ResponseGenerator class * Add FileHandler::responsePath() method to get the response output path * Add responseGenerator param to CodeGenerator constructor * Add resourceClasses param to GeneratedCode constructor, and save those classes when calling dumpFiles()
* Create Deserializable interface and Deserializes trait * Make basic typing system for DTO attributes
Also created BaseDto and BaseResponse classes, which are extended by all generated Dto and Response classes, respectively. This does two things: * Avoid implementing the same interfaces and using the same traits in generated classes * Allow us to override the Deserializes trait's static $complexArrayTypes in generated Dto and Response classes. You can't override a trait's attribute in the class that uses it, but you *can* override it in a child of the class that uses it
By passing parent schema references to child schemas, we can implement naming and typing for inline child schemas. These changes only cover single-level child schemas in responses and other schemas. These changes also include support for scalar array types.
* Make sure __construct method is at the beginning of request classes * Cast file_put_contents return value to bool in GeneratedCode::dumpToFile() * Call toString() on result of NameHelper::normalize()
We need to handle complex array types in both deserialization and array-ification of DTOs. This moves the $complexArrayTypes property out of Deserializes and into a new trait HasComplexArrayTypes, because otherwise that property would be duplicated in both Deserializes and the new trait we're going to create to handle turning DTOs into arrays.
Request bodies are now assigned to DTOs, which can be passed via resource methods and request constructors.
Use DateTimeInterface for parameters
Include warning files are autogenerated
Fix caching of schemas when normalizing
* Remove $unknownKeys from Deserializes trait * Allow null $namespaceSuffixes in Generator::makeClass()
Check for circular references when parsing schemas
…equalsOpenApiSchema()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey @HelgeSverre,
Thanks for all your hard work on this package.
A few months ago I started using it as the basis for generating jlevers/selling-partner-api, and ended up making major modifications to, mostly to make it cover more of the OpenAPI spec, which is what I needed it for. I believe this was before you'd added support for generating request body/response body DTOs, or nested DTOs.
I see that since then you've added support for DTO generation, but I think my fork has support for a few things that the upstream repo doesn't:
allOf
schemas, more customizable namespacing via theConfig
class, the ability to configure and run the generator entirely from another PHP file in addition to the command line tool, etc.Since you've made a lot of changes since I started working on my fork and I've never synced with your changes, obviously merging the two is going to be a major task. I guess I'm just trying to figure out a merge is something you have any interest in before I start doing the work to make it happen. No hard feelings at all if you don't want to merge, I've obviously changed a ton of your original code.
Cheers!