Giter Club home page Giter Club logo

Comments (14)

mattpolzin avatar mattpolzin commented on July 17, 2024 4

This issue has been fixed for OpenAPIKit releases 2.5.2 and 3.0.0-alpha.7.

Thanks all for raising and investigating this!

from swift-openapi-generator.

simonjbeaumont avatar simonjbeaumont commented on July 17, 2024 2

Thanks @miguel-arrf for taking the time to dive into this one and thanks @mattpolzin for offering to take a look at a fix in OpenAPIKit—please feel free to link an issue here and we'll be more than happy to to integrate it when its ready.

from swift-openapi-generator.

miguel-arrf avatar miguel-arrf commented on July 17, 2024 2

Hi!

Thank you all so much for the help @czechboy0 @mattpolzin @simonjbeaumont !!

I had a fix implemented in my local repository, but it was a bit less elegant 😅!

I'm on vacations and unfortunately I have limited internet connection!

If it is okay by you @czechboy0 , I will gladly open the PR in the next (more or less) 12 hours 🙂.

Thank you for the opportunity and all the help!!

from swift-openapi-generator.

simonjbeaumont avatar simonjbeaumont commented on July 17, 2024 2

@miguel-arrf wrote:

Thank you all so much for the help @czechboy0 @mattpolzin @simonjbeaumont !!

No problem!

I'm on vacations and unfortunately I have limited internet connection!

If it is okay by you @czechboy0 , I will gladly open the PR in the next (more or less) 12 hours 🙂.

Thank you for the opportunity and all the help!!

That's fine, enjoy your vacation 😎. Ping us if you don't have the bandwidth or change your mind, and one of us will pick it up.

Be great to cover this in an update to the tests too :)

from swift-openapi-generator.

miguel-arrf avatar miguel-arrf commented on July 17, 2024 1

Hi!

Yup, it's exactly there that it is happening!

So, basically the issue was starting here when decoding the data with the OpenAPI.Document.self object.

My first guess was try to use the JSONDecoder instead of the YAMLDecoder, but the issue remained. I was then able to figure out where the issue is coming from. It's coming from the Path struct from OpenAPIKit, see here. What's happening is that they are spliting the path components by the / separator, meaning that all trailing / are getting ignored.

They mention the OpenAPI specification (available here). Upon reading it, I'm not entirely sure that the correct behaviour is to eliminate the last / from a Path if there are no components after it. With this, on the specification there are no cases of any endpoint ending up with a /, so I'm assuming they aren't expecting any trailing / to appear.

I will open an issue with OpenAPIKit to try to figure out what can be done! :)

Thank you so much for the help! @czechboy0

from swift-openapi-generator.

mattpolzin avatar mattpolzin commented on July 17, 2024 1

I've not heard about this problem before, but looking at the OpenAPIKit source i can confirm the problem is in how it handles these paths (splitting on forward-slash and then joining back with slash to create a string representation).

So, the bug was born of an oversight on my part. I'm on vacation without a laptop for the next week but after that I can fix the problem upstream in OpenAPIKit (especially if someone is kind enough to create me a GitHub issue to track this bug).

from swift-openapi-generator.

mattpolzin avatar mattpolzin commented on July 17, 2024 1

@miguel-arrf thanks for offering to open that issue against OpenAPIKit! I was composing my response when your response came in, but you were spot on.

from swift-openapi-generator.

mattpolzin avatar mattpolzin commented on July 17, 2024 1

it'd be good to be confident in the fix.

Shots fired. 😄 totally kidding, 100% same page about testing philosophy.

from swift-openapi-generator.

czechboy0 avatar czechboy0 commented on July 17, 2024

Hi @miguel-arrf, thank you for taking the time to file this great issue 👏

Just recently, @simonjbeaumont and I discussed this behavior, so I suspect it is a bug on the generator currently. We'll have to investigate where exactly the trailing slash gets stripped and figure it out from there. If you're able to, you could debug the generator yourself – which is probably easiest by cloning the repo, opening it in your IDE, and launching the CLI target with a debugger attached. We have more docs on contributing here. A good first breakpoint might be around here: https://github.com/apple/swift-openapi-generator/blob/main/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift#L240, where the path is parsed from the OpenAPI doc and used to generate the client code.

Now, as a temporary workaround, you could implement a ClientMiddleware that, for a set of known operation ids modifies the path to add the trailing slash before it goes out to the transport and gets sent out. That should allow you to get rid of the redirect. Once the generator is fixed, you'll be able to delete this middleware.

from swift-openapi-generator.

czechboy0 avatar czechboy0 commented on July 17, 2024

It's possible that the trailing slash is getting stripped in OpenAPIKit – @mattpolzin have you seen this before?

from swift-openapi-generator.

czechboy0 avatar czechboy0 commented on July 17, 2024

Thanks @mattpolzin for the fix!

@miguel-arrf, do you want to do the honors of opening a PR bumping our dependency to alpha 7?

from swift-openapi-generator.

miguel-arrf avatar miguel-arrf commented on July 17, 2024

PR created! ☺️ It already has the version bump to -alpha.7. I will be able to add the tests during this weekend, when I'm back from my vacations. Should I add them to the same PR @czechboy0 ?

from swift-openapi-generator.

czechboy0 avatar czechboy0 commented on July 17, 2024

PR created! ☺️ It already has the version bump to -alpha.7. I will be able to add the tests during this weekend, when I'm back from my vacations. Should I add them to the same PR @czechboy0 ?

Yes please, it'd be good to be confident in the fix.

from swift-openapi-generator.

czechboy0 avatar czechboy0 commented on July 17, 2024

it'd be good to be confident in the fix.

Shots fired. 😄 totally kidding, 100% same page about testing philosophy.

Haha, I meant that we correctly integrate the fix 😉 No shade intended.

from swift-openapi-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.