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

Assign optional/non required arguments in the constructor if provided #581

Closed
mahakporwal02 opened this issue Jan 13, 2022 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@mahakporwal02
Copy link
Contributor

mahakporwal02 commented Jan 13, 2022

Reason/Context

  • We can add an enhancement to javascript generator to assign optional/non required arguments in the constructor during object formation.
  • Constructor accept arguments and set it to required member variables. But currently it only set values for only required arguments.
  • For example:
    If email is non required property -
const jsonSchemaDraft7 = {
  $schema: 'http://json-schema.org/draft-07/schema#',
  type: 'object',
  additionalProperties: false,
  properties: {
    email: {
      type: 'string',
      format: 'email'
    }
  }
}

The model generated would be -

class Root {
  email;
  constructor(input) {
  }
  get email() { return this.email; }
  set email(email) { this.email = email; }
}

After adding the enhancement the model generated would be -

class Root {
  email;
  constructor(input) {
  	if (input.hasOwnProperty(email)) {
  		this.email = input.email;
  	}
  }
  get email() { return this.email; }
  set email(email) { this.email = email; }
}
@mahakporwal02 mahakporwal02 added the enhancement New feature or request label Jan 13, 2022
@github-actions
Copy link
Contributor

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@ritik307
Copy link
Contributor

@derberg @fmvilas @mahakporwal02 I would like to work on this issue

@mahakporwal02
Copy link
Contributor Author

@ritik307 Apologies, didn't see your comment until now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants