{"id":37262936,"url":"https://github.com/onmoon/openapi-server-bundle","last_synced_at":"2026-01-15T23:24:38.993Z","repository":{"id":42185420,"uuid":"235130362","full_name":"onmoon/openapi-server-bundle","owner":"onmoon","description":"OpenApi Server Bundle for Symfony","archived":false,"fork":false,"pushed_at":"2025-06-25T21:11:46.000Z","size":536,"stargazers_count":11,"open_issues_count":33,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-11T05:36:56.211Z","etag":null,"topics":["api-server","code-generator","openapi","php","symfony"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onmoon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-20T15:13:51.000Z","updated_at":"2025-08-13T12:50:32.000Z","dependencies_parsed_at":"2024-05-06T12:57:52.911Z","dependency_job_id":"83ed6032-5cf1-45a6-bce2-8fadc79c4ab4","html_url":"https://github.com/onmoon/openapi-server-bundle","commit_stats":{"total_commits":98,"total_committers":6,"mean_commits":"16.333333333333332","dds":0.5306122448979591,"last_synced_commit":"8df21f359fc1c6358297f0b7b7a29ee1edbac5ad"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/onmoon/openapi-server-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmoon%2Fopenapi-server-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmoon%2Fopenapi-server-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmoon%2Fopenapi-server-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmoon%2Fopenapi-server-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onmoon","download_url":"https://codeload.github.com/onmoon/openapi-server-bundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmoon%2Fopenapi-server-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-server","code-generator","openapi","php","symfony"],"created_at":"2026-01-15T23:24:38.398Z","updated_at":"2026-01-15T23:24:38.988Z","avatar_url":"https://github.com/onmoon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony OpenApi Server Bundle\n\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fonmoon%2Fopenapi-server-bundle%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/onmoon/openapi-server-bundle/master)\n[![Test Coverage](https://coveralls.io/repos/github/onmoon/openapi-server-bundle/badge.svg?branch=master)](https://coveralls.io/github/onmoon/openapi-server-bundle?branch=master)\n[![Type Coverage](https://shepherd.dev/github/onmoon/openapi-server-bundle/coverage.svg)](https://shepherd.dev/github/onmoon/openapi-server-bundle)\n[![Latest Stable Version](https://poser.pugx.org/onmoon/openapi-server-bundle/v/stable)](https://packagist.org/packages/onmoon/openapi-server-bundle)\n[![License](https://poser.pugx.org/onmoon/openapi-server-bundle/license)](https://packagist.org/packages/onmoon/openapi-server-bundle)\n\n## About\n\nThis bundle can generate most of the usual boilerplate code you write when implementing an API.\nThe code is generated from OpenAPI specifications.\n\nThe following concerns are handled by the bundle automatically:\n- Route generation and routing\n- Validation of incoming requests against the specification\n- Strictly-typed request and response objects and API call handlers interfaces\n- Calling your code containing the API call handling logic passing the request object\n- Serializing of the returned response object\n\nAll you have to do is to implement the API call handler interfaces and return the provided response object.\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nRun\n\n```\ncomposer require onmoon/openapi-server-bundle \n```\n\nThen add the bundle class to your `config/bundles.php`:\n```php\n\u003c?php\n\nreturn [\n    OnMoon\\OpenApiServerBundle\\OpenApiServerBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n## Usage\n\nYou can configure the bundle by adding the following parameters to your `/config/packages/open_api_server.yaml`\n\n```yaml\nopen_api_server:\n  #root_name_space: App\\Generated # Namespace for DTOs and Api Interfaces\n  ## The bundle will try to derive the paths for the generated files from the namespace. If you do not want them to be \n  ## stored in \\App namespace or if you \\App namespace is not in %kernel.project_dir%/src/, then you\n  ## can specify this path manually:\n  #root_path: %kernel.project_dir%/src/Generated \n  #language_level: 8.0.0 # minimum PHP version the generated code should be compatible with\n  #generated_dir_permissions: 0755 # permissions for the generated directories\n  #full_doc_blocks: false # whether to generate DocBlocks for typed variables and params  \n  #send_nulls: false # return null values in responses if property is nullable and not required\n  #skip_http_codes: [] # List of response codes ignored while parsing specification. \n  ## Can be any open api response code ( like 500, \"5XX\", \"default\"), or\n  ## \"5**\", which will include both numeric (500) and XX (\"5XX\") codes.\n  ## Might be useful if you want to generate error responses in event listener.\n  specs:\n    petstore:\n      path: '../spec/petstore.yaml' # path to OpenApi specification\n      type: yaml  # Specification format, either yaml or json. If omitted, the specification file extension will be used.\n      name_space: PetStore # Namespace for generated DTOs and Interfaces\n      media_type: 'application/json' # media type from the specification files to use for generating request and response DTOs\n      #date_time_class: '\\Carbon\\CarbonImmutable' # FQCN which implements \\DateTimeInterface.\n      ## If set up, then generated DTOs will return instances of this class in DateTime parameters\n```\n\nAdd your OpenApi specifications to the application routes configuration file using standard `resource` keyword \nwith `open_api` type:\n\n```yaml\npetstore-api:\n  resource: 'petstore' # This should be same as in specs section of /config/packages/open_api_server.yaml\n  type: open_api\n  prefix: '/api' # Add this standard parameter to add base path to all paths in api\n  name_prefix: 'petstore_' # This will add a prefix to route names \n```\n\n## Requirements for your OpenAPI schemas\n\nFor the bundle to work properly with your specifications, they should be written in OpenAPI 3.0 format and each \noperation must have an unique `operationId`.\n\nCurrently, there are also the following limitations:\n- `number` without `format` is treated as float\n- Only scalar types are allowed in path and query parameters\n- Partial match pattern are ignored in path parameter patterns when selecting route, only `^...$` patterns are used\n- If pattern is specified in path parameter then type- and format-generated patterns are ignored\n- Only one media-type can be used for request and response body schemas. See: https://swagger.io/docs/specification/media-types/\n\n## Generating the API Server code\n\nThere are two console commands that work with the generated API server code:\n\n- Generate the server code: `php bin/console open-api:generate`\n- Delete the server code: `php bin/console open-api:delete`\n\nMost of the time you should use the `generate` command.\nIt will clear the bundle cache, delete the old generated server code if it exists and generate the new code.\n\nBe careful with the generate and delete commands, they will delete the entire contents of the directory you have specified \nin `root_path` in the `/config/packages/open_api_server.yaml` file. That directory should contain no files except \nthe code generated by this bundle, as it will be deleted every time you generate the API server code.\n\nFor each operation described in the specification, a API call handler interface will be generated that you should implement\nto handle the API calls.\n\n## Implementing the API call handlers interfaces\n\nGiven the following generated API handler interface:\n```php\n\u003c?php\n\ndeclare (strict_types=1);\n\nnamespace App\\Generated\\Apis\\PetStore\\ShowPetById;\n\nuse OnMoon\\OpenApiServerBundle\\Interfaces\\RequestHandler;\nuse App\\Generated\\Apis\\PetStore\\ShowPetById\\Dto\\Request\\ShowPetByIdRequestDto;\nuse App\\Generated\\Apis\\PetStore\\ShowPetById\\Dto\\Response\\ShowPetByIdResponse;\n\n/**\n * This interface was automatically generated\n * You should not change it manually as it will be overwritten\n */\ninterface ShowPetById extends RequestHandler\n{\n    /** Info for a specific pet */\n    public function showPetById(ShowPetByIdRequestDto $request) : ShowPetByIdResponse;\n}\n```\n\nYour API call handler could look like this:\n```php\n\u003c?php\n\nnamespace App\\Api;\n\nuse App\\Repository\\PetRepository;\nuse App\\Generated\\Apis\\PetStore\\ShowPetById\\Dto\\Request\\ShowPetByIdRequestDto;\nuse App\\Generated\\Apis\\PetStore\\ShowPetById\\Dto\\Response\\OK\\ShowPetByIdResponseDto;\nuse App\\Generated\\Apis\\PetStore\\ShowPetById\\Dto\\Response\\ShowPetByIdResponse;\nuse App\\Generated\\Apis\\PetStore\\ShowPetById\\ShowPetById;\n\nclass ShowPetByIdHandler implements ShowPetById\n{\n    private PetRepository $pets;\n\n    public function __construct(PetRepository $pets)\n    {\n        $this-\u003epets = $pets;\n    }\n\n    public function showPetById(ShowPetByIdRequestDto $request) : ShowPetByIdResponse\n    {\n        $petId = $request-\u003egetPathParameters()-\u003egetPetId();\n        $pet   = $this-\u003epets-\u003egetById($petId);\n\n        return new ShowPetByIdResponseDto($pet-\u003eid(), $pet-\u003ename());\n    }\n}\n```\n\nAdditionally, your API call handler can implement the following interfaces:\n- `\\OnMoon\\OpenApiServerBundle\\Interfaces\\SetClientIp` - if it needs the client IP address\n- `\\OnMoon\\OpenApiServerBundle\\Interfaces\\SetRequest` - if it needs the Symfony request object\n- `\\OnMoon\\OpenApiServerBundle\\Interfaces\\GetResponseCode` - if it needs to specify custom HTTP response codes\n\n## Using DTO mapper\n\nIf you want to use Doctrine entities or other business logic classes as sources for API \nresponse, you can easily copy contents into DTO using DTO mapper.\n\nInstall it with \n```\ncomposer require onmoon/dto-mapper\n```\n\nAnd use like follows\n```php\npublic function showPetById(ShowPetByIdRequestDto $request) : ShowPetByIdResponseDto\n{\n    $petId = $request-\u003egetPathParameters()-\u003egetPetId();\n    $pet   = $this-\u003epets-\u003egetById($petId);\n\n    /** @var OnMoon\\DtoMapper\\DtoMapper $this-\u003emapper */\n    return $this-\u003emapper-\u003emap($pet, ShowPetByIdResponseDto::class);\n}\n```\n\n[More information](https://github.com/onmoon/dto-mapper)\n\n## Customizing the API server behavior\n\nDuring the request handling lyfecycle the API server emits several events that can be used instead\nof the built-in Symfony Kernel events as the former provide more context. Theese events allow\nhooking into the API server functionality and modify it's behavior.\n\nThe following events are available:\n\n- `OnMoon\\OpenApiServerBundle\\Event\\Server\\RequestEvent`\n\n    The RequestEvent event occurs right before the request is validated against the OpenAPI Schema.\n    This event allows you to modify the Operation and Request objects prior to performing the \n    validation and processing the request.\n- `OnMoon\\OpenApiServerBundle\\Event\\Server\\RequestDtoEvent`\n\n    The RequestDtoEvent event occurs after the Request contents are deserialized in a Dto object representing\n    the API request and before this object is passed to your RequestHandler implementation.\n    This event allows you to modify the Operation and Request DTO (only via reflection) before it will be passed to your \n    RequestHandler implementation.\n    Note that the ResponseDTO is not created if the API endpoint expects no request body, path or query parameters.\n- `OnMoon\\OpenApiServerBundle\\Event\\Server\\ResponseDtoEvent`\n\n    The ResponseDtoEvent event occurs after the request handler class was executed returning a ResponseDto and\n    before this ResponseDto is serialized to a Response.\n    This event allows you to modify the ResponseDto contents before it will be serialized. This can be used as an\n    alternative to modyfing the Response object in a Symfony ResponseEvent, avoiding unnecessary decoding/encoding\n    of the Response body json.\n    Note that the ResponseDTO is not created if the API endpoint has no response body.\n- `OnMoon\\OpenApiServerBundle\\Event\\Server\\ResponseEvent`\n\n    The ResponseEvent event occurs right before the response is sent by the API server.\n    This event allows you to modify the Response object before the server will emit it to the client.\n\n## Customizing API server code generation\n\nDuring API server code generation the code generator emits several events that can be used to\nmodify the generated code either by changing parts of the OpenAPI specification objects or\nby changing the objects representing the various code definitions like classes, properties, methods.\n\nThe following events are available:\n\n- `OnMoon\\OpenApiServerBundle\\Event\\CodeGenerator\\ClassGraphReadyEvent`\n\n    The ClassGraphReadyEvent event occurs after all specifications\n    has been parsed and graph of classes to be generated has been\n    constructed.\n    \n    This event allows you to modify:\n    * Class names, namespaces and paths,\n    * Property attributes, getters and setters,\n    * Base interfaces and classes.\n\n- `OnMoon\\OpenApiServerBundle\\Event\\CodeGenerator\\FilesReadyEvent`\n\n    The FilesReadyEvent event occurs after all class files\n    are generated before they are written to files.\n    \n    This event allows you to modify generated files content,\n    e.g. change code style.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmoon%2Fopenapi-server-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonmoon%2Fopenapi-server-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmoon%2Fopenapi-server-bundle/lists"}