> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmembrane.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic Specification

By defining `spec` function, you can dynamically generate the collection specification. This is useful when the collection's capabilities depend on API features, user permissions, or configuration parameters.

## Implementation

```javascript theme={null}
module.exports = async ({ spec, credentials, parameters }) => {
  // Check API capabilities
  const capabilities = await makeApiRequest({
    method: 'GET',
    path: '/api/capabilities',
    credentials,
  })

  // Modify spec based on capabilities
  if (capabilities.supportsSearch) {
    spec.search = {
      parametersSchema: {
        type: 'object',
        properties: {
          query: { type: 'string' },
        },
      },
    }
  }

  // Add dynamic filter fields
  if (parameters.enableAdvancedFilters) {
    spec.list.filterFields = ['email', 'firstName', 'lastName', 'createdAt']
  }

  return spec
}
```

## Input

| Property      | Type   | Description                       |
| ------------- | ------ | --------------------------------- |
| `spec`        | object | The base collection specification |
| `credentials` | object | Connection credentials            |
| `parameters`  | object | Collection parameters             |

## Return Value

Returns the modified collection specification.

## Example

```javascript theme={null}
// Base spec:
{
  "name": "Contacts",
  "fieldsSchema": { /* ... */ },
  "list": {
    "filterFields": ["email"]
  },
  "create": {},
  "update": {}
}

// spec method returns:
{
  "name": "Contacts",
  "fieldsSchema": { /* ... */ },
  "list": {
    "filterFields": ["email", "firstName", "lastName", "createdAt"]
  },
  "create": {},
  "update": {},
  "search": {
    "parametersSchema": {
      "type": "object",
      "properties": {
        "query": { "type": "string" }
      }
    }
  }
}
```
