moon0326 / wp-openapi

19 stars 5 forks source link

Getting rid of default 200 response with provided filters #23

Closed auzil closed 2 years ago

auzil commented 2 years ago

Hi, The default /wp/v2/comments endpoint on the POST request returns response code 201 'Created', so we are trying to hide/override the 200 response code for the admin/json consumer.

Code from Path class for generateOperationsFromRouteArgs creates the default 200 response ` if ( ! empty( $this->schemaRef ) ) { $content = new ResponseContent( 'application/json', array( '$ref' => $this->schemaRef, ) ); $response = new Response( 200, 'OK' ); $response->addContent( $content ); $responses[] = $response;

} else { $responses[] = new Response( 200, 'OK' ); } `

Any advice is appreciated, thank you

moon0326 commented 2 years ago

Hi!

Thank you for opening the issue. That's a good catch!

I'm AFK at the moment, but I'll look into it in a day or so.

moon0326 commented 2 years ago

@auzil

This is a somewhat hacky as there is no method to remove an existing response object, but try activating the following plugin.

https://gist.github.com/moon0326/2cc5b9e997b9f8b64d49c563ba6108b5

  1. Copy the content
  2. Add a new file in your wp-content/plugins
  3. Go to Plugins and activate the plugin.
auzil commented 2 years ago

Thank you a lot @moon0326, you've saved my day! This snippet does exactly what is needed.

moon0326 commented 2 years ago

@auzil I'm glad it helped :) I'll go ahead and close this issue in that case. Please open a new issue if you have any other questions.