Skip to content

Commit

Permalink
Add Swagger for NDLA endpoints (#2835)
Browse files Browse the repository at this point in the history
* add swagger

* Run php-cs-fixer

* fix namespace

* document locale format

---------

Co-authored-by: emmachughes <[email protected]>
  • Loading branch information
emmachughes and emmachughes authored Dec 5, 2024
1 parent 3efb996 commit 5433bf3
Show file tree
Hide file tree
Showing 9 changed files with 2,162 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ services:
hub-vite:
image: node:18-alpine
command: [sh, -c, 'npm ci && npm run dev']
environment:
- SCARF_ANALYTICS=false
volumes:
- npm_cache:/root/.npm
- ./sourcecode/hub:/srv/www/hub
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\NdlaLegacy;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

use function resource_path;

/**
* @deprecated This exists for compatibility with old integrations. New
* integrations with Edlib should not use this.
*/
final readonly class SwaggerController
{
public function swagger(): Response
{
return response()->view('ndla-legacy.swagger');
}

public function redirect(): RedirectResponse
{
return redirect()->route('ndla-legacy.swagger', status: Response::HTTP_PERMANENTLY_REDIRECT);
}

public function schema(): BinaryFileResponse
{
return response()->file(resource_path('schema/ndla-openapi.json'), [
'Content-Type' => 'application/json',
]);
}
}
1,720 changes: 1,704 additions & 16 deletions sourcecode/hub/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion sourcecode/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"bootstrap-icons": "^1.11.3",
"choices.js": "^11.0.2",
"date-fns": "^4.1.0",
"htmx.org": "^2.0.3"
"htmx.org": "^2.0.3",
"swagger-ui": "^5.18.2"
},
"engines": {
"node": "^18"
Expand Down
7 changes: 7 additions & 0 deletions sourcecode/hub/resources/js/swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SwaggerUI from 'swagger-ui';
import 'swagger-ui/dist/swagger-ui.css';

SwaggerUI({
dom_id: '#swagger',
url: document.documentElement.getAttribute('data-openapi-url'),
});
Loading

0 comments on commit 5433bf3

Please sign in to comment.