gothinkster / flask-realworld-example-app

Exemplary real world JSON API built with Flask (Python)
https://realworld.io/
MIT License
897 stars 308 forks source link

Fix comment json format #11

Closed jk7g14 closed 7 years ago

jk7g14 commented 7 years ago

With elm front-end, if there is a comment, there is an error while loading an article.

According to realworld api https://github.com/gothinkster/realworld/tree/master/api#single-comment,

this is the right example.

{'comments': [{'updatedAt': '2016-02-18T03:22:56.637Z', 'body': 'It takes a Jacobian', 'createdAt': '2016-02-18T03:22:56.637Z', 'id': 1, 'author': {'image': 'https://i.stack.imgur.com/xHWG8.jpg', 'bio': 'I work at statefarm', 'following': False, 'username': 'jake'}}]}

but in flask-realworld, we got this.

{'comments': [{'createdAt': '2017-08-30T05:22:41.529511+00:00', 'updatedAt': '2017-08-30T05:22:41.529540+00:00', 'body': '123', 'id': 1, 'author': {'profile': {'image': None, 'bio': None, 'email': 'u2@gmail.com', 'username': 'u2', 'following': False}}}]}

The only difference between these is 'author' section. We need to remove profile key and put profile's item to 'author' section.

because I don't know how schema? works here, I just removed profile key like below...

data['author'] = data['author']['profile']

I think this is just a fast easy solution for this since I don't know how schema class works.

author = fields.Nested(ProfileSchema)

I knew this part has a problem. I don't know how to fix it lol.

realazizk commented 7 years ago

Hello,

Sorry for the delay, I didn't notice the github Email just for the new change, there is really no proper way to do this, your solution is fine.

Maybe you should add a test so that this won't happen again and I will merge it.

jk7g14 commented 7 years ago

hmm...

I tried to add a comment view test, but I can't see or access marshmallow results during the test.

realazizk commented 7 years ago

Merged thanks.

jk7g14 commented 7 years ago

Nice! I'm learning from you a lot. Thank you!