Codegen with TypeSpec #3129
-
Clear and concise description of the problem@bterlson mentioned in hackernews that:
I also watched @garethj-msft Nordic API’s presentation “Reigniting the API Description Wars with TypeSpec and the Next Generation of API Languages” where he described the history leading to TypeSpec and mentioned Microsoft’s Kiota project There is also an existing PR to add a csharp emitter #2458 My question is whether I should plan to use TypeSpec to generate OpenAPI Specification to use with Kiota, or if I should wait for codegen to be added to this repo. If codegen will be added to this repo soon, then this issue may be a good place to track its release. Anyway, I look forward to trying out TypeSpec and friends next week! Thank you for open-sourcing it. Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
This is a great discussion topic, but I will share a tracking issue here, that's a good idea. It's hard to say which you should do, it depends a lot on what your needs are and how urgent those needs are. Kiota codegen is good, so I would say, if it works for you, then you would have no problems going the openapi -> kiota route. A side project I hope to get to soon is to package this up in an emitter to make it even easier, so you could do something like In terms of timeline, we have alpha quality generators now that you can try (see https://github.com/bterlson/typespec-todo). I expect to see codegen come fully online with the rest of the project (high quality beta, with a fairly high bar for breaking changes) over the next 3 months. |
Beta Was this translation helpful? Give feedback.
-
Don't know if carrying on this discussion or opening a new one would be better, but as the title is generic, I just put it here. Let me know if you would want it in a new discussion. How I look at TypeSpec is capable much more than just to define things around the "Api realm" and enables much broader scenarios to generate code and others with custom models and emitters. In the recent days I looked through a lot of publicy available resources, packages, code regarding TypeSpec (like: Azure tooling, AutoRest, MS Graph package) and this takes me to my question: Other MS teams seems to heavily leverage the TypeSpec typing system to (re)define their own types and not going with the built-in pieces provided by Rest and Http TypeSpec modules. A dozens of decorators are implemented and for me the only way to take those to the CodeModel would be possible only by doing a custom CodeModel and change/extend the emitter code like those teams are doing. It is quite an involved process that would be done all the TypeSpec users around the globe. Example scenario: I want to add a What are the extensibility thoughts/plans regarding the support of such feature without inheriting from the When it comes to code generation, I prefer to leverage the target languages (C# in this case) tools (Roslyn) and not using some other languages (Java/Kotlin in case of Smithy, TypeScript in case of TypeSpec). |
Beta Was this translation helpful? Give feedback.
-
Thanks Brian for the elaborate explanation, and I am on the same page with you and the necessity of a CodeModel is a good thing, it is like an AST -> AST transformation from TypeSpec to CodeModel, which is futher transformed into another AST in a case where someone uses Roslyn to generate the code. Lets treat "Azure" as a domain of MSFT, and in my case my line of business API is my domain and because of the business related complexity and it's specifics will require me to have a custom CodeModel so I can articulate the domain features within it and use it further. Based on this I think with a mindset shift on how we look at the CodeModel, what if we would treat the CodeModel approach as a recipe and instead of removing it in the future from TypeSpec, turn it into patterns and practices and guidance (pun intended, @garethj_msft will know) on how someone could roll their own, what steps are needed, etc. Beside having it as guidance, as long as it is only a bunch of related POCO classes, perhaps a way could be found on how to generate these from the TypeSpec files (as currently it is generated from JSON Schemas for Azure). I think that your opinion that you've formulated here - even if personal - it determines how deep or what way one would invest into TypeSpec ecosystem. For me based on this it means to get extract out the CodeModel schemas and generation and related code and start to use that so save myself from future surprises when it will be just gone. This looks the safest and most future proof way for my journey. Please correct me if I miss something. |
Beta Was this translation helpful? Give feedback.
This is a great discussion topic, but I will share a tracking issue here, that's a good idea.
It's hard to say which you should do, it depends a lot on what your needs are and how urgent those needs are.
Kiota codegen is good, so I would say, if it works for you, then you would have no problems going the openapi -> kiota route. A side project I hope to get to soon is to package this up in an emitter to make it even easier, so you could do something like
npx tsp compile . --emit typespec-kiota --option typespec-kiota.language="csharp"
). That said, I am obviously partial to the codegen we do on the Azure SDK and are bringing to TypeSpec. Kiota codegen wouldn't work for us, so if you're in a…