Created
June 30, 2020 09:19
-
-
Save reneeb/278b9caaf9cbc3a7bec898a20aa6783a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Mojo::Loader qw(data_section); | |
use OpenAPI::Client; | |
my $spec = data_section 'main', 'swagger.json'; | |
my $client = OpenAPI::Client->new( $spec ); | |
my $tx = $client->post_end({}, body => { "" => {string1 => "hello"}}); | |
warn $tx->req->to_string; | |
warn $tx->res->to_string; | |
__DATA__ | |
@@ swagger.json | |
{ | |
"swagger": "2.0", | |
"info": { | |
"description": "", | |
"version": "1.0.0", | |
"title" : "test case" | |
}, | |
"host": "localhost:5000", | |
"basePath": "/api/v1", | |
"schemes": [ | |
"http" | |
], | |
"paths": { | |
"/endpoint" : { | |
"post": { | |
"summary": "", | |
"description": "Some endpoint that requires a POST request", | |
"operationId": "post_end", | |
"consumes": [ | |
"application/json" | |
], | |
"parameters": [ | |
{ | |
"in": "body", | |
"name": "", | |
"schema": { | |
"type" : "object", | |
"required" : [ | |
"string1" | |
], | |
"properties": { | |
"string1" : { | |
"type": "string" | |
} | |
} | |
}, | |
"description": "" | |
} | |
], | |
"responses": { | |
"201": { | |
"description": "" | |
} | |
} | |
} | |
} | |
} | |
} | |
@@ output.txt | |
reneeb@laptop$ perl open_api_client.pl | |
GET /api/v1/endpoint HTTP/1.1 | |
Host: localhost:5000 | |
Content-Length: 0 | |
HTTP/1.1 400 Bad Request | |
Date: Tue, 30 Jun 2020 09:15:01 GMT | |
Content-Length: 65 | |
Content-Type: application/json | |
{"errors":[{"message":"Missing property.","path":"\/\/string1"}]} at open_api_client.pl line 15. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment