Skip to content
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
wants to merge 112 commits into
base: master
Choose a base branch
from

Conversation

jlevers
Copy link

@jlevers jlevers commented Mar 27, 2024

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 the Config 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!

* 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.
jlevers added 30 commits June 10, 2024 01:12
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants