From 23d4a39b5b17808a7873dc46c4bcf38b2716b044 Mon Sep 17 00:00:00 2001 From: ainame Date: Wed, 30 Nov 2022 16:58:26 +0000 Subject: [PATCH] Move the option under paths section --- Docs/ConfigOptions.md | 30 +++++++++---------- .../CreateAPI/Generator/Generator+Paths.swift | 2 +- Sources/CreateOptions/ConfigOptions.swift | 16 +++++----- .../CreateAPITests/GenerateOptionsTests.swift | 3 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Docs/ConfigOptions.md b/Docs/ConfigOptions.md index 20d29b98..afba4307 100644 --- a/Docs/ConfigOptions.md +++ b/Docs/ConfigOptions.md @@ -96,6 +96,7 @@ Below you can find the complete documentation for all available options. - [exclude](#pathsexclude) - [include](#pathsinclude) - [filenameTemplate](#pathsfilenametemplate) + - [useDataForMultipartFormDataRequestBody](#pathsusedataformultipartformdatarequestbody) - [rename](#rename) - [properties](#renameproperties) - [parameters](#renameparameters) @@ -103,7 +104,6 @@ Below you can find the complete documentation for all available options. - [entities](#renameentities) - [operations](#renameoperations) - [collectionElements](#renamecollectionelements) -- [useDataForMultipartFormDataRequestBody](#usedataformultipartformdatarequestbody) --- @@ -384,20 +384,6 @@ dataTypes:
-## useDataForMultipartFormDataRequestBody - -**Type:** Bool
-**Default:** `true` - -If `false`, CreateAPI generates request body structures for "multipart/form-data" format just like it would for "application/json". -Otherwise the `body` of the generated `Request` will use `Data`. The default value is `true`. - -When using Get and it's `APIClient`, because Multipart Form Data isn't supported from the `Request` `body` property, it is best to leave this option set to `true`. -If however you have implemented your API Client, and you prefer to use structured `Codable` types to encode a Multipart Form Data request body, setting this value to `false` can be more convenient. -You might also need to use the [`dataTypes`](#datatypes) option to customise the type used to represent `binary` data. - -
- # Entities @@ -976,6 +962,20 @@ paths:
+## paths.useDataForMultipartFormDataRequestBody + +**Type:** Bool
+**Default:** `true` + +If `false`, CreateAPI generates request body structures for "multipart/form-data" format just like it would for "application/json". +Otherwise the `body` of the generated `Request` will use `Data`. The default value is `true`. + +When using Get and it's `APIClient`, because Multipart Form Data isn't supported from the `Request` `body` property, it is best to leave this option set to `true`. +If however you have implemented your API Client, and you prefer to use structured `Codable` types to encode a Multipart Form Data request body, setting this value to `false` can be more convenient. +You might also need to use the [`dataTypes`](#datatypes) option to customise the type used to represent `binary` data. + +
+ # Rename diff --git a/Sources/CreateAPI/Generator/Generator+Paths.swift b/Sources/CreateAPI/Generator/Generator+Paths.swift index 4e246b8e..b572712b 100644 --- a/Sources/CreateAPI/Generator/Generator+Paths.swift +++ b/Sources/CreateAPI/Generator/Generator+Paths.swift @@ -690,7 +690,7 @@ extension Generator { .other("application/json"), .form ] - if !options.useDataForMultipartFormDataRequestBody { + if !options.paths.useDataForMultipartFormDataRequestBody { structuredRequestBodySupportedTypes.append(.multipartForm) } if let (content, contentType) = firstContent(for: structuredRequestBodySupportedTypes) { diff --git a/Sources/CreateOptions/ConfigOptions.swift b/Sources/CreateOptions/ConfigOptions.swift index 6ec30cb6..7ea26c79 100644 --- a/Sources/CreateOptions/ConfigOptions.swift +++ b/Sources/CreateOptions/ConfigOptions.swift @@ -672,6 +672,14 @@ public struct ConfigOptions: ParsableConfiguration { /// /// @Option public var filenameTemplate: String = "%0.swift" + + /// If `false`, CreateAPI generates request body structures for "multipart/form-data" format just like it would for "application/json". + /// Otherwise the `body` of the generated `Request` will use `Data`. The default value is `true`. + /// + /// When using Get and it's `APIClient`, because Multipart Form Data isn't supported from the `Request` `body` property, it is best to leave this option set to `true`. + /// If however you have implemented your API Client, and you prefer to use structured `Codable` types to encode a Multipart Form Data request body, setting this value to `false` can be more convenient. + /// You might also need to use the [`dataTypes`](#datatypes) option to customise the type used to represent `binary` data. + @Option public var useDataForMultipartFormDataRequestBody: Bool = true } @Option public var rename: Rename @@ -712,14 +720,6 @@ public struct ConfigOptions: ParsableConfiguration { /// Rename anonymous collection elements. By default, use a singularized form of the property name @Option public var collectionElements: [String: String] = [:] } - - /// If `false`, CreateAPI generates request body structures for "multipart/form-data" format just like it would for "application/json". - /// Otherwise the `body` of the generated `Request` will use `Data`. The default value is `true`. - /// - /// When using Get and it's `APIClient`, because Multipart Form Data isn't supported from the `Request` `body` property, it is best to leave this option set to `true`. - /// If however you have implemented your API Client, and you prefer to use structured `Codable` types to encode a Multipart Form Data request body, setting this value to `false` can be more convenient. - /// You might also need to use the [`dataTypes`](#datatypes) option to customise the type used to represent `binary` data. - @Option public var useDataForMultipartFormDataRequestBody: Bool = true } // MARK: - Utilities diff --git a/Tests/CreateAPITests/GenerateOptionsTests.swift b/Tests/CreateAPITests/GenerateOptionsTests.swift index 59d6633b..c43dbdc4 100644 --- a/Tests/CreateAPITests/GenerateOptionsTests.swift +++ b/Tests/CreateAPITests/GenerateOptionsTests.swift @@ -395,7 +395,8 @@ final class GenerateOptionsTests: GenerateTestCase { name: "edgecases-multipart-formdata", configuration: """ generate: ["paths"] - useDataForMultipartFormDataRequestBody: false + paths: + useDataForMultipartFormDataRequestBody: false """ ) }