# ApiSpecSource

Where Vulnesis finds an organisation's OpenAPI and Swagger descriptions. Fields, YAML, HCL and CLI samples, and how apply treats it.

Where Vulnesis finds an organisation's OpenAPI and Swagger descriptions. Each source is one place to read specs from: a file in a repository, a URL, a host to probe for well-known paths, or a connected API gateway or catalogue. A tenant may declare many, each named.

| | |
|---|---|
| `apiVersion` | `vulnetix.com/v1` |
| `kind` | `ApiSpecSource` |
| Group | [API inventory](/platform-iac/kinds/catalogue.md#api-inventory) |
| Status | **Served.** The [config engine](/platform-iac/reference/engine.md) plans and applies it. |
| Objects per tenant | many, keyed by `metadata.name` |
| Token and role | An owner, or a service account with the developer role (its ApiKey), or an Authentik access token for either. A member is refused with HTTP 403. See [Credentials for automation](/platform-iac/reference/config-api.md#credentials-for-automation). |
| Terraform resource | [`vulnetix_api_spec_source`](/platform-iac/terraform/resources.md#vulnetix_api_spec_source), imported by name (see [Terraform and OpenTofu](#terraform-and-opentofu)) |
| CLI | [`vulnetix config apply`](/platform-iac/cli/apply.md), CLI v3.157.0 and later. |
| Pinned schema | [`v1.19.1/ApiSpecSource.schema.json`](https://github.com/Vulnesis/config-schemas/releases/download/v1.19.1/ApiSpecSource.schema.json) |
| Newest schema | [`latest/ApiSpecSource.schema.json`](https://github.com/Vulnesis/config-schemas/releases/latest/download/ApiSpecSource.schema.json) |
| First released in | [`v1.2.0`](https://github.com/Vulnesis/config-schemas/releases/tag/v1.2.0) |
| Print the built-in copy | `vulnetix config schema ApiSpecSource` |

## Minimal

Only the fields the kind requires. From `examples/ApiSpecSource/minimal.yaml`.

**YAML**

```yaml
# yaml-language-server: $schema=https://github.com/Vulnesis/config-schemas/releases/latest/download/ApiSpecSource.schema.json
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: payments-openapi
spec:
  source:
    url:
      url: https://api.acme.com/openapi.json
```

**HCL** (resource `vulnetix_api_spec_source`)

```hcl
# Only the arguments the kind requires. From config-schemas examples/ApiSpecSource/minimal.yaml.

resource "vulnetix_api_spec_source" "payments_openapi" {
  name = "payments-openapi"
  source = {
    url = {
      url = "https://api.acme.com/openapi.json"
    }
  }
}
```

Every field that has a schema default, set to that default: [`terraform/api_spec_source.tf`](https://github.com/Vulnesis/platform-iac-examples/blob/main/terraform/api_spec_source.tf) and [`yaml/ApiSpecSource.yaml`](https://github.com/Vulnesis/platform-iac-examples/blob/main/yaml/ApiSpecSource.yaml) in [Vulnesis/platform-iac-examples](https://github.com/Vulnesis/platform-iac-examples).

**CLI** (applies it)

```bash
export VULNESIS_ORG_ID=...    # the organization UUID
export VULNESIS_API_KEY=...   # the ApiKey of a developer or owner service account
vulnetix config apply -f - --manager gitops:acme/platform --auto-approve <<'EOF'
# yaml-language-server: $schema=https://github.com/Vulnesis/config-schemas/releases/latest/download/ApiSpecSource.schema.json
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: payments-openapi
spec:
  source:
    url:
      url: https://api.acme.com/openapi.json
EOF
```

## Advanced

Every field the kind supports, with a `when` expression where it takes one. From `examples/ApiSpecSource/advanced.yaml`.

**YAML**

```yaml
# yaml-language-server: $schema=https://github.com/Vulnesis/config-schemas/releases/latest/download/ApiSpecSource.schema.json
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: payments-openapi
  labels:
    team: payments
  annotations:
    ticket: https://tracker.example.com/API-311
spec:
  source:
    repo:
      repository: acme/payments
      path: api/openapi.yaml
  schedule: daily
  owner: payments-team
  tags: [payments, public]
---
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: public-api-spec
spec:
  source:
    url:
      url: https://api.acme.com/openapi.json
  probe:
    mode: exact
  schedule: hourly
---
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: staging-host
spec:
  source:
    host:
      host: staging.acme.com:8443
  probe:
    mode: authorized
    authorize: true
  schedule: weekly
---
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: edge-gateway
spec:
  source:
    connector:
      kind: aws_apigw
      ref: a1b2c3d4e5
  schedule: 6h
  owner: platform-team
  tags: [edge]
```

**HCL** (resource `vulnetix_api_spec_source`)

```hcl
# Every argument the kind supports. From config-schemas examples/ApiSpecSource/advanced.yaml.

resource "vulnetix_api_spec_source" "payments_openapi" {
  name     = "payments-openapi"
  owner    = "payments-team"
  schedule = "daily"
  source = {
    repo = {
      path       = "api/openapi.yaml"
      repository = "acme/payments"
    }
  }
  tags = ["payments", "public"]
  labels = {
    team = "payments"
  }
  annotations = {
    ticket = "https://tracker.example.com/API-311"
  }
}

resource "vulnetix_api_spec_source" "public_api_spec" {
  name = "public-api-spec"
  probe = {
    mode = "exact"
  }
  schedule = "hourly"
  source = {
    url = {
      url = "https://api.acme.com/openapi.json"
    }
  }
}

resource "vulnetix_api_spec_source" "staging_host" {
  name = "staging-host"
  probe = {
    authorize = true
    mode      = "authorized"
  }
  schedule = "weekly"
  source = {
    host = {
      host = "staging.acme.com:8443"
    }
  }
}

resource "vulnetix_api_spec_source" "edge_gateway" {
  name     = "edge-gateway"
  owner    = "platform-team"
  schedule = "6h"
  source = {
    connector = {
      kind = "aws_apigw"
      ref  = "a1b2c3d4e5"
    }
  }
  tags = ["edge"]
}
```

Every field that has a schema default, set to that default: [`terraform/api_spec_source.tf`](https://github.com/Vulnesis/platform-iac-examples/blob/main/terraform/api_spec_source.tf) and [`yaml/ApiSpecSource.yaml`](https://github.com/Vulnesis/platform-iac-examples/blob/main/yaml/ApiSpecSource.yaml) in [Vulnesis/platform-iac-examples](https://github.com/Vulnesis/platform-iac-examples).

**CLI** (applies it)

```bash
export VULNESIS_ORG_ID=...    # the organization UUID
export VULNESIS_API_KEY=...   # the ApiKey of a developer or owner service account
vulnetix config apply -f - --manager gitops:acme/platform --auto-approve <<'EOF'
# yaml-language-server: $schema=https://github.com/Vulnesis/config-schemas/releases/latest/download/ApiSpecSource.schema.json
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: payments-openapi
  labels:
    team: payments
  annotations:
    ticket: https://tracker.example.com/API-311
spec:
  source:
    repo:
      repository: acme/payments
      path: api/openapi.yaml
  schedule: daily
  owner: payments-team
  tags: [payments, public]
---
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: public-api-spec
spec:
  source:
    url:
      url: https://api.acme.com/openapi.json
  probe:
    mode: exact
  schedule: hourly
---
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: staging-host
spec:
  source:
    host:
      host: staging.acme.com:8443
  probe:
    mode: authorized
    authorize: true
  schedule: weekly
---
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: edge-gateway
spec:
  source:
    connector:
      kind: aws_apigw
      ref: a1b2c3d4e5
  schedule: 6h
  owner: platform-team
  tags: [edge]
EOF
```

## Fields

Paths use dots for nesting and `[]` for the items of a list. **Required** means required whenever the parent object is present. A default is what the server uses when the field is left out.

| Field | Type | Required | Default | Allowed values | Description |
|---|---|---|---|---|---|
| <span id="apiVersion"></span>`apiVersion` | string | yes |  | exactly `vulnetix.com/v1` | The document format version. Every kind in this release is vulnetix.com/v1. |
| <span id="kind"></span>`kind` | string | yes |  | exactly `ApiSpecSource` | Always ApiSpecSource. |
| <span id="metadata"></span>`metadata` | object | yes |  | no other keys |  |
| <span id="metadata-name"></span>`metadata.name` | string | yes |  | pattern `^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$` | The object's name, unique per kind within a tenant. It is the natural key: plan, apply, export and the Terraform provider all address an object by kind and name. |
| <span id="metadata-org"></span>`metadata.org` | string | no |  | format `uuid` | The tenant (organization UUID) the document belongs to. When set, plan and apply refuse to run against any other tenant. |
| <span id="metadata-labels"></span>`metadata.labels` | object | no |  | map of string to string (length 0 to 256); keys match `^[a-z0-9]([a-z0-9._/-]{0,61}[a-z0-9])?$` | Free key/value labels. Stored with the object, never interpreted by the server. |
| <span id="metadata-annotations"></span>`metadata.annotations` | object | no |  | map of string to string (length 0 to 4096) | Free key/value notes for people and tools, such as a ticket link. |
| <span id="spec"></span>`spec` | object | yes |  | no other keys |  |
| <span id="spec-source"></span>`spec.source` | object | yes |  | 1 to 1 keys; no other keys | The one place this reads specs from. Exactly one of its forms is set. |
| <span id="spec-source-repo"></span>`spec.source.repo` | object | no |  | no other keys | A spec file committed in a repository. |
| <span id="spec-source-repo-repository"></span>`spec.source.repo.repository` | string | yes |  | pattern `^[^/]+/[^/]+$` | owner/name on the connected forge. |
| <span id="spec-source-repo-path"></span>`spec.source.repo.path` | string | yes |  | length 1 to any | Path to the file within the repository. |
| <span id="spec-source-url"></span>`spec.source.url` | object | no |  | no other keys | A spec served at a URL. By default the URL is fetched exactly as given; set probe to look for well-known paths under a host instead. |
| <span id="spec-source-url-url"></span>`spec.source.url.url` | string | yes |  | pattern `^https?://`; format `uri` |  |
| <span id="spec-source-host"></span>`spec.source.host` | object | no |  | no other keys | A host probed for the well-known paths that serve a spec. Needs an ownership proof or an authorization, set in probe. |
| <span id="spec-source-host-host"></span>`spec.source.host.host` | string | yes |  | pattern `^[a-zA-Z0-9.-]+(:[0-9]{1,5})?$` | A hostname, optionally with a port. |
| <span id="spec-source-connector"></span>`spec.source.connector` | object | no |  | no other keys | A connected API gateway or catalogue the organisation already set up on the integrations page. |
| <span id="spec-source-connector-kind"></span>`spec.source.connector.kind` | string | yes |  | `aws_apigw`, `cloudflare_api_shield`, `swaggerhub`, `postman`, `azure_apim`, `gcp_apigee`, `kong`, `stoplight`, `readme`, `backstage` |  |
| <span id="spec-source-connector-ref"></span>`spec.source.connector.ref` | string | yes |  | length 1 to any | The gateway, API or collection id within the connector. |
| <span id="spec-probe"></span>`spec.probe` | object | no |  | no other keys | How a url or host source is reached. owned probes well-known paths once an ownership proof is verified; authorized probes after the organisation asserts it is allowed to test the host; exact fetches only the given url and never guesses a path. A url source defaults to exact; a host source must be owned or authorized. |
| <span id="spec-probe-mode"></span>`spec.probe.mode` | string | no |  | `owned`, `authorized`, `exact` |  |
| <span id="spec-probe-authorize"></span>`spec.probe.authorize` | boolean | no |  | exactly `true` | Required true when mode is authorized: the organisation asserts it may probe this host. Recorded with who applied the document. |
| <span id="spec-schedule"></span>`spec.schedule` | string | no | `daily` | `off`, `hourly`, `6h`, `daily`, `weekly` | How often the source is read. off reads only on request. |
| <span id="spec-owner"></span>`spec.owner` | string | no |  | length 0 to 256 | The team or person who owns the APIs this source finds. Stored and shown, never interpreted. |
| <span id="spec-tags"></span>`spec.tags` | array of string | no |  | 0 to 32 items; each item: length 0 to 64 | Free labels applied to every spec this source finds. |

## Applying this kind

- **Command.** `vulnetix config apply -f <file>`; the CLI line above says from which release. Plan first with [`vulnetix config plan`](/platform-iac/cli/plan.md): it shows each object as create, update, delete or no change, with a `planHash` that apply then holds to. Apply writes in one transaction.
- **Manager.** Each object records the manager that applied it (`terraform`, `console` or `gitops:<repo>`). `--prune` deletes only objects its own manager owns. See [The manager](/platform-iac/cli/plan.md#the-manager) and the [config engine](/platform-iac/reference/engine.md).
- **Status.** Applied, Unchanged or Deleted, with no other status fields. The phases the engine reports are explained under [status phases](/platform-iac/reference/engine.md#status-phases).

## How apply treats it

A tenant declares many sources, each named. A source is small and wholly declared, so apply overwrites the whole row from the document: a field the document leaves out goes back to its default. Rows made this way are marked as managed by config, and the Resolve Platform shows them read only.

## Terraform and OpenTofu

The resource is `vulnetix_api_spec_source` in the `vulnetix/resolve` provider. Its arguments are the `spec` in snake case, beside `name`, `labels` and `annotations` from `metadata`. The Minimal and Advanced HCL are above. The provider's own reference is [vulnetix_api_spec_source](https://registry.terraform.io/providers/vulnetix/resolve/latest/docs/resources/api_spec_source).

Import an object that already exists by its name:

```shell
# Import an existing ApiSpecSource by its name (metadata.name).
terraform import vulnetix_api_spec_source.payments_openapi payments-openapi
```

Install, authentication and how state is read: [Terraform and OpenTofu](/platform-iac/terraform.md).

## More examples

`examples/ApiSpecSource/authorized-host.yaml` from `Vulnesis/config-schemas`:

```yaml
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: staging-host
spec:
  source:
    host:
      host: staging.acme.com
  probe:
    mode: authorized
    authorize: true
```

`examples/ApiSpecSource/gateway.yaml` from `Vulnesis/config-schemas`:

```yaml
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: edge-gateway
spec:
  source:
    connector:
      kind: aws_apigw
      ref: abcdef1234
  schedule: 6h
```

`examples/ApiSpecSource/repo.yaml` from `Vulnesis/config-schemas`:

```yaml
apiVersion: vulnetix.com/v1
kind: ApiSpecSource
metadata:
  name: payments-openapi
  labels:
    team: payments
spec:
  source:
    repo:
      repository: acme/payments
      path: api/openapi.yaml
  schedule: daily
  owner: payments-team
  tags: [payments, public]
```

Check a file with `vulnetix config validate -f <file>`. See [Validate documents](/platform-iac/cli/validate.md). In an editor, start the file with the [schema comment](/platform-iac/schemas/editors.md).
