v3.3 | Make OpenAPI generation reusable and support @var array item types for views#133
Merged
Conversation
This file contains hidden or 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
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.
What changed
This PR significantly reworks the OpenAPI part of
sunrise/http-router.The main goal of these changes is to make the OpenAPI API more reusable and less tightly coupled to HTTP Router itself. The OpenAPI generator is still shipped together with the router, but its internal architecture is now less dependent on a specific routing implementation and can be used as a standalone foundation for integrations with other frameworks.
One practical result of this refactoring is a separate Symfony bundle:
https://github.com/sunrise-studio-development/symfony-openapi
It uses the OpenAPI API from
sunrise/http-router, while adding full support for Symfony routes and Symfony attributes. This is a good example of how the OpenAPI layer can now be extended and reused outside the main HTTP Router.@varsupport for output/view objectsFor users who use
sunrise/http-routeras their router, this PR also adds support for PHPDoc@varannotations when generating OpenAPI schemas for output/view objects.Previously, describing array item types in OpenAPI required using the
Subtypeattribute fromsunrise/hydrator. This was not always convenient, especially for response objects whereSubtypewas needed not for data hydration, but only to produce a correct OpenAPI schema.Now array item types in view/output objects can be described with PHPDoc:
or with similar PHPDoc types supported by the parser.
Subtypeis still relevant for input DTOs, where it is required for correct hydrator behavior. But response objects no longer need to useSubtypeonly for OpenAPI generation.Why this matters
These changes make the OpenAPI part of the package more flexible:
sunrise/http-router;@var.Overall, the existing HTTP Router behavior remains compatible for current users, while the OpenAPI layer becomes more standalone and extensible.