Skip to content

Preview 3: Iteration 1 #816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/cla.yml

This file was deleted.

15 changes: 14 additions & 1 deletion asp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "misc", "misc", "{65E93433-2
.gitattributes = .gitattributes
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
CONTRIBUTING.md = CONTRIBUTING.md
LICENSE.txt = LICENSE.txt
logo.svg = logo.svg
nuget.config = nuget.config
Expand Down Expand Up @@ -187,6 +186,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Common.OData.ApiExplorer.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalOpenApiExample", "examples\AspNetCore\WebApi\MinimalOpenApiExample\MinimalOpenApiExample.csproj", "{124C18D1-F72A-4380-AE40-E7511AC16C62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SomeODataOpenApiExample", "examples\AspNetCore\OData\SomeODataOpenApiExample\SomeODataOpenApiExample.csproj", "{94A9AF81-A7BE-4E6C-81B1-8BFF4B6E1B78}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SomeOpenApiODataWebApiExample", "examples\AspNet\OData\SomeOpenApiODataWebApiExample\SomeOpenApiODataWebApiExample.csproj", "{AC952FBF-D7DC-4DE4-AD1C-4CEA589034F5}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Common\test\Common.Acceptance.Tests\Common.Acceptance.Tests.projitems*{0be9efaa-3627-46fe-9861-9121ee8f0e26}*SharedItemsImports = 5
Expand Down Expand Up @@ -406,6 +409,14 @@ Global
{124C18D1-F72A-4380-AE40-E7511AC16C62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{124C18D1-F72A-4380-AE40-E7511AC16C62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{124C18D1-F72A-4380-AE40-E7511AC16C62}.Release|Any CPU.Build.0 = Release|Any CPU
{94A9AF81-A7BE-4E6C-81B1-8BFF4B6E1B78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94A9AF81-A7BE-4E6C-81B1-8BFF4B6E1B78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94A9AF81-A7BE-4E6C-81B1-8BFF4B6E1B78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94A9AF81-A7BE-4E6C-81B1-8BFF4B6E1B78}.Release|Any CPU.Build.0 = Release|Any CPU
{AC952FBF-D7DC-4DE4-AD1C-4CEA589034F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC952FBF-D7DC-4DE4-AD1C-4CEA589034F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC952FBF-D7DC-4DE4-AD1C-4CEA589034F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC952FBF-D7DC-4DE4-AD1C-4CEA589034F5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -488,6 +499,8 @@ Global
{B39C3FE5-227F-4403-B246-1277906ACF7D} = {49EA6476-901C-4D4F-8E45-98BC8A2780EB}
{496A5B79-AFD2-45AC-AF9A-1CD28A7E1CDB} = {031927C1-BF12-42A9-A91D-6907E8C7F1C7}
{124C18D1-F72A-4380-AE40-E7511AC16C62} = {E0E64F6F-FB0C-4534-B815-2217700B50BA}
{94A9AF81-A7BE-4E6C-81B1-8BFF4B6E1B78} = {49EA6476-901C-4D4F-8E45-98BC8A2780EB}
{AC952FBF-D7DC-4DE4-AD1C-4CEA589034F5} = {7BB01633-6E2C-4837-B618-C7F09B18E99E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {91FE116A-CEFB-4304-A8A6-CFF021C7453A}
Expand Down
6 changes: 6 additions & 0 deletions build/steps-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ parameters:
default: Release

steps:
- task: UseDotNet@2
displayName: Install .NET 3.1
inputs:
packageType: sdk
version: 3.1.x

- task: UseDotNet@2
displayName: Install .NET SDK
inputs:
Expand Down
4 changes: 0 additions & 4 deletions build/test.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

<ItemGroup Condition=" '$(IsAspNetCore)' == 'true' ">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.2-*" />
</ItemGroup>

<ItemGroup>
<Using Include="Moq" />
<Using Include="Xunit" />
Expand Down
10 changes: 8 additions & 2 deletions build/test.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<FluentAssertionsVersion>6.5.1</FluentAssertionsVersion>
<FluentAssertionsVersion Condition=" '$(TargetFramework)' != 'net6.0' ">5.10.3</FluentAssertionsVersion>
<FluentAssertionsVersion>6.6.0</FluentAssertionsVersion>
<FluentAssertionsVersion Condition=" '$(TargetFramework)' == 'net452' ">5.10.3</FluentAssertionsVersion>
<TestHostVersion>6.0.4-*</TestHostVersion>
<TestHostVersion Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">3.1.24</TestHostVersion>
</PropertyGroup>

<ItemGroup Condition=" '$(IsSharedProject)' == 'false' ">
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
</ItemGroup>

<ItemGroup Condition=" '$(IsAspNetCore)' == 'true' ">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(TestHostVersion)" />
</ItemGroup>

<ItemGroup>
<Using Include="FluentAssertions" />
</ItemGroup>
Expand Down
39 changes: 0 additions & 39 deletions docs/CLA.md

This file was deleted.

3 changes: 2 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ If you would like to contribute to the repository, first identify the scale of w

### Submitting a pull request

You will need to sign a [Contributor License Agreement](CLA.md) when submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to follow the instructions provided by the CLA bot when you send the pull request. This needs to only be done once for any .NET Foundation OSS project.
You will need to sign a [Contributor License Agreement](https://cla.dotnetfoundation.org/dotnet/aspnet-api-versioning) when submitting your pull request. To complete the Contributor License Agreement (CLA), you
will need to follow the instructions provided by the CLA bot when you send the pull request. This needs to only be done once for any .NET Foundation OSS project.

If you don't know what a pull request is read this article: https://help.github.com/articles/using-pull-requests. Make sure that the repository can build and that all tests pass. Familiarize yourself with the project workflow and our coding conventions. The coding and style guidelines are described and enforced by `.editorconfig` as well as .NET Compiler Platform analyzers. These tools will automatically override your default settings without changing your environment. Violations will cause the build to fail.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Configuration( IAppBuilder appBuilder )
// in the underlying routing system. the order of route registration is important as well.
//
// DO NOT use configuration.MapHttpAttributeRoutes();
configuration.MapVersionedODataRoute( "odata", "api", modelBuilder.GetEdmModels() );
configuration.MapVersionedODataRoute( "odata", "api", modelBuilder );
configuration.Routes.MapHttpRoute( "orders", "api/{controller}/{id}", new { id = Optional } );

configuration.Formatters.Remove( configuration.Formatters.XmlFormatter );
Expand Down
3 changes: 1 addition & 2 deletions examples/AspNet/OData/OpenApiODataWebApiExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void Configuration( IAppBuilder builder )
new SupplierConfiguration(),
},
};
var models = modelBuilder.GetEdmModels();

// global odata query options
configuration.Count();
Expand All @@ -71,7 +70,7 @@ public void Configuration( IAppBuilder builder )
// INFO: only pass the route prefix to GetEdmModels if you want to split the models; otherwise, both routes contain all models

// WHEN VERSIONING BY: query string, header, or media type
configuration.MapVersionedODataRoute( "odata", "api", models );
configuration.MapVersionedODataRoute( "odata", "api", modelBuilder );

// WHEN VERSIONING BY: url segment
// configuration.MapVersionedODataRoute( "odata-bypath", "api/v{apiVersion}", models );
Expand Down
31 changes: 31 additions & 0 deletions examples/AspNet/OData/SomeOpenApiODataWebApiExample/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace ApiVersioning.Examples;

/// <summary>
/// Represents a book.
/// </summary>
public class Book
{
/// <summary>
/// Gets or sets the book identifier.
/// </summary>
/// <value>The International Standard Book Number (ISBN).</value>
public string Id { get; set; }

/// <summary>
/// Gets or sets the book author.
/// </summary>
/// <value>The author of the book.</value>
public string Author { get; set; }

/// <summary>
/// Gets or sets the book title.
/// </summary>
/// <value>The title of the book.</value>
public string Title { get; set; }

/// <summary>
/// Gets or sets the book publication year.
/// </summary>
/// <value>The year the book was first published.</value>
public int Published { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace ApiVersioning.Examples;

using Asp.Versioning;
using Microsoft.AspNet.OData.Query;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Description;

/// <summary>
/// Represents a RESTful service of books.
/// </summary>
[ApiVersion( 1.0 )]
[RoutePrefix( "api/books" )]
public class BooksController : ApiController
{
private static readonly Book[] books = new Book[]
{
new() { Id = "9781847490599", Title = "Anna Karenina", Author = "Leo Tolstoy", Published = 1878 },
new() { Id = "9780198800545", Title = "War and Peace", Author = "Leo Tolstoy", Published = 1869 },
new() { Id = "9780684801520", Title = "The Great Gatsby", Author = "F. Scott Fitzgerald", Published = 1925 },
new() { Id = "9780486280615", Title = "The Adventures of Huckleberry Finn", Author = "Mark Twain", Published = 1884 },
new() { Id = "9780140430820", Title = "Moby Dick", Author = "Herman Melville", Published = 1851 },
new() { Id = "9780060934347", Title = "Don Quixote", Author = "Miguel de Cervantes", Published = 1605 },
};

/// <summary>
/// Gets all books.
/// </summary>
/// <param name="options">The current OData query options.</param>
/// <returns>All available books.</returns>
/// <response code="200">The successfully retrieved books.</response>
[HttpGet]
[Route]
[ResponseType( typeof( IEnumerable<Book> ) )]
public IHttpActionResult Get( ODataQueryOptions<Book> options ) =>
Ok( options.ApplyTo( books.AsQueryable() ) );

/// <summary>
/// Gets a single book.
/// </summary>
/// <param name="id">The requested book identifier.</param>
/// <param name="options">The current OData query options.</param>
/// <returns>The requested book.</returns>
/// <response code="200">The book was successfully retrieved.</response>
/// <response code="404">The book does not exist.</response>
[HttpGet]
[Route( "{id}" )]
[ResponseType( typeof( Book ) )]
public IHttpActionResult Get( string id, ODataQueryOptions<Book> options )
{
var book = books.FirstOrDefault( book => book.Id == id );

if ( book == null )
{
return NotFound();
}

return Ok( options.ApplyTo( book, new ODataQuerySettings(), default ) );
}
}
41 changes: 41 additions & 0 deletions examples/AspNet/OData/SomeOpenApiODataWebApiExample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace ApiVersioning.Examples;

using Microsoft.Owin.Hosting;
using System.Diagnostics;

/// <summary>
/// Represents the current application.
/// </summary>
public class Program
{
private const string Url = "http://localhost:9008/";
private const string LaunchUrl = Url + "swagger";
private static readonly ManualResetEvent resetEvent = new( false );

/// <summary>
/// The main entry point to the application.
/// </summary>
/// <param name="args">The arguments provided at start-up, if any.</param>
public static void Main( string[] args )
{
Console.CancelKeyPress += OnCancel;

using ( WebApp.Start<Startup>( Url ) )
{
Console.WriteLine( "Content root path: " + Startup.ContentRootPath );
Console.WriteLine( "Now listening on: " + Url );
Console.WriteLine( "Application started. Press Ctrl+C to shut down." );
Process.Start( LaunchUrl );
resetEvent.WaitOne();
}

Console.CancelKeyPress -= OnCancel;
}

private static void OnCancel( object sender, ConsoleCancelEventArgs e )
{
Console.Write( "Application is shutting down..." );
e.Cancel = true;
resetEvent.Set();
}
}
Loading