Skip to content

Commit

Permalink
Merge "REST: Replace invalid-property-id with `invalid-path-paramet…
Browse files Browse the repository at this point in the history
…er`"
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jun 21, 2024
2 parents c660d03 + 6acad48 commit 763c4fe
Show file tree
Hide file tree
Showing 41 changed files with 330 additions and 182 deletions.
2 changes: 1 addition & 1 deletion repo/rest-api/specs/global/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"context": { "parameter": "{path_parameter}" }
}
},
"InvalidPropertyIdExample": {
"InvalidFilterPropertyIdExample": {
"value": {
"code": "invalid-property-id",
"message": "Not a valid property ID: {property_id}",
Expand Down
35 changes: 18 additions & 17 deletions repo/rest-api/specs/global/responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-field": { "$ref": "./examples.json#/InvalidFieldExample" }
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" }
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" }
}
}
},
Expand All @@ -553,7 +553,7 @@
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" }
"invalid-property-id": { "$ref": "./examples.json#/InvalidFilterPropertyIdExample" }
}
}
},
Expand All @@ -570,7 +570,8 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" }
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-property-id": { "$ref": "./examples.json#/InvalidFilterPropertyIdExample" }
}
}
},
Expand Down Expand Up @@ -623,7 +624,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"property-statement-id-mismatch": { "$ref": "./examples.json#/PropertyStatementIdMismatchExample" }
}
Expand Down Expand Up @@ -663,7 +664,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -740,7 +741,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"property-statement-id-mismatch": { "$ref": "./examples.json#/PropertyStatementIdMismatchExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
Expand Down Expand Up @@ -809,7 +810,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"property-statement-id-mismatch": { "$ref": "./examples.json#/PropertyStatementIdMismatchExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
Expand Down Expand Up @@ -906,7 +907,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -964,7 +965,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -1010,7 +1011,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -1050,7 +1051,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -1095,7 +1096,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -1156,7 +1157,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-language-code": { "$ref": "./examples.json#/InvalidLanguageCodeExample" }
}
}
Expand Down Expand Up @@ -1197,7 +1198,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 All @@ -1220,7 +1221,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"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 @@ -1627,7 +1628,7 @@
"application/json": {
"schema": { "$ref": "./response-parts.json#/Error" },
"examples": {
"invalid-property-id": { "$ref": "./examples.json#/InvalidPropertyIdExample" },
"invalid-path-parameter": { "$ref": "./examples.json#/InvalidPathParameterExample" },
"invalid-statement-id": { "$ref": "./examples.json#/InvalidStatementIdExample" },
"property-statement-id-mismatch": { "$ref": "./examples.json#/PropertyStatementIdMismatchExample" },
"invalid-edit-tag": { "$ref": "./examples.json#/InvalidEditTagExample" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare( strict_types=1 );

namespace Wikibase\Repo\RestApi\Application\UseCaseRequestValidation;

use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\Repo\RestApi\Application\UseCases\UseCaseError;
use Wikibase\Repo\RestApi\Application\Validation\PropertyIdValidator;

/**
* @license GPL-2.0-or-later
*/
class PropertyIdFilterValidatingDeserializer {

private PropertyIdValidator $propertyIdValidator;

public function __construct( PropertyIdValidator $validator ) {
$this->propertyIdValidator = $validator;
}

/**
* @throws UseCaseError
*/
public function validateAndDeserialize( string $propertyId ): NumericPropertyId {
$validationError = $this->propertyIdValidator->validate( $propertyId );
if ( $validationError ) {
$invalidPropertyId = $validationError->getContext()[PropertyIdValidator::CONTEXT_VALUE];
throw new UseCaseError(
UseCaseError::INVALID_PROPERTY_ID,
"Not a valid property ID: $invalidPropertyId",
[ UseCaseError::CONTEXT_PROPERTY_ID => $invalidPropertyId ]
);
}
return new NumericPropertyId( $propertyId );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public function __construct( PropertyIdValidator $validator ) {
public function validateAndDeserialize( string $propertyId ): NumericPropertyId {
$validationError = $this->propertyIdValidator->validate( $propertyId );
if ( $validationError ) {
$invalidPropertyId = $validationError->getContext()[PropertyIdValidator::CONTEXT_VALUE];
throw new UseCaseError(
UseCaseError::INVALID_PROPERTY_ID,
"Not a valid property ID: $invalidPropertyId",
[ UseCaseError::CONTEXT_PROPERTY_ID => $invalidPropertyId ]
UseCaseError::INVALID_PATH_PARAMETER,
"Invalid path parameter: 'property_id'",
[ UseCaseError::CONTEXT_PARAMETER => 'property_id' ]
);
}
return new NumericPropertyId( $propertyId );
Expand Down
Loading

0 comments on commit 763c4fe

Please sign in to comment.