preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

API failing to render json #132

Closed kiwiroy closed 3 years ago

kiwiroy commented 3 years ago

With recent changes to the way Mojolicious routes for requests with format parameters the editor no longer retrieves data from the api but instead errors with a TypeError: items is undefined at /yancy/app.js:693.

As mentioned on IRC: https://github.com/preaction/Yancy/blob/42111830eccb514f5dbacba2fb6b358d79bf1860/lib/Mojolicious/Plugin/Yancy/resources/public/yancy/app.js#L682 could be changed to.

$.get( this.currentOperations["list"].url, query, null, 'json' ).done( 

Without this, the request headers are Accept: */* and json is never selected as a format in Yancy::Controller#list ($c->respond_to).

However, Yancy goes to lengths to set the format to json for api routes in

https://github.com/preaction/Yancy/blob/42111830eccb514f5dbacba2fb6b358d79bf1860/lib/Yancy/Plugin/Editor.pm#L420-L457

Mojolicious::Plugin::OpenAPI reverses this by undefing format when configuring the route https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/master/lib/Mojolicious/Plugin/OpenAPI.pm#L232-L233

M::P::OpenAPI could be patched, but I'll open a PR for a local fix.

preaction commented 3 years ago

Fixed by merging #133. Thanks!