Skip to content

Commit be7db04

Browse files
Update example with verified endpoints
1 parent 318a702 commit be7db04

10 files changed

+65
-23
lines changed

examples/AspNetCore/OData/ODataOpenApiExample/Program.cs

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
options.Count().Select().OrderBy();
2020
options.RouteOptions.EnableKeyInParenthesis = false;
2121
options.RouteOptions.EnableNonParenthesisForEmptyParameterFunction = true;
22+
options.RouteOptions.EnablePropertyNameCaseInsensitive = true;
2223
options.RouteOptions.EnableQualifiedOperationCall = false;
2324
options.RouteOptions.EnableUnqualifiedOperationCall = true;
2425
} );
@@ -80,6 +81,12 @@
8081

8182
// Configure the HTTP request pipeline.
8283

84+
if ( app.Environment.IsDevelopment() )
85+
{
86+
// navigate to ~/$odata to determine whether any endpoints did not match an odata route template
87+
app.UseODataRouteDebug();
88+
}
89+
8390
app.UseSwagger();
8491
app.UseSwaggerUI(
8592
options =>

examples/AspNetCore/OData/ODataOpenApiExample/V1/OrdersController.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Asp.Versioning;
55
using Asp.Versioning.OData;
66
using Microsoft.AspNetCore.Mvc;
7-
using Microsoft.AspNetCore.OData.Formatter;
87
using Microsoft.AspNetCore.OData.Query;
98
using Microsoft.AspNetCore.OData.Results;
109
using Microsoft.AspNetCore.OData.Routing.Controllers;
@@ -25,6 +24,7 @@ public class OrdersController : ODataController
2524
/// <returns>The requested order.</returns>
2625
/// <response code="200">The order was successfully retrieved.</response>
2726
/// <response code="404">The order does not exist.</response>
27+
[HttpGet]
2828
[Produces( "application/json" )]
2929
[ProducesResponseType( typeof( Order ), Status200OK )]
3030
[ProducesResponseType( Status404NotFound )]
@@ -39,6 +39,7 @@ public SingleResult<Order> Get( int key ) =>
3939
/// <returns>The created order.</returns>
4040
/// <response code="201">The order was successfully placed.</response>
4141
/// <response code="400">The order is invalid.</response>
42+
[HttpPost]
4243
[MapToApiVersion( 1.0 )]
4344
[Produces( "application/json" )]
4445
[ProducesResponseType( typeof( Order ), Status201Created )]
@@ -93,7 +94,7 @@ public SingleResult<Order> MostExpensive( int key ) =>
9394
/// <returns>The order line items.</returns>
9495
/// <response code="200">The line items were successfully retrieved.</response>
9596
/// <response code="404">The order does not exist.</response>
96-
[HttpGet( "api/Orders/{key}/LineItems" )]
97+
[HttpGet]
9798
[Produces( "application/json" )]
9899
[ProducesResponseType( typeof( ODataValue<IEnumerable<LineItem>> ), Status200OK )]
99100
[ProducesResponseType( Status404NotFound )]

examples/AspNetCore/OData/ODataOpenApiExample/V1/PeopleController.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class PeopleController : ODataController
2424
/// <returns>The requested person.</returns>
2525
/// <response code="200">The person was successfully retrieved.</response>
2626
/// <response code="404">The person does not exist.</response>
27+
[HttpGet]
2728
[Produces( "application/json" )]
2829
[ProducesResponseType( typeof( Person ), Status200OK )]
2930
[ProducesResponseType( Status404NotFound )]
@@ -62,16 +63,16 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
6263
[ProducesResponseType( Status404NotFound )]
6364
[EnableQuery( AllowedQueryOptions = Select )]
6465
public SingleResult<Person> MostExpensive( ODataQueryOptions<Person> options, CancellationToken ct ) =>
65-
SingleResult.Create(
66-
new Person[]
67-
{
66+
SingleResult.Create(
67+
new Person[]
68+
{
6869
new()
6970
{
70-
Id = 42,
71-
FirstName = "Elon",
71+
Id = 42,
72+
FirstName = "Elon",
7273
LastName = "Musk",
7374
},
74-
}.AsQueryable() );
75+
}.AsQueryable() );
7576

7677
/// <summary>
7778
/// Gets the most expensive person.
@@ -91,11 +92,11 @@ public SingleResult<Person> MostExpensive(
9192
CancellationToken ct ) =>
9293
SingleResult.Create(
9394
new Person[]
94-
{
95+
{
9596
new()
96-
{
97-
Id = key,
98-
FirstName = "John",
97+
{
98+
Id = key,
99+
FirstName = "John",
99100
LastName = "Doe",
100101
},
101102
}.AsQueryable() );

examples/AspNetCore/OData/ODataOpenApiExample/V2/OrdersController.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class OrdersController : ODataController
2323
/// </summary>
2424
/// <returns>All available orders.</returns>
2525
/// <response code="200">The successfully retrieved orders.</response>
26+
[HttpGet]
2627
[Produces( "application/json" )]
2728
[ProducesResponseType( typeof( ODataValue<IEnumerable<Order>> ), Status200OK )]
2829
[EnableQuery( MaxTop = 100, AllowedQueryOptions = Select | Top | Skip | Count )]
@@ -45,7 +46,7 @@ public IQueryable<Order> Get()
4546
/// <returns>The requested order.</returns>
4647
/// <response code="200">The order was successfully retrieved.</response>
4748
/// <response code="404">The order does not exist.</response>
48-
[HttpGet( "api/Orders/{key}" )]
49+
[HttpGet]
4950
[Produces( "application/json" )]
5051
[ProducesResponseType( typeof( Order ), Status200OK )]
5152
[ProducesResponseType( Status404NotFound )]
@@ -60,6 +61,7 @@ public SingleResult<Order> Get( int key ) =>
6061
/// <returns>The created order.</returns>
6162
/// <response code="201">The order was successfully placed.</response>
6263
/// <response code="400">The order is invalid.</response>
64+
[HttpPost]
6365
[Produces( "application/json" )]
6466
[ProducesResponseType( typeof( Order ), Status201Created )]
6567
[ProducesResponseType( Status400BadRequest )]
@@ -84,6 +86,7 @@ public IActionResult Post( [FromBody] Order order )
8486
/// <response code="204">The order was successfully updated.</response>
8587
/// <response code="400">The order is invalid.</response>
8688
/// <response code="404">The order does not exist.</response>
89+
[HttpPatch]
8790
[Produces( "application/json" )]
8891
[ProducesResponseType( typeof( Order ), Status200OK )]
8992
[ProducesResponseType( Status204NoContent )]
@@ -148,7 +151,7 @@ public IActionResult Rate( int key, [FromBody] ODataActionParameters parameters
148151
/// <returns>The order line items.</returns>
149152
/// <response code="200">The line items were successfully retrieved.</response>
150153
/// <response code="404">The order does not exist.</response>
151-
[HttpGet( "api/Orders/{key}/LineItems" )]
154+
[HttpGet]
152155
[Produces( "application/json" )]
153156
[ProducesResponseType( typeof( ODataValue<IEnumerable<LineItem>> ), Status200OK )]
154157
[ProducesResponseType( Status404NotFound )]

examples/AspNetCore/OData/ODataOpenApiExample/V2/PeopleController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class PeopleController : ODataController
2323
/// <param name="options">The current OData query options.</param>
2424
/// <returns>All available people.</returns>
2525
/// <response code="200">The successfully retrieved people.</response>
26+
[HttpGet]
2627
[Produces( "application/json" )]
2728
[ProducesResponseType( typeof( ODataValue<IEnumerable<Person>> ), Status200OK )]
2829
public IActionResult Get( ODataQueryOptions<Person> options )
@@ -83,6 +84,7 @@ public IActionResult Get( ODataQueryOptions<Person> options )
8384
/// <returns>The requested person.</returns>
8485
/// <response code="200">The person was successfully retrieved.</response>
8586
/// <response code="404">The person does not exist.</response>
87+
[HttpGet]
8688
[Produces( "application/json" )]
8789
[ProducesResponseType( typeof( Person ), Status200OK )]
8890
[ProducesResponseType( Status404NotFound )]
@@ -128,7 +130,7 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
128130
/// <returns>The person's home address.</returns>
129131
/// <response code="200">The home address was successfully retrieved.</response>
130132
/// <response code="404">The person does not exist.</response>
131-
[HttpGet( "api/People/{key}/HomeAddress" )]
133+
[HttpGet]
132134
[Produces( "application/json" )]
133135
[ProducesResponseType( typeof( Address ), Status200OK )]
134136
[ProducesResponseType( Status404NotFound )]

examples/AspNetCore/OData/ODataOpenApiExample/V3/AcmeController.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class AcmeController : ODataController
1919
/// </summary>
2020
/// <returns>All available suppliers.</returns>
2121
/// <response code="200">The supplier successfully retrieved.</response>
22+
[HttpGet]
2223
[EnableQuery]
2324
[Produces( "application/json" )]
2425
[ProducesResponseType( typeof( ODataValue<Supplier> ), Status200OK )]
@@ -28,7 +29,7 @@ public class AcmeController : ODataController
2829
/// Gets the products associated with the supplier.
2930
/// </summary>
3031
/// <returns>The associated supplier products.</returns>
31-
[HttpGet( "api/Acme/Products" )]
32+
[HttpGet]
3233
[EnableQuery]
3334
public IQueryable<Product> GetProducts() => NewSupplier().Products.AsQueryable();
3435

@@ -38,6 +39,7 @@ public class AcmeController : ODataController
3839
/// <param name="navigationProperty">The name of the related navigation property.</param>
3940
/// <param name="link">The related entity identifier.</param>
4041
/// <returns>None</returns>
42+
[HttpPut]
4143
[ProducesResponseType( Status204NoContent )]
4244
[ProducesResponseType( Status404NotFound )]
4345
public IActionResult CreateRef(
@@ -50,6 +52,7 @@ public IActionResult CreateRef(
5052
/// <param name="relatedKey">The related entity identifier.</param>
5153
/// <param name="navigationProperty">The name of the related navigation property.</param>
5254
/// <returns>None</returns>
55+
[HttpDelete]
5356
[ProducesResponseType( Status204NoContent )]
5457
[ProducesResponseType( Status404NotFound )]
5558
public IActionResult DeleteRef(

examples/AspNetCore/OData/ODataOpenApiExample/V3/OrdersController.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class OrdersController : ODataController
2424
/// <returns>All available orders.</returns>
2525
/// <response code="200">Orders successfully retrieved.</response>
2626
/// <response code="400">The order is invalid.</response>
27+
[HttpGet]
2728
[Produces( "application/json" )]
2829
[ProducesResponseType( typeof( ODataValue<IEnumerable<Order>> ), Status200OK )]
2930
[EnableQuery( MaxTop = 100, AllowedQueryOptions = Select | Top | Skip | Count )]
@@ -46,6 +47,7 @@ public IQueryable<Order> Get()
4647
/// <returns>The requested order.</returns>
4748
/// <response code="200">The order was successfully retrieved.</response>
4849
/// <response code="404">The order does not exist.</response>
50+
[HttpGet]
4951
[Produces( "application/json" )]
5052
[ProducesResponseType( typeof( Order ), Status200OK )]
5153
[ProducesResponseType( Status404NotFound )]
@@ -60,6 +62,7 @@ public SingleResult<Order> Get( int key ) =>
6062
/// <returns>The created order.</returns>
6163
/// <response code="201">The order was successfully placed.</response>
6264
/// <response code="400">The order is invalid.</response>
65+
[HttpPost]
6366
[ProducesResponseType( typeof( Order ), Status201Created )]
6467
[ProducesResponseType( Status400BadRequest )]
6568
public IActionResult Post( [FromBody] Order order )
@@ -83,6 +86,7 @@ public IActionResult Post( [FromBody] Order order )
8386
/// <response code="204">The order was successfully updated.</response>
8487
/// <response code="400">The order is invalid.</response>
8588
/// <response code="404">The order does not exist.</response>
89+
[HttpPatch]
8690
[Produces( "application/json" )]
8791
[ProducesResponseType( typeof( Order ), Status200OK )]
8892
[ProducesResponseType( Status204NoContent )]
@@ -110,6 +114,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Order> delta )
110114
/// <returns>None</returns>
111115
/// <response code="204">The order was successfully canceled.</response>
112116
/// <response code="404">The order does not exist.</response>
117+
[HttpDelete]
113118
[ProducesResponseType( Status204NoContent )]
114119
[ProducesResponseType( Status404NotFound )]
115120
public IActionResult Delete( int key, bool suspendOnly ) => NoContent();
@@ -120,6 +125,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Order> delta )
120125
/// <returns>The most expensive order.</returns>
121126
/// <response code="200">The order was successfully retrieved.</response>
122127
/// <response code="404">The no orders exist.</response>
128+
[HttpGet]
123129
[Produces( "application/json" )]
124130
[ProducesResponseType( typeof( Order ), Status200OK )]
125131
[ProducesResponseType( Status404NotFound )]
@@ -136,6 +142,7 @@ public SingleResult<Order> MostExpensive() =>
136142
/// <response code="204">The order was successfully rated.</response>
137143
/// <response code="400">The parameters are invalid.</response>
138144
/// <response code="404">The order does not exist.</response>
145+
[HttpPost]
139146
[ProducesResponseType( Status204NoContent )]
140147
[ProducesResponseType( Status400BadRequest )]
141148
[ProducesResponseType( Status404NotFound )]
@@ -157,7 +164,7 @@ public IActionResult Rate( int key, [FromBody] ODataActionParameters parameters
157164
/// <returns>The order line items.</returns>
158165
/// <response code="200">The line items were successfully retrieved.</response>
159166
/// <response code="404">The order does not exist.</response>
160-
[HttpGet( "api/Orders/{key}/LineItems" )]
167+
[HttpGet]
161168
[Produces( "application/json" )]
162169
[ProducesResponseType( typeof( ODataValue<IEnumerable<LineItem>> ), Status200OK )]
163170
[ProducesResponseType( Status404NotFound )]

examples/AspNetCore/OData/ODataOpenApiExample/V3/PeopleController.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class PeopleController : ODataController
2424
/// <param name="options">The current OData query options.</param>
2525
/// <returns>All available people.</returns>
2626
/// <response code="200">The successfully retrieved people.</response>
27+
[HttpGet]
2728
[Produces( "application/json" )]
2829
[ProducesResponseType( typeof( ODataValue<IEnumerable<Person>> ), Status200OK )]
2930
public IActionResult Get( ODataQueryOptions<Person> options )
@@ -87,6 +88,7 @@ public IActionResult Get( ODataQueryOptions<Person> options )
8788
/// <returns>The requested person.</returns>
8889
/// <response code="200">The person was successfully retrieved.</response>
8990
/// <response code="404">The person does not exist.</response>
91+
[HttpGet]
9092
[Produces( "application/json" )]
9193
[ProducesResponseType( typeof( Person ), Status200OK )]
9294
[ProducesResponseType( Status404NotFound )]
@@ -121,6 +123,7 @@ public IActionResult Get( int key, ODataQueryOptions<Person> options )
121123
/// <returns>The created person.</returns>
122124
/// <response code="201">The person was successfully created.</response>
123125
/// <response code="400">The person was invalid.</response>
126+
[HttpPost]
124127
[Produces( "application/json" )]
125128
[ProducesResponseType( typeof( Person ), Status201Created )]
126129
[ProducesResponseType( Status400BadRequest )]
@@ -179,7 +182,7 @@ public IActionResult Promote( int key, [FromBody] ODataActionParameters paramete
179182
/// <returns>The person's home address.</returns>
180183
/// <response code="200">The home address was successfully retrieved.</response>
181184
/// <response code="404">The person does not exist.</response>
182-
[HttpGet( "api/People/{key}/HomeAddress" )]
185+
[HttpGet]
183186
[Produces( "application/json" )]
184187
[ProducesResponseType( typeof( Address ), Status200OK )]
185188
[ProducesResponseType( Status404NotFound )]
@@ -200,7 +203,7 @@ public IActionResult GetHomeAddress( int key ) =>
200203
/// <returns>The person's work address.</returns>
201204
/// <response code="200">The work address was successfully retrieved.</response>
202205
/// <response code="404">The person does not exist.</response>
203-
[HttpGet( "api/People/{key}/WorkAddress" )]
206+
[HttpGet]
204207
[Produces( "application/json" )]
205208
[ProducesResponseType( typeof( Address ), Status200OK )]
206209
[ProducesResponseType( Status404NotFound )]

examples/AspNetCore/OData/ODataOpenApiExample/V3/ProductsController.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.AspNetCore.Mvc;
77
using Microsoft.AspNetCore.OData.Deltas;
88
using Microsoft.AspNetCore.OData.Extensions;
9-
using Microsoft.AspNetCore.OData.Formatter;
109
using Microsoft.AspNetCore.OData.Query;
1110
using Microsoft.AspNetCore.OData.Results;
1211
using Microsoft.AspNetCore.OData.Routing.Controllers;
@@ -31,6 +30,7 @@ public class ProductsController : ODataController
3130
/// </summary>
3231
/// <returns>All available products.</returns>
3332
/// <response code="200">Products successfully retrieved.</response>
33+
[HttpGet]
3434
[EnableQuery]
3535
[Produces( "application/json" )]
3636
[ProducesResponseType( typeof( ODataValue<IEnumerable<Product>> ), Status200OK )]
@@ -43,6 +43,7 @@ public class ProductsController : ODataController
4343
/// <returns>The requested product.</returns>
4444
/// <response code="200">The product was successfully retrieved.</response>
4545
/// <response code="404">The product does not exist.</response>
46+
[HttpGet]
4647
[EnableQuery]
4748
[Produces( "application/json" )]
4849
[ProducesResponseType( typeof( Product ), Status200OK )]
@@ -58,6 +59,7 @@ public SingleResult<Product> Get( int key ) =>
5859
/// <response code="201">The product was successfully created.</response>
5960
/// <response code="204">The product was successfully created.</response>
6061
/// <response code="400">The product is invalid.</response>
62+
[HttpPost]
6163
[Produces( "application/json" )]
6264
[ProducesResponseType( typeof( Product ), Status201Created )]
6365
[ProducesResponseType( Status204NoContent )]
@@ -84,6 +86,7 @@ public IActionResult Post( [FromBody] Product product )
8486
/// <response code="204">The product was successfully updated.</response>
8587
/// <response code="400">The product is invalid.</response>
8688
/// <response code="404">The product does not exist.</response>
89+
[HttpPatch]
8790
[Produces( "application/json" )]
8891
[ProducesResponseType( typeof( Product ), Status200OK )]
8992
[ProducesResponseType( Status204NoContent )]
@@ -113,6 +116,7 @@ public IActionResult Patch( int key, [FromBody] Delta<Product> delta )
113116
/// <response code="204">The product was successfully updated.</response>
114117
/// <response code="400">The product is invalid.</response>
115118
/// <response code="404">The product does not exist.</response>
119+
[HttpPut]
116120
[Produces( "application/json" )]
117121
[ProducesResponseType( typeof( Product ), Status200OK )]
118122
[ProducesResponseType( Status204NoContent )]
@@ -134,6 +138,7 @@ public IActionResult Put( int key, [FromBody] Product update )
134138
/// <param name="key">The product to delete.</param>
135139
/// <returns>None</returns>
136140
/// <response code="204">The product was successfully deleted.</response>
141+
[HttpDelete]
137142
[ProducesResponseType( Status204NoContent )]
138143
[ProducesResponseType( Status404NotFound )]
139144
public IActionResult Delete( int key ) => NoContent();
@@ -144,7 +149,7 @@ public IActionResult Put( int key, [FromBody] Product update )
144149
/// <param name="key">The product identifier.</param>
145150
/// <returns>The supplier</returns>
146151
/// <returns>The requested supplier.</returns>
147-
[HttpGet( "api/Products/{key}/Supplier" )]
152+
[HttpGet]
148153
[EnableQuery]
149154
[Produces( "application/json" )]
150155
[ProducesResponseType( typeof( Supplier ), Status200OK )]
@@ -158,6 +163,7 @@ public SingleResult<Supplier> GetSupplier( int key ) =>
158163
/// <param name="key">The product identifier.</param>
159164
/// <param name="navigationProperty">The name of the related navigation property.</param>
160165
/// <returns>The supplier link.</returns>
166+
[HttpGet]
161167
[Produces( "application/json" )]
162168
[ProducesResponseType( typeof( ODataId ), Status200OK )]
163169
[ProducesResponseType( Status404NotFound )]
@@ -181,6 +187,7 @@ public IActionResult GetRef( int key, string navigationProperty )
181187
/// <param name="navigationProperty">The name of the related navigation property.</param>
182188
/// <param name="link">The related entity identifier.</param>
183189
/// <returns>None</returns>
190+
[HttpPut]
184191
[ProducesResponseType( Status204NoContent )]
185192
[ProducesResponseType( Status404NotFound )]
186193
public IActionResult CreateRef(
@@ -195,6 +202,7 @@ public IActionResult CreateRef(
195202
/// <param name="navigationProperty">The name of the related navigation property.</param>
196203
/// <param name="relatedKey">The related entity identifier.</param>
197204
/// <returns>None</returns>
205+
[HttpDelete]
198206
[ProducesResponseType( Status204NoContent )]
199207
[ProducesResponseType( Status404NotFound )]
200208
public IActionResult DeleteRef(

0 commit comments

Comments
 (0)