Skip to content

Latest commit

 

History

History
66 lines (45 loc) · 5.95 KB

README.md

File metadata and controls

66 lines (45 loc) · 5.95 KB

Examples of using Swift OpenAPI Generator

This directory contains examples of how to use and integrate Swift OpenAPI Generator with other packages in the ecosystem.

Important: Many of these examples have been deliberately simplified and are intended for illustrative purposes only.

All the examples can be found in the Examples directory of the Swift OpenAPI Generator repository.

To run an example locally, for example hello-world-urlsession-client-example, clone the Swift OpenAPI Generator repository, and run the example, as shown below:

% git clone https://github.com/apple/swift-openapi-generator
% cd swift-openapi-generator/Examples
% swift run --package-path hello-world-urlsession-client-example

Getting started

Each of the following packages shows an end-to-end working example with the given transport.

Various content types

The following packages show working with various content types, such as JSON, URL-encoded request bodies, plain text, raw bytes, multipart bodies, as well as event streams, such as JSON Lines, JSON Sequence, and Server-sent Events.

Integrations

Middleware

Ahead-of-time (manual) code generation

The recommended way to use Swift OpenAPI generator is by integrating the build plugin, which all of the examples above use. The build plugin generates Swift code from your OpenAPI document at build time, and you don't check in the generated code into your git repository.

However, if you cannot use the build plugin, for example because you must check in your generated code, use the command plugin, which you trigger manually either in Xcode or on the command line. See the following example for this workflow:

If you can't even use the command plugin, for example because your package is not allowed to depend on Swift OpenAPI Generator, you can invoke the generator CLI manually from a Makefile. See the following example for this workflow: