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

Support other language output #392

Open
johnwc opened this issue Jul 30, 2022 · 7 comments · Fixed by #401
Open

Support other language output #392

johnwc opened this issue Jul 30, 2022 · 7 comments · Fixed by #401
Assignees
Labels
enhancement New feature or request

Comments

@johnwc
Copy link

johnwc commented Jul 30, 2022

Example, OpenAPI Generator supports creating clients in TypeScript, allow choosing what client language to generate.

@christianhelle
Copy link
Owner

First of all, thank you for taking the time to suggest this!

I can easily add this for the CLI Tool but I don't know if it makes sense the Visual Studio addon. I haven't heard of anyone who uses Visual Studio as an IDE for TypeScript. I thought most (if not all) web developers moved to Visual Studio Code.

The tooling for generating code behind files is a really old API and last time I checked it only supported C# and VB.NET. I can though just use the code generator to generate files on the file system and hopefully Visual Studio will pickup the changes.

Anyway, I'll look into this and see what I can do.

@christianhelle christianhelle self-assigned this Aug 1, 2022
@christianhelle christianhelle added the enhancement New feature or request label Aug 1, 2022
@johnwc
Copy link
Author

johnwc commented Aug 2, 2022

Visual Studio Pro is an extremely strong IDE for TypeScript. Most developers I know that have used and learned how to fully utilize Visual Studio, would not touch VS Code with a 10' pole! VS is so much more powerful of an IDE than VS Code. It's why one is free and the other is not.

I'm not really sure I follow with what you are referring to with generating code behind files. VS does not "generate code" behind files for cs or vb files, as they are already... code. I think you may be thinking of windows UI development, where VS will generate the code for WinForms. Also, the new VS 2022 utilizes language engines much like VS Code.

When we use VS to develop web projects, we usually utilize Node and npm manager along with task runner. We are not creating node packages in VS, we write all our site's JS in TS and compile it down to JS to be referenced on our site. So, we utilize the open api generator to create our client api TS for us in our existing web/vue project.

Also, I think you missed the bigger picture that was being requested. There are several different types of languages that the code generator supports producing. The request was to allow to choose the generator.

@christianhelle
Copy link
Owner

So I just tried to do a create new typescript react project in Visual Studio. I have no idea what I'm doing but I wanted to see what Visual Studio generates. I think I can implement a context menu on the solution explorer for a .json (or .yml) file, and also a .nswag file that will launch the code generator CLI tool with a certain set of command-line arguments. I know that OpenAPI Generator and NSwag supports generating TypeScript clients as my colleagues who do web apps use them.

As for the "code behind" files, well this is basically the output of a Visual Studio Custom Tool which that can be configured to a .NET project item (like .cs or .vb) that executes upon any changes to the contents of the project item. This API has been around for ages and depends on very old COM libraries. The core feature of this Visual Studio extension is basically adding some context menu helpers to be able to use a code generator that is launched from a VS Custom Tool upon making changes to the selected file.

I think I understand what you are requesting.

This is how I understand it:

Instead of generating a code-behind file like in .NET projects, I will build something that just executes the code generator to produce files with the selected directory. I know that with NSwag Studio you can configure relative paths so if we for example have a .nswag file in the Visual Studio project, I can build context menus for the given file which allows you to select which code generator to use and will just execute the code generator. Visual Studio should pickup changes in the file system and refresh the solution explorer.

@christianhelle
Copy link
Owner

I started working on this recently. I started with my CLI tool as its easier to test things using on multiple platforms and OS versions

If you haven't already tried, you install this as a dotnet tool via dotnet tool install --global rapicgen

$ rapicgen typescript -?
Generate TypeScript API client

Usage: rapicgen typescript [options] <generator> <swaggerFile> <outputPath>

Arguments:
  generator         The tech stack to use for the generated client library
                    Allowed values are: Angular, Aurelia, Axios, Fetch, Inversify, JQuery, NestJS, Node, ReduxQuery,
                    Rxjs.
                    Default value is: Angular.
  swaggerFile       Path to the Swagger / Open API specification file
  outputPath        Output folder to write the generated code to
                    Default value is: typescript-generated-code.

Options:
  -nl|--no-logging  Disables Analytics and Error Reporting
  -?|-h|--help      Show help information.

Here's a usage example:

$ rapicgen typescript Angular Swagger.json ./generated-code

So far this only specifies which tech stack to use when generating code using OpenAPI Generator. If you have any specific usages then I would love to include them in this tool

I'll try to start working on the Visual Studio extension in the coming week, if work or family doesn't get too much in the way :D

@johnwc
Copy link
Author

johnwc commented Aug 15, 2022

Why add a separate generator class and not change it so the <generator> be a selection/option that gets passed to the OA java generator? That way it is not locked down to x or y client types, but whatever client type the underlining OA java generator supports. Where the option <generator> is typescript-axios, typescript-fetch, cpp-restsdk, powershell or whatever the developer needs it to produce.
rapicgen typescript [options] <generator> -> rapicgen [options] <generator>

@christianhelle
Copy link
Owner

That was my original design until I noticed that the parameters for each generator are quite different from each other. Even the TypeScript generators. I'm aiming to expose the config options for each supported generator to have a UI in the Visual Studio settings screen. I have this command: rapicgen openapi but this generates C# code and I have users already relying on this. I will probably, going forward, adapt what you suggested, and have a command that is a pure pass-through tooling to use OpenAPI Generator.

Thanks again for your time and suggestions

@christianhelle
Copy link
Owner

christianhelle commented Aug 24, 2022

I'll keep this open until I finish implementing the solution explorer context menus for generating TypeScript

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
2 participants