Kong / insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets, SSE and gRPC. With Cloud, Local and Git storage.
https://insomnia.rest
Apache License 2.0
34.17k stars 1.92k forks source link

inso CLI generates invalid config if protocol is missing from server URL #5495

Open reitzig opened 1 year ago

reitzig commented 1 year ago

Expected Behavior

Output:

_format_version: "1.1"
services:
  - name: Some_Service
    protocol: http
    host: foo.bar.svc.cluster.local
    port: 80
    path: /
    plugins: []
    routes:
      - tags:
          &a1
          - OAS3_import
          - OAS3file_openapi_mwe.yaml
        name: Some_Service-getHello
        methods:
          - GET
        paths:
          - /hello$
        strip_path: false
    tags: *a1

or a descriptive error.

Actual Behavior

Output:

_format_version: "1.1"
services:
  - name: Some_Service
    protocol: http
    host: localhost
    port: 80
    path: /foo.bar.svc.cluster.local
    plugins: []
    routes:
      - tags:
          &a1
          - OAS3_import
          - OAS3file_openapi_mwe.yaml
        name: Some_Service-getHello
        methods:
          - GET
        paths:
          - /hello$
        strip_path: false
    tags: *a1

Note services[0].host and services[0].path.

While inso guesses/defaults to HTTP and port 80, parsing the server path seems to get tripped up by the lack of protocol.

Reproduction Steps

  1. Create file openapi_mwe.yaml with content:
    
    openapi: 3.0.2
    info:
    title: Some Service
    version: "@project.version@"
    contact:
    name: Me
    description: bar

servers:

tags:

paths: /hello: get: operationId: getHello description: "Says hello" tags:


2. FWIW, run `inso lint spec openapi_mwe.yaml` -- OK
3. Run `inso generate config -t declarative openapi_mwe.yaml`

### Is there an existing issue for this?

- [X] I have searched the [issue tracker](https://www.github.com/Kong/insomnia/issues) for this problem.

### Additional Information

_No response_

### Insomnia Version

inso CLI 3.6.0, 3.12.0

### What operating system are you using?

Ubuntu

### Operating System Version

Linux 70be28549172 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 Linux

### Installation method

`wget -qO- https://github.com/Kong/insomnia/releases/download/lib%403.6.0/inso-linux-3.6.0.tar.xz | tar -xJ`

### Last Known Working Insomnia version

_No response_
reitzig commented 1 year ago

While inso guesses/defaults to HTTP and port 80

FWIW, a silent yet insecure default may not be ideal. I'd expect a straight-up error (no default) or at least a linter warning (if not error).