apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.38k stars 114 forks source link

Old and new examples #576

Open barthoffman opened 4 months ago

barthoffman commented 4 months ago

Question

Thanks for your work on the OpenAPI generator.

The current repo shows update #472 which removes the old tutorials. Going through the old tutorials the swift-package-manager tutorial still reference GreetingClient in the Xcode steps: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/tutorials/swift-openapi-generator/clientxcode

In this tutorial the outline is to create a separate framework but it will never reveal the contents e.g. GreetingClient() from the framework (Tutorial Step 9). Looking at the new examples an addition is made in the OpenApi definition like this:

If you split the generated code into a separate library, such as a framework or a SwiftPM library product, you also need to change the accessModifier to either public or package.

generate:
  - types
  - client
accessModifier: public

source: https://github.com/apple/swift-openapi-generator/tree/main/Examples/HelloWorldiOSClientAppExample

If one changes the accessModifier to package you get the announced error message but if you use public nothing seems to happen. Maybe I overlooked but the new samples don’t show using a framework anymore? Is this for a reason or did I miss an update?

Am assuming that others could run into the same questions so was requested to raise an issue after emailing.

Looking forward to your reaction

barthoffman commented 4 months ago

Small addition: the tutorials generating servers stubs add the call for /emojis returning in plainText instead of JSON. This is not returning in the later tutorials. There is info in the new tutorials about using plainText so someone who wants can find it. Was wondering if for learning purposes this should be added in the later tutorials for completeness.

czechboy0 commented 4 months ago

Hi @barthoffman,

can you clarify whether you're reporting what you believe is a bug in the tutorials, or if you're saying you'd like us to bring back the old tutorials from pre-1.0 days?

GreetingClient is still used in the tutorials. Tutorials are separate from Examples, where Examples are meant to be self-contained projects.

If you found multiple issues, please file a separate issue for each problem, to make sure we can correctly track fixing them all. Thanks!

barthoffman commented 4 months ago

HI @czechboy0,

I think in the tutorial a piece of info is missing to make it work as expected: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/tutorials/swift-openapi-generator/clientxcode Not sure if it's bug.

What happens if you follow the instructions: 1. In Configuring your target to use the Swift OpenAPI Generator plugin (Step 10) no confirmation is asked as indicated but it will still work. Then 2. in Using the generated code in your target step 9 doesn't seem to "expose" the public calls from the framework. Xcode indicates: This struct might not be available in this context

I looked into the available repository samples to find what might be missing and here 3. the accessModifier in the definition is mentioned. This made me assume there might be some info missing on how to use the Framework from the tutorial above correctly. Maybe something changed in the accessmodifiers? The new examples however don't seem to have a sample using a framework (or I missed it).

I think my main question is if you could run through the tutorial too to check the findings and see if I made a mistake or something is indeed missing.

Im not specifically asking to bring the old tutorials back although I assume that to make the current tutorials work for learning purposes they should be complete (including GreetingClient?). An alternative would be a working sample with a separated framework?

If you want me to file the findings separately I can, more important would be confirmation the tutorial is correct. If there is something missing it might turn people away from further exploration if the initial learning steps are incomplete.