Skip to content

Configuration Reference

CoApi's configuration system is designed to provide maximum flexibility while maintaining sensible defaults and clear precedence rules. The configuration follows a hierarchical approach that allows both global settings and client-specific overrides, enabling developers to customize behavior across their entire API client ecosystem or for individual services.

Overview

CoApi's configuration architecture balances declarative convenience with programmatic control. By supporting both annotation-driven and property-based configuration, it accommodates different development styles and deployment scenarios. The system prioritizes explicit property declarations while providing annotation fallbacks for backward compatibility and rapid prototyping.

Configuration Properties

Global Properties

PropertyTypeDefaultDescriptionSource
coapi.enabledBooleantrueEnable/disable CoApi functionalityCoApiProperties.kt
coapi.modeClientModeAUTOGlobal client mode (AUTO, REACTIVE, SYNC)CoApiProperties.kt
coapi.base-packagesList<String>[]Base packages for client discoveryCoApiProperties.kt

Client Properties

PropertyTypeDefaultDescriptionSource
coapi.clients.<name>.base-urlString""Base URL for the clientClientProperties.kt
coapi.clients.<name>.load-balancedBoolean?nullEnable load balancing for the clientClientProperties.kt

Reactive Client Properties

PropertyTypeDefaultDescriptionSource
coapi.clients.<name>.reactive.filter.namesList<String>[]Reactive filter function namesClientProperties.kt
coapi.clients.<name>.reactive.filter.typesList<String>[]Reactive filter function typesClientProperties.kt

Sync Client Properties

PropertyTypeDefaultDescriptionSource
coapi.clients.<name>.sync.interceptor.namesList<String>[]Sync interceptor namesSyncClientDefinition.kt

Configuration Resolution Flow

The configuration system follows a strict precedence order to ensure predictable behavior:

mermaid
flowchart TD
    A[Start Configuration Resolution] --> B{"Check Properties File"}
    B -->|Has coapi.clients.<name>.base-url| C[Use Properties baseUrl]
    B -->|No properties baseUrl| D{Check @CoApi Annotation}
    D -->|Has baseUrl| E[Use Annotation baseUrl]
    D -->|No annotation baseUrl| F[Throw Configuration Exception]
    
    A --> G{Check coapi.clients.<name>.load-balanced}
    G -->|Has property| H[Use Properties loadBalanced]
    G -->|No property| I{Check @LoadBalanced Annotation}
    I -->|Has annotation| J[Use Annotation loadBalanced]
    I -->|No annotation| K[Use Default Behavior]
    
    C --> L[Resolve Complete Configuration]
    E --> L
    H --> L
    J --> L
    K --> L

Property Hierarchy

The configuration hierarchy determines how different configuration sources are merged and prioritized:

mermaid
graph TD
    subgraph "Global Level"
        A[coapi.enabled]
        B[coapi.mode]
        C[coapi.base-packages]
    end
    
    subgraph "Client Level"
        D[coapi.clients.<name>.base-url]
        E[coapi.clients.<name>.load-balanced]
    end
    
    subgraph "Client Sub-Level"
        F[coapi.clients.<name>.reactive.filter.*]
        G[coapi.clients.<name>.sync.interceptor.*]
    end
    
    subgraph "Annotation Level"
        H["@CoApi(baseUrl)"]
        I["@LoadBalanced"]
    end
    
    A --> D
    B --> D
    C --> D
    D --> F
    D --> G
    E --> F
    E --> G
    H --> D
    I --> E

Client Configuration Example

A complete client configuration example showing all available options:

mermaid
graph TB
    subgraph "Application.yml"
        A["coapi:"]
    end
    
    subgraph "Global Settings"
        B["enabled: true"]
        C["mode: AUTO"]
        D["base-packages:"]
        E[ - com.example.clients]
    end
    
    subgraph "Client Definitions"
        F["clients:"]
        G["GitHubApiClient:"]
        H["base-url: https://api.github.com"]
        I["ServiceApiClient:"]
        J["load-balanced: true"]
        K["reactive:"]
        L["filter:"]
        M["names:"]
        N[ - loadBalancerExchangeFilterFunction]
        O["types:"]
        P[" - org.springframework.cloud.client.loadbalancer.reactive.LoadBalancedExchangeFilterFunction"]
        Q["sync:"]
        R["interceptor:"]
        S["names:"]
        T[ - loadBalancerInterceptor]
    end
    
    A --> B
    A --> C
    A --> D
    D --> E
    A --> F
    F --> G
    G --> H
    F --> I
    I --> J
    I --> K
    K --> L
    L --> M
    M --> N
    L --> O
    O --> P
    I --> Q
    Q --> R
    R --> S
    S --> T

Configuration Resolution Sequence

The resolution process follows a well-defined sequence to ensure predictable behavior:

mermaid
sequenceDiagram
    participant P as Properties File
    participant A as Annotations
    participant F as FactoryBean
    participant C as Client Instance
    
    autonumber
    
    F->>P: Check coapi.clients.<name>.base-url
    alt Has property
        P-->>F: Return baseUrl from properties
    else No property
        F->>A: Check @CoApi annotation
        alt Has annotation
            A-->>F: Return baseUrl from annotation
        else No annotation
            F-->>F: Throw ConfigurationException
        end
    end
    
    F->>P: Check coapi.clients.<name>.load-balanced
    alt Has property
        P-->>F: Return loadBalanced from properties
    else No property
        F->>A: Check @LoadBalanced annotation
        alt Has annotation
            A-->>F: Return loadBalanced from annotation
        else No annotation
            F-->>F: Use default behavior
        end
    end
    
    F->>F: Build ClientDefinition
    F-->>C: Return configured client

YAML Configuration Example

yaml
coapi:
  enabled: true
  mode: AUTO  # AUTO, REACTIVE, SYNC
  base-packages:
    - com.example.clients
  clients:
    GitHubApiClient:
      base-url: https://api.github.com
    ServiceApiClient:
      load-balanced: true
      reactive:
        filter:
          names:
            - loadBalancerExchangeFilterFunction
          types:
            - org.springframework.cloud.client.loadbalancer.reactive.LoadBalancedExchangeFilterFunction
      sync:
        interceptor:
          names:
            - loadBalancerInterceptor

Cross-References

References

Source Files