# WithOpenApiDocument

- Module: [Aspire.Hosting.Azure.ApiManagement](/reference/api/go/aspire.hosting.azure.apimanagement.md)
- Version: `17.0.0-preview.1.26567.5`
- Kind: `method`
- Defined on: [`AzureApiManagementApiResource`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementapiresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Imports an OpenAPI document from a file into an API.

## Remarks

The document is read when generating infrastructure for publish or deploy, never during run mode.
It must exist and contain non-whitespace content by the time infrastructure is generated.
An API can have only one OpenAPI source: either a document file or an endpoint.
Repeating the same source configuration is allowed; configuring a different source throws.

## Definition

```go
func (AzureApiManagementApiResource) WithOpenApiDocument(
    documentPath string,
    options ...*WithOpenApiDocumentOptions,
) AzureApiManagementApiResource
```

## Parameters

- `documentPath` (`string`) -- The document path, relative to the AppHost directory when not absolute.
- `options` (`...*WithOpenApiDocumentOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithOpenApiDocumentOptions` argument.

- `Format` ([`*AzureApiManagementOpenApiFormat`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementopenapiformat.md)) -- The document format. The file extension is used when omitted.

## Returns

[`AzureApiManagementApiResource`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementapiresource.md) -- The API Management API resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`AzureApiManagementApiResource`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementapiresource.md)
