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

API failing to render json #132

Closed
kiwiroy opened this issue May 7, 2021 · 1 comment
Closed

API failing to render json #132

kiwiroy opened this issue May 7, 2021 · 1 comment

Comments

@kiwiroy
Copy link
Contributor

kiwiroy commented May 7, 2021

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:

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

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

if ( $method eq 'get' ) {
# heuristic: is per-item if have a param in path
if ( $id_field ) {
# per-item - GET = "read"
return {
action => 'get',
format => 'json',
};
}
else {
# per-schema - GET = "list"
return {
action => 'list',
format => 'json',
};
}
} elsif ( $method eq 'post' ) {
return {
action => 'set',
format => 'json',
};
} elsif ( $method eq 'put' ) {
die "'$method' $path needs id_field" if !$id_field;
return {
action => 'set',
format => 'json',
};
} elsif ( $method eq 'delete' ) {
die "'$method' $path needs id_field" if !$id_field;
return {
action => 'delete',
format => 'json',
};
}
else {
die "Unknown method '$method'";
}
}

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
Copy link
Owner

Fixed by merging #133. Thanks!

preaction added a commit that referenced this issue May 9, 2021
    [Fixed]

    - Fixed issues with `format` changes in Mojolicious 9.11. Thanks
      @kiwiroy for reporting and fixing these issues! [Github #131,
      #132, #133]
    - Reorganized documentation into Guides, more like Mojolicious. This
      is a work-in-progress, so there's lot more to do.
    - Removed fallback template rendering from standalone app. The
      standalone app is going to evolve into a base class for starting
      new Yancy apps, and this feature does not fit well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants