-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[BUG] '/' prepended to paths that don't start with '/' #2702
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
This was introduced with #1034. Not having a leading
But you are bringing an interesting case... A question from my side: |
@jmini I don't think we have a choice but to "fix" specs, otherwise generators may individually attempt to apply fixes to create meaningful generated code. Paths are intended to be appended to the base URL, but it seems like a base url of I'd have to look across some generators to offer a suggestion on how we might best approach this. But I think we'll need to fix any issues in generators as they arise. |
@jmini, @jimschubert I don't expect the generator to correct a path specified in the schema. I expect a generator to take exactly what is in the schema and insert it into templates. If the generated code does not make sense, the schema needs to be adjusted by the user of the generator. We use the full URI of a resource as it's identifier. So our API returns these strings and our users store strings like I would like to switch from swagger-codegen to openapi-generator, but this is preventing me right now. [0] https://github.com/django/django/blob/master/django/urls/base.py#L27 |
@dkliban these two comments pretty accurately demonstrate our dilemma regarding fixing or ignoring invalid documents:
and
Even so, some users such as yourself might rely on tooling which doesn't follow the OpenAPI specification appropriately (swagger-codegen). Take these url, path, and combinations for instance:
My point in my previous comment was that, if swagger-parser doesn't treat the last two options as invalid and also doesn't normalize the spec to provide tooling a "valid" object model according to the specification, then it is up to tooling to normalize these combinations. In all of the examples above, we know what the combined output should be for a given URL. But even in the second example, we have no choice really but to modify what the user provides since it's technically valid for both inputs. One option I see to help alleviate this problem is to introduce a It's also possible to create a custom template, which may also potentially help solve the issue. This past weekend, we've added experimental support for custom templates using Handlebars. Granted, this would require rewriting any affected code in handlebars templates, but the built-in adapter supports conditions (if/eq/neq) as well as string operations (a custom Eventually, I'd like to include an immutable input configuration which can be passed to templates such that users who customize templates may have greater control over outputs. I intend this work to be part of project #5 |
@jimschubert Thanks for putting together that patch! It looks great. I was planning to work around this problem by just doing a search and replace on the generated code[0]. However, I would much rather not have to do that. |
@jimschubert Thanks for adding the extra flag! Just tried it out and it works. |
Bug Report Checklist
Description
I am currently trying to switch from swagger-codegen-cli to openapi-generator-cli, but I ran into a problem with the generated Python client code. I do not experience the same behavior when generating client code using swagger-codegen-cli.
/
is prepended to paths that don't start with a/
. This is a problem because my OpenAPI schema includes paths that consist of a single path parameter. e.g.:{artifact_href}
. In the generated code this is turned into/{artifact_href}
. Since the path parameter being passed in looks like/pulp/api/v3/artifacts/1234/
, the client makes a request tohttp://localhost//pulp/api/v3/artifacts/1234/
and the server is unable to service the request. Notice the//
in the URL.This problem is not unique to the Python generator. I am seeing the exact same behavior for Ruby also.
openapi-generator version
The latest docker image of openapi-generator-cli.
OpenAPI declaration file content or url
https://docs.pulpproject.org/en/3.0/nightly/api.json
Command line used for generation
Steps to reproduce
Generate a Python client with the schema from above. Observe that the client that is generated has
while the path for this operation in the OpenAPI schema was simply
{artifact_href}
. I would expect the generator to not modify the path value.Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered: