Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active October 7, 2019 23:05
Show Gist options
  • Save justinyoo/c5cd857042083f4c84bff28e4a7899e9 to your computer and use it in GitHub Desktop.
Save justinyoo/c5cd857042083f4c84bff28e4a7899e9 to your computer and use it in GitHub Desktop.
Many Meanings of Message Validation
public class OrderItem
{
public string ItemId { get; set; }
public int Amount { get; set; }
}
public class OrderItemValidator : AbstractValidator<OrderItem>
{
public OrderItemValidator()
{
RuleFor(item => item.ItemId).Matches(@"\w+\-\w+\-\w+");
RuleFor(item => item.Amount).GreaterThan(0).LessThanOrEqualTo(100);
}
}
var orderItem = new OrderItem();
var validator = new OrderItemValidator();
var result = validator.Validate(orderItem);
...
paths:
# Path definition
/pets:
get:
description: Returns all pets from the system that the user has access to
responses:
'200':
description: A list of pets.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/pet'
...
components:
...
schemas:
# Schema definition
pet:
type: object
required:
- name
properties:
name:
type: string
address:
$ref: '#/components/schemas/Address'
age:
type: integer
format: int32
minimum: 0
...
{
"orderId": 123,
"items": [
{
"itemId": "pizza-hwaiian-large",
"amount": 1
},
{
"itemId": "water-sparkling-medium",
"amount": 1
}
]
}
<description>
...
<types>
// Definition of data contract
</types>
...
<interface>
// Definition of service contract
</interface>
...
<service>
// Definition of service endpoint
</service>
...
</description>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment