starfishmod / wpapi-swaggergenerator Goto Github PK
View Code? Open in Web Editor NEWGenerate a swagger file for your Wordpress based on the API plugins installed
License: MIT License
Generate a swagger file for your Wordpress based on the API plugins installed
License: MIT License
wp/v2
is intended for WordPress core resources. You should pick a namespace specific to your plugin.
Hi, your plugin is amazing.
Just a question.. There is a way to relate an object to an already defined definition?
Example:
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'event',
'type' => 'object',
'properties' => array(...)
);
$other_schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'something_needing_an_array_of_events',
'type' => 'object',
'properties' => array(
'listing' => array(
'description' => __( 'listing of events.' )
'type' => 'array',
'items' => array(
// something like:
//'type' => 'event',
//'$ref' => '#/definitions/event'
),
)
)
);
Thanks in advance
example.com/index.php/apigenerate/swagger
translates to
example.com/apigenerate/swagger
and then 404s.
Attempted to generate the file on a single site install, and multisite. Same issue on both.
Is there a way of implementing SwaggerGenerator with custom registered routes. I tried defining a schema but couldn't get it working ..
Could you provide me with an example?
After Wordpress 4.7 upgrade empty enums appeared into template POST parameters in several enpoints (Page, Post):
e.g.:
{
"name":"template",
"type":"string",
"in":"formData",
"description":"Teematiedosto joka n\u00e4ytt\u00e4\u00e4 kohteen.",
"enum":[
""
]
}
Currently I don't think it handles multi-site well and needs to be fixed. see #3 for a reference to this
Hi!
On behalf of Pantheon, I'm writing a tutorial on why integration tests are critical for your WP REST API endpoints, and how you can go about writing them.
Given your use of register_rest_field()
, I think you could benefit from reading and applying the tutorial. And, because the tutorial isn't yet published, I'd very much appreciate any constructive criticism you have, so that we can make the tutorial an evergreen resource for the community.
Thanks in advance for your time. Happy to take any questions, comments, etc. you might have in this Github issue, or on the document itself (you'll need to be signed into Dropbox).
It'd be great if this could be submitted to the plugin directory. Earlier on the make WordPress chat someone asked for this exact functionality. I'd be happy to submit (with you as the author) if you let me know your username on wordpress.org
Generated JSON contains enums in date-time properties in definitions section (which causes client generations to fail).
E.g. generated attachment:
definitions:
attachment:
type: object
properties:
date:
description: 'The date the object was published, in the site''s timezone.'
type: string
format: date-time
enum:
- view
- edit
- embed
Wordpress seems to support HEAD calls so that should be available to all GET endpoints also.
Loaded plugin, and ran the generator to output swagger.json
goto JSON Schema Validator , select schema Swagger API 2.0
cut/paste swagger.json from WP.
many failures:
NOTE: same validation works fine against petstore swagger.json
Swagger schema: OpenAPI-Specification/schemas/v2.0/schema.json
Swagger-Editor and Swagger-Validator did not like it either.
Can you push and example of the swagger.json you are generating to this repo?
Please include a list of plugins your are using and versions.
I have some time to help in testing with external tools, unfortunately I don't know php.
I also used Convert JSON to YAML Online to create yaml from the swagger.json file.
Setup: Ubuntu Host, Docker WP/MySQL, Docker SwaggerUI
So I'm making a repo to show how-to author basic REST API endpoints, and I'd like to have a swagger file for that. For some reason this plugin is not working for me. (Checked the plugin btw it works for me)
plugins/{plugin}/index.php
<?php
/*
Plugin Name: CODESIGN2 WordPress REST API Example Plugin
Plugin URI: https://www.codesign2.co.uk
Description: Really basic WordPress REST API Example Plugin
Version: 1.0.0
Author: CD2Team
Author URI: https://www.codesign2.co.uk
*/
add_action('rest_api_init', function(){
foreach([
'Test'
] as $endpoint) {
require_once( __DIR__."/controllers/{$endpoint}Controller.php");
$controller_class = "{$endpoint}Controller";
$controller = new $controller_class();
$controller->register_routes();
}
});
plugins/{plugin}/controllers/TestController.php
<?php
use WP_REST_Server;
use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
class TestController extends WP_REST_Controller {
public function __construct() {
$this->namespace = 'test/v1';
}
public function register_routes() {
register_rest_route(
"{$this->namespace}",
"/date",
[
[
'methods' => WP_REST_Server::READABLE,
'callback' => [$this, 'index'],
'permission_callback' => [$this, 'index_permissions_check'],
'args' => [],
]
]
);
}
public function index(WP_REST_Request $request) {
$data = date('Y-m-d H:i:s');
return new WP_REST_Response( $data, 200);
}
public function index_permissions_check(WP_REST_Request $request) {
return true;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.