OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using a property of type string with ENUM Values, and a default value the generated code will produce a
incorrect usage of the default value - caused by a missing self Keyword
openapi-generator version
latest (docker image)
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Buggy Model generation
description: This demonstrate a Bug when using Default Values from ENUM Property
version: 1.0.0
servers:
- url: 'https://api.example.com'
paths:
/bug:
get:
summary: A Bug.
responses:
'200':
$ref: '#/components/responses/BuggyResponse'
components:
responses:
BuggyResponse:
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Notification"
schemas:
Notification:
type: object
properties:
severity:
type: string
enum:
- INFO
- WARNING
- ERROR
default: "INFO"
example: "INFO"
message:
type: string
example: "Hi There"
Generate Client from the provided example using the CLI Command from the Generation Details section.
open Notification.php and see the error in Line 207
public function __construct(array $data = null)
{
$this->container['severity'] = $data['severity'] ?? SEVERITY_INFO; // <-- this must be a self::SEVERITY_INFO
}
Bug Report Checklist
Description
When using a property of type string with ENUM Values, and a default value the generated code will produce a incorrect usage of the default value - caused by a missing self Keyword
openapi-generator version
latest (docker image)
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Notification.php
and see the error in Line 207Related issues/PRs
No similar Bug Report Found, bug maybe related to
Suggest a fix
As a workaround we apply changes to the template itself (which is not very future proof, but will fix this behavior for us)