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

feat: enable Typescript Input #594

Merged
merged 22 commits into from
Mar 3, 2022

Conversation

ron-debajyoti
Copy link
Contributor

@ron-debajyoti ron-debajyoti commented Jan 21, 2022

Description

  • Added TypescriptInputProcessor along with options to allow processing and generation of json schemas based on options like uniqueNames, compilerOptions
  • Added tests for TypescriptInputProcessor
  • Added 2 usage examples java-from-typescript-type and java-from-typescript-type-with-options.

Related issue(s)

Fixes #187

@ron-debajyoti ron-debajyoti changed the title feat: Enable Typescript Input feat: enable Typescript Input Jan 21, 2022
@ron-debajyoti
Copy link
Contributor Author

Hey @jonaslagoni !

I made this draft PR for issue #187 . Please check it out and provide your feedback on whether I'm heading in the right direction. There's still a lot of work left like writing proper tests and adding more implementation features based on the library I'm using.

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice progress! 🎉

I made this draft PR for issue #187 . Please check it out and provide your feedback on whether I'm heading in the right direction. There's still a lot of work left like writing proper tests and adding more implementation features based on the library I'm using.

I just realized that we run into a bit of a problem here 😄

Currently, the input type has always been one file, or rather one JSON object which of course wont fit here. So we need to adapt the input processing to accommodate these new input types.

Would you like to start the issue? 🙂

src/processors/TypeScriptInputProcessor.ts Outdated Show resolved Hide resolved
src/processors/TypeScriptInputProcessor.ts Outdated Show resolved Hide resolved
test/processors/TypeScriptInputProcessor.spec.ts Outdated Show resolved Hide resolved
@ron-debajyoti
Copy link
Contributor Author

Sorry @jonaslagoni for the late reply, I was kinda busy with my university coursework. I'm also going to reply to the comments above here.

Currently, the input type has always been one file, or rather one JSON object which of course wont fit here. So we need to adapt the input processing to accommodate these new input types.

Yeah so is this the case for handling the whole Typescript project? For that, we need to use the tsconfig.json of the project and then pass the required TYPE, as described here. Currently, to just start working I tested it using a type declaration example.

Additionally, I'm trying to understand what more input types are we going to accept here? Since we either have to get the individual type.ts files or the tsconfig.json file, it was easier to just consider a base path as a string. If I misunderstood something please do mention.

@jonaslagoni
Copy link
Member

Yeah so is this the case for handling the whole Typescript project? For that, we need to use the tsconfig.json of the project and then pass the required TYPE, as described here. Currently, to just start working I tested it using a type declaration example.

Additionally, I'm trying to understand what more input types are we going to accept here? Since we either have to get the individual type.ts files or the tsconfig.json file, it was easier to just consider a base path as a string. If I misunderstood something please do mention.

My recommendation is to start small, what is the absolute minimum we need to support in order to say we have this feature. So for now don't worry about projects, but a single file 🙂 (unless the library supports providing the content of a file that would be better 😄)

I would suggest you took a look at how you can change the current processor line to follow this format:

process(input: any): CommonInputModel {
   if(typeof input !== 'string') throw error;
   const pathToFile = input;

As I dont know the library in and out, try to see what is possible and feel free to ping me with what worked and didnt 🙂

@coveralls
Copy link

coveralls commented Jan 31, 2022

Pull Request Test Coverage Report for Build 1929157128

  • 37 of 42 (88.1%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 92.946%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/processors/TypeScriptInputProcessor.ts 34 39 87.18%
Totals Coverage Status
Change from base Build 1928274956: -0.1%
Covered Lines: 2567
Relevant Lines: 2633

💛 - Coveralls

@ron-debajyoti ron-debajyoti marked this pull request as ready for review February 1, 2022 17:02
@ron-debajyoti
Copy link
Contributor Author

@jonaslagoni So I guess this is the absolute base case of the implementation where I pass a .ts file as { baseFile : ourFile } as input Record, and it generates and adds all the types present in the file to our common model.

There's a lot more features to add to this, like :

  • generate selected types
  • generate types from a whole project using tsconfig.json.....
    and many more to explore. Let me know your views and if possible we can have a discussion.

Also let me know if I need to improve on the documentation of the current implementation.

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @ron-debajyoti 💪

A couple of things are missing until we can merge:

@ron-debajyoti
Copy link
Contributor Author

ron-debajyoti commented Feb 16, 2022

Hey @jonaslagoni . Here's the summary of the latest commits :

  • added the options: ProcessorOptions support in TypeScriptInputProcessor to allow users to generate schemas based on options like uniqueNames, compilerOptions as defined in typescript-json-schema here. Added an additional test for that as well.
  • added an example of generating Java models from a TypeScript input. I figured that since AbstractGenerator calls InputProcessor.process during model generation, generating a language model (for eg. Java ) from a TypeScript file would be a good example.
  • updated docs in examples and the main README.md.

Please review and let me know if I had missed something.
Edit: looks like black-box testing in ubuntu is failing

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a few comments, but overall it looks great 👍

@magicmatatjahu think it's time you take a look if you want to, as we have reached the final state before merging.

examples/java-from-typescript-type/index.ts Outdated Show resolved Hide resolved
docs/usage.md Show resolved Hide resolved
docs/usage.md Outdated Show resolved Hide resolved
@ron-debajyoti
Copy link
Contributor Author

ron-debajyoti commented Mar 2, 2022

@magicmatatjahu this has been pending for review for many days 😅

@jonaslagoni
Copy link
Member

@magicmatatjahu this has been pending for review for many days

Life of OpenSource unfortunately 😄

@magicmatatjahu do you want to review it, or can we go ahead?

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one suggestion :) Rest lgtm. Awesome work!

src/processors/TypeScriptInputProcessor.ts Show resolved Hide resolved
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jonaslagoni
Copy link
Member

/rtm

@jonaslagoni jonaslagoni merged commit 737ade9 into asyncapi:master Mar 3, 2022
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.51.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.0.0-next.23 🎉

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable TS input
5 participants