OpenAPITools / OpenAPITools/openapi-generator

[BUG] Validator throws "attribute .servers.invalid url" error

Open
#8,033 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When validating a remote OpenAPI spec with a server URL that uses variable substitution placeholders, the openapi-generator throws the following error:

❯ java -jar openapi-generator-cli.jar validate -i https://gist.githubusercontent.com/badsyntax/50ba5ec813a6ecac942b6ee177de0cae/raw/6586e44937cd91e99e1344cdda4b4708cda76b98/test.yml
Validating spec (https://gist.githubusercontent.com/badsyntax/50ba5ec813a6ecac942b6ee177de0cae/raw/6586e44937cd91e99e1344cdda4b4708cda76b98/test.yml)
Errors:
        - attribute .servers.invalid url : https://{host}/admin

[error] Spec has 1 errors.

If you validate the same file from local disk, no errors are thrown:

❯ java -jar openapi-generator-cli.jar validate -i ./test.yml 
Validating spec (./test.yml)
No validation issues detected.
openapi-generator version
5.0.0-beta3
OpenAPI declaration file content or url

https://gist.githubusercontent.com/badsyntax/50ba5ec813a6ecac942b6ee177de0cae/raw/6586e44937cd91e99e1344cdda4b4708cda76b98/test.yml

openapi: 3.0.3
info:
  title: Title
  version: 0.51.0
servers:
  - url: https://{host}/admin
    variables:
      host:
        default: box.example.com
        description: The API hostname.
paths:
  /me:
    get:
      operationId: getMe
      responses:
        200:
          description: Successful operation
Generation Details
Steps to reproduce

Shows the bug when validating a remote file:

java -jar openapi-generator-cli.jar validate -i https://gist.githubusercontent.com/badsyntax/50ba5ec813a6ecac942b6ee177de0cae/raw/6586e44937cd91e99e1344cdda4b4708cda76b98/test.yml

Show no bug when validating a local file:

java -jar openapi-generator-cli.jar validate -i ./test.yml
Related issues/PRs

Possibly related: https://github.com/swagger-api/swagger-parser/issues/1329

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CLI validate command and compare how it loads remote and local OpenAPI documents. Reproduce using the provided remote URL and test.yml, then confirm that a server URL using {host} with a declared default validates identically from both sources without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.