diff --git a/wp-content/mu-plugins/gure-ametsa/api.php b/wp-content/mu-plugins/gure-ametsa/api.php index 269e06f..8e9c801 100644 --- a/wp-content/mu-plugins/gure-ametsa/api.php +++ b/wp-content/mu-plugins/gure-ametsa/api.php @@ -105,9 +105,73 @@ add_action( 'graphql_register_types', function () { ) ); } ); -/* Documentación Swagger (/rest-api/docs/): solo para usuarios conectados, salvo API_DOCS_PUBLIC=true */ +/* + * Documentación Swagger (/rest-api/docs/). + * + * El plugin WP API SwaggerUI genera bien el esquema OpenAPI (/rest-api/schema), pero su paquete + * en wordpress.org no incluye los archivos de la interfaz (assets/), así que su página sale en blanco. + * Servimos nuestra propia página con Swagger UI oficial (versión fijada y con integridad SRI). + * Solo para usuarios conectados, salvo API_DOCS_PUBLIC=true. + */ +define( 'GA_SWAGGER_UI_VERSION', '5.33.0' ); + add_action( 'template_redirect', function () { - if ( 'docs' === get_query_var( 'swagger_api' ) && 'true' !== getenv( 'API_DOCS_PUBLIC' ) && ! is_user_logged_in() ) { + if ( 'docs' !== get_query_var( 'swagger_api' ) ) { + return; + } + if ( 'true' !== getenv( 'API_DOCS_PUBLIC' ) && ! is_user_logged_in() ) { auth_redirect(); } + + $cdn = 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@' . GA_SWAGGER_UI_VERSION; + $config = array( + 'url' => home_url( '/rest-api/schema' ), + 'nonce' => is_user_logged_in() ? wp_create_nonce( 'wp_rest' ) : '', + ); + nocache_headers(); + header( 'Content-Type: text/html; charset=utf-8' ); + ?> + + +
+ + + +