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

Generate example function for TypeScript models #462

Closed
jonaslagoni opened this issue Mar 6, 2023 · 4 comments · Fixed by #674
Closed

Generate example function for TypeScript models #462

jonaslagoni opened this issue Mar 6, 2023 · 4 comments · Fixed by #674
Labels
enhancement New feature or request good first issue Good for newcomers released

Comments

@jonaslagoni
Copy link
Member

jonaslagoni commented Mar 6, 2023

Reason/Context

In Modelina for TypeScript, you can make it generate the models generate functions that return a basic instance example, this should be possible through the CLI.

To do this I suggest we add a flag called tsExampleInstance as a boolean. If true the generator should include the following options:

  presets: [
    {
      preset: TS_COMMON_PRESET,
      options: {
        example: true
      }
    }
  ]

Which should be added here:

fileGenerator = new TypeScriptFileGenerator({
as the code example shows: https://github.com/asyncapi/modelina/blob/master/examples/typescript-generate-jsonbinpack/index.ts

These will be the generated results: https://github.com/asyncapi/modelina/blob/master/examples/typescript-generate-example/__snapshots__/index.spec.ts.snap

Remember to also add a test here:

describe('for TypeScript', () => {

Related documentation: https://github.com/asyncapi/modelina/blob/master/docs/languages/TypeScript.md#generate-example-data-function

Feel free to reach out if you have any questions or get stuck!

@jonaslagoni jonaslagoni added the enhancement New feature or request label Mar 6, 2023
@Souvikns Souvikns added the good first issue Good for newcomers label Mar 6, 2023
@bhavyastar
Copy link

Hey @jonaslagoni @Souvikns I would like to work on this issue!

@chinma-yyy
Copy link
Contributor

Hey @jonaslagoni , I was working on this issue and I have almost completed it but when I added the test script for the functionality it gives an error
image
for every toEqual it is giving this error what should I do? Earlier it used to work fine.

@jonaslagoni
Copy link
Member Author

Try add the PR as a draft PR so we can see the changes @chinma-yyy 🙂

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.51.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