Skip to content
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] URI encoded $ref not properly decoded #5720

Closed
5 of 6 tasks
SimonIT opened this issue Mar 26, 2020 · 5 comments · Fixed by #7191
Closed
5 of 6 tasks

[BUG] URI encoded $ref not properly decoded #5720

SimonIT opened this issue Mar 26, 2020 · 5 comments · Fixed by #7191

Comments

@SimonIT
Copy link
Contributor

SimonIT commented Mar 26, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I wanted to generate a dart lib for flutter with the provided swagger yaml config. The problem is, that some of the generated class names contain spaces which are not valid. After writing a fix for it (PR #5693), I used swagger to edit the yaml. Swagger suggests to use %20 instead of normal spaces inside $ref definition links because it's an URI (see docs). Now I got the problem, that some class names contain %20.

openapi-generator version

4.2.3

OpenAPI declaration file content or url

https://raw.githubusercontent.com/wbt-solutions/openproject_dart_sdk/master/openProject_swagger.yaml

Command line used for generation

I used the command java -jar .\openapi-generator-cli-4.2.3.jar generate -g dart -i openProject_swagger.yaml -o openproject_dart_sdk/ inside the Windows Powershell.

Steps to reproduce

Execute the command with the provided config and look for example in the model\work_package.dart.

Related issues/PRs

Haven't found any.

Suggest a fix

Properly decode the $ref attribute as URI.

@auto-labeler
Copy link

auto-labeler bot commented Mar 26, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@SimonIT
Copy link
Contributor Author

SimonIT commented Mar 27, 2020

I don't know, why the bot added the dart label. The problem is for every language, I think. I tried also Java and there is the problem, too.
I would also provide a PR for fixing this problem, but I can't find the code for parsing the open api config. If someone would give me a hint, I will try to fix this.

@bzmw
Copy link

bzmw commented Aug 12, 2020

Having a similar issue here: PagerDuty/api-schema#82

Was there any resolution that you found @SimonIT

@SimonIT
Copy link
Contributor Author

SimonIT commented Aug 12, 2020

I discovered now that if you replace this line


with

        return URLDecoder.decode(ref);

the name gets properly decoded. I will make a PR.
It would be very nice if you can approve my fix

sbu-WBT added a commit to wbt-solutions/openapi-generator that referenced this issue Aug 12, 2020
@sbu-WBT sbu-WBT mentioned this issue Aug 12, 2020
6 tasks
@SimonIT
Copy link
Contributor Author

SimonIT commented Aug 13, 2020

Okay, I tested it myself with the provided command from your issue and this didn't fix your problem.
I think your problem is, that #/paths/ is nowhere handled by the generator because IntelliJ couldn't find any occurrences of it in the whole project. I think you have to change you specification or you make a PR which solves this.

wing328 pushed a commit that referenced this issue Sep 8, 2020
* Properly decode $ref
fixes #5720

* Specify decoding encoding

* Nicer syntax

* UTF-8 typo

* Unescape special characters

* Change order of unescaping to prevent escaped sequences by accident

* Comment for special decoding

Co-authored-by: Jim Schubert <james.schubert@gmail.com>

* Add unit test for simple ref decoding

Co-authored-by: Jim Schubert <james.schubert@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants