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.23k stars 89 forks source link

programmatic init #497

Closed pkasson closed 4 months ago

pkasson commented 5 months ago

Question

Is it possible to generate client code without building within Xcode (i.e. dynamically) ... and how to start server programmatically ?

simonjbeaumont commented 5 months ago

Hey @pkasson!

When you say "dynamically, without building in Xcode", do you mean you'd like to:

  1. build outside of Xcode, in which case, yes. Checkout any of our tutorials that mention SwiftPM (cf. Xcode) or any of our examples which can be built swift build^1; or
  2. build in Xcode but "dynamically", by which you mean some form of automatic build where you don't have to trigger a build to pick up changes and have the generated code available for you to use in the consuming module. In which case, no, you cannot. The code is generated by a Swift package plugin, which runs at build time. If this is something you'd like, please file a request against Xcode^2.

When you say "start the server programmatically", you can use swift run on the command line with any of our server examples, or otherwise start the server by running the binary directly.

Finally, the title of your issue is "programmatic init". If this is about a command to bootstrap a package from scratch, without an Xcode project, then you may be interested in #448.

Does this answer your questions? If not, could you provide more details as to what you're trying to achieve and how?

Happy holidays :)

pkasson commented 5 months ago

@simonjbeaumont - thanks for the great response !

  1. Yes - build via a script, API using SPM, so that client code can be built outside XC
  2. As in number 1, using SPM, generate the code, to be able to run later - i.e. a 'batch' build to run / test in a script

Happy holidays ;)

simonjbeaumont commented 5 months ago

Ok. Probably start looking at one of the examples in the Examples/ directory of this repo. There are two using manual generation workflows. One uses Swift package command plugin, the other uses a makefile. They are the ones prefixed with manual-generation- and each has a covering readme.

They should help you get started.

But if you just want to be out of Xcode, neither of these is necessary as the code is built for you by SwiftPM just by depending on the plugin. For this, see any of the hello-world- examples. These also have covering readmes and can be built with swift build and the code is generated at build time automatically.

czechboy0 commented 4 months ago

Hi @pkasson, hopefully the info Si provided can get you started. If you have follow-up questions, please reply here and we can reopen the issue if needed.