-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b267a37
commit c3ae32f
Showing
7 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Back to the [Table of Contents](README.md) | ||
|
||
Previous topic: | ||
[Implementation](3.implementation.md) | ||
|
||
--- | ||
|
||
# OCPI Contracts | ||
|
||
The package contains a number of classes which are used to represent OCPI objects. You can see the full list of contract models [here](https://github.com/BitzArt/OCPI.Net/tree/main/src/OCPI.Net.Contracts). | ||
|
||
|
||
## Validation | ||
|
||
The package contains a collection of validators which you can use to validate incoming OCPI requests. To use a validator, call the `OcpiValidate` method of the `OcpiController` class. The method only allows validating OCPI models from the `OCPI.Contracts` namespace. In case of invalid request, further request handling will be aborted, and the error response will be returned to the client. | ||
|
||
```csharp | ||
[OcpiEndpoint(OcpiModule.Locations, "Receiver", "2.2.1")] | ||
[Route("2.2.1/locations")] | ||
[OcpiAuthorize] | ||
public class OcpiLocationsReceiverController : OcpiController | ||
{ | ||
[HttpPut("{countryCode}/{partyId}/{locationId}")] | ||
public IActionResult Put( | ||
[FromRoute] string countryCode, | ||
[FromRoute] string partyId, | ||
[FromRoute] string locationId, | ||
[FromBody] OcpiLocation location) | ||
{ | ||
// Use a built-in OCPI validator | ||
OcpiValidate(location); | ||
|
||
// Your Location PUT logic | ||
Return OcpiOk(result); | ||
} | ||
|
||
// Other endpoint methods... | ||
} | ||
``` | ||
|
||
Validation functionality is built on top of [FluentValidation](https://github.com/FluentValidation/FluentValidation) nuget package. | ||
|
||
--- | ||
|
||
Next topic: | ||
[Error handling](5.error-handling.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters