Skip to content

Commit

Permalink
Updating to latest openapi spec (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
etoledom authored Oct 4, 2024
1 parent 0aa60a6 commit a520545
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Profile URL: \(profile.profileUrl)
Display name: \(profile.displayName)
Preferred User Name: \(profile.displayName)
Thumbnail URL: \(profile.avatarUrl)
Verified accounts (\(profile.numberVerifiedAccounts ?? 0)): \(profile.verifiedAccounts)
Wallets: \(String(describing: profile.payments?.cryptoWallets))
Last edit: \(String(describing: profile.lastProfileEdit))
Registration date: \(String(describing: profile.registrationDate))
Expand Down
2 changes: 1 addition & 1 deletion Sources/Gravatar/Network/APIErrorPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
/// Error payload for the REST API calls.
public protocol APIErrorPayload: Sendable {
/// A business error code that identifies this error. (This is not the HTTP status code.)
var code: String { get }
var code: String? { get }
/// Error message that comes from the REST API.
var message: String? { get }
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Gravatar/OpenApi/Generated/ModelError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ struct ModelError: Codable, Hashable, Sendable {
/// The error message
private(set) var error: String
/// The error code for the error message
private(set) var code: String
private(set) var code: String?

@available(*, deprecated, message: "init will become internal on the next release")
init(error: String, code: String) {
init(error: String, code: String? = nil) {
self.error = error
self.code = code
}
Expand All @@ -30,7 +30,7 @@ struct ModelError: Codable, Hashable, Sendable {
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: InternalCodingKeys.self)
try container.encode(error, forKey: .error)
try container.encode(code, forKey: .code)
try container.encodeIfPresent(code, forKey: .code)
}

// Decodable protocol methods
Expand All @@ -39,6 +39,6 @@ struct ModelError: Codable, Hashable, Sendable {
let container = try decoder.container(keyedBy: InternalCodingKeys.self)

error = try container.decode(String.self, forKey: .error)
code = try container.decode(String.self, forKey: .code)
code = try container.decodeIfPresent(String.self, forKey: .code)
}
}
23 changes: 16 additions & 7 deletions Sources/Gravatar/OpenApi/Generated/VerifiedAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ public struct VerifiedAccount: Codable, Hashable, Sendable {
public private(set) var serviceIcon: String
/// The URL to the user's profile on the service.
public private(set) var url: String
/// Whether the verified account is hidden from the user's profile.
public private(set) var isHidden: Bool

// NOTE: This init is maintained manually.
// Avoid deleting this init until the deprecation of is applied.
@available(*, deprecated, message: "init will become internal on the next release")
public init(serviceLabel: String, serviceIcon: String, url: String) {
self.serviceLabel = serviceLabel
self.serviceIcon = serviceIcon
self.url = url
self.serviceType = ""
self.init(
serviceType: "",
serviceLabel: serviceLabel,
serviceIcon: serviceIcon,
url: url,
isHidden: false
)
}

// NOTE: This init is maintained manually.
// Avoid deleting this init until the deprecation of is applied.
init(serviceType: String, serviceLabel: String, serviceIcon: String, url: String) {
init(serviceType: String, serviceLabel: String, serviceIcon: String, url: String, isHidden: Bool) {
self.serviceType = serviceType
self.serviceLabel = serviceLabel
self.serviceIcon = serviceIcon
self.url = url
self.isHidden = isHidden
}

@available(*, deprecated, message: "CodingKeys will become internal on the next release.")
Expand All @@ -41,6 +47,7 @@ public struct VerifiedAccount: Codable, Hashable, Sendable {
case serviceLabel = "service_label"
case serviceIcon = "service_icon"
case url
case isHidden = "is_hidden"
}

// Encodable protocol methods
Expand All @@ -51,6 +58,7 @@ public struct VerifiedAccount: Codable, Hashable, Sendable {
try container.encode(serviceLabel, forKey: .serviceLabel)
try container.encode(serviceIcon, forKey: .serviceIcon)
try container.encode(url, forKey: .url)
try container.encode(isHidden, forKey: .isHidden)
}

// Decodable protocol methods
Expand All @@ -62,5 +70,6 @@ public struct VerifiedAccount: Codable, Hashable, Sendable {
serviceLabel = try container.decode(String.self, forKey: .serviceLabel)
serviceIcon = try container.decode(String.self, forKey: .serviceIcon)
url = try container.decode(String.self, forKey: .url)
isHidden = try container.decode(Bool.self, forKey: .isHidden)
}
}
39 changes: 25 additions & 14 deletions Tests/GravatarTests/Resources/Profiles/fullProfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,38 @@
{
"service_type": "wordpress",
"service_label": "WordPress",
"service_icon": "https://secure.gravatar.com/icons/wordpress.svg",
"url": "http://notreal.wordpress.com"
"service_icon": "https://gravatar.com/icons/wordpress.svg",
"url": "http://notreal.wordpress.com",
"is_hidden": false
}
],
"pronunciation": "John",
"pronouns": "he/him",
"links": [
"pronouns": "John",
"timezone": "",
"languages": [
{
"label": "My site verified",
"url": "https://notreal.wordpress.com/"
"code": "en",
"name": "English",
"is_primary": true,
"order": 0
},
{
"label": "Gravatar",
"url": "https://gravatar.com"
"code": "es",
"name": "Spanish",
"is_primary": false,
"order": 1
}
],
"interests": [
"first_name": "John",
"last_name": "Appleseed",
"is_organization": false,
"links": [
{
"id": 2779,
"name": "Beach Tennis"
},
"label": "A link",
"url": "http://notreal.wordpress.com"
}
],
"interests": [
{
"id": 589,
"name": "Software Engineering"
Expand Down Expand Up @@ -71,6 +82,6 @@
}
],
"number_verified_accounts": 1,
"last_profile_edit": "2024-05-28T14:17:03Z",
"registration_date": "2018-01-24T14:23:32Z"
"last_profile_edit": "2024-09-04T11:54:32Z",
"registration_date": "2024-05-28T10:40:22Z"
}
81 changes: 73 additions & 8 deletions openapi/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ components:
- service_label
- service_icon
- url
- is_hidden
properties:
service_type:
type: string
Expand All @@ -165,6 +166,11 @@ components:
format: uri
examples:
- https://example.tumblr.com/
is_hidden:
type: boolean
description: Whether the verified account is hidden from the user's profile.
examples:
- false
GalleryImage:
type: object
description: A gallery image a user has uploaded.
Expand Down Expand Up @@ -471,7 +477,6 @@ components:
description: The error code for the error message
required:
- error
- code
securitySchemes:
apiKey:
type: http
Expand All @@ -487,6 +492,48 @@ components:
tokenUrl: https://public-api.wordpress.com/oauth2/token
scopes: {}
description: WordPress OAuth token to authenticate the request.
responses:
not_authorized:
description: Not Authorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
examples:
unauthorized:
value:
error: You are not authorized to perform this action
insufficient_scope:
description: Insufficient Scope
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
examples:
insufficient_scope:
value:
code: insufficient_scope
error: >-
The provided token does not contain the required scope for
this request.
rate_limit_exceeded:
description: Rate Limit Exceeded
headers:
X-RateLimit-Limit:
$ref: '#/components/headers/X-RateLimit-Limit'
X-RateLimit-Remaining:
$ref: '#/components/headers/X-RateLimit-Remaining'
X-RateLimit-Reset:
$ref: '#/components/headers/X-RateLimit-Reset'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
examples:
rate_limit_exceeded:
value:
error: Rate limit exceeded
code: rate_limit_exceeded
paths:
/profiles/{profileIdentifier}:
get:
Expand Down Expand Up @@ -531,13 +578,7 @@ paths:
$ref: '#/components/headers/X-RateLimit-Reset'
'429':
description: Rate limit exceeded
headers:
X-RateLimit-Limit:
$ref: '#/components/headers/X-RateLimit-Limit'
X-RateLimit-Remaining:
$ref: '#/components/headers/X-RateLimit-Remaining'
X-RateLimit-Reset:
$ref: '#/components/headers/X-RateLimit-Reset'
$ref: '#/components/responses/rate_limit_exceeded'
'500':
description: Internal server error
/me/associated-email:
Expand Down Expand Up @@ -566,6 +607,12 @@ paths:
schema:
type: object
$ref: '#/components/schemas/AssociatedResponse'
'401':
description: Not Authorized
$ref: '#/components/responses/not_authorized'
'403':
description: Insufficient Scope
$ref: '#/components/responses/insufficient_scope'
/me/avatars:
get:
summary: List avatars
Expand Down Expand Up @@ -594,6 +641,12 @@ paths:
type: array
items:
$ref: '#/components/schemas/Avatar'
'401':
description: Not Authorized
$ref: '#/components/responses/not_authorized'
'403':
description: Insufficient Scope
$ref: '#/components/responses/insufficient_scope'
post:
summary: Upload new avatar image
description: Uploads a new avatar image for the authenticated user.
Expand Down Expand Up @@ -637,6 +690,12 @@ paths:
value:
error: Unsupported image type
code: unsupported_image
'401':
description: Not Authorized
$ref: '#/components/responses/not_authorized'
'403':
description: Insufficient Scope
$ref: '#/components/responses/insufficient_scope'
/me/avatars/{imageId}/email:
post:
summary: Set avatar for the hashed email
Expand Down Expand Up @@ -672,3 +731,9 @@ paths:
responses:
'204':
description: Avatar successfully set
'401':
description: Not Authorized
$ref: '#/components/responses/not_authorized'
'403':
description: Insufficient Scope
$ref: '#/components/responses/insufficient_scope'

0 comments on commit a520545

Please sign in to comment.