Skip to content

Commit 2aac6e2

Browse files
committed
add hello world and swaggerhub compatibility
1 parent a8e7f40 commit 2aac6e2

File tree

9 files changed

+151
-5
lines changed

9 files changed

+151
-5
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ APP_SECRET=d63e877b0444331114e7842dd8105ae1
1919
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
2020
#TRUSTED_HOSTS='^(localhost|example\.com)$'
2121
###< symfony/framework-bundle ###
22+
23+
###> nelmio/cors-bundle ###
24+
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1|app\.swaggerhub\.com)(:[0-9]+)?$
25+
###< nelmio/cors-bundle ###

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"symfony/yaml": "4.4.*"
1313
},
1414
"require-dev": {
15+
"nelmio/cors-bundle": "^2.1"
1516
},
1617
"config": {
1718
"preferred-install": {

composer.lock

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
return [
44
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
5+
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
56
];

config/packages/nelmio_cors.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
nelmio_cors:
2+
defaults:
3+
allow_credentials: true
4+
origin_regex: true
5+
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
6+
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
7+
allow_headers: ['Content-Type', 'Authorization']
8+
expose_headers: ['Link']
9+
max_age: 3600
10+
paths:
11+
'^/': null

config/routes.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#index:
2-
# path: /
3-
# controller: App\Controller\DefaultController::index
1+
index:
2+
path: /
3+
controller: App\Controller\DefaultController::index

doc/openapi.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
openapi: 3.0.3
2+
info:
3+
title: TDD Demo ForumPHP 2020
4+
5+
version: 1.0.0
6+
7+
# See https://swagger.io/docs/specification/paths-and-operations/
8+
paths:
9+
10+
/:
11+
get:
12+
summary: Get an entity by aboId
13+
responses:
14+
'200':
15+
description: OK
16+
content:
17+
application/json:
18+
schema:
19+
$ref: '#/components/schemas/HelloWorld'
20+
21+
# See https://swagger.io/docs/specification/components/
22+
components:
23+
24+
# See https://swagger.io/docs/specification/data-models/
25+
# NB : they appear in the generated doc
26+
schemas:
27+
HelloWorld:
28+
type: object
29+
required: [ hello ]
30+
properties:
31+
hello:
32+
type: string
33+
example: world
34+
35+
# See https://swagger.io/docs/specification/api-host-and-base-path/
36+
servers:
37+
- url: 'https://localhost:8000'
38+
description: dev
39+
40+
# See https://app.swaggerhub.com/help/integrations/api-auto-mocking
41+
- description: SwaggerHub API Auto Mocking
42+
url: https://virtserver.swaggerhub.com/JMLamodiere/tdd-demo_forum_php_2020/1.0.0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Controller;
5+
6+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7+
use Symfony\Component\HttpFoundation\JsonResponse;
8+
use Symfony\Component\HttpFoundation\Request;
9+
use Symfony\Component\HttpFoundation\Response;
10+
11+
class DefaultController extends AbstractController
12+
{
13+
public function index(Request $request): Response
14+
{
15+
return new JsonResponse(['hello' => 'world']);
16+
}
17+
}

symfony.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
{
2+
"nelmio/cors-bundle": {
3+
"version": "1.5",
4+
"recipe": {
5+
"repo": "github.com/symfony/recipes",
6+
"branch": "master",
7+
"version": "1.5",
8+
"ref": "6388de23860284db9acce0a7a5d9d13153bcb571"
9+
},
10+
"files": [
11+
"config/packages/nelmio_cors.yaml"
12+
]
13+
},
214
"php": {
315
"version": "7.4"
416
},

0 commit comments

Comments
 (0)