-
Notifications
You must be signed in to change notification settings - Fork 394
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
Added insomia importer #525
Open
StormGear
wants to merge
18
commits into
foss42:main
Choose a base branch
from
StormGear:add-feat-insomia
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,470
−1
Open
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d1e5916
using fvm for flutter versioning ignore .fvm folder
StormGear be7954d
added necessary insomnia enums and exports
StormGear a247c6c
added necessary insomnia models
StormGear 756c118
use the insomnia collect to get the actual requests
StormGear 92c559d
map insomnia resources to HttpRequestModel
StormGear 16e6fc5
added CHANGELOG, LICENSE, and README to the insomnia package
StormGear 072919a
example usage of the insomnia package
StormGear ac29e31
unit tests for the insomnia package
StormGear f4eaf94
made necessary name and typo corrections
StormGear f241fc5
Included a field which can help determine the values of isHeaderEnabl…
StormGear 7bc8fdd
added support for formdata and text
StormGear 5de7fd6
Merge branch 'main' into add-feat-insomia
ashitaprasad 9a945a3
Merge branch 'foss42:main' into add-feat-insomia
StormGear 7b43a29
Merge branch 'foss42:main' into add-feat-insomia
StormGear 180fd59
add environment when insomia v4 is imported
StormGear ad77ed8
Merge branch 'foss42:main' into add-feat-insomia
StormGear 0ebe336
readded the TODO
StormGear 02c0e03
Merge branch 'add-feat-insomia' of github.com:StormGear/apidash into …
StormGear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
.fvm | ||
.fvmrc | ||
|
||
# IntelliJ related | ||
*.iml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'curl_io.dart'; | ||
export 'postman_io.dart'; | ||
export 'insomnia_io.dart'; |
122 changes: 122 additions & 0 deletions
122
packages/apidash_core/lib/import_export/insomnia_io.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import 'package:insomnia_collection/models/insomnia_environment.dart'; | ||
import 'package:seed/seed.dart'; | ||
import '../consts.dart'; | ||
import '../models/models.dart'; | ||
import '../utils/utils.dart'; | ||
import 'package:insomnia_collection/insomnia_collection.dart' as ins; | ||
|
||
class InsomniaIO { | ||
List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) { | ||
content = content.trim(); | ||
try { | ||
final ic = ins.insomniaCollectionFromJsonStr(content); | ||
final requests = ins.getRequestsFromInsomniaCollection(ic); | ||
|
||
/// TODO; Get env from the insomnia collection | ||
// final environmentVariables = ins.getEnvironmentVariablesFromInsomniaEnvironment(env); | ||
|
||
return requests | ||
.map((req) => (req.$1, insomniaRequestToHttpRequestModel(req.$2))) | ||
.toList(); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
InsomniaEnvironment? getInsomiaEnvironment(String content) { | ||
content = content.trim(); | ||
try { | ||
final env = ins.insomniaEnvironmentFromJsonStr(content); | ||
|
||
return env; | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
HttpRequestModel insomniaRequestToHttpRequestModel(ins.Resource request) { | ||
HTTPVerb method; | ||
|
||
try { | ||
method = HTTPVerb.values.byName((request.method ?? "").toLowerCase()); | ||
} catch (e) { | ||
method = kDefaultHttpMethod; | ||
} | ||
String url = stripUrlParams(request.url ?? ""); | ||
List<NameValueModel> headers = []; | ||
List<bool> isHeaderEnabledList = []; | ||
|
||
List<NameValueModel> params = []; | ||
List<bool> isParamEnabledList = []; | ||
|
||
for (var header in request.headers ?? <ins.Header>[]) { | ||
var name = header.name ?? ""; | ||
var value = header.value ?? ""; | ||
var activeHeader = header.disabled ?? false; | ||
headers.add(NameValueModel(name: name, value: value)); | ||
isHeaderEnabledList.add(!activeHeader); | ||
} | ||
|
||
for (var query in request.parameters ?? <ins.Parameter>[]) { | ||
var name = query.name ?? ""; | ||
var value = query.value; | ||
var activeQuery = query.disabled ?? false; | ||
params.add(NameValueModel(name: name, value: value)); | ||
isParamEnabledList.add(!activeQuery); | ||
} | ||
|
||
ContentType bodyContentType = kDefaultContentType; | ||
String? body; | ||
List<FormDataModel>? formData; | ||
if (request.body != null) { | ||
if (request.body?.mimeType != null) { | ||
try { | ||
if (request.body?.mimeType == 'text/plain') { | ||
bodyContentType = ContentType.text; | ||
} else if (request.body?.mimeType == 'application/json') { | ||
bodyContentType = ContentType.json; | ||
} else if (request.body?.mimeType == 'multipart/form-data') { | ||
bodyContentType = ContentType.formdata; | ||
formData = []; | ||
for (var fd in request.body?.params ?? <ins.Formdatum>[]) { | ||
var name = fd.name ?? ""; | ||
FormDataType formDataType; | ||
try { | ||
formDataType = FormDataType.values.byName(fd.type ?? ""); | ||
} catch (e) { | ||
formDataType = FormDataType.text; | ||
} | ||
var value = switch (formDataType) { | ||
FormDataType.text => fd.value ?? "", | ||
FormDataType.file => fd.src ?? "" | ||
}; | ||
formData.add(FormDataModel( | ||
name: name, | ||
value: value, | ||
type: formDataType, | ||
)); | ||
} | ||
} else { | ||
bodyContentType = | ||
ContentType.values.byName(request.body?.mimeType ?? ""); | ||
} | ||
} catch (e) { | ||
bodyContentType = kDefaultContentType; | ||
} | ||
body = request.body?.text; | ||
} | ||
} | ||
|
||
return HttpRequestModel( | ||
method: method, | ||
url: url, | ||
headers: headers, | ||
params: params, | ||
isHeaderEnabledList: isHeaderEnabledList, | ||
isParamEnabledList: isParamEnabledList, | ||
body: body, | ||
bodyContentType: bodyContentType, | ||
formData: formData, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
- Implement fromJson object and fromJson String for Insomnia v4 json format |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not remove comments without reading it. It is a TODO, which can be resolved by someone.