-
-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Python codegen for the OpenAPI backend (#21316)
- Loading branch information
Showing
16 changed files
with
1,188 additions
and
25 deletions.
There are no files selected for viewing
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
4 changes: 4 additions & 0 deletions
4
src/python/pants/backend/experimental/openapi/codegen/python/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 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_sources() |
Empty file.
18 changes: 18 additions & 0 deletions
18
src/python/pants/backend/experimental/openapi/codegen/python/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,18 @@ | ||
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from pants.backend.experimental.openapi.register import rules as openapi_rules | ||
from pants.backend.experimental.openapi.register import target_types as openapi_target_types | ||
from pants.backend.experimental.python.register import rules as python_rules | ||
from pants.backend.experimental.python.register import target_types as python_target_types | ||
from pants.backend.openapi.codegen.python.rules import rules as openapi_python_codegen_rules | ||
|
||
|
||
def target_types(): | ||
return [*python_target_types(), *openapi_target_types()] | ||
|
||
|
||
def rules(): | ||
return [*python_rules(), *openapi_rules(), *openapi_python_codegen_rules()] |
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
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 2024 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"]) |
Empty file.
42 changes: 42 additions & 0 deletions
42
src/python/pants/backend/openapi/codegen/python/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,42 @@ | ||
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
import itertools | ||
|
||
from pants.backend.openapi.target_types import OpenApiDocumentGeneratorTarget, OpenApiDocumentTarget | ||
from pants.backend.python.target_types import PrefixedPythonResolveField | ||
from pants.engine.target import BoolField, DictStringToStringField, StringField | ||
|
||
|
||
class OpenApiPythonGeneratorNameField(StringField): | ||
alias = "python_generator_name" | ||
required = False | ||
help = "Python generator name" | ||
|
||
|
||
class OpenApiPythonAdditionalPropertiesField(DictStringToStringField): | ||
alias = "python_additional_properties" | ||
help = "Additional properties for python generator" | ||
|
||
|
||
class OpenApiPythonSkipField(BoolField): | ||
alias = "skip_python" | ||
default = False | ||
help = "If true, skips generation of Python sources from this target" | ||
|
||
|
||
def rules(): | ||
return [ | ||
target.register_plugin_field(field) | ||
for target, field in itertools.product( | ||
( | ||
OpenApiDocumentTarget, | ||
OpenApiDocumentGeneratorTarget, | ||
), | ||
( | ||
OpenApiPythonSkipField, | ||
OpenApiPythonGeneratorNameField, | ||
OpenApiPythonAdditionalPropertiesField, | ||
PrefixedPythonResolveField, | ||
), | ||
) | ||
] |
Oops, something went wrong.