Skip to content

Commit

Permalink
Update OpenAPI spec (#330)
Browse files Browse the repository at this point in the history
* Update api-gravatar.json

* Update code

* Generate quickeditor.api file
  • Loading branch information
AdamGrzybkowski authored Sep 25, 2024
1 parent f638792 commit d3e9d0e
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import com.gravatar.ui.components.ComponentState
import com.yalantis.ucrop.UCrop
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.net.URI

@Composable
internal fun AvatarPicker(
Expand Down Expand Up @@ -201,7 +202,7 @@ private suspend fun AvatarPickerAction.handle(
) {
when (this) {
is AvatarPickerAction.AvatarSelected -> {
onAvatarSelected(AvatarUpdateResult(avatar.imageUrl.toUri()))
onAvatarSelected(AvatarUpdateResult(avatar.imageUrl.toString().toUri()))
snackState.showQESnackbar(
message = context.getString(R.string.avatar_selected_confirmation),
withDismissAction = true,
Expand Down Expand Up @@ -302,7 +303,7 @@ private fun AvatarPickerPreview() {
emailAvatars = EmailAvatars(
avatars = listOf(
Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = "1"
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.net.URI

internal class AvatarPickerViewModel(
private val email: Email,
Expand Down Expand Up @@ -245,7 +244,7 @@ internal fun Profile.copyAvatar(avatar: Avatar): Profile {
hash = this@copyAvatar.hash
displayName = this@copyAvatar.displayName
profileUrl = this@copyAvatar.profileUrl
avatarUrl = URI.create(avatar.imageUrl)
avatarUrl = avatar.imageUrl
avatarAltText = avatar.altText
location = this@copyAvatar.location
description = this@copyAvatar.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.gravatar.quickeditor.ui.avatarpicker.AvatarsSectionUiState
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
import com.gravatar.restapi.models.Avatar
import com.gravatar.ui.GravatarTheme
import java.net.URI

@Composable
internal fun AvatarsSection(
Expand Down Expand Up @@ -89,7 +90,7 @@ private fun AvatarSectionPreview() {
avatars = listOf(
AvatarUi.Uploaded(
avatar = Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = "1"
rating = Avatar.Rating.G
altText = "alt"
Expand Down Expand Up @@ -118,7 +119,7 @@ private fun AvatarSectionGridPreview() {
avatars = List(6) {
AvatarUi.Uploaded(
avatar = Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = it.toString()
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.gravatar.quickeditor.ui.avatarpicker.AvatarsSectionUiState
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
import com.gravatar.restapi.models.Avatar
import com.gravatar.ui.GravatarTheme
import java.net.URI

@Composable
internal fun HorizontalAvatarsSection(
Expand Down Expand Up @@ -144,7 +145,7 @@ private fun HorizontalAvatarSectionPreview() {
avatars = List(6) {
AvatarUi.Uploaded(
avatar = Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = it.toString()
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal val avatarSize = 96.dp
internal fun Avatar(avatar: AvatarUi, onAvatarSelected: (Avatar) -> Unit, modifier: Modifier) {
when (avatar) {
is AvatarUi.Uploaded -> SelectableAvatar(
imageUrl = avatar.avatar.imageUrl,
imageUrl = avatar.avatar.imageUrl.toString(),
isSelected = avatar.isSelected,
isLoading = avatar.isLoading,
onAvatarClicked = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.gravatar.quickeditor.ui.avatarpicker.AvatarsSectionUiState
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
import com.gravatar.restapi.models.Avatar
import com.gravatar.ui.GravatarTheme
import java.net.URI

@Composable
internal fun VerticalAvatarsSection(
Expand Down Expand Up @@ -183,7 +184,7 @@ private fun VerticalAvatarSectionPreview() {
avatars = List(6) {
AvatarUi.Uploaded(
avatar = Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = it.toString()
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.io.File
import java.net.URI

class AvatarRepositoryTest {
private val testDispatcher = StandardTestDispatcher()
Expand Down Expand Up @@ -154,7 +155,7 @@ class AvatarRepositoryTest {
}

private fun createAvatar(id: String, isSelected: Boolean = false) = Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = id
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.gravatar.ui.components.ComponentState
import com.gravatar.uitestutils.RoborazziTest
import org.junit.Test
import org.robolectric.annotation.Config
import java.net.URI

class AvatarPickerTest : RoborazziTest() {
private val profile = defaultProfile(
Expand All @@ -28,14 +29,14 @@ class AvatarPickerTest : RoborazziTest() {
emailAvatars = EmailAvatars(
avatars = listOf(
Avatar {
imageUrl = "/image/url1"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = "1"
rating = Avatar.Rating.G
altText = "alt"
updatedDate = ""
},
Avatar {
imageUrl = "/image/url2"
imageUrl = URI.create("https://gravatar.com/avatar/test2")
imageId = "2"
rating = Avatar.Rating.G
altText = "alt"
Expand All @@ -60,14 +61,14 @@ class AvatarPickerTest : RoborazziTest() {
emailAvatars = EmailAvatars(
avatars = listOf(
Avatar {
imageUrl = "/image/url1"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = "1"
rating = Avatar.Rating.G
altText = "alt"
updatedDate = ""
},
Avatar {
imageUrl = "/image/url2"
imageUrl = URI.create("https://gravatar.com/avatar/test2")
imageId = "2"
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.io.File
import java.net.URI

class AvatarPickerViewModelTest {
private val testDispatcher = StandardTestDispatcher()
Expand Down Expand Up @@ -550,7 +551,7 @@ class AvatarPickerViewModelTest {
)

private fun createAvatar(id: String) = Avatar {
imageUrl = "/image/url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
imageId = id
rating = Avatar.Rating.G
altText = "alt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.gravatar.restapi.models.Avatar
import com.gravatar.uitestutils.RoborazziTest
import org.junit.Test
import org.robolectric.annotation.Config
import java.net.URI

class AvatarsSectionTest : RoborazziTest() {
@Test
Expand Down Expand Up @@ -86,7 +87,7 @@ private fun createAvatarList(size: Int): List<AvatarUi> {
return List(size) {
AvatarUi.Uploaded(
avatar = Avatar {
imageUrl = "/image/url/$it"
imageUrl = URI.create("https://gravatar.com/avatar/test/$it")
imageId = it.toString()
rating = Avatar.Rating.G
altText = "alt"
Expand Down
10 changes: 5 additions & 5 deletions gravatar/api/gravatar.api
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ public final class com/gravatar/extensions/UserProfileExtensionsKt {
}

public final class com/gravatar/restapi/models/Avatar {
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Lcom/gravatar/restapi/models/Avatar$Rating;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/net/URI;Lcom/gravatar/restapi/models/Avatar$Rating;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getAltText ()Ljava/lang/String;
public final fun getImageId ()Ljava/lang/String;
public final fun getImageUrl ()Ljava/lang/String;
public final fun getImageUrl ()Ljava/net/URI;
public final fun getRating ()Lcom/gravatar/restapi/models/Avatar$Rating;
public final fun getSelected ()Ljava/lang/Boolean;
public final fun getUpdatedDate ()Ljava/lang/String;
Expand All @@ -183,16 +183,16 @@ public final class com/gravatar/restapi/models/Avatar$Builder {
public final fun build ()Lcom/gravatar/restapi/models/Avatar;
public final fun getAltText ()Ljava/lang/String;
public final fun getImageId ()Ljava/lang/String;
public final fun getImageUrl ()Ljava/lang/String;
public final fun getImageUrl ()Ljava/net/URI;
public final fun getRating ()Lcom/gravatar/restapi/models/Avatar$Rating;
public final fun getSelected ()Ljava/lang/Boolean;
public final fun getUpdatedDate ()Ljava/lang/String;
public final fun setAltText (Ljava/lang/String;)Lcom/gravatar/restapi/models/Avatar$Builder;
public final synthetic fun setAltText (Ljava/lang/String;)V
public final fun setImageId (Ljava/lang/String;)Lcom/gravatar/restapi/models/Avatar$Builder;
public final synthetic fun setImageId (Ljava/lang/String;)V
public final fun setImageUrl (Ljava/lang/String;)Lcom/gravatar/restapi/models/Avatar$Builder;
public final synthetic fun setImageUrl (Ljava/lang/String;)V
public final fun setImageUrl (Ljava/net/URI;)Lcom/gravatar/restapi/models/Avatar$Builder;
public final synthetic fun setImageUrl (Ljava/net/URI;)V
public final fun setRating (Lcom/gravatar/restapi/models/Avatar$Rating;)Lcom/gravatar/restapi/models/Avatar$Builder;
public final synthetic fun setRating (Lcom/gravatar/restapi/models/Avatar$Rating;)V
public final fun setSelected (Ljava/lang/Boolean;)Lcom/gravatar/restapi/models/Avatar$Builder;
Expand Down
6 changes: 4 additions & 2 deletions gravatar/openapi/api-gravatar.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"image_url": {
"type": "string",
"description": "Image URL",
"format": "uri",
"examples": [
"https://gravatar.com/userimage/252014526/d38bele5a98a2bbc40df69172a2a8348.jpeg"
]
Expand Down Expand Up @@ -558,6 +559,7 @@
},
"Error": {
"type": "object",
"description": "An error response from the API.",
"properties": {
"error": {
"type": "string",
Expand Down Expand Up @@ -689,9 +691,9 @@
],
"parameters": [
{
"name": "selected_email",
"name": "selected_email_hash",
"in": "query",
"description": "The email address used to determine which avatar is selected. The 'selected' attribute in the avatar list will be set to 'true' for the avatar associated with this email.",
"description": "The sha256 hash of the email address used to determine which avatar is selected. The 'selected' attribute in the avatar list will be set to 'true' for the avatar associated with this email.",
"schema": {
"type": "string",
"default": null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ internal interface AvatarsApi {
* Responses:
* - 200: Successful retrieval of avatars
*
* @param selectedEmail The email address used to determine which avatar is selected. The &#39;selected&#39; attribute in the avatar list will be set to &#39;true&#39; for the avatar associated with this email. (optional, default to "null")
* @param selectedEmailHash The sha256 hash of the email address used to determine which avatar is selected. The &#39;selected&#39; attribute in the avatar list will be set to &#39;true&#39; for the avatar associated with this email. (optional, default to "null")
* @return [kotlin.collections.List<Avatar>]
*/
@GET("me/avatars")
suspend fun getAvatars(
@Query("selected_email") selectedEmail: kotlin.String? = "null",
@Query("selected_email_hash") selectedEmailHash: kotlin.String? = "null",
): Response<kotlin.collections.List<Avatar>>

/**
Expand Down
6 changes: 3 additions & 3 deletions gravatar/src/main/java/com/gravatar/restapi/models/Avatar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Avatar private constructor(
public val imageId: kotlin.String,
// Image URL
@SerializedName("image_url")
public val imageUrl: kotlin.String,
public val imageUrl: java.net.URI,
// Rating associated with the image.
@SerializedName("rating")
public val rating: Avatar.Rating,
Expand Down Expand Up @@ -79,7 +79,7 @@ public class Avatar private constructor(

// Image URL
@set:JvmSynthetic // Hide 'void' setter from Java
public var imageUrl: kotlin.String? = null
public var imageUrl: java.net.URI? = null

// Rating associated with the image.
@set:JvmSynthetic // Hide 'void' setter from Java
Expand All @@ -99,7 +99,7 @@ public class Avatar private constructor(

public fun setImageId(imageId: kotlin.String?): Builder = apply { this.imageId = imageId }

public fun setImageUrl(imageUrl: kotlin.String?): Builder = apply { this.imageUrl = imageUrl }
public fun setImageUrl(imageUrl: java.net.URI?): Builder = apply { this.imageUrl = imageUrl }

public fun setRating(rating: Avatar.Rating?): Builder = apply { this.rating = rating }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.google.gson.annotations.SerializedName
import java.util.Objects

/**
*
* An error response from the API.
*
* @param error The error message
* @param code The error code for the error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class AvatarService(private val okHttpClient: OkHttpClient? = null) {
withContext(GravatarSdkDI.dispatcherIO) {
val service = instance.getGravatarV3Service(okHttpClient, oauthToken)

val response = service.getAvatars(selectedEmail = hash.toString())
val response = service.getAvatars(selectedEmailHash = hash.toString())

if (response.isSuccessful) {
response.body() ?: error("Response body is null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.junit.Rule
import org.junit.Test
import retrofit2.Response
import java.io.File
import java.net.URI

class AvatarServiceTest {
@get:Rule
Expand All @@ -24,7 +25,7 @@ class AvatarServiceTest {

private val avatar = Avatar {
imageId = "id"
imageUrl = "url"
imageUrl = URI.create("https://gravatar.com/avatar/test")
selected = false
altText = ""
rating = Avatar.Rating.G
Expand Down

0 comments on commit d3e9d0e

Please sign in to comment.