Skip to content

Commit

Permalink
Support Java codegen for the OpenAPI backend (pantsbuild#16862)
Browse files Browse the repository at this point in the history
Initial implementation for a codegen feature in the OpenAPI backend
  • Loading branch information
alonsodomin authored Sep 28, 2022
1 parent 191ab4e commit c944831
Show file tree
Hide file tree
Showing 24 changed files with 1,595 additions and 1 deletion.
Empty file.
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.
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.
8 changes: 8 additions & 0 deletions src/python/pants/backend/openapi/codegen/java/BUILD
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 src/python/pants/backend/openapi/codegen/java/extra_fields.py
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),
]
Loading

0 comments on commit c944831

Please sign in to comment.