You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Motivation
We have an example project showing ahead-of-time generation using the
`swift-openapi-generator` CLI directly, driven by a Makefile. This PR
polishes it up a bit and makes it more flexible. Additionally, the
generated code had not been updated since we switched the default access
modifier from package to internal.
### Modifications
- Allow overriding a bunch of things when calling `make`.
- Prompt for confirmation before blowing away the output directory.
- Regenerate sources to pick up the new access modifier.
- Add a `help` target.
### Result
More extensive example.
E.g. running the following command:
```console
% make help
Run make with one of the following targets:
help: Display this help.
generate: Generate the sources using swift-openapi-generator.
build: Runs swift build.
clean: Delete the output directory used for generated sources.
clean-all: Clean everything, including the checkout of swift-openapi-generator.
dump: Dump all derived values used by the Makefile.
The following options can be overriden on the command line:
SWIFT_OPENAPI_GENERATOR_GIT_URL (e.g. https://github.com/apple/swift-openapi-generator)
SWIFT_OPENAPI_GENERATOR_GIT_TAG (e.g. 1.0.0)
SWIFT_OPENAPI_GENERATOR_CLONE_DIR (e.g. .swift-openapi-generator)
SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION (e.g. release)
OPENAPI_YAML_PATH (e.g. openapi.yaml)
OPENAPI_GENERATOR_CONFIG_PATH (e.g. openapi-generator-config.yaml)
OUTPUT_DIRECTORY (e.g. Sources/ManualGeneratorInvocationClient/Generated)
```
### Test Plan
CI should still build the package.
generate: $(SWIFT_OPENAPI_GENERATOR_BIN)$(OPENAPI_YAML_PATH)$(OPENAPI_GENERATOR_CONFIG_PATH)$(OUTPUT_DIRECTORY)# Generate the sources using swift-openapi-generator.
38
+
$< generate \
39
+
--config "$(OPENAPI_GENERATOR_CONFIG_PATH)"\
40
+
--output-directory "$(OUTPUT_DIRECTORY)"\
41
+
"$(OPENAPI_YAML_PATH)"
42
+
43
+
build: # Runs swift build.
44
+
swift build
45
+
46
+
clean: # Delete the output directory used for generated sources.
47
+
@echo 'Delete entire directory: $(OUTPUT_DIRECTORY)? [y/N] '&&read ans && [ $${ans:-N} = y ] || (echo "Aborted";exit 1)
48
+
rm -rf "$(OUTPUT_DIRECTORY)"
49
+
50
+
clean-all: clean # Clean everything, including the checkout of swift-openapi-generator.
51
+
@echo 'Delete checkout of swift-openapi-generator $(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)? [y/N] '&&read ans && [ $${ans:-N} = y ] || (echo "Aborted";exit 1)
52
+
rm -rf "$(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)"
53
+
54
+
55
+
dump: # Dump all derived values used by the Makefile.
Copy file name to clipboardExpand all lines: Examples/manual-generation-generator-cli-example/Sources/ManualGeneratorInvocationClient/Generated/Client.swift
Copy file name to clipboardExpand all lines: Examples/manual-generation-generator-cli-example/Sources/ManualGeneratorInvocationClient/Generated/Types.swift
+38-38Lines changed: 38 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ import struct Foundation.Data
10
10
importstruct Foundation.Date
11
11
#endif
12
12
/// A type that performs HTTP operations defined by the OpenAPI document.
13
-
packageprotocolAPIProtocol:Sendable{
13
+
internalprotocolAPIProtocol:Sendable{
14
14
/// - Remark: HTTP `GET /greet`.
15
15
/// - Remark: Generated from `#/paths//greet/get(getGreeting)`.
0 commit comments