Skip to content

Instantly share code, notes, and snippets.

@jianghaolu
Created August 19, 2020 02:33
Show Gist options
  • Save jianghaolu/792ab5a998a7a81cebfd474e1aaab2ff to your computer and use it in GitHub Desktop.
Save jianghaolu/792ab5a998a7a81cebfd474e1aaab2ff to your computer and use it in GitHub Desktop.
AutoRest Java Customizations

Intro

There are primarily 3 places a user of AutoRest Java can customize the generated code:

  1. pre-gen

An example of this is transforms of Swagger docs. This is similar to modifying the Swagger spec, thus giving users the least control of the output code.

  1. cmdline arguments

The commandline arguments are often customizations requested by users. This is controlled as part of the generation, thus having lots of power to alter the output code. But the arguments are limited to simple boolean or string inputs. It also requires a long turnaround time for AutoRest Java developers to support a new commandline argument.

  1. post procssessing

As of today the users can modify the output code directly, or write a transformation for the output code. This gives users the most control as they can directly modify the output code as needed.

Proposed new infrastructure

  1. Customizable pre processor

Users will have access to the code model emitted by modeler four. They are allowed to add / remove a method. For paging / lro methods that might generate a set of methods in the output Java code, modifying here may be more cost effective.

However, this does require the user to have a good understanding of the code model. Thus will not be recommended. It serves as a secret feature, used only when there's a bug in modelerfour, and the customer needs an urgent fix in the output code while the modelerfour fix isn't available yet.

  1. Trimmed down commandline arguments

Today's v4 codegen inherited some outdated commandline arguments from v3. We should be able to trim it down. Also, commandline arguments like "custom-types" might be better suited as part of the post processor, as users do have to provide a long list of input in a comma separated format, which is prone to errors.

  1. A brand new post processor

Originally proposed in Azure/autorest.java#617, it suggested two ways to post process:

  • Return a map of file names to file contents and allow users to modify in any way they want
  • Return a DSL representation of the output Java package including all the classes and expose methods in DSL for users to modify the output code in any way they want

However, talking to .NET and Python folks, we learned that .NET has taken a different approach: https://github.com/azure/autorest.csharp#customizing-the-generated-code. They only expose certain modifications and do not allow more freedom in customization. We are also discouraged to keep going down our route as it might bring undesired abuse from our users.

But this design blurs the line between a post processor and the commandline arguments. I can see some customizations receiving confusions on whether they are customized through a post processor or commandline arguments. I would prefer a more definitive guide between these two, eliminating the possibility that users have to look at many places to find the customization they need.

Hybrid Post Processor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment