-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] OpenAPI import does not seem to honor default variables in servers declaration #1640
Comments
👋 Thanks for opening your first issue! If you're reporting a 🐞 bug, please make sure To help make this a smooth process, please be sure you have first read the |
Looks like an issue with SwaggerParser seeing the template as incorrect syntax. This is the error I have in the dev tools using your file.
|
Sorry for the late reply.. :( I made a temporary fix and forgot about this. Anyway.. that error message is because my example was incomplete. The definitions for the $ref is missing. Here's a more complete file that wont import and don't give that error:
|
After replacing the url it works: |
I'm seeing this problem too with Insomnia 7.0.5 on macOS 10.15.1 The import failure happens when I use a variable for the server port. I started with the petstore sample from the OAS specification repo Then modified the servers block to be
Insomnia shows two errors
I don't get any syntax errors about the file and it imports successfully into Postman 7.13.0. Hoping to get things working with Insomnia though :) Full modified petstore.yaml showing the problem
|
Not sure if it is the same or not, but I also can not import OpenAPI to insomnia because of 2 errors.
The first error is also shown when you go to Application > Preferences under "Data" tab and use "Import from clipboard" option. Sadly, currently it seems impossible to import an OpenAPI spec into insomnia. |
I'm affected by this bug as well. I get "Cannot read property 'map' of undefined." whether I import from URL or file. |
Exactly in the same situation as @vitalis. Also I just wanted to point out that the bug does not occur when you directly copy&paste your openapi.json inside of the Insomnia Rest Designer text editor. |
I recently built functionality to honor default variables in an OpenAPI spec server, as part of the insomnia/packages/openapi-2-kong/src/kubernetes/variables.js Lines 3 to 33 in 453745d
In terms of importing, I wasn't able to reproduce the errors being reported (on v7.1.1). @vitaliis or @SylannBin, could you please share some reproduction steps for what you're seeing? Are you facing this with the example specification (#1640 (comment)) or a different one? |
First, I'm on Macos Catalina, and I use Insomnia Steps to reproduce:
From clipboardCopy the content of data below and choose From clipboard I get the following error alone and the text is not selectable. TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined From urlhttp://localhost:8000/openapi.json From fileAND OpenAPI json schemaIt's based of the fastapi doc for Oauth2 bearer token login, so I think it represents a fairly common case. See data{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/login/access-token": {
"post": {
"tags": [
"Users"
],
"summary": "Login Access Token",
"description": "Login and get an access token with your credentials.",
"operationId": "login_access_token_login_access_token_post",
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/Body_login_access_token_login_access_token_post"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AccessTokenSchema"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"AccessTokenSchema": {
"title": "AccessTokenSchema",
"required": [
"access_token",
"token_type"
],
"type": "object",
"properties": {
"access_token": {
"title": "Access Token",
"type": "string"
},
"token_type": {
"title": "Token Type",
"type": "string"
}
}
},
"Body_login_access_token_login_access_token_post": {
"title": "Body_login_access_token_login_access_token_post",
"required": [
"username",
"password"
],
"type": "object",
"properties": {
"grant_type": {
"title": "Grant Type",
"pattern": "password",
"type": "string"
},
"username": {
"title": "Username",
"type": "string"
},
"password": {
"title": "Password",
"type": "string"
},
"scope": {
"title": "Scope",
"type": "string",
"default": ""
},
"client_id": {
"title": "Client Id",
"type": "string"
},
"client_secret": {
"title": "Client Secret",
"type": "string"
}
}
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {
"$ref": "#/components/schemas/ValidationError"
}
}
}
},
"ValidationError": {
"title": "ValidationError",
"required": [
"loc",
"msg",
"type"
],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"type": "string"
}
},
"msg": {
"title": "Message",
"type": "string"
},
"type": {
"title": "Error Type",
"type": "string"
}
}
}
},
"securitySchemes": {
"OAuth2PasswordBearer": {
"type": "oauth2",
"flows": {
"password": {
"scopes": {},
"tokenUrl": "/login/access-token"
}
}
}
}
}
} |
Thanks for that @SylannBin! A missing That has been resolved by #2007 though, and will be included in the next release of Insomnia Core. I confirmed by importing that specification successfully while running on the latest
This is because Designer already includes the fix 😄 |
Right. The issue is gone when you add the Good that it is generally resolved by #2007. Thanks, @develohpanda for the info! |
Details
I'm trying to import an OpenAPI 3 spec that uses variables in the server url. Default values are provided for these in the variables declaration. This results in an error when i try to import the file: Invalid URL: http://{host}:{port}/{basePath}
If I replace the url with the following string it works: http://localhost:8080/filemanagement
OpenAPI yaml file (parts of it - but it can be used to reproduce the bug and import works after replacing the servers/url part):
The text was updated successfully, but these errors were encountered: