Skip to content

OpenAPI Options

Configuration for generating OpenAPI specification files and endpoints for NpgsqlRest APIs.

Overview

json
{
  "NpgsqlRest": {
    "OpenApiOptions": {
      "Enabled": false,
      "FileName": "npgsqlrest_openapi.json",
      "UrlPath": "/openapi.json",
      "FileOverwrite": true,
      "DocumentTitle": null,
      "DocumentVersion": "1.0.0",
      "DocumentDescription": null,
      "AddCurrentServer": true,
      "Servers": [],
      "SecuritySchemes": []
    }
  }
}

Settings Reference

SettingTypeDefaultDescription
EnabledboolfalseEnable OpenAPI generation.
FileNamestring"npgsqlrest_openapi.json"File name for generated OpenAPI file. null to skip file generation.
UrlPathstring"/openapi.json"URL path for OpenAPI endpoint. null to skip endpoint generation.
FileOverwritebooltrueOverwrite existing files.
DocumentTitlestringnullAPI title in the info section. Uses database name if null.
DocumentVersionstring"1.0.0"API version in the info section.
DocumentDescriptionstringnullAPI description in the info section.
AddCurrentServerbooltrueInclude current server in the servers section.
Serversarray[]Additional server entries for the servers section.
SecuritySchemesarray[]Security schemes for authentication documentation.

Document Info

Configure the OpenAPI document metadata:

json
{
  "NpgsqlRest": {
    "OpenApiOptions": {
      "Enabled": true,
      "DocumentTitle": "My API",
      "DocumentVersion": "2.0.0",
      "DocumentDescription": "REST API for my application"
    }
  }
}

Servers

Add server entries to the OpenAPI specification:

json
{
  "NpgsqlRest": {
    "OpenApiOptions": {
      "AddCurrentServer": true,
      "Servers": [
        {
          "Url": "https://api.example.com",
          "Description": "Production server"
        },
        {
          "Url": "https://staging-api.example.com",
          "Description": "Staging server"
        }
      ]
    }
  }
}

Security Schemes

Define authentication schemes for the OpenAPI document. Supported types:

  • Http - For Bearer and Basic authentication
  • ApiKey - For Cookie, Header, or Query parameter authentication

Bearer Token Authentication

json
{
  "SecuritySchemes": [
    {
      "Name": "bearerAuth",
      "Type": "Http",
      "Scheme": "Bearer",
      "BearerFormat": "JWT",
      "Description": "JWT Bearer token authentication"
    }
  ]
}

Basic Authentication

json
{
  "SecuritySchemes": [
    {
      "Name": "basicAuth",
      "Type": "Http",
      "Scheme": "Basic",
      "Description": "HTTP Basic authentication"
    }
  ]
}
json
{
  "SecuritySchemes": [
    {
      "Name": "cookieAuth",
      "Type": "ApiKey",
      "In": ".AspNetCore.Cookies",
      "ApiKeyLocation": "Cookie",
      "Description": "Cookie-based authentication"
    }
  ]
}

API Key in Header

json
{
  "SecuritySchemes": [
    {
      "Name": "apiKeyAuth",
      "Type": "ApiKey",
      "In": "X-API-Key",
      "ApiKeyLocation": "Header",
      "Description": "API key in header"
    }
  ]
}

Security Scheme Settings

SettingTypeDescription
NamestringUnique scheme identifier.
TypestringScheme type: "Http" or "ApiKey".
SchemestringHTTP auth scheme ("Bearer", "Basic"). For Type: "Http" only.
BearerFormatstringBearer token format (e.g., "JWT"). Optional.
InstringCookie/header/query name. For Type: "ApiKey" only.
ApiKeyLocationstringLocation: "Cookie", "Header", or "Query". For Type: "ApiKey" only.
DescriptionstringDescription of the security scheme.

Complete Example

Production configuration with multiple security schemes:

json
{
  "NpgsqlRest": {
    "OpenApiOptions": {
      "Enabled": true,
      "FileName": "openapi.json",
      "UrlPath": "/openapi.json",
      "FileOverwrite": true,
      "DocumentTitle": "My REST API",
      "DocumentVersion": "1.0.0",
      "DocumentDescription": "REST API generated from PostgreSQL functions",
      "AddCurrentServer": true,
      "Servers": [
        {
          "Url": "https://api.example.com",
          "Description": "Production server"
        }
      ],
      "SecuritySchemes": [
        {
          "Name": "bearerAuth",
          "Type": "Http",
          "Scheme": "Bearer",
          "BearerFormat": "JWT",
          "Description": "JWT Bearer token authentication"
        },
        {
          "Name": "cookieAuth",
          "Type": "ApiKey",
          "In": ".AspNetCore.Cookies",
          "ApiKeyLocation": "Cookie",
          "Description": "Cookie-based authentication"
        }
      ]
    }
  }
}

Next Steps

Released under the MIT License.