Skip to content

Commit

Permalink
* Scribe now natively supports all info fields described here https:…
Browse files Browse the repository at this point in the history
  • Loading branch information
ProjectZero4 committed Sep 14, 2023
1 parent b32959d commit ee93872
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
32 changes: 32 additions & 0 deletions config/scribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@
*/
'description' => '',

/*
* A URL to the Terms of Service for the API. This MUST be in the form of a URL.
* See https://swagger.io/specification/v3/#info-object for more info
*/
'terms_of_service' => null,

/*
* Contact details for users of the Api to use to get more information or help.
* See https://swagger.io/specification/v3/#info-object for more info
*/
'contact' => [
'name' => null,
'email' => null,
'url' => null,
],

/*
* License information about who can use the api and to what extent
* See https://swagger.io/specification/v3/#info-object for more info
*/
'license' => [
'name' => null,
'url' => null,
],

/*
* The current version string of the api
* See https://swagger.io/specification/v3/#info-object for more info
*/
'version' => null,


/*
* The base URL displayed in the docs. If this is empty, Scribe will use the value of config('app.url') at generation time.
* If you're using `laravel`` type, you can set this to a dynamic string, like '{{ config("app.tenant_url") }}' to get a dynamic base URL.
Expand Down
5 changes: 4 additions & 1 deletion src/Writing/OpenAPISpecWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function generateSpecContent(array $groupedEndpoints): array
'info' => [
'title' => $this->config->get('title') ?: config('app.name', ''),
'description' => $this->config->get('description', ''),
'version' => '1.0.0',
'version' => $this->config->get('version', ''),
'termsOfService' => $this->config->get('terms_of_service', ''),
'contact' => $this->config->get('contact', []),
'license' => $this->config->get('license', []),
],
'servers' => [
[
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ info:
title: Laravel
description: ''
version: 3.9.9
termsOfService: http://api.api.dev/terms-of-service
contact:
name: Scribe Support
email: support@scribe.test
url: https://scribe.knuckles.wtf/laravel
license:
name: MIT License
url: https://github.com/knuckleswtf/scribe/blob/master/LICENSE.md
servers:
-
url: 'http://localhost'
Expand Down
11 changes: 11 additions & 0 deletions tests/GenerateDocumentation/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ public function generated_openapi_spec_file_is_correct()
RouteFacade::get('/api/echoesUrlParameters/{param}/{param2}/{param3?}/{param4?}', [TestController::class, 'echoesUrlParameters']);

config(['scribe.openapi.enabled' => true]);
config(['scribe.version' => '2.4.1']);
config(['scribe.terms_of_service' => 'http://api.api.dev/terms-of-service']);
config(['scribe.contact' => [
'name' => 'Scribe Support',
'email' => 'support@scribe.test',
'url' => 'https://scribe.knuckles.wtf/laravel',
]]);
config(['scribe.license' => [
'name' => 'MIT License',
'url' => 'https://github.com/knuckleswtf/scribe/blob/master/LICENSE.md',
]]);
config(['scribe.openapi.overrides' => [
'info.version' => '3.9.9',
]]);
Expand Down
16 changes: 15 additions & 1 deletion tests/Unit/OpenAPISpecWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ class OpenAPISpecWriterTest extends TestCase
'title' => 'My Testy Testes API',
'description' => 'All about testy testes.',
'base_url' => 'http://api.api.dev',
'version' => '2.4.1',
'terms_of_service' => 'http://api.api.dev/terms-of-service',
'contact' => [
'name' => 'Scribe Support',
'email' => 'support@scribe.test',
'url' => 'https://scribe.knuckles.wtf/laravel',
],
'license' => [
'name' => 'MIT License',
'url' => 'https://github.com/knuckleswtf/scribe/blob/master/LICENSE.md',
],
];

/** @test */
Expand All @@ -36,7 +47,10 @@ public function follows_correct_spec_structure()
$this->assertEquals(OpenAPISpecWriter::SPEC_VERSION, $results['openapi']);
$this->assertEquals($this->config['title'], $results['info']['title']);
$this->assertEquals($this->config['description'], $results['info']['description']);
$this->assertNotEmpty($results['info']['version']);
$this->assertEquals($this->config['contact'], $results['info']['contact']);
$this->assertEquals($this->config['version'], $results['info']['version']);
$this->assertEquals($this->config['license'], $results['info']['license']);
$this->assertEquals($this->config['terms_of_service'], $results['info']['termsOfService']);
$this->assertEquals($this->config['base_url'], $results['servers'][0]['url']);
$this->assertIsArray($results['paths']);
$this->assertGreaterThan(0, count($results['paths']));
Expand Down

0 comments on commit ee93872

Please sign in to comment.