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

[BUG] [Javascript] Setting a property as default doesn't work #19604

Open
5 of 6 tasks
Poolmann opened this issue Sep 17, 2024 · 1 comment
Open
5 of 6 tasks

[BUG] [Javascript] Setting a property as default doesn't work #19604

Poolmann opened this issue Sep 17, 2024 · 1 comment

Comments

@Poolmann
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version

7.8.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Title
  description: Title
  version: 1.0.0
paths:
  '/user':
    get:
      responses:
        200:
          description: "success"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequiredProperties'

components:
  schemas:
    RequiredProperties:
      type: object
      required:
        - requiredWithDefault
        - requiredWithoutDefault
      properties:
        requiredWithDefault:
          type: string
          default: "4.5.0"
        requiredWithoutDefault:
          type: string
        notRequiredWithDefault:
          type: string
          default: "4.5.0"
        notRequiredWithoutDefault:
          type: string
Generation Details

java -jar openapi-generator-cli.jar generate -i required.yaml -g javascript -o req_test

Steps to reproduce

Generate client, run:

var Title = require("title");

var test = new Title.RequiredProperties();
console.log(test)

Output:

RequiredProperties {
  requiredWithDefault: '4.5.0',
  requiredWithoutDefault: undefined
}

I would expect properties with a default to be initialized as well (with the DEFAULT). Especially since this is the case with all the other generators that I'm using (Java, Python, C#, PHP).

@wing328
Copy link
Member

wing328 commented Sep 20, 2024

I would expect properties with a default to be initialized as well (with the DEFAULT).

thanks for reporting the issue.

May I know if you've time to contribute a PR to add the default value support in the JS client? We can work with you on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants