Skip to content

[Draft] Add support for multiple HTTP verbs in one Function #567

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Choice] .NET version: 6.0-bullseye-slim, 6.0-jammy, 6.0-focal
ARG VARIANT="6.0-jammy"
ARG VARIANT="7.0-jammy"
FROM mcr.microsoft.com/dotnet/sdk:${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
Expand Down
45 changes: 22 additions & 23 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "DevContainer for .NET",

"build": {
"dockerfile": "./Dockerfile",
"context": ".",
"args": {
"VARIANT": "6.0-jammy"
"VARIANT": "7.0-jammy"
// Use this only if you need Razor support, until OmniSharp supports .NET 6 properly
// "VARIANT": "6.0-focal"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
// Azure Functions
Expand All @@ -22,25 +22,25 @@
// Azure Static Web Apps
// 4280
],

"features": {
// Uncomment the below to install Azure CLI
"ghcr.io/devcontainers/features/azure-cli:1": {
"version": "latest"
},

// Uncomment the below to install GitHub CLI
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "latest"
},

// Uncomment the below to install node.js
"ghcr.io/devcontainers/features/node:1": {
"version": "lts",
"nodeGypDependencies": true,
"nvmInstallPath": "/usr/local/share/nvm"
},

// Install common utilities
"ghcr.io/devcontainers/features/common-utils:1": {
"installZsh": true,
Expand All @@ -51,11 +51,11 @@
"gid": "1000"
}
},

"overrideFeatureInstallOrder": [
"ghcr.io/devcontainers/features/common-utils"
],

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
Expand All @@ -65,40 +65,40 @@
// Recommended extensions - GitHub
"cschleiden.vscode-github-actions",
"GitHub.vscode-pull-request-github",

// Recommended extensions - Azure
"Azurite.azurite",
"ms-azuretools.vscode-bicep",

// Recommended extensions - Collaboration
"eamodio.gitlens",
"EditorConfig.EditorConfig",
// "MS-vsliveshare.vsliveshare-pack",
"streetsidesoftware.code-spell-checker",

// Recommended extensions - .NET
"Fudge.auto-using",
"jongrant.csharpsortusings",
"kreativ-software.csharpextensions",

// Recommended extensions - Power Platform
// "microsoft-IsvExpTools.powerplatform-vscode",

// Recommended extensions - Markdown
"bierner.github-markdown-preview",
"DavidAnson.vscode-markdownlint",
"docsmsft.docs-linting",
"johnpapa.read-time",
"yzhang.markdown-all-in-one",

// Required extensions
"GitHub.copilot",
"ms-dotnettools.csharp",
"ms-vscode.PowerShell",
"ms-vscode.vscode-node-azure-pack",
"VisualStudioExptTeam.vscodeintellicode"
],

"settings": {
// Uncomment if you want to use zsh as the default shell
"terminal.integrated.defaultProfile.linux": "zsh",
Expand All @@ -107,13 +107,13 @@
"path": "/usr/bin/zsh"
}
},

// Uncomment if you want to use CaskaydiaCove Nerd Font as the default terminal font
"terminal.integrated.fontFamily": "CaskaydiaCove Nerd Font",

// Uncomment if you want to disable the minimap view
"editor.minimap.enabled": false,

// Recommended settings for the explorer pane
"explorer.sortOrder": "type",
"explorer.fileNesting.enabled": true,
Expand All @@ -125,14 +125,13 @@
}
}
},

// Uncomment if you want to use bash in 'postCreateCommand' after the container is created
// "postCreateCommand": "/bin/bash ./.devcontainer/post-create.sh > ~/post-create.log",

// Uncomment if you want to use zsh in 'postCreateCommand' after the container is created
"postCreateCommand": "/usr/bin/zsh ./.devcontainer/post-create.sh > ~/post-create.log",

// Uncomment if you want to connect other than 'root'. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Azure Functions OpenAPI Extension #

Supports multiple HTTP methods on the same endpoint

```
[OpenApiOperation(operationId: "containerOperations", tags: new[] { "container" }, Summary = "Operations on containers", Description = "Operations on containers", Visibility = OpenApiVisibilityType.Important)]
//GetOperations
[OpenApiRequestBody(verb: "Get", contentType: "application/json", bodyType: typeof(ContainerGet), Required = true, Description = "Container to get")]
[OpenApiResponseWithBody(verb: "Get", statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ContainerGet), Description = "Gets container info")]
[OpenApiResponseWithoutBody(verb: "Get", statusCode: HttpStatusCode.BadRequest, Summary = "Invalid container supplied", Description = "Invalid container supplied")]
//DeleteOperations
[OpenApiRequestBody(verb: "Delete", contentType: "application/json", bodyType: typeof(ContainerDelete), Required = true, Description = "Container to delete")]
[OpenApiResponseWithBody(verb: "Delete", statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ContainerInfo), Description = "Deletes container")]
[OpenApiResponseWithoutBody(verb: "Delete", statusCode: HttpStatusCode.BadRequest, Summary = "Invalid container supplied", Description = "Invalid container supplied")]
//PostOperations
[OpenApiRequestBody(verb: "Post", contentType: "application/json", bodyType: typeof(ContainerCreate), Required = true, Description = "Container to create")]
[OpenApiResponseWithBody(verb: "Post", statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ContainerInfo), Description = "Created container")]
[OpenApiResponseWithoutBody(verb: "Post", statusCode: HttpStatusCode.BadRequest, Summary = "Invalid container supplied", Description = "Invalid container supplied")]
[Function("Containers")]
public Async.Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "GET", "POST", "DELETE")] HttpRequestData req)
=> _auth.CallIfUser(req, r => r.Method switch {
"GET" => Get(r),
"POST" => Post(r),
"DELETE" => Delete(r),
_ => throw new NotSupportedException(),
});
```

| Out-of-Proc Worker | In-Proc Worker |
| :----------------: | :------------: |
| [![](https://img.shields.io/nuget/dt/Microsoft.Azure.Functions.Worker.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/) [![](https://img.shields.io/nuget/v/Microsoft.Azure.Functions.Worker.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/) | [![](https://img.shields.io/nuget/dt/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) [![](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public PingHttpTrigger(ILogger<PingHttpTrigger> log)

[Function(nameof(PingHttpTrigger.Ping))]
[OpenApiOperation(operationId: "ping", tags: new[] { "ping" }, Summary = "Pings for health check", Description = "This pings for health check.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Summary = "Successful operation", Description = "Successful operation")]
[OpenApiResponseWithBody(verb: "GET", statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Summary = "Successful operation", Description = "Successful operation")]
public async Task<HttpResponseData> Ping(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "ping")] HttpRequestData req)
{
Expand Down
Loading