# config

Source: https://apigenie.pl/techdocs/reference/cli-config

Prints the effective configuration, checks a configuration file, and prints the JSON Schema of the
configuration file.

## Usage

```sh
apigenie config [--config FILE | --no-config] [--json] [--origin] [--for SECTION]
apigenie config check [FILE]
apigenie config schema [--for SECTION | --standalone-server] [--out FILE]
```

## Description

The commands of `apigenie`, `apigenie-generator`, `apigenie-server` and `apigenie-catalog` read
their settings from the [configuration file](/techdocs/reference/cli-configuration):
`apigenie.yaml` in the current directory or a parent up to the root of the repository, or the file
given with `--config`. Every
file is checked against a JSON Schema (draft-7) when it is loaded. The schema is made of one part
per section, so it covers the settings of all four executables.

### apigenie config

Prints the settings the commands use: the values of the file, those set by environment variables,
and the defaults of the settings the file leaves out. Sections without any setting are left out.

| Option            | Description |
| ----------------- | ----------- |
| `--config FILE`   | Uses FILE instead of the file found in the repository. |
| `--no-config`     | Uses no file: prints the defaults. |
| `--json`          | Prints JSON instead of YAML. |
| `--origin`        | Annotates each value with where it comes from. |
| `--for SECTION`   | Prints one section only: `catalog`, `lint`, `format`, `diff`, `generate`, `generate.<target>` (for example `generate.client_go`) or `mock`. |

With `--origin`, the YAML output has a comment after each value:

```yaml
commands:
  lint:
    extends:
      - recommended # apigenie.yaml (repository file)
  mock:
    server:
      host: 127.0.0.1 # default
      port: 8080 # environment APIGENIE_SERVER_PORT
```

The origins are:

| Origin | Meaning |
| ------ | ------- |
| `<path> (repository file)` | the file found in the current directory or a parent |
| `--config <path>` | the file given with `--config` |
| `environment <VARIABLE>` | an environment variable of `apigenie-server` (`APIGENIE_SERVER_PORT` and the others listed in [mock server](/techdocs/reference/cli-server)), which wins over the file |
| `default` | the value used when the file leaves the setting out |

With `--json --origin`, the output is an object with the configuration under `config` and the
origin of each value, keyed by its JSON pointer, under `origins`.

Below a section with `extends` (such as `extends: [recommended]` in `lint`, `format` or `diff`), only
the values of the file are shown: the presets set the others.

Settings given on the command line of a command (such as `--port` of `apigenie-server`) are not part
of the configuration and are not shown.

### apigenie config check

Validates FILE, or the file found in the repository, against the schema. It prints `<file>: ok`
and exits with 0 when the file is valid. Otherwise it prints each error with its position and the
JSON pointer of the value, and exits with 2:

```text
$ apigenie config check apigenie.yaml
apigenie.yaml:4:11: /commands/fromat: unknown property 'fromat'; did you mean 'format'?
apigenie.yaml:9:15: /commands/format/openapi/indent: expected type integer, found string
apigenie.yaml:12:20: /commands/generate/server_express/validation: "zod" is not one of "ajv", "generated", "none"
```

Every unknown setting is reported at once. Of the other errors, the first one found is
reported.

### apigenie config schema

Prints the JSON Schema of the configuration file, of one section with `--for`, or of a standalone
`apigenie-server` file (`apigenie-server.yaml`, whose root holds the settings of `commands.mock`) with
`--standalone-server`. `--out FILE` writes it to FILE.

The schema of each release is also published on the website, at
`https://apigenie.pl/schemas/apigenie-config/<version>.json` and
`https://apigenie.pl/schemas/apigenie-server-config/<version>.json`, with `latest.json` for the last
release. See [editor support](/techdocs/reference/cli-overview#editor-support).

## Exit status

| Status | Meaning |
| ------ | ------- |
| 0 | Success; `config check`: the file is valid. |
| 2 | `config check` found errors in the file, the configuration file can't be loaded, or a usage error: an unknown section, no file to check. |

These are the statuses of every command ([exit status](/techdocs/reference/cli-overview#exit-status)).

## See also

- [Configuration](/techdocs/reference/cli-configuration): the sections of the file.
- [Mock server configuration](/techdocs/reference/cli-server#configuration).
