Project is using Swift OpenAPI Generator, connected as plugin, so it semi-automatically regenerates the code to reflect changes made to OpenAPI specifiation in openapi.yaml.
Keep this in mind if you need to make changes to API related logic and feel free to propose pull requests.
Disclaimer: This is unofficial project, build only based on the official doc. OpenAPI specification was as well build by the author of the project since no official one was provided even by requests.
A library package that exposes generated (from OpenAPI specification) client as is. Allows to make all requests including cases where mutually exclusive parameters could be passed to endpoints.
Under the hood, the client uses the URLSession API to perform the HTTP calls, wrapped in the Swift OpenAPI URLSession Transport.
For header mutation HTTPTypes is used.
Whenever the openapi.yaml document changes, rerun the code generation.
Open terminal at package folder and:
% swift package generate-code-from-openapi
Plugin ‘OpenAPIGeneratorCommand’ wants permission to write to the package directory.
Stated reason: “To write the generated Swift files back into the source directory of the package.”.
Allow this plugin to write to the package directory? (yes/no) yes
...
✅ OpenAPI code generation for target 'CommandPluginInvocationClient' successfully completed.In another package or project, add this one as a package dependency.
Then, use the provided client API:
import YooMoneyAPI
let client = YooMoneyAPIClient()
let response = try await client.createPayment(amount: 123)
print("Received response: \(response)")For testing purposes you can use default Credentials fromEnvironment static var. In this case you need to set environment variables "APP_USERNAME" and "APP_PASSWORD". In Xcode you can set them with Edit scheme menu.
- Move
HeaderMiddlewareto a separate SPM (as withOSLogLoggingMiddleware). - Document main functions
- Refactor OpenAPI spec as for
Confirmationrelated schemas. [done]. Note that Swift types for schemas withdiscriminatorhave two issues: Refer to: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md- When generating type from the the most laconic
discriminator-allOfnotation (when and all schemas comprising the parent schema include parent in allOf of their schema.) it is not possible to init the type properly. Only the map identifier can be passed to enum. - When generating type from
discriminator-oneOfnotation (when and all schemas comprising the parent schema include parent in allOf of their schema but we list them explicitly viaoneOf) we end up in recursion. It is possible to break recursion by introducingBasetype. But yet generated init is too verbose and not too smart. We can make things more strict by introducingconstin for discriminator field in child schemas, but it works only for primitive schemas (compareConfirmationandPaymentMethod,PaymentMethodData). Default attribute works neither way.
- When generating type from the the most laconic
- Unify
Receiptand CreatePaymentReceiptby sharing common properties withReceiptBaseby means ofallOff`.