Skip to content

Update sample app that applies v1.5.0 #528

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 1 commit into from
Dec 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
<!--<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.0" />
</ItemGroup>-->
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
<!--<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.0" />
</ItemGroup>-->
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using AutoFixture;

using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Configurations;
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions;
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfProc.SecurityFlows;
using Microsoft.Azure.Functions.Worker.Http;
Expand All @@ -21,11 +22,13 @@ namespace Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfP
public class PetHttpTrigger
{
private readonly ILogger _logger;
private readonly OpenApiSettings _openapi;
private readonly Fixture _fixture;

public PetHttpTrigger(ILoggerFactory loggerFactory, Fixture fixture)
public PetHttpTrigger(ILoggerFactory loggerFactory, OpenApiSettings openapi, Fixture fixture)
{
this._logger = loggerFactory.ThrowIfNullOrDefault().CreateLogger<PetHttpTrigger>();
this._openapi = openapi.ThrowIfNullOrDefault();
this._fixture = fixture.ThrowIfNullOrDefault();
}

Expand All @@ -40,6 +43,8 @@ public PetHttpTrigger(ILoggerFactory loggerFactory, Fixture fixture)
public async Task<HttpResponseData> UpdatePet(
[HttpTrigger(AuthorizationLevel.Anonymous, "PUT", Route = "pet")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<Pet>()).ConfigureAwait(false);
Expand All @@ -56,6 +61,8 @@ public async Task<HttpResponseData> UpdatePet(
public async Task<HttpResponseData> AddPet(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "pet")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<Pet>()).ConfigureAwait(false);
Expand All @@ -72,6 +79,8 @@ public async Task<HttpResponseData> AddPet(
public async Task<HttpResponseData> FindByStatus(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "pet/findByStatus")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var status = req.Query("status")
Expand All @@ -97,6 +106,8 @@ public async Task<HttpResponseData> FindByStatus(
public async Task<HttpResponseData> FindByTags(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "pet/findByTags")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var tags = req.Query("tags")
Expand Down Expand Up @@ -128,6 +139,8 @@ public async Task<HttpResponseData> FindByTags(
public async Task<HttpResponseData> GetPetById(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "pet/{petId}")] HttpRequestData req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var pet = this._fixture.Build<Pet>().With(p => p.Id, petId).Create();
Expand All @@ -147,6 +160,8 @@ public async Task<HttpResponseData> GetPetById(
public async Task<HttpResponseData> UpdatePetWithForm(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "pet/{petId}")] HttpRequestData req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var pet = this._fixture.Build<Pet>().With(p => p.Id, petId).Create();
Expand All @@ -167,6 +182,8 @@ public async Task<HttpResponseData> UpdatePetWithForm(
public async Task<HttpResponseData> DeletePet(
[HttpTrigger(AuthorizationLevel.Anonymous, "DELETE", Route = "pet/{petId}")] HttpRequestData req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

return await Task.FromResult(response).ConfigureAwait(false);
Expand All @@ -181,6 +198,8 @@ public async Task<HttpResponseData> DeletePet(
public async Task<HttpResponseData> UploadFile(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "pet/{petId}/uploadImage")] HttpRequestData req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<ApiResponse>()).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using AutoFixture;

using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Configurations;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
Expand All @@ -17,11 +18,13 @@ namespace Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfP
public class StoreHttpTrigger
{
private readonly ILogger _logger;
private readonly OpenApiSettings _openapi;
private readonly Fixture _fixture;

public StoreHttpTrigger(ILoggerFactory loggerFactory, Fixture fixture)
public StoreHttpTrigger(ILoggerFactory loggerFactory, OpenApiSettings openapi, Fixture fixture)
{
this._logger = loggerFactory.ThrowIfNullOrDefault().CreateLogger<PetHttpTrigger>();
this._openapi = openapi.ThrowIfNullOrDefault();
this._fixture = fixture.ThrowIfNullOrDefault();
}

Expand All @@ -32,6 +35,8 @@ public StoreHttpTrigger(ILoggerFactory loggerFactory, Fixture fixture)
public async Task<HttpResponseData> GetInventory(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "store/inventory")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var result = this._fixture.Create<Dictionary<string, int>>();
Expand All @@ -49,6 +54,8 @@ public async Task<HttpResponseData> GetInventory(
public async Task<HttpResponseData> PlaceOrder(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "store/order")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<Order>()).ConfigureAwait(false);
Expand All @@ -65,6 +72,8 @@ public async Task<HttpResponseData> PlaceOrder(
public async Task<HttpResponseData> GetOrderById(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "store/order/{orderId}")] HttpRequestData req, long orderId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var order = this._fixture.Build<Order>().With(p => p.Id, orderId).Create();
Expand All @@ -82,6 +91,8 @@ public async Task<HttpResponseData> GetOrderById(
public async Task<HttpResponseData> DeleteOrder(
[HttpTrigger(AuthorizationLevel.Anonymous, "DELETE", Route = "store/order/{orderId}")] HttpRequestData req, long orderId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

return await Task.FromResult(response).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using AutoFixture;

using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Configurations;
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfProc.Headers;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
Expand All @@ -19,11 +20,13 @@ namespace Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfP
public class UserHttpTrigger
{
private readonly ILogger _logger;
private readonly OpenApiSettings _openapi;
private readonly Fixture _fixture;

public UserHttpTrigger(ILoggerFactory loggerFactory, Fixture fixture)
public UserHttpTrigger(ILoggerFactory loggerFactory, OpenApiSettings openapi, Fixture fixture)
{
this._logger = loggerFactory.ThrowIfNullOrDefault().CreateLogger<PetHttpTrigger>();
this._openapi = openapi.ThrowIfNullOrDefault();
this._fixture = fixture.ThrowIfNullOrDefault();
}

Expand All @@ -34,6 +37,8 @@ public UserHttpTrigger(ILoggerFactory loggerFactory, Fixture fixture)
public async Task<HttpResponseData> CreateUser(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "user")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<User>()).ConfigureAwait(false);
Expand All @@ -48,6 +53,8 @@ public async Task<HttpResponseData> CreateUser(
public async Task<HttpResponseData> CreateUsersWithArrayInput(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "user/createWithArray")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<List<User>>()).ConfigureAwait(false);
Expand All @@ -62,6 +69,8 @@ public async Task<HttpResponseData> CreateUsersWithArrayInput(
public async Task<HttpResponseData> CreateUsersWithListInput(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "user/createWithList")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

await response.WriteAsJsonAsync(this._fixture.Create<List<User>>()).ConfigureAwait(false);
Expand All @@ -77,6 +86,8 @@ public async Task<HttpResponseData> CreateUsersWithListInput(
public async Task<HttpResponseData> LoginUser(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "user/login")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.Headers.Add("X-Rate-Limit", this._fixture.Create<int>().ToString());
Expand All @@ -93,6 +104,8 @@ public async Task<HttpResponseData> LoginUser(
public async Task<HttpResponseData> LogoutUser(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "user/logout")] HttpRequestData req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

return await Task.FromResult(response).ConfigureAwait(false);
Expand All @@ -107,6 +120,8 @@ public async Task<HttpResponseData> LogoutUser(
public async Task<HttpResponseData> GetUserByName(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "user/{username:regex((?!^login$)(^.+$))}")] HttpRequestData req, string username)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var response = req.CreateResponse(HttpStatusCode.OK);

var user = this._fixture.Build<User>().With(p => p.Username, username).Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
<!--<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.5.0" />
</ItemGroup>-->
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
Expand All @@ -22,11 +23,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.InProc
public class PetHttpTrigger
{
private readonly ILogger<PetHttpTrigger> _logger;
private readonly OpenApiSettings _openapi;
private readonly Fixture _fixture;

public PetHttpTrigger(ILogger<PetHttpTrigger> log, Fixture fixture)
public PetHttpTrigger(ILogger<PetHttpTrigger> log, OpenApiSettings openapi, Fixture fixture)
{
this._logger = log.ThrowIfNullOrDefault();
this._openapi = openapi.ThrowIfNullOrDefault();
this._fixture = fixture.ThrowIfNullOrDefault();
}

Expand All @@ -41,6 +44,8 @@ public PetHttpTrigger(ILogger<PetHttpTrigger> log, Fixture fixture)
public async Task<IActionResult> UpdatePet(
[HttpTrigger(AuthorizationLevel.Anonymous, "PUT", Route = "pet")] HttpRequest req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

return await Task.FromResult(new OkObjectResult(this._fixture.Create<Pet>())).ConfigureAwait(false);
}

Expand All @@ -53,6 +58,8 @@ public async Task<IActionResult> UpdatePet(
public async Task<IActionResult> AddPet(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "pet")] HttpRequest req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

return await Task.FromResult(new OkObjectResult(this._fixture.Create<Pet>())).ConfigureAwait(false);
}

Expand All @@ -65,6 +72,8 @@ public async Task<IActionResult> AddPet(
public async Task<IActionResult> FindByStatus(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "pet/findByStatus")] HttpRequest req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var status = req.Query["status"]
.Select(p =>
{
Expand All @@ -86,6 +95,8 @@ public async Task<IActionResult> FindByStatus(
public async Task<IActionResult> FindByTags(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "pet/findByTags")] HttpRequest req)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var tags = req.Query["tags"]
.Select(p =>
{
Expand Down Expand Up @@ -113,6 +124,8 @@ public async Task<IActionResult> FindByTags(
public async Task<IActionResult> GetPetById(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "pet/{petId}")] HttpRequest req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var pet = this._fixture.Build<Pet>().With(p => p.Id, petId).Create();

return await Task.FromResult(new OkObjectResult(pet)).ConfigureAwait(false);
Expand All @@ -128,6 +141,8 @@ public async Task<IActionResult> GetPetById(
public async Task<IActionResult> UpdatePetWithForm(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "pet/{petId}")] HttpRequest req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

var pet = this._fixture.Build<Pet>().With(p => p.Id, petId).Create();

return await Task.FromResult(new OkObjectResult(pet)).ConfigureAwait(false);
Expand All @@ -144,6 +159,8 @@ public async Task<IActionResult> UpdatePetWithForm(
public async Task<IActionResult> DeletePet(
[HttpTrigger(AuthorizationLevel.Anonymous, "DELETE", Route = "pet/{petId}")] HttpRequest req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

return await Task.FromResult(new OkResult()).ConfigureAwait(false);
}

Expand All @@ -156,6 +173,8 @@ public async Task<IActionResult> DeletePet(
public async Task<IActionResult> UploadFile(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "pet/{petId}/uploadImage")] HttpRequest req, long petId)
{
this._logger.LogInformation($"document title: {this._openapi.DocTitle}");

return await Task.FromResult(new OkObjectResult(this._fixture.Create<ApiResponse>())).ConfigureAwait(false);
}
}
Expand Down
Loading