Skip to content

Support base64-encoded data #55

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

Merged

Conversation

rnro
Copy link
Contributor

@rnro rnro commented Sep 26, 2023

Motivation

OpenAPI supports base64-encoded data but to this point OpenAPI Generator has not (apple/swift-openapi-generator#11).

Modifications

Introduce the Base64EncodedData codable type to allow users in the generator to describe byte types which must be en/de-coded.

Result

Users will be able to describe base64-encoded data as OpenAPIRuntime.Base64EncodedData e.g.

public typealias MyData = OpenAPIRuntime.Base64EncodedData

Test Plan

Added a round-trip encode/decode test testEncodingDecodingRoundTrip_base64_success

@rnro rnro requested a review from czechboy0 September 26, 2023 12:29
@rnro rnro force-pushed the base64_encoded_data_type_string_format_byte branch from 83125e6 to b1cd56e Compare September 26, 2023 12:32
Copy link
Collaborator

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users will be able to describe base64-encoded data as OpenAPIRuntime.Base64EncodedData e.g.

public typealias MyData = OpenAPIRuntime.Base64EncodedData

By users, do we mean the generator will emit this type alias when it encounters format: base64 in the OpenAPI document?

@rnro
Copy link
Contributor Author

rnro commented Sep 26, 2023

By users, do we mean the generator will emit this type alias when it encounters format: base64 in the OpenAPI document?

Sorry, yes, the generator. I think we will use format: byte though as that's mentioned in the 3.03 spec

@czechboy0
Copy link
Contributor

@swift-server-bot add to allowlist

@rnro rnro force-pushed the base64_encoded_data_type_string_format_byte branch 2 times, most recently from 4a10d8c to bc27f86 Compare October 4, 2023 16:13
@rnro
Copy link
Contributor Author

rnro commented Oct 4, 2023

@swift-server-bot test this please

rnro added 3 commits October 5, 2023 07:55
Motivation

OpenAPI supports base64-encoded data but to this point OpenAPI Generator
has not (apple/swift-openapi-generator#11).

Modifications

Introduce the `Base64EncodedData` codable type to allow users in the
generator to describe byte types which must be en/de-coded.

Result

Users will be able to describe base64-encoded data as
`OpenAPIRuntime.Base64EncodedData` e.g.
```
public typealias MyData = OpenAPIRuntime.Base64EncodedData
```

Test Plan

Added a round-trip encode/decode test `testEncodingDecodingRoundTrip_base64_success`
@rnro rnro force-pushed the base64_encoded_data_type_string_format_byte branch from 6a86b64 to dffa64c Compare October 5, 2023 06:55
@rnro rnro force-pushed the base64_encoded_data_type_string_format_byte branch from a8c8212 to 1427a01 Compare October 5, 2023 12:06
Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor requests, otherwise looks good! Could you also open a PR of the generator changes, so that we can review both before we start landing them? That's our usual workflow. That means that locally you need to develop the two branches together.

@rnro
Copy link
Contributor Author

rnro commented Oct 6, 2023

The accompanying generator change is apple/swift-openapi-generator#326

@czechboy0
Copy link
Contributor

@swift-server-bot add to allowlist

Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, just rerunning the integration test which should pass now that 0.3.0 has been released.

Copy link
Collaborator

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice—thanks @rnro !

@czechboy0 czechboy0 merged commit 506953d into apple:main Oct 10, 2023
@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Oct 10, 2023
czechboy0 pushed a commit to apple/swift-openapi-generator that referenced this pull request Oct 10, 2023
This change accompanies
apple/swift-openapi-runtime#55 and relies on it
for the `OpenAPIRuntime.Base64EncodedData` type.

### Motivation

OpenAPI supports base64-encoded data but to this point Swift OpenAPI
Generator has not
(#11).

### Modifications

A data type specified as `type: string, format: byte` will now result in
a generated type which is `Codable` and backed by a
`OpenAPIRuntime.Base64EncodedData` type which knows how to encode and
decode base64 data.

### Result

Users will be able to specify request/response payloads as
base64-encoded data which will be encoded and decoded transparently

### Test Plan

Unit tested locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants