OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.99k stars 6.6k forks source link

[BUG][typescript-node] Default value missing when using allof #16345

Open noamk-hl opened 1 year ago

noamk-hl commented 1 year ago

Bug Report Checklist

Description

When a property uses allof for common configuration (such as enum values) and a default, the default isn't set in the model.

What I get

'fruitType'?: FruitEnum;

Expected:

'fruitType'?: FruitEnum = FruitEnum.Apple;
openapi-generator version

6.6.0

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: "1.0.0"
  title: "Test default enum value"
paths:
  /eat:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: "object"
              properties:
                fruit_type:
                  allOf:
                  - $ref: '#/components/schemas/FruitEnum'
                  default: "apple"
      responses:
        200:
          description: "Yummy"

components:
  schemas:
    FruitEnum:
      type: "string"
      enum: [
          "melon",
          "apple"
        ]

This schema is based on schemas generated by drf-spectacular.

By the way, changing to the following does work:

fruit_type:
  allOf:
  - $ref: '#/components/schemas/FruitEnum'
  type: "string"
  default: "apple"
Generation Details
openapi-generator-cli generate -g typescript-node -i schema.yaml
Steps to reproduce

Generate the client code.

Related issues/PRs

12634 is similar but not the same

ty-v1 commented 1 year ago

The same bug occurs in other typescript generators.

atoms42 commented 9 months ago

I am on version 7.3.0 and am seeing similar behaviour. Default values don't appear to be added for fields of any type.