Skip to content

Commit

Permalink
Merge "REST: Replace label/description/aliases-not-defined"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Sep 5, 2024
2 parents 0973358 + e968d82 commit d2980ec
Show file tree
Hide file tree
Showing 37 changed files with 85 additions and 206 deletions.
36 changes: 0 additions & 36 deletions repo/rest-api/specs/global/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,42 +155,6 @@
}
}
},
"ItemLabelNotDefinedExample": {
"value": {
"code": "label-not-defined",
"message": "Item with the ID {item_id} does not have a label in the language: {language_code}"
}
},
"PropertyLabelNotDefinedExample": {
"value": {
"code": "label-not-defined",
"message": "Property with the ID {property_id} does not have a label in the language: {language_code}"
}
},
"ItemDescriptionNotDefinedExample": {
"value": {
"code": "description-not-defined",
"message": "Item with the ID {item_id} does not have a description in the language: {language_code}"
}
},
"PropertyDescriptionNotDefinedExample": {
"value": {
"code": "description-not-defined",
"message": "Property with the ID {property_id} does not have a description in the language: {language_code}"
}
},
"ItemAliasesNotDefinedExample": {
"value": {
"code": "aliases-not-defined",
"message": "Item with the ID {item_id} does not have aliases in the language: {language_code}"
}
},
"PropertyAliasesNotDefinedExample": {
"value": {
"code": "aliases-not-defined",
"message": "Property with the ID {property_id} does not have aliases in the language: {language_code}"
}
},
"PatchedInvalidSitelinkTypeExample": {
"value": {
"code": "patched-invalid-sitelink-type'",
Expand Down
24 changes: 12 additions & 12 deletions repo/rest-api/specs/global/responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@
"item-not-found": {
"$ref": "./examples.json#/ItemNotFoundExample"
},
"label-not-defined": {
"$ref": "./examples.json#/ItemLabelNotDefinedExample"
"resource-not-found": {
"$ref": "./examples.json#/ResourceNotFoundExample"
}
}
}
Expand All @@ -277,8 +277,8 @@
"property-not-found": {
"$ref": "./examples.json#/PropertyNotFoundExample"
},
"label-not-defined": {
"$ref": "./examples.json#/PropertyLabelNotDefinedExample"
"resource-not-found": {
"$ref": "./examples.json#/ResourceNotFoundExample"
}
}
}
Expand All @@ -301,8 +301,8 @@
"item-not-found": {
"$ref": "./examples.json#/ItemNotFoundExample"
},
"aliases-not-defined": {
"$ref": "./examples.json#/ItemAliasesNotDefinedExample"
"resource-not-found": {
"$ref": "./examples.json#/ResourceNotFoundExample"
}
}
}
Expand All @@ -325,8 +325,8 @@
"property-not-found": {
"$ref": "./examples.json#/PropertyNotFoundExample"
},
"aliases-not-defined": {
"$ref": "./examples.json#/PropertyAliasesNotDefinedExample"
"resource-not-found": {
"$ref": "./examples.json#/ResourceNotFoundExample"
}
}
}
Expand All @@ -349,8 +349,8 @@
"item-not-found": {
"$ref": "./examples.json#/ItemNotFoundExample"
},
"description-not-defined": {
"$ref": "./examples.json#/ItemDescriptionNotDefinedExample"
"resource-not-found": {
"$ref": "./examples.json#/ResourceNotFoundExample"
}
}
}
Expand All @@ -373,8 +373,8 @@
"property-not-found": {
"$ref": "./examples.json#/PropertyNotFoundExample"
},
"description-not-defined": {
"$ref": "./examples.json#/PropertyDescriptionNotDefinedExample"
"resource-not-found": {
"$ref": "./examples.json#/ResourceNotFoundExample"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public function execute( GetItemAliasesInLanguageRequest $request ): GetItemAlia

$aliases = $this->itemAliasesInLanguageRetriever->getAliasesInLanguage( $itemId, $languageCode );
if ( !$aliases ) {
throw new UseCaseError(
UseCaseError::ALIASES_NOT_DEFINED,
"Item with the ID $itemId does not have aliases in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'aliases' );
}

return new GetItemAliasesInLanguageResponse( $aliases, $lastModified, $revisionId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ public function execute( GetItemDescriptionRequest $request ): GetItemDescriptio

$description = $this->itemDescriptionRetriever->getDescription( $itemId, $languageCode );
if ( $description === null ) {
throw new UseCaseError(
UseCaseError::DESCRIPTION_NOT_DEFINED,
"Item with the ID {$itemId} does not have a description in the language: {$languageCode}"
);
throw UseCaseError::newResourceNotFound( 'description' );
}

return new GetItemDescriptionResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ public function execute( GetItemLabelRequest $request ): GetItemLabelResponse {

$label = $this->itemLabelRetriever->getLabel( $itemId, $languageCode );
if ( !$label ) {
throw new UseCaseError(
UseCaseError::LABEL_NOT_DEFINED,
"Item with the ID {$itemId->getSerialization()} does not have a label in the language: {$languageCode}"
);
throw UseCaseError::newResourceNotFound( 'label' );
}

return new GetItemLabelResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public function execute( GetPropertyAliasesInLanguageRequest $request ): GetProp

$aliases = $this->propertyAliasesRetriever->getAliasesInLanguage( $propertyId, $languageCode );
if ( !$aliases ) {
throw new UseCaseError(
UseCaseError::ALIASES_NOT_DEFINED,
"Property with the ID $propertyId does not have aliases in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'aliases' );
}

return new GetPropertyAliasesInLanguageResponse( $aliases, $lastModified, $revisionId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public function execute( GetPropertyDescriptionRequest $request ): GetPropertyDe

$description = $this->descriptionRetriever->getDescription( $propertyId, $languageCode );
if ( !$description ) {
throw new UseCaseError(
UseCaseError::DESCRIPTION_NOT_DEFINED,
"Property with the ID {$propertyId->getSerialization()} does not have a description in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'description' );
}

return new GetPropertyDescriptionResponse( $description, $lastModified, $revisionId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public function execute( GetPropertyLabelRequest $request ): GetPropertyLabelRes

$label = $this->labelRetriever->getLabel( $propertyId, $languageCode );
if ( !$label ) {
throw new UseCaseError(
UseCaseError::LABEL_NOT_DEFINED,
"Property with the ID {$propertyId->getSerialization()} does not have a label in the language: {$languageCode}"
);
throw UseCaseError::newResourceNotFound( 'label' );
}

return new GetPropertyLabelResponse( $label, $lastModified, $revisionId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public function execute( RemoveItemDescriptionRequest $request ): void {
try {
$description = $item->getDescriptions()->getByLanguage( $languageCode );
} catch ( OutOfBoundsException $e ) {
throw new UseCaseError(
UseCaseError::DESCRIPTION_NOT_DEFINED,
"Item with the ID $itemId does not have a description in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'description' );
}
$item->getDescriptions()->removeByLanguage( $languageCode );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public function execute( RemoveItemLabelRequest $request ): void {
try {
$label = $item->getLabels()->getByLanguage( $languageCode );
} catch ( OutOfBoundsException $e ) {
throw new UseCaseError(
UseCaseError::LABEL_NOT_DEFINED,
"Item with the ID $itemId does not have a label in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'label' );
}

$item->getLabels()->removeByLanguage( $languageCode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public function execute( RemovePropertyDescriptionRequest $request ): void {
try {
$description = $property->getDescriptions()->getByLanguage( $languageCode );
} catch ( OutOfBoundsException $e ) {
throw new UseCaseError(
UseCaseError::DESCRIPTION_NOT_DEFINED,
"Property with the ID $propertyId does not have a description in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'description' );
}

$property->getDescriptions()->removeByLanguage( $languageCode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public function execute( RemovePropertyLabelRequest $request ): void {
try {
$label = $property->getLabels()->getByLanguage( $languageCode );
} catch ( OutOfBoundsException $e ) {
throw new UseCaseError(
UseCaseError::LABEL_NOT_DEFINED,
"Property with the ID $propertyId does not have a label in the language: $languageCode"
);
throw UseCaseError::newResourceNotFound( 'label' );
}

$property->getLabels()->removeByLanguage( $languageCode );
Expand Down
6 changes: 0 additions & 6 deletions repo/rest-api/src/Application/UseCases/UseCaseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
*/
class UseCaseError extends UseCaseException {

public const ALIASES_NOT_DEFINED = 'aliases-not-defined';
public const CANNOT_MODIFY_READ_ONLY_VALUE = 'cannot-modify-read-only-value';
public const DATA_POLICY_VIOLATION = 'data-policy-violation';
public const DESCRIPTION_NOT_DEFINED = 'description-not-defined';
public const INVALID_KEY = 'invalid-key';
public const INVALID_PATH_PARAMETER = 'invalid-path-parameter';
public const INVALID_QUERY_PARAMETER = 'invalid-query-parameter';
public const INVALID_VALUE = 'invalid-value';
public const ITEM_NOT_FOUND = 'item-not-found';
public const ITEM_REDIRECTED = 'redirected-item';
public const ITEM_STATEMENT_ID_MISMATCH = 'item-statement-id-mismatch';
public const LABEL_NOT_DEFINED = 'label-not-defined';
public const MISSING_FIELD = 'missing-field';
public const PATCH_RESULT_INVALID_KEY = 'patch-result-invalid-key';
public const PATCH_RESULT_INVALID_VALUE = 'patch-result-invalid-value';
Expand Down Expand Up @@ -78,18 +75,15 @@ class UseCaseError extends UseCaseException {
public const CONTEXT_VIOLATION_CONTEXT = 'violation_context';

public const EXPECTED_CONTEXT_KEYS = [
self::ALIASES_NOT_DEFINED => [],
self::CANNOT_MODIFY_READ_ONLY_VALUE => [ self::CONTEXT_PATH ],
self::DATA_POLICY_VIOLATION => [ self::CONTEXT_VIOLATION, self::CONTEXT_VIOLATION_CONTEXT ],
self::DESCRIPTION_NOT_DEFINED => [],
self::INVALID_KEY => [ self::CONTEXT_PATH, self::CONTEXT_KEY ],
self::INVALID_PATH_PARAMETER => [ self::CONTEXT_PARAMETER ],
self::INVALID_QUERY_PARAMETER => [ self::CONTEXT_PARAMETER ],
self::INVALID_VALUE => [ self::CONTEXT_PATH ],
self::ITEM_NOT_FOUND => [],
self::ITEM_REDIRECTED => [ self::CONTEXT_REDIRECT_TARGET ],
self::ITEM_STATEMENT_ID_MISMATCH => [ self::CONTEXT_ITEM_ID, self::CONTEXT_STATEMENT_ID ],
self::LABEL_NOT_DEFINED => [],
self::MISSING_FIELD => [ self::CONTEXT_PATH, self::CONTEXT_FIELD ],
self::PATCH_RESULT_VALUE_TOO_LONG => [ self::CONTEXT_PATH, self::CONTEXT_LIMIT ],
self::PATCH_RESULT_INVALID_KEY => [ self::CONTEXT_PATH, self::CONTEXT_KEY ],
Expand Down
3 changes: 0 additions & 3 deletions repo/rest-api/src/RouteHandlers/ErrorResponseToHttpStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class ErrorResponseToHttpStatus {
UseCaseError::PERMISSION_DENIED => 403,

// 404 errors:
UseCaseError::ALIASES_NOT_DEFINED => 404,
UseCaseError::DESCRIPTION_NOT_DEFINED => 404,
UseCaseError::ITEM_NOT_FOUND => 404,
UseCaseError::LABEL_NOT_DEFINED => 404,
UseCaseError::PROPERTY_NOT_FOUND => 404,
UseCaseError::RESOURCE_NOT_FOUND => 404,
UseCaseError::STATEMENT_NOT_FOUND => 404,
Expand Down
60 changes: 12 additions & 48 deletions repo/rest-api/src/RouteHandlers/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3976,8 +3976,8 @@
"item-not-found": {
"$ref": "#/components/examples/ItemNotFoundExample"
},
"label-not-defined": {
"$ref": "#/components/examples/ItemLabelNotDefinedExample"
"resource-not-found": {
"$ref": "#/components/examples/ResourceNotFoundExample"
}
}
}
Expand All @@ -4002,8 +4002,8 @@
"property-not-found": {
"$ref": "#/components/examples/PropertyNotFoundExample"
},
"label-not-defined": {
"$ref": "#/components/examples/PropertyLabelNotDefinedExample"
"resource-not-found": {
"$ref": "#/components/examples/ResourceNotFoundExample"
}
}
}
Expand All @@ -4028,8 +4028,8 @@
"item-not-found": {
"$ref": "#/components/examples/ItemNotFoundExample"
},
"aliases-not-defined": {
"$ref": "#/components/examples/ItemAliasesNotDefinedExample"
"resource-not-found": {
"$ref": "#/components/examples/ResourceNotFoundExample"
}
}
}
Expand All @@ -4054,8 +4054,8 @@
"property-not-found": {
"$ref": "#/components/examples/PropertyNotFoundExample"
},
"aliases-not-defined": {
"$ref": "#/components/examples/PropertyAliasesNotDefinedExample"
"resource-not-found": {
"$ref": "#/components/examples/ResourceNotFoundExample"
}
}
}
Expand All @@ -4080,8 +4080,8 @@
"item-not-found": {
"$ref": "#/components/examples/ItemNotFoundExample"
},
"description-not-defined": {
"$ref": "#/components/examples/ItemDescriptionNotDefinedExample"
"resource-not-found": {
"$ref": "#/components/examples/ResourceNotFoundExample"
}
}
}
Expand All @@ -4106,8 +4106,8 @@
"property-not-found": {
"$ref": "#/components/examples/PropertyNotFoundExample"
},
"description-not-defined": {
"$ref": "#/components/examples/PropertyDescriptionNotDefinedExample"
"resource-not-found": {
"$ref": "#/components/examples/ResourceNotFoundExample"
}
}
}
Expand Down Expand Up @@ -7131,42 +7131,6 @@
}
}
},
"ItemLabelNotDefinedExample": {
"value": {
"code": "label-not-defined",
"message": "Item with the ID {item_id} does not have a label in the language: {language_code}"
}
},
"PropertyLabelNotDefinedExample": {
"value": {
"code": "label-not-defined",
"message": "Property with the ID {property_id} does not have a label in the language: {language_code}"
}
},
"ItemDescriptionNotDefinedExample": {
"value": {
"code": "description-not-defined",
"message": "Item with the ID {item_id} does not have a description in the language: {language_code}"
}
},
"PropertyDescriptionNotDefinedExample": {
"value": {
"code": "description-not-defined",
"message": "Property with the ID {property_id} does not have a description in the language: {language_code}"
}
},
"ItemAliasesNotDefinedExample": {
"value": {
"code": "aliases-not-defined",
"message": "Item with the ID {item_id} does not have aliases in the language: {language_code}"
}
},
"PropertyAliasesNotDefinedExample": {
"value": {
"code": "aliases-not-defined",
"message": "Property with the ID {property_id} does not have aliases in the language: {language_code}"
}
},
"PatchedInvalidSitelinkTypeExample": {
"value": {
"code": "patched-invalid-sitelink-type'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe( newGetItemAliasesInLanguageRequestBuilder().getRouteDescription(), ()
.assertValidRequest()
.makeRequest();

assertValidError( response, 404, 'aliases-not-defined' );
assert.include( response.body.message, languageCode );
assertValidError( response, 404, 'resource-not-found', { resource_type: 'aliases' } );
assert.strictEqual( response.body.message, 'The requested resource does not exist' );
} );
} );
Loading

0 comments on commit d2980ec

Please sign in to comment.