Bladeren bron

Merge remote-tracking branch 'origin/master' into v4

# Conflicts:
#	tests/GenerateDocumentation/OutputTest.php
shalvah 2 jaren geleden
bovenliggende
commit
03ab275a4a

+ 1 - 1
README.md

@@ -9,7 +9,7 @@
 
 > [v3 is out now](https://scribe.knuckles.wtf/blog/2021/06/08/laravel-v3)!
 
-Scribe helps you generate API documentation for humans from your Laravel/Lumen/[Dingo](https://github.com/dingo/api) codebase. See a live example at [demo.scribe.knuckles.wtf](https://demo.scribe.knuckles.wtf). There's a [Node.js version](https://github.com/knuckleswtf/scribe-js), too!
+Scribe helps you generate API documentation for humans from your Laravel/Lumen/[Dingo](https://github.com/dingo/api) codebase. See a live example at [demo.scribe.knuckles.wtf](https://demo.scribe.knuckles.wtf).
 
 ## Features
 - Pretty single-page HTML doc, with human-friendly text, code samples, and included in-browser API tester ("Try It Out")

+ 13 - 3
src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php

@@ -101,11 +101,14 @@ class GetFromLaravelAPI extends Strategy
             $urlThing = $this->getNameOfUrlThing($endpointData->uri, $name);
             if ($urlThing) {
                 $rootNamespace = app()->getNamespace();
-                if (class_exists($class = "{$rootNamespace}Models\\" . Str::title($urlThing))
+                $className = $this->urlThingToClassName($urlThing);
+                if (class_exists($class = "{$rootNamespace}Models\\" . $className)
                     // For the heathens that don't use a Models\ directory
-                    || class_exists($class = $rootNamespace . Str::title($urlThing))) {
+                    || class_exists($class = $rootNamespace . $className)) {
                     $argumentInstance = new $class;
-                    $type = $this->normalizeTypeName($argumentInstance->getKeyType());
+                    if ($argumentInstance->getKeyName() === $argumentInstance->getRouteKeyName()) {
+                        $type = $this->normalizeTypeName($argumentInstance->getKeyType());
+                    }
                 }
             }
 
@@ -158,4 +161,11 @@ class GetFromLaravelAPI extends Strategy
             return null;
         }
     }
+
+    protected function urlThingToClassName(string $urlThing): string
+    {
+        $className = Str::title($urlThing);
+        $className = str_replace(['-', '_'], '', $className);
+        return $className;
+    }
 }

+ 0 - 10
tests/Fixtures/TestPostBindedInterfaceController.php

@@ -1,10 +0,0 @@
-<?php
-
-namespace Knuckles\Scribe\Tests\Fixtures;
-
-class TestPostBindedInterfaceController
-{
-    public function update(TestPostBindedInterface $post)
-    {
-    }
-}

+ 1 - 1
tests/Fixtures/TestPostBindedInterface.php → tests/Fixtures/TestPostBoundInterface.php

@@ -2,6 +2,6 @@
 
 namespace Knuckles\Scribe\Tests\Fixtures;
 
-interface TestPostBindedInterface
+interface TestPostBoundInterface
 {
 }

+ 10 - 0
tests/Fixtures/TestPostBoundInterfaceController.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace Knuckles\Scribe\Tests\Fixtures;
+
+class TestPostBoundInterfaceController
+{
+    public function update(TestPostBoundInterface $post)
+    {
+    }
+}

+ 5 - 5
tests/GenerateDocumentation/OutputTest.php

@@ -10,9 +10,9 @@ use Knuckles\Scribe\Tests\Fixtures\TestController;
 use Knuckles\Scribe\Tests\Fixtures\TestGroupController;
 use Knuckles\Scribe\Tests\Fixtures\TestPartialResourceController;
 use Knuckles\Scribe\Tests\Fixtures\TestPost;
-use Knuckles\Scribe\Tests\Fixtures\TestPostBindedInterface;
+use Knuckles\Scribe\Tests\Fixtures\TestPostBoundInterface;
 use Knuckles\Scribe\Tests\Fixtures\TestPostController;
-use Knuckles\Scribe\Tests\Fixtures\TestPostBindedInterfaceController;
+use Knuckles\Scribe\Tests\Fixtures\TestPostBoundInterfaceController;
 use Knuckles\Scribe\Tests\Fixtures\TestPostUserController;
 use Knuckles\Scribe\Tests\Fixtures\TestUser;
 use Knuckles\Scribe\Tests\TestHelpers;
@@ -330,11 +330,11 @@ class OutputTest extends BaseLaravelTest
     }
 
     /** @test */
-    public function generates_correct_url_params_from_resource_routes_and_model_binding_with_binded_interfaces()
+    public function generates_correct_url_params_from_resource_routes_and_model_binding_with_bound_interfaces()
     {
-        $this->app->bind(TestPostBindedInterface::class, fn() => new TestPost());
+        $this->app->bind(TestPostBoundInterface::class, fn() => new TestPost());
 
-        RouteFacade::resource('posts', TestPostBindedInterfaceController::class)->only('update');
+        RouteFacade::resource('posts', TestPostBoundInterfaceController::class)->only('update');
 
         config(['scribe.routes.0.match.prefixes' => ['*']]);
         config(['scribe.routes.0.apply.response_calls.methods' => []]);