Skip to content

Commit

Permalink
Merge "REST: Replace the invalid-item-id error with the generalized…
Browse files Browse the repository at this point in the history
… `invalid-path-parameter` one."
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jun 20, 2024
2 parents 1ab98be + 46b126c commit 16d98f1
Show file tree
Hide file tree
Showing 47 changed files with 334 additions and 201 deletions.
7 changes: 4 additions & 3 deletions repo/rest-api/specs/global/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"message": "Not a valid field: {field}"
}
},
"InvalidItemIdExample": {
"InvalidPathParameterExample": {
"value": {
"code": "invalid-item-id",
"message": "Not a valid item ID: {item_id}"
"code": "invalid-path-parameter",
"message": "Invalid path parameter: '{path_parameter}'",
"context": { "parameter": "{path_parameter}" }
}
},
"InvalidPropertyIdExample": {
Expand Down
36 changes: 18 additions & 18 deletions repo/rest-api/specs/global/responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-field": { "$ref": "./examples.json#/InvalidFieldExample" }
}
}
Expand Down Expand Up @@ -517,7 +517,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" }
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" }
}
}
},
Expand Down Expand Up @@ -551,7 +551,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" }
}
}
Expand Down Expand Up @@ -603,7 +603,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"item-statement-id-mismatch": { "$ref": "./examples.json#/ItemStatementIdMismatchExample" }
}
Expand Down Expand Up @@ -641,7 +641,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
"comment-too-long": { "$ref": "./examples.json#/CommentTooLongExample" },
"statement-data-missing-field": { "$ref": "./examples.json#/StatementDataMissingFieldExample" },
Expand Down Expand Up @@ -710,7 +710,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"item-statement-id-mismatch": { "$ref": "./examples.json#/ItemStatementIdMismatchExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
Expand Down Expand Up @@ -787,7 +787,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"item-statement-id-mismatch": { "$ref": "./examples.json#/ItemStatementIdMismatchExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
Expand Down Expand Up @@ -829,7 +829,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-site-id": { "$ref": "./examples.json#/InvalidSiteIdExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
"comment-too-long": { "$ref": "./examples.json#/CommentTooLongExample" }
Expand All @@ -849,7 +849,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-site-id": { "$ref": "./examples.json#/InvalidSiteIdExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
"comment-too-long": { "$ref": "./examples.json#/CommentTooLongExample" },
Expand All @@ -876,7 +876,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" },
"invalid-label": { "$ref": "./examples.json#/InvalidLabelExample" },
"label-empty": { "$ref": "./examples.json#/LabelEmptyExample" },
Expand Down Expand Up @@ -934,7 +934,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" },
"invalid-description": { "$ref": "./examples.json#/InvalidDescriptionExample" },
"description-empty": { "$ref": "./examples.json#/DescriptionEmptyExample" },
Expand Down Expand Up @@ -989,7 +989,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
"comment-too-long": { "$ref": "./examples.json#/CommentTooLongExample" }
Expand Down Expand Up @@ -1029,7 +1029,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
"comment-too-long": { "$ref": "./examples.json#/CommentTooLongExample" }
Expand Down Expand Up @@ -1069,7 +1069,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" },
"alias-empty": { "$ref": "./examples.json#/AliasEmptyExample" },
"alias-list-empty": { "$ref": "./examples.json#/AliasListEmptyExample" },
Expand Down Expand Up @@ -1119,7 +1119,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-site-id": { "$ref": "./examples.json#/InvalidSiteIdExample" }
}
}
Expand All @@ -1137,7 +1137,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" }
}
}
Expand Down Expand Up @@ -1173,7 +1173,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
"comment-too-long": { "$ref": "./examples.json#/CommentTooLongExample" },
"invalid-patch": { "$ref": "./examples.json#/InvalidPatchExample" },
Expand Down Expand Up @@ -1594,7 +1594,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-item-id": { "$ref": "./examples.json#/InvalidItemIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"item-statement-id-mismatch": { "$ref": "./examples.json#/ItemStatementIdMismatchExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
* @license GPL-2.0-or-later
*/
class ItemIdRequestValidatingDeserializer {

/**
* @throws UseCaseError
*/
public function validateAndDeserialize( ItemIdRequest $request ): ItemId {
try {
return new ItemId( $request->getItemId() );
} catch ( InvalidArgumentException $e ) {
throw new UseCaseError( UseCaseError::INVALID_ITEM_ID, "Not a valid item ID: {$request->getItemId()}" );
throw new UseCaseError(
UseCaseError::INVALID_PATH_PARAMETER,
"Invalid path parameter: 'item_id'",
[ UseCaseError::CONTEXT_PARAMETER => 'item_id' ]
);
}
}

Expand Down
5 changes: 3 additions & 2 deletions repo/rest-api/src/Application/UseCases/UseCaseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class UseCaseError extends UseCaseException {
public const DESCRIPTION_EMPTY = 'description-empty';
public const DESCRIPTION_NOT_DEFINED = 'description-not-defined';
public const DESCRIPTION_TOO_LONG = 'description-too-long';
public const INVALID_PATH_PARAMETER = 'invalid-path-parameter';
public const INVALID_DESCRIPTION = 'invalid-description';
public const INVALID_EDIT_TAG = 'invalid-edit-tag';
public const INVALID_FIELD = 'invalid-field';
public const INVALID_ITEM_ID = 'invalid-item-id';
public const INVALID_LABEL = 'invalid-label';
public const INVALID_LANGUAGE_CODE = 'invalid-language-code';
public const INVALID_OPERATION_CHANGED_PROPERTY = 'invalid-operation-change-property-of-statement';
Expand Down Expand Up @@ -124,6 +124,7 @@ class UseCaseError extends UseCaseException {
public const CONTEXT_MATCHING_ITEM_ID = 'matching-item-id';
public const CONTEXT_MATCHING_PROPERTY_ID = 'matching-property-id';
public const CONTEXT_OPERATION = 'operation';
public const CONTEXT_PARAMETER = 'parameter';
public const CONTEXT_PATH = 'path';
public const CONTEXT_ITEM_ID = 'item-id';
public const CONTEXT_PROPERTY_ID = 'property-id';
Expand All @@ -148,12 +149,12 @@ class UseCaseError extends UseCaseException {
self::DESCRIPTION_EMPTY => [],
self::DESCRIPTION_NOT_DEFINED => [],
self::DESCRIPTION_TOO_LONG => [ self::CONTEXT_CHARACTER_LIMIT ],
self::INVALID_PATH_PARAMETER => [ self::CONTEXT_PARAMETER ],
self::INVALID_ALIAS_LIST => [ self::CONTEXT_LANGUAGE ],
self::INVALID_ALIAS => [],
self::INVALID_DESCRIPTION => [],
self::INVALID_EDIT_TAG => [],
self::INVALID_FIELD => [],
self::INVALID_ITEM_ID => [],
self::INVALID_LABEL => [],
self::INVALID_LANGUAGE_CODE => [],
self::INVALID_OPERATION_CHANGED_PROPERTY => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ErrorResponseToHttpStatus {

private static array $lookupTable = [
UseCaseError::INVALID_ITEM_ID => 400,
UseCaseError::INVALID_PATH_PARAMETER => 400,
UseCaseError::INVALID_PROPERTY_ID => 400,
UseCaseError::INVALID_SITE_ID => 400,
UseCaseError::INVALID_STATEMENT_ID => 400,
Expand Down
Loading

0 comments on commit 16d98f1

Please sign in to comment.