forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Java codegen for the OpenAPI backend (pantsbuild#16862)
Initial implementation for a codegen feature in the OpenAPI backend
- Loading branch information
1 parent
191ab4e
commit c944831
Showing
24 changed files
with
1,595 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
4 changes: 4 additions & 0 deletions
4
src/python/pants/backend/experimental/openapi/codegen/java/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_sources() |
Empty file.
15 changes: 15 additions & 0 deletions
15
src/python/pants/backend/experimental/openapi/codegen/java/register.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from pants.backend.experimental.java.register import rules as java_rules | ||
from pants.backend.openapi.codegen.java.rules import rules as java_codegen_rules | ||
|
||
|
||
def target_types(): | ||
return [] | ||
|
||
|
||
def rules(): | ||
return [*java_rules(), *java_codegen_rules()] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_sources() | ||
|
||
python_tests(name="tests", dependencies=[":lockfiles"]) | ||
|
||
resources(name="lockfiles", sources=["*.test.lock"]) |
38 changes: 38 additions & 0 deletions
38
src/python/pants/backend/openapi/codegen/java/extra_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from pants.backend.openapi.target_types import OpenApiDocumentGeneratorTarget, OpenApiDocumentTarget | ||
from pants.engine.target import BoolField, StringField | ||
from pants.jvm.target_types import PrefixedJvmJdkField, PrefixedJvmResolveField | ||
|
||
|
||
class OpenApiJavaModelPackageField(StringField): | ||
alias = "java_model_package" | ||
help = "Root package for generated model code" | ||
|
||
|
||
class OpenApiJavaApiPackageField(StringField): | ||
alias = "java_api_package" | ||
help = "Root package for generated API code" | ||
|
||
|
||
class OpenApiJavaSkipField(BoolField): | ||
alias = "skip_java" | ||
default = False | ||
help = "If true, skips generation of Java sources from this target" | ||
|
||
|
||
def rules(): | ||
return [ | ||
OpenApiDocumentTarget.register_plugin_field(OpenApiJavaSkipField), | ||
OpenApiDocumentTarget.register_plugin_field(OpenApiJavaModelPackageField), | ||
OpenApiDocumentTarget.register_plugin_field(OpenApiJavaApiPackageField), | ||
OpenApiDocumentGeneratorTarget.register_plugin_field(OpenApiJavaSkipField), | ||
OpenApiDocumentGeneratorTarget.register_plugin_field(OpenApiJavaModelPackageField), | ||
OpenApiDocumentGeneratorTarget.register_plugin_field(OpenApiJavaApiPackageField), | ||
# Default Pants JVM fields | ||
OpenApiDocumentTarget.register_plugin_field(PrefixedJvmJdkField), | ||
OpenApiDocumentTarget.register_plugin_field(PrefixedJvmResolveField), | ||
OpenApiDocumentGeneratorTarget.register_plugin_field(PrefixedJvmJdkField), | ||
OpenApiDocumentGeneratorTarget.register_plugin_field(PrefixedJvmResolveField), | ||
] |
Oops, something went wrong.