Skip to content

Commit

Permalink
Fix and Edit build time OpenAPI/ra
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick-Anderson committed Aug 15, 2024
1 parent a9dcecf commit b074ef6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
27 changes: 26 additions & 1 deletion aspnetcore/fundamentals/openapi/buildtime-openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,36 @@ dotnet add package Microsoft.Extensions.ApiDescription.Server --prerelease

The `Microsoft.Extensions.ApiDescription.Server` package automatically generates the Open API document(s) associated with the app during build and populates them into the app's output directory:

Consider a template created API app named `MyTestApi`:

### [Visual Studio](#tab/visual-studio)

The output tab of Visual Studio includes the output similar to the following:

```text
1>Generating document named 'v1'.
1>Writing document named 'v1' to 'MyProjectPath\obj\MyTestApi.json'.
```

### [.NET CLI](#tab/net-cli)

```cli
$ dotnet build
$ cat bin/Debub/net9.0/{ProjectName}.json
$ cat obj/MyTestApi.json
```

---

The generated `obj/{MyProjectName}.json` file contains the [OpenAPI version, title, endpoints, and more](https://learn.openapis.org/specification/structure.html). The following JSON shows the first few lines of obj/MyTestApi.json file:

```json
{
"openapi": "3.0.0",
"info": {
"title": "MyTestApi",



## Customize build-time document generation

### Modify the output directory of the generated Open API file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
</PropertyGroup>

<!--<snippet_doc_name>-->
<PropertyGroup>
<OpenApiGenerateDocumentsOptions>--document-name v2</OpenApiGenerateDocumentsOptions>
</PropertyGroup>

<!--</snippet_doc_name>-->

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"openapi": "3.0.1",
"info": {
"title": "MyTestApi | v1",
"version": "1.0.0"
},
"paths": {
"/weatherforecast": {
"get": {
"tags": [
"MyTestApi"
],
"operationId": "GetWeatherForecast",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date"
},
"temperatureC": {
"type": "integer",
"format": "int32"
},
"temperatureF": {
"type": "integer",
"format": "int32"
},
"summary": {
"type": "string",
"nullable": true
}
}
}
}
}
}
}
}
}
}
},
"components": { },
"tags": [
{
"name": "MyTestApi"
}
]
}

0 comments on commit b074ef6

Please sign in to comment.