WPAPI-SwaggerGenerator icon indicating copy to clipboard operation
WPAPI-SwaggerGenerator copied to clipboard

target a reference

Open Arrig0 opened this issue 8 years ago • 3 comments

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

Arrig0 avatar Nov 09 '17 16:11 Arrig0

thanks :) I'm not sure I understand what you are wanting to do? Can you provide some context?

starfishmod avatar Nov 10 '17 01:11 starfishmod

One of the major benefits of JSON Schema is its ability to compose larger schemas by reusing or combining existing schemas. Schema definitions can be referenced each other ( from an external document or the same document ) using the $ref keyword.

What i'm trying to achieve is just nesting schemas.

Suppose i have an Event object (schema title "event") and a Venue object (schema title "venue"). SwaggerGenerator build a "definitions" section with all objects (user, post, event, venue, cpt(s) etc..)

Event has a field "venue" and would like to reference the Venue schema.

Something like this: "venue": { "$ref": "#/definitions/venue" }

Is this possible?

Arrig0 avatar Nov 10 '17 08:11 Arrig0

If I understand you correctly then... then yes kind of... Swagger (OAI v2) uses the JSON schema quite a bit and there is a JSON schema for OAIv2 I believe. This library tries to follow the OAIv2 schema as closely as possible and the schema does support nested definitions in a limited way. So yes this may work already....? However it may be that after writing your schema using the WP API structure that the swagger generator does not create what you want then it may need tweaking. Can I suggest you write/use your plugin and then run the generator - check the output and if it doesn't match what it should do then get back to me with the plugin, the current output and the expected output.

starfishmod avatar Nov 13 '17 05:11 starfishmod