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

should render additionalProperties #68

Closed
jonaslagoni opened this issue Feb 18, 2021 · 3 comments · Fixed by #240
Closed

should render additionalProperties #68

jonaslagoni opened this issue Feb 18, 2021 · 3 comments · Fixed by #240
Labels
enhancement New feature or request released

Comments

@jonaslagoni
Copy link
Sponsor Member

jonaslagoni commented Feb 18, 2021

Reason/Context

Currently the CommonModel does include additionalProperties, however they are not rendered as properties in the generator

Questions:

  • How should we handle additionalProperties if we already have a property called additionalProperties?
@magicmatatjahu
Copy link
Member

@jonaslagoni You pinged me about problems with addProperties etc in slack, so I give you some tips here, also to check by another people from community:

For additionalProperties:

  • in TS and JS we should render for additionalProperties additional accessor for set and get, but not native, but something like getAdditionalProperty(key: string): {type} and setAdditionalProperty(key: string, value: {type}): void.
  • in Java we can make something similar public {type} getAddtionalProperty(String key) { this.additionalProperties.get(key) } and similar setAdditionalProperty.

For patternProperties situation is very similar to additionalProperties. We have an example:

{
  "type": "object",
  "patternProperties": {
    "^S_": { "type": "string" },
    "^I_": { "type": "integer" }
  },
  "additionalProperties": false
}
  • in TS and JS we should render:
patternProperties: Record<string, any>;

getPatternProperty(key: string): {type | undefined} {
  return patternProperties[key];
}

setPatternProperty(key: string, value: any): void {
  // here we must check patterns
  if (/^S_/.test(key) && typeof value === "string") {
    this.patternProperties[key] = value;
  }
  if (/^I_/.test(key) && typeof value === "number") {
    this.patternProperties[key] = value;
  }
  // maybe throw error
}
  • for Java very similar like for TS - additional get and set for patternProperties and inside them check pattern before saving data.

additionalProperties and patternProperties you can render in 2 ways:

  • using additionalContent preset for class here or
  • adjust renderProperties in appropriate renderer

@jonaslagoni jonaslagoni changed the title Additional properties need to be generated Add preset hook to render additionalProperties Feb 25, 2021
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

@github-actions github-actions bot added the stale label Apr 27, 2021
@jonaslagoni jonaslagoni added this to the Improvement iteration milestone Jun 9, 2021
@jonaslagoni jonaslagoni changed the title Add preset hook to render additionalProperties should render additionalProperties Jun 16, 2021
@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants