Skip to content

[Runtime] Accept header #37

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
merged 14 commits into from
Aug 24, 2023
Merged

Conversation

czechboy0
Copy link
Contributor

@czechboy0 czechboy0 commented Aug 10, 2023

Motivation

SOAR-0003 was accepted, this is the runtime side of the implementation.

Modifications

  • Introduced a new protocol AcceptableProtocol, which all the generated, operation-specific Accept enums conform to.
  • Introduced a new struct QualityValue, which wraps the quality parameter of the content type. Since the precision is capped at 3 decimal places, the internal storage is in 1000's, allowing for more reliable comparisons, as floating point numbers are only used when serialized into headers.
  • Introduced a new struct AcceptHeaderContentType, generic over AcceptableProtocol, which adds QualityValue to each generated Accept enum.
  • Introduced new extensions on Converter that allow setting and getting the Accept header.

Result

These are the requirements for apple/swift-openapi-generator#185.

Test Plan

Added unit tests for both QualityValue and AcceptHeaderContentType, and for the new Converter methods.

@czechboy0 czechboy0 changed the title [WIP Prototype] Accept header [Runtime] Accept header Aug 23, 2023
@czechboy0 czechboy0 marked this pull request as ready for review August 23, 2023 11:55
czechboy0 and others added 3 commits August 24, 2023 13:21
Co-authored-by: George Barnett <gbarnett@apple.com>
…ft-openapi-runtime into hd-accept-header-prototype
@czechboy0 czechboy0 merged commit 24546b1 into apple:main Aug 24, 2023
@czechboy0 czechboy0 deleted the hd-accept-header-prototype branch August 24, 2023 12:48
@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Aug 24, 2023
czechboy0 added a commit to apple/swift-openapi-generator that referenced this pull request Aug 24, 2023
[Generator] Accept header

### Motivation

Fixes #160.

SOAR-0003 was accepted, this is the generator side of the implementation. The runtime side, which must land first, is at: apple/swift-openapi-runtime#37.

### Modifications

- Adapted the generator logic for the changes - see the file-based reference tests for concrete examples of what the generated `AcceptableContentType` enum looks like.
- Introduced `translateRawRepresentableEnum`, which allows sharing logic between generating this new enum and other string-based enums.
- Explicitly skip parameters that match reserved headers, as dictated by the specification.

### Result

SOAR-0003 as proposed, working behind the `multipleContentTypes` feature flag.

### Test Plan

Adapted PetstoreConsumerTests to test the new behavior, adapter reference tests.


Reviewed by: gjcairo, glbrntt

Builds:
     ✔︎ pull request validation (5.8) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (docc test) - Build finished. 
     ✔︎ pull request validation (integration test) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#185
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