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

More content negotion in v3 #113

Closed
plk opened this issue Feb 14, 2019 · 4 comments
Closed

More content negotion in v3 #113

plk opened this issue Feb 14, 2019 · 4 comments
Assignees
Labels

Comments

@plk
Copy link

plk commented Feb 14, 2019

Sorry to be a pain. I am still working on getting a v3 spec to work and I'm getting 500 errors for everything beyond the simple example of #110 (which works now). Here's a simple example of a post with a simple body which give me the same No responses rules defined for Accept application/json error.

use v5.16;
use Mojo::Base -strict;
use Mojolicious::Lite;

get '/test' => sub {
  my $c = shift->openapi->valid_input or return;
  $c->render(status => 200, openapi => "test");
  },
  'File';

plugin OpenAPI => {schema => 'v3', url => 'data://main/file.yaml'};

my $ua = Mojo::UserAgent->new;
my $res = $ua->post("/v1/test" => {Accept => 'application/json'} =>
                                   json => {username => 'testuser'})->res;

package main;
__DATA__
@@ file.yaml
openapi: 3.0.0
info:
  title: Title
  description: Description
  version: 1.0.0
servers:
  - url: 'https://server1.com/v1'
  - url: 'https://server2.com/v1'
paths:
  '/test':
    post:
      operationId: "File"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Test"
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                type: string
components:
  schemas:
    Test:
      type: object
      required:
        - username
      properties:
        username:
          type: string

@jhthorsen
Copy link
Owner

Well... there’s a reason why you have to be a pain: My implementation isn’t good enough 🙈😭😉

I don’t know when I will find time to look at this, but this will be a priority once I free up some time.

@plk
Copy link
Author

plk commented Feb 26, 2019

Any chance to look at this? I really want to move a project to OpenAPI3 ...

@jhthorsen jhthorsen self-assigned this Mar 2, 2019
@jhthorsen
Copy link
Owner

jhthorsen commented Mar 2, 2019

Your example is invalid @plk: You have "post" in your spec, but "get" in the example application.

I'll reopen the issue if there is still and issue after you change the code.

@jhthorsen
Copy link
Owner

Also, I did convert your script to an OK test:

use Mojo::Base -strict;
use Test::Mojo;

use Mojolicious::Lite;
post '/test' => sub {
  my $c = shift->openapi->valid_input or return;
  $c->render(status => 200, openapi => 'test');
}, 'File';

plugin OpenAPI => {schema => 'v3', url => 'data://main/file.yaml'};

my $t = Test::Mojo->new;
$t->post_ok('/v1/test', {Accept => 'application/json'} => json => {username => 'testuser'})
  ->status_is(200)->content_is('"test"');

done_testing;

__DATA__
@@ file.yaml
openapi: 3.0.0
info:
  title: Title
  description: Description
  version: 1.0.0
servers:
  - url: 'https://server1.com/v1'
  - url: 'https://server2.com/v1'
paths:
  '/test':
    post:
      operationId: "File"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Test"
        required: true
      responses:
        "200":
          description: Description
          content:
            application/json:
              schema:
                type: string
components:
  schemas:
    Test:
      type: object
      required:
        - username
      properties:
        username:
          type: string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants