-
Notifications
You must be signed in to change notification settings - Fork 48
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
Cannot depend on generated client #22
Comments
This seems to be similar to issue #6 I think it has something to do the implementation returning all the files:
|
Any updates on this? I'm trying to use
Building |
I can't depend on the generated code either in typescript. @wing328 Can you post an example of how to depend on the outputs of this? |
Hi, I tried to solve this issue but unfortunately I couldn't find a way around a major obstacle. The generator-cli's output is not transparent, which is the reason why the output files can't be defined in advance, which is required for bazel. In other words, I couldn't find a way to define the output files based on the yaml, since the way bazel is built, you would have to parse the yaml in advance and additionally know the implementation of the generator-cli, which defines the naming convention (eg. InlineResponse500.ts) The workaround for me is to just generate the client manually and compiling the resulting typescript files as usual with bazel. (Which is not a solution one is looking for in this repo) I don't really see any benefit in using this "bazel" tool. Which is a pity if you try to use open-api in a bigger project, where you need to automate these steps. |
I think the only way to do this is have this be a appropriate provider and create a switch statement for every language to filter for the "library" files. I was going to write something specific for the few languages that we needed support for, but we went a completely different route. |
Hi, this question was raised on stackoverflow, and some workarounds, at least for python, are discussed there: |
Also, the java rules can take a source jar in srcs, so one workaround for the generated java code is to zip up the java files from the generated directory. Something like this:
The maven deps I got from the generated build.gradle file, but I got compilation errors like this
so something's not lined up between the generated code and the deps, but the main idea is the |
+1 |
this makes it "impossible" to work with in a multi language repository |
Hi guys, |
Hi all,
The trick is the NOTE: you need your own main.go file:
Inspired from C++ example here: https://stackoverflow.com/questions/48417712/how-to-build-static-library-from-the-generated-source-files-using-bazel-build |
Using copy_to_directory and including the result as openapi_generator(
name = "xcover_client_codegen",
additional_properties = {
"packageName": "xcover_python_client",
},
generator = "python",
spec = "swagger.json",
)
copy_to_directory(
name = "xcover_python_client",
srcs = [":xcover_client_codegen"],
include_srcs_patterns = ["xcover_client_codegen/xcover_python_client/**"],
replace_prefixes = {
"xcover_client_codegen/xcover_python_client": "",
},
)
py_library(
name = "xcover_python_client_lib",
# Output from openapi_generator is a directory and not a list of files, so we
# include it as data instead of as srcs, in order to prevent Bazel from emitting
# a warning that no .py files were found.
data = [
":xcover_python_client",
],
imports = ["."],
visibility = ["//visibility:public"],
deps = [
requirement("python_dateutil"),
requirement("urllib3"),
],
) But really the OpenAPI generator rules should probably be rewritten as repository rules... (https://bazel.build/extending/repo) |
Here's a solution to the problem that doesn't use openapi_generator(
name = "my_client",
additional_properties = {
"packageName": "my_client",
},
generator = "python",
spec = "swagger.json",
)
py_library(
name = "my_client_py",
data = [":my_client"],
imports = ["./my_client"],
visibility = ["//visibility:public"],
deps = [
requirement("python_dateutil"),
requirement("urllib3"),
],
) |
I have seen some issues while running the go-gin-server generator, has anyone been able to use the go-server generator for go successfully? If we try to use the copy_to_directory(), the go_library() panics with unused dep statements. |
This would be a bug in the code generation and should be fixed as part of the main project. I am able to generate code with the go-server generator in my project. Make sure you also use the latest version of the cli. |
Hopefully I'm missing something simple, but so far as I can tell, when using
openapi_generator
it doesn't appear to declare and outputs. So in my use case, I am generating a Python client which will then be depended on by apy_library
. This doesn't appear to work.I'd appreciate if someone could provide an example where they depend on a generated client and how that gets wired up. Thanks!
Some additional context on what I've tried:
The above will claim that the
my_api_client_src
target doesn't contain any python files, so I've tried depending on it as data instead and making a dedicatedpy_library
target for it, but that doesn't appear to work either.The text was updated successfully, but these errors were encountered: