Skip to content
Latchkey

openapi-generator "specified file ... is not valid JSON/YAML" in CI

OpenAPI Generator parses the input spec as JSON or YAML before anything else. A syntax error (bad indentation, a tab, an unquoted special character) makes the parser fail with a message that the file is not valid JSON/YAML, citing the line and column.

What this error means

openapi-generator-cli fails with a parser error such as "while scanning ... found character \"\\t\" that cannot start any token" or "is not valid JSON/YAML", with a line/column reference.

openapi-generator
Exception in thread "main" com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.MarkedYAMLException:
while scanning for the next token
found character '\t' that cannot start any token
 in 'reader', line 12, column 1

Common causes

A YAML syntax error in the spec

A tab character, inconsistent indentation, or an unquoted value containing a special character makes the YAML unparseable.

A truncated or wrong-format file

The file was partially written, has a BOM, or is actually a different format than the extension implies.

How to fix it

Validate and fix the spec syntax

  1. Run the generator validator or a YAML linter to get the exact line.
  2. Replace tabs with spaces and quote values with special characters.
  3. Re-run generation once the file parses cleanly.
Terminal
openapi-generator-cli validate -i openapi.yaml

Lint YAML in CI before generation

Catch malformed specs with a fast lint step so the generator never sees broken input.

.github/workflows/ci.yml
- run: npx yaml-lint openapi.yaml
- run: openapi-generator-cli generate -i openapi.yaml -g go -o ./client

How to prevent it

  • Lint or validate the spec before each generation run.
  • Configure editors to use spaces, never tabs, in YAML.
  • Quote string values that contain :, #, or leading symbols.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →