Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removed unnecessary grouping by prefix #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM webdevops/php-nginx-dev:7.3

RUN wget -O "/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-arm64-linux" \
RUN if $(uname -m) == 'arm64';
Goodmain marked this conversation as resolved.
Show resolved Hide resolved
then wget -O "/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-arm64-linux" \
&& chmod +x "/usr/local/bin/go-replace" \
&& "/usr/local/bin/go-replace" --version
&& "/usr/local/bin/go-replace" --version;
fi
6 changes: 4 additions & 2 deletions src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,13 @@ public function saveConsume()

public function saveTags()
{
$tagIndex = 1;
$globalPrefix = config('auto-doc.global_prefix');
Goodmain marked this conversation as resolved.
Show resolved Hide resolved

$explodedUri = explode('/', $this->uri);
Goodmain marked this conversation as resolved.
Show resolved Hide resolved

$tag = Arr::get($explodedUri, $tagIndex);
$tag = (!empty($globalPrefix) && "/{$explodedUri[1]}" === $globalPrefix)
? Arr::get($explodedUri, 2)
: Arr::get($explodedUri, 1);
Comment on lines +569 to +571
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please to implement something like this

Suggested change
$tag = (!empty($globalPrefix) && "/{$explodedUri[1]}" === $globalPrefix)
? Arr::get($explodedUri, 2)
: Arr::get($explodedUri, 1);
$tag = array_shift($explodedUri);
if ($globalPrefix === $tag)) {
$tag = array_shift($explodedUri);
}


$this->item['tags'] = [$tag];
}
Expand Down
22 changes: 22 additions & 0 deletions tests/SwaggerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,28 @@ public function testAddDataPostRequest()
$service->addData($request, $response);
}

public function testAddDataGlobalPostRequest()
{
$this->addGlobalPrefix();

config(['auto-doc.security' => 'jwt']);

$this->mockDriverGetEmptyAndSaveTpmData($this->getJsonFixture('tmp_data_global_post_user_request'));

$service = app(SwaggerService::class);

$request = $this->generateRequest('post', '/global/users', [
'users' => [1,2],
'query' => null
], [], [
'authorization' => 'Bearer some_token'
]);

$response = $this->generateResponse('example_success_users_post_response.json');

$service->addData($request, $response);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please implement test case for global prefix equals /global and we call api /global

public function testAddDataToEarlyGeneratedDoc()
{
config(['auto-doc.security' => 'jwt']);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"swagger": "2.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please correct formatting

"host": "localhost",
"basePath": "/",
"schemes": [],
"paths": {
"/global/users": {
"post": {
"tags": [
"users"
],
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "",
"required": true,
"schema": {
"$ref": "#/definitions/globalusersObject"
}
}
],
"responses": {
"200": {
"description": "Operation successfully done",
"schema": {
"example": [
{
"id": 1,
"name": "admin",
"users": [
{
"id": 1,
"name": "admin"
}
]
},
{
"id": 2,
"name": "client",
"users": [
{
"id": 2,
"name": "first_client"
},
{
"id": 3,
"name": "second_client"
}
]
}
]
}
}
},
"security": [
{
"jwt": []
}
],
"description": "",
"summary": "test"
}
}
},
"definitions": {
"globalusersObject": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": ""
},
"user_id": {
"type": "integer",
"description": "with_to_array_rule_string_name"
},
"is_email_enabled": {
"type": "string",
"description": "test_rule_without_to_string"
}
},
"example": {
"users": [
1,
2
],
"query": null
},
"required": [
"query"
]
}
},
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
"title": "Name of Your Application",
"termsOfService": "",
"contact": {
"email": "[email protected]"
}
},
"securityDefinitions": {
"jwt": {
"type": "apiKey",
"name": "authorization",
"in": "header"
}
}
}