Example or Tutorial?
buildgreatthings opened this issue · comments
Hi there,
I was able to generate the Swift files from my OpenAPI3 spec. However, I'm having a hard time importing the package into my Xcode workspace.
The steps I did are:
- Generate the package files
- Add local package in my existing project
- In my main code I tried added in variations of the "Example Request" code.
ValidatorPy is the package name I used when generating. Without even getting the models yet, both ValidatorPy and APIClient are not in scope "cannot find 'APIClient' in scope" error.
How should I be importing the Swaggen code?
let getUserRequest = ValidatorPy.User.GetUser.Request(id: 123)
let apiClient = APIClient.default
apiClient.makeRequest(getUserRequest) { apiResponse in
switch apiResponse {
case .result(let apiResponseValue):
if let user = apiResponseValue.success {
print("GetUser returned user \(user)")
} else {
print("GetUser returned \(apiResponseValue)")
}
case .error(let apiError):
print("GetUser failed with \(apiError)")
}
}
There are two ways I tried importing the package.
- Dragging the package into my Xcode project
- Importing package dependency with these Apple Dev site steps
I also tried "import ValidatorPy" in addition the above steps.
@yonaskolb Could you help clarify please? I'd be happy to contribute this to documentation.
When I copy paste your example code, it doesn't work. I changed the request module path to my own generated route. After that it errors with wrong context.
In order to build, I have to change the apiResponse to apiResponse.result and also change .result/.error to .success/.failure. However, now the switch statement never finishes or is called.
hey,
I'm also a first time user of SwagGen and it works fine for me.
@awcchungster did you import your generated SPM before using it? (edit: yes you did)
import ValidatorPy
...
let apiClient = APIClient.default
-
When you compile only your module, does it compile without errors?
-
Did you link your module to your target where you are using it?
I moved off native iOS bindings for my API and use React Native. It was much easier to develop in.