Skip to content

Commit 746afb5

Browse files
committed
Update docs
1 parent 0c455c8 commit 746afb5

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed

docs/openapi-core.md

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,19 @@ public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
8888
};
8989

9090
public List<OpenApiServer> Servers { get; set; } = new List<OpenApiServer>();
91+
92+
public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V2;
9193
}
9294
```
9395

94-
It's often required for the API app to have more than one base URL, with different hostname. To have [additional server URL information](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#serverObject), add `OpenApiServer` details to the class implementing the `IOpenApiConfigurationOptions` interface like:
96+
97+
### Overriding Base URLs ###
98+
99+
It's often required for the API app to have more than one base URL, with different hostname. To have [additional server URL information](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#serverObject), declare the `OpenApi__HostNames` value with comma delimited base URLs. Then, it will automatically sets up your base URLs.
100+
101+
> Find the [Configuration](openapi.md#configuration) section for the full list of the app settings keys.
102+
103+
Alternatively, add `OpenApiServer` details to the `Servers` property like:
95104

96105
```csharp
97106
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
@@ -103,12 +112,36 @@ public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
103112
new OpenApiServer() { Url = "https://contoso.com/api/" },
104113
new OpenApiServer() { Url = "https://fabrikam.com/api/" },
105114
};
115+
116+
...
117+
}
118+
```
119+
120+
> **NOTE**:
121+
>
122+
> * If no base URL is declared, the Azure Functions app's URL will be added as a default.
123+
> * The OpenAPI v2 (Swagger) document only shows the the first server name on both UI and document, while the OpenAPI v3 document shows the first server name on the UI and all server names on the document.
124+
125+
126+
### Overriding OpenAPI Version ###
127+
128+
The default version of OpenAPI document rendered is V2 (AKA Swagger). However, you can override the default rendering behaviour by implementing the `OpenApiVersion` property.
129+
130+
```csharp
131+
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
132+
{
133+
...
134+
135+
public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
136+
137+
...
106138
}
107139
```
108140

109-
> **NOTE**: As this extension automatically generates the server URL, these extra URLs are only appended, not overwriting the one automatically generated. And, the API v2 (Swagger) document won't be impacted by these extra URLs, while the OpenAPI v3 document shows all server URLs in the document, including the automatically generated one.
110141

111-
Instead of implementing `IOpenApiConfigurationOptions`, you can inherit `DefaultOpenApiConfigurationOptions`. As both `Info` and `Servers` properties have the modifier of `virtual`, you can freely override both or leave them as default.
142+
### Inheriting `DefaultOpenApiConfigurationOptions` ###
143+
144+
Instead of implementing `IOpenApiConfigurationOptions`, you can inherit `DefaultOpenApiConfigurationOptions`. As `Info`, `Servers` and `OpenApiVersion` properties have the modifier of `virtual`, you can freely override them or leave them as default.
112145

113146
```csharp
114147
public class MyOpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions
@@ -131,6 +164,14 @@ public class MyOpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions
131164
Url = new Uri("http://opensource.org/licenses/MIT"),
132165
}
133166
};
167+
168+
public override List<OpenApiServer> Servers { get; set; } = new List<OpenApiServer>()
169+
{
170+
new OpenApiServer() { Url = "https://contoso.com/api/" },
171+
new OpenApiServer() { Url = "https://fabrikam.com/api/" },
172+
};
173+
174+
public override OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
134175
}
135176
```
136177

@@ -499,6 +540,54 @@ public static class DummyHttpTrigger
499540
* `Description`: is the description of the response.
500541

501542

543+
### `OpenApiExampleAttribute` ###
544+
545+
This decorator implements the example attribute defined in the [`Schema object`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.1.md#schemaObject) section.
546+
547+
```csharp
548+
// Example
549+
public class CatExample : OpenApiExample<Cat>
550+
{
551+
public override IOpenApiExample<Cat> Build(NamingStrategy namingStrategy = null)
552+
{
553+
this.Examples.Add(OpenApiExampleResolver.Resolve("nabi", new Cat() { Id = 123, Name = "Nabi" }, namingStrategy));
554+
555+
return this;
556+
}
557+
}
558+
559+
// Model
560+
[OpenApiExample(typeof(CatExample))]
561+
public class Cat
562+
{
563+
public int Id { get; set; }
564+
565+
public string Name { get; set; }
566+
}
567+
568+
// This will result in:
569+
// {
570+
// "components": {
571+
// "schemas": {
572+
// "cat": {
573+
// "type": "object",
574+
// "properties": {
575+
// "id": {
576+
// "type": "integer"
577+
// "format": "int32"
578+
// },
579+
// "name": {
580+
// "type": "string"
581+
// }
582+
// },
583+
// "example": "{\"id\":123,\"name\":\"Nabi\"}"
584+
// }
585+
// }
586+
// }
587+
// }
588+
```
589+
590+
502591
### `OpenApiSchemaVisibilityAttribute` ###
503592

504593
This decorator is a part of extended property for custom connectors of Azure Logic Apps and Power Platform.

docs/openapi.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ While using this library, if you find any issue, please raise a ticket on the [I
2222
For detailed getting started document, find this [Enable OpenAPI Endpoints on Azure Functions (Preview)](enable-open-api-endpoints.md) page.
2323

2424

25+
## Configuration ##
26+
27+
For the extension's advanced configuration, it expects the following config keys.
28+
29+
2530
### Configure Authorization Level ###
2631

2732
As a default, all endpoints to render Swagger UI and OpenAPI documents have the authorisation level of `AuthorizationLevel.Anonymous`. However, if you want to secure those endpoints, change their authorisation level to `AuthorizationLevel.Functions` and pass the API Key through either request header or querystring parameter. This can be done through the environment variables. Here's the sample `local.settings.json` file. The other values are omitted for brevity.
@@ -52,3 +57,16 @@ You may want to only enable the Swagger UI page during the development time, and
5257
```
5358

5459
If you set the `OpenApi__HideSwaggerUI` value to `true`, the Swagger UI page won't be showing up, and you will see the 404 error. The default value is `false`.
60+
61+
62+
### Configure Custom Base URLs ###
63+
64+
There's a chance that you want to expose the UI and OpenAPI document through [Azure API Management](https://docs.microsoft.com/azure/api-management/api-management-key-concepts?WT.mc_id=github-0000-juyoo) or load balancing services like [Azure Front Door](https://docs.microsoft.com/azure/frontdoor/front-door-overview?WT.mc_id=github-0000-juyoo). You can configure an environment variable to add them. Here's the sample `local.settings.json` file. The other values are omitted for brevity.
65+
66+
```json
67+
{
68+
"Values": {
69+
"OpenApi__HostNames": "https://contoso.com/api/,https://fabrikam.com/api/"
70+
}
71+
}
72+
```

0 commit comments

Comments
 (0)