-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary OpenAPI format not working as expected #364
Comments
Upon further inspection of the repo, I found out that #362 kind of solves this issue. I should've looked into the recent commits before posting an issue. /// - Remark: Generated from `#/components/schemas/Message`.
public struct Message: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Message/key`.
public var key: Swift.String?
/// - Remark: Generated from `#/components/schemas/Message/value`.
public var value: OpenAPIRuntime.Base64EncodedData?
/// Creates a new `Message`.
///
/// - Parameters:
/// - key:
/// - value:
public init(
key: Swift.String? = nil,
value: OpenAPIRuntime.Base64EncodedData? = nil
) {
self.key = key
self.value = value
}
public enum CodingKeys: String, CodingKey {
case key
case value
}
} Is the usage of Base64EncodedData the expected result from now on? |
Kind of. Are you sure you want to use In OpenAPI 3.1, those would be spelled If you're sending these values in JSON, the former wouldn't work, only the latter. And the new base64 special type was added recently as well, after 0.3.0. To summarize, you should be able to change from: type: string
format: binary to type: string
format: byte And it should work even with the latest released version (the OpenAPIKit bump only happened on main, hasn't been released yet). Please confirm that this addresses your issue 🙂 |
Oh I forgot this is currently still hidden behind a feature flag, you'll need to enable it:
|
Thank you for your response! Using I suppose the base64DataEncodingDecoding flag enables the automatic encoding and decoding of the Base64EncodedData to Swift.Data? Is there any documentation on how to use the feature flag? Or do I have to fork the generator in order to add it? |
It's documented here: https://swiftpackageindex.com/apple/swift-openapi-generator/0.3.3/documentation/swift-openapi-generator/configuring-the-generator#Create-a-configuration-file You'll just add it to your config file, such as: generate:
- types
- client
featureFlags:
- base64DataEncodingDecoding Then the generator will produce |
It is indeed documented there, although there aren't any example config files including feature flags (which is understandable since there's only one for now). It might be a good idea to add additional examples that show how to do this in the docs. Seems to work fine now. Out of curiosity, is there a particular reason why OpenAPIRuntime.Base64EncodedData is used instead of Swift.Data? The previous conversion to Swift.Data seemed way more comfortable to work with. |
Also, the fact that |
Makes a lot of sense. Thank you! |
The problem
I have been using the 0.2.x versions of the swift-openapi-* tools for a while now. I recently tried updating my code to use the "new" 0.3.x versions and stumbled upon the following issue.
As shown in the code below, the 0.3.x ignore any string field with a binary format.
I'm aware that this project is on a 0.x.y version and is therefore expected to have major changes from version to version without any guarantee of API stability; but I cannot find a way to make the generator produce properties with a Data type (without having to manually convert from binary to base64 on both the server and the client) with the new versions.
Thank you in advance for reading me!
Spec
Code generated on 0.2.x
0.2.3
0.2.5
Code generated on 0.3.x
0.3.3
0.3.6
The text was updated successfully, but these errors were encountered: