-
Notifications
You must be signed in to change notification settings - Fork 75
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
Design customization process from typespec generation #1950
Comments
My personal preference is a hybrid of #2 and #3. If the following two things are true:
Then we will not generate metadata files and will put only At this point @joheredi @witemple-msft thoughts? |
also /cc @deyaaeldeen since I think what I'm describing is basically a configuration-by-convention version of what he was trying to implement before his recent DTO |
+1 on @xirzec proposal because it just works. We can iterate over it later if a need to arises. |
Thanks Jeff's input and I think we could start with this option and improve the process in future if necessary. And the experience of the hybrid option would be:
|
I agree, 2 & 3 sound good and should work now. This is how I understand the process from a library developer perspective:
|
The part that's up in the air to me is if we always generate into our repo like the customization tool is going to be used or if it's opt-in. If it is opt-in, we need some mechanism to signal this. Since we got strong pushback on adding a new emitter flag (because the scripts and specs repo wants to only give us the package directory) would be to do something like checking for a subfolder being manually created. That said, if we wanted to simplify by always having customization there and requiring that extra step when generating non-customized packages, I'm fine with that too. At least it makes it clear how to customize when you need it without needing to know the convention. |
I'm fine with always generating as if we were having customization, and we can listen for partner feedback to decide if we want to implement some extra heuristics. |
The |
This is regardless if azure-sdk-for-js true or generate-metadata true. If we can make dev-tool public available, we can even generate the source code into sources/generated folder when working outside of the azure-sdk-for-js repo like codegen's own testing. |
Personally I would prefer the Another point is that we may have scenarios to generate code outside of SDK repo e.g testing environment or external customers, running that tool could be challenging. @joheredi How do you think? |
Devtool already has some logic to detect project roots within libraries in azure-sdk-for-js. I guess if we can reuse that in the emitter to detect if running within the repo and generate under sources/generated (assume the azure-sdk-for-js flag to true). This way we always generate under sources/generated for the repo and stand alone library when generating outside of the repo |
FWIW I don't think we should make devtool public, it is tightly coupled by design to the mono repo so I'm not sure investing on opening it will give us good ROI |
Just confirm my understanding is below: This way we always generate under |
After offline discussion we have our final design. Please notice we would provide another command 1st-time of customer's experience
2nd time to refresh customized SDK
The ci steps in swagger pr
|
If service team already knows they need customization for the 1st time, can they run one script to ensure init code generated with all configuration and folder structure set correctly? |
@lirenhe I don't think it is possible to run one script in our current design and I agree with @joheredi that we would listen for partner feedback to decide if we want to implement some extra heuristics/steps/flags. Our assumption is that if we could keep high quality codegen customization is not a requirement in most cases. |
Close this issue considering the design is finalized. |
Background
We have customization requirement on generated code when we use the typespec as input. Currently we have openai and loadtesting SDK customized but with different approach. I think it's better to design clear and consistent expectations on:
Option 1: Enable
source-code-folder-path
optionThis is also the swagger way for customization and usually we could edit the config file in
swagger/README.md
under SDK folder(see example).Different from swagger, in typespec all configs would save in spec repo which means both ci runs in spec pr and local gens in sdk repo would share the same config. To make it work we need to generate the top-level
index.ts
(if missing) to expose all api to public.End user experience
TypeSpec-Project-Process.ps1
;src
folderPros & Cons
Option 2: Always generated in
src/generated
Similar to Option 1, but here we would not differentiate the customization or not, the generated code would always in
src/generated
folder. Also we would detect if there is a top-level index.ts under src folder, if missing generate one. Customers can't point to any specific folder for generated code.This option could work well if service team would have their customization codes in most cases, otherwise it seems redundant.
End user experience
TypeSpec-Project-Process.ps1
;src
folderPros & Cons
Option 3: Use tool
dev-tool customization apply
We have a tool(link) which could merge customization code and generated code. And the code structure would be like:
To allow codegen to generate in
sources/generated
folder we need an optionsource-code-folder-path
orallow-costomization
.End user experience
source-code-folder-path: ./sources/generated
TypeSpec-Project-Process.ps1
;sources
folder;dev-tool customization apply -s sources/generated/src
TypeSpec-Project-Process.ps1
;To optimize above steps we could integrate customization tool as part of codegen, then the codegen's behavior would be like:
./sources/generated
customization apply
to combine both parts2.1 If no customization, just copy to
src
2.2 If customization, combine them
Improved end user experience
TypeSpec-Project-Process.ps1
;sources
folder;TypeSpec-Project-Process.ps1
;Pros & Cons
src
folder./sources/customizations
Option 4: In-place modify the generated code
This is Java's way to do customization(refer). They have
@Generated
annotation in generated code, so customers could modify them so their codegen could recognize it and keep these customizations.End user experience
TypeSpec-Project-Process.ps1
;src
folderPros & Cons
Personally both Option 1 and Option 3 could work for me.
@xirzec @joheredi @qiaozha Could you take a look at above options and share your ideas?
/cc @lirenhe @raych1
The text was updated successfully, but these errors were encountered: