Skip to content
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

Wrong json returned from the api #1464

Closed
Leptopoda opened this issue Jan 27, 2023 · 2 comments · Fixed by #1477
Closed

Wrong json returned from the api #1464

Leptopoda opened this issue Jan 27, 2023 · 2 comments · Fixed by #1477
Labels
API changes involving using the app api Backend Issue or PR related to the backend code bug Something isn't working Frontend Issue or PR related to the frontend code good first issue Good for newcomers php Pull requests that update Php code

Comments

@Leptopoda
Copy link
Contributor

Leptopoda commented Jan 27, 2023

Description
Another API problem I'm facing lately. The returned Recipe will have the id field as an integer what we clearly don't want.

Steps to reproduce the behavior:

  1. Execute any request that'll return a Recipe. This can be /api/v1/import or /api/v1/recipes/{id}
  2. log the responded json into a file
  3. see that the id is a number and not a string what causes the serializer/parser to throw an exception.

Expected behavior
The id should be surrounded by parentheses to make it a String

{
  "@context": "http:\/\/schema.org",
  "@type": "Recipe",
  "mainEntityOfPage": "https:\/\/www.allrecipes.com\/recipe\/283074\/easy-heart-shaped-cake\/",
  "name": "Easy Heart-Shaped Cake",
  "image": "https:\/\/imagesvc.meredithcorp.io\/v3\/mm\/image?url=https%3A%2F%2Fimages.media-allrecipes.com%2Fuserphotos%2F8979442.jpg",
  "datePublished": "2021-01-20T00:41:46.000Z",
  "description": "This heart-shaped cake combines Ann McGavin Stout's Homemade Vanilla Cake recipe and QueenCook's Easy Valentine's Day Cake frosting recipe. The result is a supremely tasty, no-fail heart cake.",
  "prepTime": "PT1H0M0S",
  "cookTime": "PT0H45M0S",
  "totalTime": "PT2H25M0S",
  "recipeYield": 1,
  "recipeIngredient": [
    "2 cups white sugar",
    "1 cup unsalted butter, softened",
    "2 teaspoons vanilla extract",
    "2 teaspoons almond extract",
    "4 large eggs",
    "3 cups all-purpose flour",
    "\u2153 cup cornstarch",
    "1 tablespoon baking powder",
    "\u00be teaspoon salt",
    "1\u2009\u00bd cups milk",
    "2 cups unsalted butter, softened",
    "4 teaspoons vanilla extract",
    "8 cups powdered sugar",
    "2 tablespoons whole milk, or more as needed",
    "2 drops red food coloring, or as desired",
    "2 drops yellow food coloring, or as desired",
    "sprinkles as needed"
  ],
  "recipeInstructions": [
    "Preheat the oven to 350 degrees F (175 degrees C). Grease an 8-inch square pan and an 8-inch round pan. Line bottoms with parchment or wax paper. Grease paper and dust lightly with flour.",
    "Beat white sugar, butter, vanilla, and almond extract in a large bowl with an electric mixer on high speed until light and fluffy. Beat in eggs, 1 at a time, until well combined.",
    "Stir flour, cornstarch, baking powder, and salt together in another bowl.",
    "Beat 1 cup dry ingredients into wet ingredients until just combined. Add 1\/2 cup milk; beat until combined. Continue adding 1 cup dry ingredients and 1\/2 cup milk, beating after each addition, until all are used and batter is smooth. Divide evenly between the prepared pans.",
    "Bake in the preheated oven until a toothpick inserted in the center of each cake comes out clean, 45 to 50 minutes. Cool in pans on wire racks for 10 minutes. Remove from pans and cool completely on racks.",
    "Beat butter and vanilla together in a large bowl with an electric mixer on medium speed until combined, about 30 seconds. Gradually add powdered sugar, beating after each addition and adding milk as needed, until frosting is fluffy, smooth, and spreadable.",
    "Remove 1\/3 cup frosting and divide between 2 small bowls. Tint 1 dark pink with red food coloring. Tint the other orange-pink with red and yellow food coloring. Tint remaining frosting light pink with red food coloring.",
    "Set square cake on a work surface and rotate 45 degrees so that it resembles a diamond. Spread a little light pink frosting on left and right top sides of the diamond. Cut round cake in half crosswise to make 2 half-moons. Attach half-moons to top left and top right sides of diamond, gently pressing cake pieces together to adhere. Spread remaining light pink frosting over the assembled cake. Drop spoonfuls of dark pink and pink-orange frosting onto cake. Drag an offset spatula through frosting to create a marbled look.",
    "Pat sprinkles onto the sides of the cake. Chill, covered, for up to 3 days. Let stand at room temperature 30 minutes before slicing into 16 pieces."
  ],
  "recipeCategory": "Dessert",
  "recipeCuisine": [],
  "author": [
    {
      "@type": "Person",
      "name": "thehungryscientist"
    }
  ],
  "aggregateRating": {
    "@type": "AggregateRating",
    "itemReviewed": "Easy Heart-Shaped Cake",
    "bestRating": "5",
    "worstRating": "1"
  },
  "nutrition": {
    "@type": "NutritionInformation",
    "calories": "778.3 calories",
    "carbohydrateContent": "109.4 g",
    "cholesterolContent": "140 mg",
    "fatContent": "36.6 g",
    "fiberContent": "0.7 g",
    "proteinContent": "5.2 g",
    "saturatedFatContent": "22.6 g",
    "sodiumContent": "205.8 mg",
    "sugarContent": "87.9 g"
  },
  "review": [],
  "keywords": "",
  "tool": [],
  "url": "https:\/\/www.allrecipes.com\/recipe\/283074\/easy-heart-shaped-cake\/",
  "dateModified": "2021-01-30T15:02:50+0000",
  "dateCreated": "2021-01-30T14:57:15+0000",
  "id": "48",
  "printImage": true,
  "imageUrl": "\/apps\/cookbook\/webapp\/recipes\/48\/image?size=full"
}

Actual behavior

{
  "@context": "http:\/\/schema.org",
  "@type": "Recipe",
  "mainEntityOfPage": "https:\/\/www.allrecipes.com\/recipe\/283074\/easy-heart-shaped-cake\/",
  "name": "Easy Heart-Shaped Cake",
  "image": "https:\/\/imagesvc.meredithcorp.io\/v3\/mm\/image?url=https%3A%2F%2Fimages.media-allrecipes.com%2Fuserphotos%2F8979442.jpg",
  "datePublished": "2021-01-20T00:41:46.000Z",
  "description": "This heart-shaped cake combines Ann McGavin Stout's Homemade Vanilla Cake recipe and QueenCook's Easy Valentine's Day Cake frosting recipe. The result is a supremely tasty, no-fail heart cake.",
  "prepTime": "PT1H0M0S",
  "cookTime": "PT0H45M0S",
  "totalTime": "PT2H25M0S",
  "recipeYield": 1,
  "recipeIngredient": [
    "2 cups white sugar",
    "1 cup unsalted butter, softened",
    "2 teaspoons vanilla extract",
    "2 teaspoons almond extract",
    "4 large eggs",
    "3 cups all-purpose flour",
    "\u2153 cup cornstarch",
    "1 tablespoon baking powder",
    "\u00be teaspoon salt",
    "1\u2009\u00bd cups milk",
    "2 cups unsalted butter, softened",
    "4 teaspoons vanilla extract",
    "8 cups powdered sugar",
    "2 tablespoons whole milk, or more as needed",
    "2 drops red food coloring, or as desired",
    "2 drops yellow food coloring, or as desired",
    "sprinkles as needed"
  ],
  "recipeInstructions": [
    "Preheat the oven to 350 degrees F (175 degrees C). Grease an 8-inch square pan and an 8-inch round pan. Line bottoms with parchment or wax paper. Grease paper and dust lightly with flour.",
    "Beat white sugar, butter, vanilla, and almond extract in a large bowl with an electric mixer on high speed until light and fluffy. Beat in eggs, 1 at a time, until well combined.",
    "Stir flour, cornstarch, baking powder, and salt together in another bowl.",
    "Beat 1 cup dry ingredients into wet ingredients until just combined. Add 1\/2 cup milk; beat until combined. Continue adding 1 cup dry ingredients and 1\/2 cup milk, beating after each addition, until all are used and batter is smooth. Divide evenly between the prepared pans.",
    "Bake in the preheated oven until a toothpick inserted in the center of each cake comes out clean, 45 to 50 minutes. Cool in pans on wire racks for 10 minutes. Remove from pans and cool completely on racks.",
    "Beat butter and vanilla together in a large bowl with an electric mixer on medium speed until combined, about 30 seconds. Gradually add powdered sugar, beating after each addition and adding milk as needed, until frosting is fluffy, smooth, and spreadable.",
    "Remove 1\/3 cup frosting and divide between 2 small bowls. Tint 1 dark pink with red food coloring. Tint the other orange-pink with red and yellow food coloring. Tint remaining frosting light pink with red food coloring.",
    "Set square cake on a work surface and rotate 45 degrees so that it resembles a diamond. Spread a little light pink frosting on left and right top sides of the diamond. Cut round cake in half crosswise to make 2 half-moons. Attach half-moons to top left and top right sides of diamond, gently pressing cake pieces together to adhere. Spread remaining light pink frosting over the assembled cake. Drop spoonfuls of dark pink and pink-orange frosting onto cake. Drag an offset spatula through frosting to create a marbled look.",
    "Pat sprinkles onto the sides of the cake. Chill, covered, for up to 3 days. Let stand at room temperature 30 minutes before slicing into 16 pieces."
  ],
  "recipeCategory": "Dessert",
  "recipeCuisine": [],
  "author": [
    {
      "@type": "Person",
      "name": "thehungryscientist"
    }
  ],
  "aggregateRating": {
    "@type": "AggregateRating",
    "itemReviewed": "Easy Heart-Shaped Cake",
    "bestRating": "5",
    "worstRating": "1"
  },
  "nutrition": {
    "@type": "NutritionInformation",
    "calories": "778.3 calories",
    "carbohydrateContent": "109.4 g",
    "cholesterolContent": "140 mg",
    "fatContent": "36.6 g",
    "fiberContent": "0.7 g",
    "proteinContent": "5.2 g",
    "saturatedFatContent": "22.6 g",
    "sodiumContent": "205.8 mg",
    "sugarContent": "87.9 g"
  },
  "review": [],
  "keywords": "",
  "tool": [],
  "url": "https:\/\/www.allrecipes.com\/recipe\/283074\/easy-heart-shaped-cake\/",
  "dateModified": "2021-01-30T15:02:50+0000",
  "dateCreated": "2021-01-30T14:57:15+0000",
  "id": 48,
  "printImage": true,
  "imageUrl": "\/apps\/cookbook\/webapp\/recipes\/48\/image?size=full"
}

Screenshots
n.a.

Browser
n.a.

Versions
Nextcloud server version:Nextcloud Hub 3 (25.0.3)
Cookbook version: 0.10.1
Database system: MariaDB and sqlite

EDIT: The original report had some false statements in it but I clarified it now

@christianlupus
Copy link
Collaborator

It might be a good idea to warn the devs in the matrix channel about the change from integer to string. Do you want to do that or should I write it? An early warning will help them to adopt accordingly.

@christianlupus christianlupus added php Pull requests that update Php code Backend Issue or PR related to the backend code Frontend Issue or PR related to the frontend code API changes involving using the app api good first issue Good for newcomers labels Feb 8, 2023
@Leptopoda
Copy link
Contributor Author

I can do that :)

You might now understand all the confusion I had when we talked about it being a string or an int 🙃

christianlupus added a commit that referenced this issue Mar 17, 2023
make server api compliant fixes #1464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API changes involving using the app api Backend Issue or PR related to the backend code bug Something isn't working Frontend Issue or PR related to the frontend code good first issue Good for newcomers php Pull requests that update Php code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants