Skip to content

[Registry] Make 'Content-Version' optional for archive and manifest download API #6153

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 2 commits into from
Feb 15, 2023

Conversation

yim-lee
Copy link
Contributor

@yim-lee yim-lee commented Feb 14, 2023

Motivation:
The 'Content-Version' header is required in all registry server responses to indicate API version. However, it shouldn't be required for responses that don't/can't change, such as the download archive and fetch package manifest endpoints. This may also cause problems for registry that have these files hosted elsewhere, because they may not have full control over response headers.

Modifications:

  • Modify registry API spec to make 'Content-Version' optional for the said endpoints
  • Adjust RegistryClient

rdar://105415468

@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 14, 2023

@swift-ci please test

@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 14, 2023

@swift-ci please smoke test

@@ -1379,7 +1391,7 @@ paths:
schema:
type: integer
Content-Version:
$ref: "#/components/headers/contentVersion"
$ref: "#/components/headers/optionalContentVersion"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK we can't override $ref.

Ideally we'd want to do something like this:

Suggested change
$ref: "#/components/headers/optionalContentVersion"
$ref: "#/components/headers/contentVersion"
required: false

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

That's right, whether a header is required is part of the content, so to have an optional variant of the same header, we have to fully duplicate it.

@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 14, 2023

@swift-ci please smoke test Windows

fileprivate func validateAPIVersion(_ expectedVersion: RegistryClient.APIVersion = .v1) throws {
guard self.apiVersion == expectedVersion else {
fileprivate func validateAPIVersion(_ expectedVersion: RegistryClient.APIVersion = .v1, isOptional: Bool = false) throws {
let apiVersion = self.apiVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use this so we don't need to call self.apiVersion twice.

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

lgtm

@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 14, 2023

@swift-ci please smoke test macOS

schema:
type: string
enum:
- - "1"
Copy link
Member

Choose a reason for hiding this comment

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

Why the double dash here? (Both here and in contentVersion above), I'd expect just

enum:
  - "1"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure. I thought it was some weird syntax that I didn't know about. Amended in 69a4a02

@yim-lee yim-lee force-pushed the optional-api-version branch from e0021d8 to 69a4a02 Compare February 14, 2023 20:21
@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 14, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 14, 2023

@swift-ci please smoke test Windows

…ownload API

Motivation:
The 'Content-Version' header is required in all registry server responses to indicate API version.
However, it shouldn't be required for responses that don't/can't change, such as the download
archive and fetch package manifest endpoints. This may also cause problems for registry that have
these files hosted elsewhere, because they may not have full control over response headers.

Modifications:
- Modify registry API spec to make 'Content-Version' optional for the said endpoints
- Adjust `RegistryClient`

rdar://105415468
@yim-lee yim-lee force-pushed the optional-api-version branch from 69a4a02 to 6928903 Compare February 15, 2023 01:37
@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 15, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented Feb 15, 2023

@swift-ci please smoke test Windows

@yim-lee yim-lee merged commit e093d2c into swiftlang:main Feb 15, 2023
@yim-lee yim-lee deleted the optional-api-version branch February 15, 2023 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants