Skip to content

Commit

Permalink
Generate operationId for class endpoints (zircote#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Oct 27, 2023
1 parent 2cd2d91 commit da8463f
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Processors/OperationId.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ public function __invoke(Analysis $analysis)
}

$context = $operation->_context;
if ($context && $context->method) {
if ($context) {
$source = $context->class ?? $context->interface ?? $context->trait;
$operationId = null;
if ($source) {
$method = $context->method ? ('::' . $context->method) : '';
if ($context->namespace) {
$operationId = $context->namespace . '\\' . $source . '::' . $context->method;
$operationId = $context->namespace . '\\' . $source . $method;
} else {
$operationId = $source . '::' . $context->method;
$operationId = $source . $method;
}
} else {
} elseif ($context->method) {
$operationId = $context->method;
}
$operationId = strtoupper($operation->method) . '::' . $operation->path . '::' . $operationId;
$operation->operationId = $this->hash ? md5($operationId) : $operationId;

if ($operationId) {
$operationId = strtoupper($operation->method) . '::' . $operation->path . '::' . $operationId;
$operation->operationId = $this->hash ? md5($operationId) : $operationId;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/AttributeInheritance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: 6e8c7c1a5488a11e2b1bf5f3b726c29c
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/ClassRef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/endpoint:
get:
operationId: f835f4c3d03452d2e5d2f48b7c314e2f
responses:
'200':
description: 'All good'
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/CustomAttributeSchema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: da8efe0fc0b09040d0bda7cf58d9421d
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/CustomAttributes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: 242c3431636158b96b85e2adbefa76f4
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/CustomPropertyAttribute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api:
get:
operationId: 232f976e7ad23d1e147e984eb3da3506
responses:
'200':
description: 'All good'
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/Docblocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api/endpoint:
get:
operationId: deb4d2aa2d9e471e6e6a6c8ed61123d0
responses:
'200':
description: 'successful operation'
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/DuplicateRef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: 3f9d6af187f46eeacb56ecc9ebbf5fba
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/MergeTraits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api/endpoint:
get:
operationId: f2c3bf0cddeaf2c12b195131fb1d4e5f
responses:
'200':
description: 'successful operation'
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/MergeTraitsExtended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api/endpoint:
get:
operationId: 7bc218b8e28854bc705f3b582ab21668
responses:
'200':
description: 'successful operation'
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/Scratch/MultiplePathsForEndpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ paths:
/api/class/endpoint:
get:
description: 'A class endpoint'
operationId: f6fa254544c561ced460509c98adbc8b
responses:
'200':
description: OK
/api/class/endpoint2:
get:
description: 'Another class endpoint'
operationId: 7816e3a6652e1e4782355ec5675e75f8
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/NestedAdditionalProperties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: b81d5bbc60cb1ce6c15eb67081315573
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/NestedSchema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api/endpoint:
get:
operationId: b870e13084c8a89270151bb3e43f215a
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/Nullable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: 4608e00dd49333806891310fdc161547
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/PromotedProperty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: ff3eaf9da24371c37532fd0de82a3212
responses:
'200':
description: OK
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/PropertyInheritance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api/endpoint:
get:
operationId: 6e9f788346a2235f83520975c9ba68c8
responses:
'200':
description: 'successful operation'
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Scratch/ThirdPartyAnnotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ info:
paths:
/api/endpoint:
get:
operationId: d5f395c872bfd6677e6c30c55c7d5463
responses:
'200':
description: 'successful operation'
Expand Down

0 comments on commit da8463f

Please sign in to comment.