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 Java codegen for the OpenAPI backend #16862

Merged
merged 7 commits into from
Sep 28, 2022

Conversation

alonsodomin
Copy link
Contributor

@alonsodomin alonsodomin commented Sep 14, 2022

Initial implementation for a codegen feature in the OpenAPI backend. This is based on the OpenAPI Generator tool, which supports many different languages.

At this point, only the Java sources are generated with no support to detect the runtime dependencies, which will be added as this PR progresses.

Because the OpenAPI Java generator doesn't have a single JVM dependency, the inference of the runtime dependencies is based on parsing the generated Maven POM file. We use a simple sample OpenAPI spec file to do that as the runtime dependencies will always be the same regardless of what is the input given to the OpenAPI Java generator.

@jyggen
Copy link
Member

jyggen commented Sep 14, 2022

Exciting! I was actually planning to do the same thing but for Python when I've got some spare time, but now I'll definitely hold that off and piggback off of the work here once it's merged. 🎉

@alonsodomin
Copy link
Contributor Author

@jyggen sounds like a plan, we can defo work together on adding support for more languages incrementally. Also, feel free to provide with any feedback/ideas where this implementation may differ from what you had in mind.

@alonsodomin alonsodomin marked this pull request as ready for review September 26, 2022 10:37
Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!


extra_jvm_options = [*subsystem.jvm_options, *request.extra_jvm_options]

jvm_process = JvmProcess(
Copy link
Member

Choose a reason for hiding this comment

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

Since this code is specific to the JVM, it's probably not generic to all of openapi the way its module namespace might suggest.

But also: since this is used in exactly one other @rule, it feels like premature optimization to extract it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is indeed a bit of a premature optimisation. The idea behind this is to make it easier to implement code generation for other languages as all of them use the same generation tool.

In other words: this is not specific to the Java code generator, the code generation tool is a JVM tool which can generate code for a wide variety of languages as it takes in its argument list the target language (aka generator) to be used: https://openapi-generator.tech/docs/generators

So with this rule, supporting new generators consist on adding a new enum value to OpenAPIGeneratorType and then implementing the backend for that generator so that it uses this rule to build the final process the same way the java generator does.

@jyggen mentioned he was interested in implementing the Python code generation, which would benefit from this. I guess the main inconvenience is that this will in fact still depend on the JVM rules.

Copy link
Member

Choose a reason for hiding this comment

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

Ok: sounds good. Thanks!

_MAVEN_NAMESPACE = "http://maven.apache.org/POM/4.0.0"
_MAVEN_NAMESPACE_MAP = {"mvn": _MAVEN_NAMESPACE}


Copy link
Member

Choose a reason for hiding this comment

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

Hah, neat. Potentially related to #13684

@alonsodomin alonsodomin merged commit c944831 into pantsbuild:main Sep 28, 2022
benjyw pushed a commit that referenced this pull request Sep 15, 2023
This PR adds the openai `java` codegen backend, 
introduced in #16862, to src/python/pants/bin/BUILD

Closes #19836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: OpenAPI OpenAPI backend-related issues category:new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants