Skip to content

Commit

Permalink
Update example with verified endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsensesoftware committed May 8, 2022
1 parent 318a702 commit be7db04
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 23 deletions.
7 changes: 7 additions & 0 deletions examples/AspNetCore/OData/ODataOpenApiExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
options.Count().Select().OrderBy();
options.RouteOptions.EnableKeyInParenthesis = false;
options.RouteOptions.EnableNonParenthesisForEmptyParameterFunction = true;
options.RouteOptions.EnablePropertyNameCaseInsensitive = true;
options.RouteOptions.EnableQualifiedOperationCall = false;
options.RouteOptions.EnableUnqualifiedOperationCall = true;
} );
Expand Down Expand Up @@ -80,6 +81,12 @@

// Configure the HTTP request pipeline.

if ( app.Environment.IsDevelopment() )
{
// navigate to ~/$odata to determine whether any endpoints did not match an odata route template
app.UseODataRouteDebug();
}

app.UseSwagger();
app.UseSwaggerUI(
options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Asp.Versioning;
using Asp.Versioning.OData;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Results;
using Microsoft.AspNetCore.OData.Routing.Controllers;
Expand All @@ -25,6 +24,7 @@ public class OrdersController : ODataController
/// <returns>The requested order.</returns>
/// <response code="200">The order was successfully retrieved.</response>
/// <response code="404">The order does not exist.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -39,6 +39,7 @@ public class OrdersController : ODataController
/// <returns>The created order.</returns>
/// <response code="201">The order was successfully placed.</response>
/// <response code="400">The order is invalid.</response>
[HttpPost]
[MapToApiVersion( 1.0 )]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status201Created )]
Expand Down Expand Up @@ -93,7 +94,7 @@ public IActionResult Post( [FromBody] Order order )
/// <returns>The order line items.</returns>
/// <response code="200">The line items were successfully retrieved.</response>
/// <response code="404">The order does not exist.</response>
[HttpGet( "api/Orders/{key}/LineItems" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<LineItem>> ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PeopleController : ODataController
/// <returns>The requested person.</returns>
/// <response code="200">The person was successfully retrieved.</response>
/// <response code="404">The person does not exist.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Person ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down Expand Up @@ -62,16 +63,16 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
[ProducesResponseType( Status404NotFound )]
[EnableQuery( AllowedQueryOptions = Select )]
public SingleResult<Person> MostExpensive( ODataQueryOptions<Person> options, CancellationToken ct ) =>
SingleResult.Create(
new Person[]
{
SingleResult.Create(
new Person[]
{
new()
{
Id = 42,
FirstName = "Elon",
Id = 42,
FirstName = "Elon",
LastName = "Musk",
},
}.AsQueryable() );
}.AsQueryable() );

/// <summary>
/// Gets the most expensive person.
Expand All @@ -91,11 +92,11 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
CancellationToken ct ) =>
SingleResult.Create(
new Person[]
{
{
new()
{
Id = key,
FirstName = "John",
{
Id = key,
FirstName = "John",
LastName = "Doe",
},
}.AsQueryable() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class OrdersController : ODataController
/// </summary>
/// <returns>All available orders.</returns>
/// <response code="200">The successfully retrieved orders.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<Order>> ), Status200OK )]
[EnableQuery( MaxTop = 100, AllowedQueryOptions = Select | Top | Skip | Count )]
Expand All @@ -45,7 +46,7 @@ public IQueryable<Order> Get()
/// <returns>The requested order.</returns>
/// <response code="200">The order was successfully retrieved.</response>
/// <response code="404">The order does not exist.</response>
[HttpGet( "api/Orders/{key}" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -60,6 +61,7 @@ public IQueryable<Order> Get()
/// <returns>The created order.</returns>
/// <response code="201">The order was successfully placed.</response>
/// <response code="400">The order is invalid.</response>
[HttpPost]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status201Created )]
[ProducesResponseType( Status400BadRequest )]
Expand All @@ -84,6 +86,7 @@ public IActionResult Post( [FromBody] Order order )
/// <response code="204">The order was successfully updated.</response>
/// <response code="400">The order is invalid.</response>
/// <response code="404">The order does not exist.</response>
[HttpPatch]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status200OK )]
[ProducesResponseType( Status204NoContent )]
Expand Down Expand Up @@ -148,7 +151,7 @@ public IActionResult Rate( int key, [FromBody] ODataActionParameters parameters
/// <returns>The order line items.</returns>
/// <response code="200">The line items were successfully retrieved.</response>
/// <response code="404">The order does not exist.</response>
[HttpGet( "api/Orders/{key}/LineItems" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<LineItem>> ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PeopleController : ODataController
/// <param name="options">The current OData query options.</param>
/// <returns>All available people.</returns>
/// <response code="200">The successfully retrieved people.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<Person>> ), Status200OK )]
public IActionResult Get( ODataQueryOptions<Person> options )
Expand Down Expand Up @@ -83,6 +84,7 @@ public IActionResult Get( ODataQueryOptions<Person> options )
/// <returns>The requested person.</returns>
/// <response code="200">The person was successfully retrieved.</response>
/// <response code="404">The person does not exist.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Person ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down Expand Up @@ -128,7 +130,7 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
/// <returns>The person's home address.</returns>
/// <response code="200">The home address was successfully retrieved.</response>
/// <response code="404">The person does not exist.</response>
[HttpGet( "api/People/{key}/HomeAddress" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Address ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AcmeController : ODataController
/// </summary>
/// <returns>All available suppliers.</returns>
/// <response code="200">The supplier successfully retrieved.</response>
[HttpGet]
[EnableQuery]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<Supplier> ), Status200OK )]
Expand All @@ -28,7 +29,7 @@ public class AcmeController : ODataController
/// Gets the products associated with the supplier.
/// </summary>
/// <returns>The associated supplier products.</returns>
[HttpGet( "api/Acme/Products" )]
[HttpGet]
[EnableQuery]
public IQueryable<Product> GetProducts() => NewSupplier().Products.AsQueryable();

Expand All @@ -38,6 +39,7 @@ public class AcmeController : ODataController
/// <param name="navigationProperty">The name of the related navigation property.</param>
/// <param name="link">The related entity identifier.</param>
/// <returns>None</returns>
[HttpPut]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status404NotFound )]
public IActionResult CreateRef(
Expand All @@ -50,6 +52,7 @@ public class AcmeController : ODataController
/// <param name="relatedKey">The related entity identifier.</param>
/// <param name="navigationProperty">The name of the related navigation property.</param>
/// <returns>None</returns>
[HttpDelete]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status404NotFound )]
public IActionResult DeleteRef(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OrdersController : ODataController
/// <returns>All available orders.</returns>
/// <response code="200">Orders successfully retrieved.</response>
/// <response code="400">The order is invalid.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<Order>> ), Status200OK )]
[EnableQuery( MaxTop = 100, AllowedQueryOptions = Select | Top | Skip | Count )]
Expand All @@ -46,6 +47,7 @@ public IQueryable<Order> Get()
/// <returns>The requested order.</returns>
/// <response code="200">The order was successfully retrieved.</response>
/// <response code="404">The order does not exist.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -60,6 +62,7 @@ public IQueryable<Order> Get()
/// <returns>The created order.</returns>
/// <response code="201">The order was successfully placed.</response>
/// <response code="400">The order is invalid.</response>
[HttpPost]
[ProducesResponseType( typeof( Order ), Status201Created )]
[ProducesResponseType( Status400BadRequest )]
public IActionResult Post( [FromBody] Order order )
Expand All @@ -83,6 +86,7 @@ public IActionResult Post( [FromBody] Order order )
/// <response code="204">The order was successfully updated.</response>
/// <response code="400">The order is invalid.</response>
/// <response code="404">The order does not exist.</response>
[HttpPatch]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status200OK )]
[ProducesResponseType( Status204NoContent )]
Expand Down Expand Up @@ -110,6 +114,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Order> delta )
/// <returns>None</returns>
/// <response code="204">The order was successfully canceled.</response>
/// <response code="404">The order does not exist.</response>
[HttpDelete]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status404NotFound )]
public IActionResult Delete( int key, bool suspendOnly ) => NoContent();
Expand All @@ -120,6 +125,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Order> delta )
/// <returns>The most expensive order.</returns>
/// <response code="200">The order was successfully retrieved.</response>
/// <response code="404">The no orders exist.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Order ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -136,6 +142,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Order> delta )
/// <response code="204">The order was successfully rated.</response>
/// <response code="400">The parameters are invalid.</response>
/// <response code="404">The order does not exist.</response>
[HttpPost]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status400BadRequest )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -157,7 +164,7 @@ public IActionResult Rate( int key, [FromBody] ODataActionParameters parameters
/// <returns>The order line items.</returns>
/// <response code="200">The line items were successfully retrieved.</response>
/// <response code="404">The order does not exist.</response>
[HttpGet( "api/Orders/{key}/LineItems" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<LineItem>> ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PeopleController : ODataController
/// <param name="options">The current OData query options.</param>
/// <returns>All available people.</returns>
/// <response code="200">The successfully retrieved people.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<Person>> ), Status200OK )]
public IActionResult Get( ODataQueryOptions<Person> options )
Expand Down Expand Up @@ -87,6 +88,7 @@ public IActionResult Get( ODataQueryOptions<Person> options )
/// <returns>The requested person.</returns>
/// <response code="200">The person was successfully retrieved.</response>
/// <response code="404">The person does not exist.</response>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Person ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down Expand Up @@ -121,6 +123,7 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
/// <returns>The created person.</returns>
/// <response code="201">The person was successfully created.</response>
/// <response code="400">The person was invalid.</response>
[HttpPost]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Person ), Status201Created )]
[ProducesResponseType( Status400BadRequest )]
Expand Down Expand Up @@ -179,7 +182,7 @@ public IActionResult Promote( int key, [FromBody] ODataActionParameters paramete
/// <returns>The person's home address.</returns>
/// <response code="200">The home address was successfully retrieved.</response>
/// <response code="404">The person does not exist.</response>
[HttpGet( "api/People/{key}/HomeAddress" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Address ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -200,7 +203,7 @@ public IActionResult Promote( int key, [FromBody] ODataActionParameters paramete
/// <returns>The person's work address.</returns>
/// <response code="200">The work address was successfully retrieved.</response>
/// <response code="404">The person does not exist.</response>
[HttpGet( "api/People/{key}/WorkAddress" )]
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Address ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Deltas;
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Results;
using Microsoft.AspNetCore.OData.Routing.Controllers;
Expand All @@ -31,6 +30,7 @@ public class ProductsController : ODataController
/// </summary>
/// <returns>All available products.</returns>
/// <response code="200">Products successfully retrieved.</response>
[HttpGet]
[EnableQuery]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataValue<IEnumerable<Product>> ), Status200OK )]
Expand All @@ -43,6 +43,7 @@ public class ProductsController : ODataController
/// <returns>The requested product.</returns>
/// <response code="200">The product was successfully retrieved.</response>
/// <response code="404">The product does not exist.</response>
[HttpGet]
[EnableQuery]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Product ), Status200OK )]
Expand All @@ -58,6 +59,7 @@ public class ProductsController : ODataController
/// <response code="201">The product was successfully created.</response>
/// <response code="204">The product was successfully created.</response>
/// <response code="400">The product is invalid.</response>
[HttpPost]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Product ), Status201Created )]
[ProducesResponseType( Status204NoContent )]
Expand All @@ -84,6 +86,7 @@ public IActionResult Post( [FromBody] Product product )
/// <response code="204">The product was successfully updated.</response>
/// <response code="400">The product is invalid.</response>
/// <response code="404">The product does not exist.</response>
[HttpPatch]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Product ), Status200OK )]
[ProducesResponseType( Status204NoContent )]
Expand Down Expand Up @@ -113,6 +116,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Product> delta )
/// <response code="204">The product was successfully updated.</response>
/// <response code="400">The product is invalid.</response>
/// <response code="404">The product does not exist.</response>
[HttpPut]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Product ), Status200OK )]
[ProducesResponseType( Status204NoContent )]
Expand All @@ -134,6 +138,7 @@ public IActionResult Put( int key, [FromBody] Product update )
/// <param name="key">The product to delete.</param>
/// <returns>None</returns>
/// <response code="204">The product was successfully deleted.</response>
[HttpDelete]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status404NotFound )]
public IActionResult Delete( int key ) => NoContent();
Expand All @@ -144,7 +149,7 @@ public IActionResult Put( int key, [FromBody] Product update )
/// <param name="key">The product identifier.</param>
/// <returns>The supplier</returns>
/// <returns>The requested supplier.</returns>
[HttpGet( "api/Products/{key}/Supplier" )]
[HttpGet]
[EnableQuery]
[Produces( "application/json" )]
[ProducesResponseType( typeof( Supplier ), Status200OK )]
Expand All @@ -158,6 +163,7 @@ public IActionResult Put( int key, [FromBody] Product update )
/// <param name="key">The product identifier.</param>
/// <param name="navigationProperty">The name of the related navigation property.</param>
/// <returns>The supplier link.</returns>
[HttpGet]
[Produces( "application/json" )]
[ProducesResponseType( typeof( ODataId ), Status200OK )]
[ProducesResponseType( Status404NotFound )]
Expand All @@ -181,6 +187,7 @@ public IActionResult GetRef( int key, string navigationProperty )
/// <param name="navigationProperty">The name of the related navigation property.</param>
/// <param name="link">The related entity identifier.</param>
/// <returns>None</returns>
[HttpPut]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status404NotFound )]
public IActionResult CreateRef(
Expand All @@ -195,6 +202,7 @@ public IActionResult GetRef( int key, string navigationProperty )
/// <param name="navigationProperty">The name of the related navigation property.</param>
/// <param name="relatedKey">The related entity identifier.</param>
/// <returns>None</returns>
[HttpDelete]
[ProducesResponseType( Status204NoContent )]
[ProducesResponseType( Status404NotFound )]
public IActionResult DeleteRef(
Expand Down

0 comments on commit be7db04

Please sign in to comment.