Browse Source

update ApiPlatform configuration and enable OpenApi UI

Olivier Massot 6 months ago
parent
commit
d69f0f1830

+ 25 - 0
api/config/packages/api_platform.yaml

@@ -7,3 +7,28 @@ api_platform:
         json: ['application/merge-patch+json']
     swagger:
         versions: [3]
+        api_keys:
+            apiKey:
+                name: Authorization
+                type: header
+    enable_docs: true
+    enable_swagger: true
+    enable_swagger_ui: true
+    formats:
+        jsonld:
+            mime_types: ['application/ld+json']
+        json:
+            mime_types: ['application/json']
+        html:
+            mime_types: ['text/html']
+    docs_formats:
+        jsonld: ['application/ld+json']
+        jsonopenapi: ['application/vnd.openapi+json']
+        html: ['text/html']
+    defaults:
+        stateless: true
+        cache_headers:
+            vary: ['Content-Type', 'Authorization', 'Origin']
+        extra_properties:
+            standard_put: true
+            rfc_7807_compliant_errors: true

+ 5 - 0
api/config/routes.yaml

@@ -1,3 +1,8 @@
 controllers:
     resource: ../src/Controller/
     type: attribute
+
+api_platform:
+    resource: .
+    type: api_platform
+    prefix: /api

+ 1 - 3
api/src/Entity/Author.php

@@ -9,9 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
 use Doctrine\Common\Collections\Collection;
 
 #[ORM\Entity]
-#[ApiResource(operations: [
-    new Get()
-])]
+#[ApiResource]
 class Author
 {
     #[ORM\Id]

+ 1 - 1
api/src/Entity/Song.php

@@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Serializer\Annotation\Groups;
 
 #[ORM\Entity]
-#[ApiResource(operations: [])]
+#[ApiResource]
 class Song
 {
     #[ORM\Id]

+ 15 - 0
docker/caddy/caddy/Caddyfile

@@ -4,7 +4,22 @@
 
 local.api.snc-demo.fr {
   tls internal
+
+  # Serve static assets directly
+  @static {
+    path /bundles/* /favicon.ico /robots.txt
+    file {
+      try_files {path}
+    }
+  }
+  root * /var/www/html/public
+  file_server @static {
+    root /var/www/html/public
+  }
+
+  # Proxy everything else to the API
   reverse_proxy http://snc_demo_api
+
   log {
     output file /var/log/api-access.log {
       roll_size 10mb

+ 25 - 5
readme.md

@@ -42,11 +42,31 @@ Start the nuxt server:
 
 ## Add Fixtures
 
+	ALTER TABLE `snc_demo`.`author` AUTO_INCREMENT = 1;
     INSERT INTO `snc_demo`.`author` (`name`)
-    VALUES ('Georges Brassens');
-    
+    VALUES 
+        ('Artist 1'),
+        ('Artist 2'),
+        ('Artist 3');
+
+    ALTER TABLE `snc_demo`.`song` AUTO_INCREMENT = 1;
     INSERT INTO `snc_demo`.`song` (`title`, `author_id`)
     VALUES
-        ('Heureux qui comme Ulysse', 1),
-        ('Les passantes', 1),
-        ("Dans l'eau de la claire fontaine", 1);
+        ('Song A', 1),
+        ('Song B', 1),
+        ('Song C', 1),
+        ('Song D', 2),
+        ('Song E', 2),
+        ('Song F', 3),
+        ('Song G', 3);
+
+
+## Accessing the OpenAPI Interface
+
+The OpenAPI interface is available at:
+
+```
+https://local.api.snc-demo.fr/api/docs
+```
+
+This interface provides documentation for all available API routes.