mirror of
https://github.com/foss42/apidash.git
synced 2025-05-19 23:36:36 +08:00
Merge branch 'main' into add-feature-header-env-suggestions
This commit is contained in:
88
.github/workflows/aur-publish.yml
vendored
Normal file
88
.github/workflows/aur-publish.yml
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
name: Update AUR Package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
paths:
|
||||
- 'pubspec.yaml'
|
||||
|
||||
jobs:
|
||||
aur-publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get version from pubspec
|
||||
id: get_version
|
||||
run: |
|
||||
VERSION=$(grep 'version:' pubspec.yaml | awk '{print $2}' | cut -d'+' -f1)
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get checksums
|
||||
id: get_checksums
|
||||
run: |
|
||||
# Download the x86_64 .deb
|
||||
wget https://github.com/foss42/apidash/releases/download/v${{ steps.get_version.outputs.version }}/apidash-linux-amd64.deb
|
||||
|
||||
# Download the arm64 .deb
|
||||
wget https://github.com/foss42/apidash/releases/download/v${{ steps.get_version.outputs.version }}/apidash-linux-arm64.deb
|
||||
|
||||
# Download the LICENSE
|
||||
wget https://raw.githubusercontent.com/foss42/apidash/main/LICENSE
|
||||
|
||||
# Generate SHA512 checksums
|
||||
DEB_X86_64_CHECKSUM=$(sha512sum apidash-linux-amd64.deb | awk '{print $1}')
|
||||
DEB_ARM64_CHECKSUM=$(sha512sum apidash-linux-arm64.deb | awk '{print $1}')
|
||||
LICENSE_CHECKSUM=$(sha512sum LICENSE | awk '{print $1}')
|
||||
|
||||
echo "deb_x86_64_checksum=$DEB_X86_64_CHECKSUM" >> $GITHUB_OUTPUT
|
||||
echo "deb_arm64_checksum=$DEB_ARM64_CHECKSUM" >> $GITHUB_OUTPUT
|
||||
echo "license_checksum=$LICENSE_CHECKSUM" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Publish AUR package
|
||||
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
|
||||
with:
|
||||
pkgname: apidash-bin
|
||||
pkgbuild: |
|
||||
# Maintainer: Angelo Geulin <angelogeulin123 at gmail dot com>
|
||||
|
||||
pkgname=apidash-bin
|
||||
pkgver=${{ steps.get_version.outputs.version }}
|
||||
pkgrel=1
|
||||
pkgdesc="Beautiful open-source cross-platform API Client"
|
||||
arch=('x86_64' 'aarch64')
|
||||
url="https://apidash.dev"
|
||||
license=('Apache-2.0')
|
||||
depends=()
|
||||
options=('!emptydirs' '!strip')
|
||||
source=("LICENSE::https://raw.githubusercontent.com/foss42/apidash/main/LICENSE")
|
||||
source_x86_64=("apidash-linux-amd64.deb::https://github.com/foss42/apidash/releases/download/v${{ steps.get_version.outputs.version }}/apidash-linux-amd64.deb")
|
||||
source_aarch64=("apidash-linux-arm64.deb::https://github.com/foss42/apidash/releases/download/v${{ steps.get_version.outputs.version }}/apidash-linux-arm64.deb")
|
||||
sha512sums=('${{ steps.get_checksums.outputs.license_checksum }}')
|
||||
sha512sums_x86_64=('${{ steps.get_checksums.outputs.deb_x86_64_checksum }}')
|
||||
sha512sums_aarch64=('${{ steps.get_checksums.outputs.deb_arm64_checksum }}')
|
||||
|
||||
package() {
|
||||
if [ "$CARCH" = "x86_64" ]; then
|
||||
_debfile="$srcdir/apidash-linux-amd64.deb"
|
||||
elif [ "$CARCH" = "aarch64" ]; then
|
||||
_debfile="$srcdir/apidash-linux-arm64.deb"
|
||||
fi
|
||||
ar -x "${_debfile}" data.tar.zst
|
||||
bsdtar -xf data.tar.zst -C "$pkgdir/"
|
||||
|
||||
# Fix permissions of directories
|
||||
find "$pkgdir/" -type d -exec chmod 755 {} \;
|
||||
|
||||
# Create a symlink inside /usr/bin
|
||||
mkdir -p "${pkgdir}/usr/bin"
|
||||
ln -s /usr/share/apidash/apidash "$pkgdir/usr/bin/apidash"
|
||||
|
||||
install -Dm644 "$srcdir/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
}
|
||||
commit_username: ${{ secrets.AUR_USERNAME }}
|
||||
commit_email: ${{ secrets.AUR_EMAIL }}
|
||||
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
|
||||
commit_message: "Update to version ${{ steps.get_version.outputs.version }}"
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,6 +9,8 @@
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
.fvm
|
||||
.fvmrc
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
|
@ -11,12 +11,29 @@ You can contribute to the project in any or all of the following ways:
|
||||
- Add documentation
|
||||
- Add a new feature, resolve an existing issue or add a new test to the project. (Goto [Code Contribution Guidelines](#code-contribution-guidelines)).
|
||||
|
||||
## Resources for New Contributors
|
||||
|
||||
- API Dash Code Walkthrough - [Video](https://www.youtube.com/live/rIlwCTKNz-A?si=iMxTxzkpY_ySo4Ow&t=339)
|
||||
- Getting Started with Flutter - [Video](https://www.youtube.com/watch?v=8K2gV1P6ZHI)
|
||||
- API Dash Developer Guide - [Read](https://github.com/foss42/apidash/blob/main/doc/dev_guide/README.md)
|
||||
|
||||
## Code Contribution Guidelines
|
||||
|
||||
### Why we do not assign issues to anyone?
|
||||
|
||||
- By not assigning issues upfront, anyone can feel welcome to contribute without feeling like the issue is already "taken."
|
||||
- This also prevents discouraging new contributors who might feel locked out if issues are pre-assigned.
|
||||
- Contributors are encouraged to pick issues that align with their skills and interests. To take initiative rather than waiting for permission or being "assigned" work.
|
||||
- Sometimes contributors express interest but never follow through. If issues are assigned prematurely, others might avoid working on them, delaying progress.
|
||||
- Leaving issues unassigned ensures that work can proceed without bottlenecks if someone goes inactive.
|
||||
- Open issues encourage community discussion and brainstorming. Prematurely assigning an issue can stifle input from others who might have better ideas or solutions.
|
||||
- As open-source work is often voluntary, and contributors' availability can change. Keeping issues unassigned allows anyone to step in if the original contributor becomes unavailable.
|
||||
This also supports multiple contributors collaborating on larger or complex issues.
|
||||
|
||||
### I have not contributed to any open source project before. Will I get any guidance?
|
||||
|
||||
In case you are new to the open source ecosystem, we would be more than happy to guide you through the entire process. Just join our [Discord server](https://bit.ly/heyfoss) and drop a message in the **#foss** channel.
|
||||
|
||||
## Code Contribution Guidelines
|
||||
|
||||
### Some things to keep in mind before opening a PR
|
||||
|
||||
> PRs with precise changes (like adding a new test, resolving a bug/issue, adding a new feature) are always preferred over a single PR with a ton of file changes as they are easier to review and merge.
|
||||
|
@ -89,7 +89,7 @@ API Dash can be downloaded from the links below:
|
||||
| --- | --- |
|
||||
| Postman | ✅ |
|
||||
| cURL | ✅ |
|
||||
| Insomnia | https://github.com/foss42/apidash/issues/125 |
|
||||
| Insomnia | ✅ |
|
||||
| OpenAPI | https://github.com/foss42/apidash/issues/121 |
|
||||
| hurl | https://github.com/foss42/apidash/issues/123 |
|
||||
| HAR | https://github.com/foss42/apidash/issues/122 |
|
||||
|
@ -23,7 +23,58 @@
|
||||
|
||||
## Arch Linux (PKGBUILD)
|
||||
|
||||
TODO Instructions
|
||||
Steps to update and release the Arch Linux package
|
||||
|
||||
1. Install required packages:
|
||||
|
||||
```bash
|
||||
sudo pacman -S base-devel
|
||||
```
|
||||
|
||||
2. Clone the ApiDash AUR repository:
|
||||
|
||||
```bash
|
||||
git clone https://aur.archlinux.org/apidash-bin.git
|
||||
cd apidash-bin
|
||||
```
|
||||
|
||||
3. Get the recent `.deb` release from the [releases page](https://github.com/foss42/apidash/releases/)
|
||||
|
||||
4. Generate new checksums:
|
||||
|
||||
```bash
|
||||
sha512sum apidash-linux-amd64.deb LICENSE
|
||||
```
|
||||
|
||||
5. Update the `PKGBUILD` file:
|
||||
|
||||
- Change `pkgver` to the new version
|
||||
- Reset `pkgrel` to 1
|
||||
- Update `sha512sums` with the new checksums
|
||||
|
||||
6. Build the package
|
||||
|
||||
```bash
|
||||
# Clean build files (if they exist from previous builds)
|
||||
# rm -rf pkg/ src/
|
||||
|
||||
# Build and install the package
|
||||
makepkg -si
|
||||
```
|
||||
|
||||
7. Update .SRCINFO:
|
||||
|
||||
```bash
|
||||
makepkg --printsrcinfo > .SRCINFO
|
||||
```
|
||||
|
||||
8. Commit and push the changes:
|
||||
|
||||
```bash
|
||||
git add PKGBUILD .SRCINFO
|
||||
git commit -m "Update to v[NEW_VERSION]"
|
||||
git push
|
||||
```
|
||||
|
||||
## FlatHub (Flatpak)
|
||||
|
||||
|
@ -25,9 +25,24 @@ You can read more [here](https://docs.flutter.dev/platform-integration/macos/bui
|
||||
|
||||
In case you are having a local build failure on macOS due to "audio_session" do check out issue https://github.com/foss42/apidash/issues/510 for solution.
|
||||
|
||||
## Android (Work in Progress)
|
||||
## Android
|
||||
|
||||
Add the `multiDexEnabled true` line to the `defaultConfig` section at `android/app/build.gradle file`
|
||||
In case you are targeting the Android API level <21 or the project and the libraries it references exceed 65,536 methods, you encounter the following build error that indicates your app has reached the limit of the Android build architecture:
|
||||
|
||||
```
|
||||
trouble writing output:
|
||||
Too many field references: 131000; max is 65536.
|
||||
You may try using --multi-dex option.
|
||||
```
|
||||
|
||||
OR
|
||||
|
||||
```
|
||||
Conversion to Dalvik format failed:
|
||||
Unable to execute dex: method ID not in [0, 0xffff]: 65536
|
||||
```
|
||||
|
||||
To solve this problem, add the `multiDexEnabled true` line to the `defaultConfig` section in `android/app/build.gradle file`
|
||||
|
||||
```
|
||||
android {
|
||||
@ -39,7 +54,38 @@ android {
|
||||
}
|
||||
```
|
||||
|
||||
For more information on multidex support, you can refer to the Android developer guide on [Configuring Multidex](https://developer.android.com/studio/build/multidex).
|
||||
For more information on multidex support, you can refer to the Android developer guide on [Configuring Multidex](https://developer.android.com/studio/build/multidex).
|
||||
|
||||
If you are experiencing build failure issues while debugging due to Gradle/JDK/AGP version resolving try upgrading the gradle version by CLI command
|
||||
|
||||
```
|
||||
gradle wrapper --gradle-version <latest compatible version>
|
||||
```
|
||||
|
||||
In case the above command fails, edit the Gradle distribution reference in the `gradle/wrapper/gradle-wrapper.properties` file. The following example sets the Gradle version to 8.8 in the `gradle-wrapper.properties` file.
|
||||
|
||||
```
|
||||
...
|
||||
distributionUrl = https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
...
|
||||
```
|
||||
|
||||
Upgrade AGP by specifying the plugin version in the top-level `build.gradle` file. The following example sets the plugin to version 8.8.0 from the `build.gradle` file:
|
||||
|
||||
```
|
||||
plugins {
|
||||
...
|
||||
id 'com.android.application' version '8.8.0' apply false
|
||||
id 'com.android.library' version '8.8.0' apply false
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
For more information on:
|
||||
- Gradle and Java version compatibility, you can refer to [Compatibility Matrix](https://docs.gradle.org/current/userguide/compatibility.html).
|
||||
- Gradle and Android Gradle Plugin compatibility, you can refer to [Update Gradle](https://developer.android.com/build/releases/gradle-plugin).
|
||||
|
||||
Note : It is highly recommended that always ensure gradle and agp versions are compatible with your JDK version not the vice-versa and having atleast JDK 17 is recommmended.
|
||||
|
||||
## Web
|
||||
|
||||
|
94
doc/proposals/2025/fosshack/dark_knight_history.md
Normal file
94
doc/proposals/2025/fosshack/dark_knight_history.md
Normal file
@ -0,0 +1,94 @@
|
||||
# History Service Implementation for Auto-Clearing API Requests
|
||||
|
||||
Initial proposals:
|
||||
- https://github.com/foss42/apidash/pull/577
|
||||
- https://github.com/foss42/apidash/pull/578
|
||||
|
||||
Issue - https://github.com/foss42/apidash/issues/551
|
||||
PR - https://github.com/foss42/apidash/pull/604 https://github.com/foss42/apidash/pull/616
|
||||
Project Link - https://fossunited.org/hack/fosshack25/p/i0aod39ham
|
||||
|
||||
## Team Dart Knight
|
||||
|
||||
+ User - `Vishwa Karthik`
|
||||
+ Mail - `vishwa.prarthana@gmail.com`
|
||||
|
||||
## Do Checkout
|
||||
+ [Issues with Isolate & Compute Methodology](https://github.com/foss42/apidash/pull/604#issuecomment-2676863276)
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
This document outlines the implementation of the autoClearHistory feature in APIDASH to efficiently manage stored API request history while maintaining a smooth user experience across all supported platforms.
|
||||
|
||||
## Features
|
||||
### Auto-Clear History on App Launch
|
||||
|
||||
+ When the app is launched, it automatically clears 50 old API records to prevent excessive local storage usage.
|
||||
|
||||
+ This helps in keeping the app responsive and prevents unnecessary memory consumption.
|
||||
|
||||
+ Triggered using autoClearHistory() from HistoryServiceImpl.
|
||||
|
||||
### Dynamic Auto-Clear Trigger (State Management-Based)
|
||||
|
||||
+ Uses Riverpod StateNotifier to monitor the API request list dynamically.
|
||||
|
||||
+ If the length exceeds 50, the history clearance is automatically triggered, just to avoid heavy duty on app launch.
|
||||
|
||||
+ Reason to use State management here is to resist unnecessary local database call because user may keep switching apps/window during development cycle.
|
||||
|
||||
### Platform-Specific Cleanup Handling
|
||||
|
||||
+ For Android & iOS: Uses AppLifecycleState.paused via WidgetsBindingObserver to trigger autoClearHistory() when the app goes to the background.
|
||||
|
||||
+ For Windows, macOS, Linux:Uses window_manager to detect app minimize events and trigger cleanup accordingly.
|
||||
|
||||
+ Ensures proper handling since AppLifecycleState does not work on desktops.
|
||||
|
||||
### Batch Deletion Strategy
|
||||
|
||||
+ Deleting 50 records at a time minimizes performance issues.
|
||||
|
||||
+ Ensures smooth UX by avoiding excessive database transactions.
|
||||
|
||||
+ Users can continue adding new requests seamlessly without experiencing lag.
|
||||
|
||||
## [Issues with Clearing via Isolates](https://github.com/foss42/apidash/pull/604)
|
||||
|
||||
## My Findings...
|
||||
|
||||
Local Database Hive do not support concurrent connections or transactions due to Native OS locking the hive files on the user desired directory, (hive.lock) files.
|
||||
|
||||
+ Linux Based Arch Distributions and Apple System follow strict file lock system and wouldn't allow opening or accessing boxes from multiple isolates.
|
||||
|
||||
## Reasoning
|
||||
+ `Hive.init` and `hive.initFlutter` are both method-channel and main UI thread operations which needs many data accessibility which are only available in main thread isolate.
|
||||
|
||||
## Cheap Work Around Solution
|
||||
1. Close Hive in the main thread
|
||||
2. Start an isolate
|
||||
3. Initialize Hive in that isolate
|
||||
4. Offload tasks to new isolate & Close Hive
|
||||
5. Re-Open Hive Box in the main thread
|
||||
|
||||
## Problems
|
||||
+ Although the database transactions are fast, there are high chances the database behavior becomes highly unpredictable.
|
||||
+ The cleaning service job trigger logic had to changed, since calling it main function may become stupidity.
|
||||
|
||||
## Technical Issues
|
||||
+ With issues stated, frequent switches between threads will make too many open/close hive boxes to hinder performance of the app.
|
||||
+ App may stop working abruptly
|
||||
+ IOS Production app may not allow these operations to do so, and may kill the app.
|
||||
+ The Hive documentation clearly states that it is not designed for multi-threaded use.
|
||||
+ Simultaneous reads/writes across isolates may lead to inconsistencies.
|
||||
|
||||
## What about... [PR 604](https://github.com/foss42/apidash/pull/604)
|
||||
+ The reason why it could have worked for Android, is due to its lenient OS behavior although its Linux-based distribution.
|
||||
+ Even though Android doesn't throw an error, it's still not safe to open Hive in multiple isolates.
|
||||
|
||||
## Note
|
||||
+ There is another database called 'Isar' which probably supports multi-threaded concurrent transactions which could have been possible to resolve this functionality.
|
||||
|
||||
## Conclusion
|
||||
+ The issue opened is very real but the way it has to be tackled is just to clear them in main isolate using optimization techniques like batch request, clearing history in frequent intervals and few more everything in Main Thread ONLY.
|
5
doc/proposals/2025/fosshack/hackelements.md
Normal file
5
doc/proposals/2025/fosshack/hackelements.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Documentation chnages for Android
|
||||
|
||||
Issue - https://github.com/foss42/apidash/issues/584
|
||||
PR - https://github.com/foss42/apidash/pull/589
|
||||
Link - https://fossunited.org/hack/fosshack25/p/alqifpr39s
|
86
doc/proposals/2025/fosshack/mavericks_chatbot.md
Normal file
86
doc/proposals/2025/fosshack/mavericks_chatbot.md
Normal file
@ -0,0 +1,86 @@
|
||||
# Add ChatBot for API Assistance
|
||||
|
||||
Issue - https://github.com/foss42/apidash/issues/605
|
||||
PR - https://github.com/foss42/apidash/pull/608
|
||||
Link - https://fossunited.org/hack/fosshack25/p/7e6upj6f19
|
||||
|
||||
### What we planned to do:
|
||||
|
||||
We aim to implement a **ChatBot feature** in API Dash with the following capabilities:
|
||||
|
||||
1. **Explain API**:
|
||||
- **Description**: Analyze API responses and provide explanations in natural language.
|
||||
- **Features**: Generate clear descriptions of the API, including:
|
||||
- Purpose of the API.
|
||||
- Key parameters and their roles.
|
||||
- Response structure and fields.
|
||||
- Useful for **documentation** and **understanding API behavior**.
|
||||
2. **Debug Requests Based on Status Codes & Error Messages**:
|
||||
- **Description**: Provide **structured debugging suggestions** for failed API requests.
|
||||
- **Features**:
|
||||
- Analyze status codes (e.g., 4xx, 5xx) and error messages.
|
||||
- Offer step-by-step guidance to resolve issues.
|
||||
3. **Generate Test Cases**:
|
||||
- **Description**: Automatically generate **test cases** for API endpoints.
|
||||
- **Features**: Includes
|
||||
- Valid input scenarios.
|
||||
- Edge cases (e.g., invalid inputs, boundary values).
|
||||
- Expected responses and status codes.
|
||||
- Ensure test cases are **ready to use** in testing frameworks
|
||||
4. **Generate Sample Codes**:
|
||||
- **Description**: Generate **ready-to-run code snippets** for various programming languages (e.g., Dart, Python, JavaScript, React, Flutter).
|
||||
- **Features:** Includes
|
||||
- API integration code.
|
||||
- Error handling.
|
||||
- UI components for frontend frameworks (e.g: React).
|
||||
- Ensure the code is **directly usable** with minimal modifications.
|
||||
|
||||
## What we built
|
||||
|
||||
### **1. Ollama Model Integration**
|
||||
|
||||
- **Dependency**: We integrated the AI chatbot with API Dash using the `ollama_dart: ^0.2.2` package.
|
||||
- **System Requirements**: To use the Ollama model, the system must have the Ollama application installed locally with a compatible model.
|
||||
- **Implementation**:
|
||||
- The interaction with the Ollama model is handled in `lib/services/ollama_services.dart`.
|
||||
- We tested multiple models, including `deepseek:r1:1.5b`, `ollama3.2:3b`, and `llama3.2:1b`.
|
||||
- Among these, `ollama3.2:3b` delivered the most accurate responses.
|
||||
- **Recommendation**: Use `ollama3.2:3b` or higher models for better accuracy.
|
||||
- **Customization**: Developers can switch models by modifying the “`model:''`” parameter in `/apidash/lib/services/ollama_service.dart`.
|
||||
|
||||
### **2. Dynamic UI: ChatBot Widget**
|
||||
|
||||
- **Design**:
|
||||
- A mini widget (`?`) is placed at the bottom right of the response panel.
|
||||
- When clicked, it expands into an AI chatbot interface.
|
||||
- **Features**:
|
||||
- **Explain API**: Provides explanations for API functionalities.
|
||||
- **Debug API**: Assists in debugging API-related issues.
|
||||
- **Test Cases**: Generates test cases for APIs.
|
||||
- **Generate Code**: Helps in generating code snippets for API integration.
|
||||
- **General Questions**: Users can ask general questions about ApiDash.
|
||||
- **Markdown Support**:
|
||||
- We used the `“package:flutter_markdown/flutter_markdown.dart”`package to format and display responses in a clean, readable manner.
|
||||
|
||||
|
||||
### Setup Guide
|
||||
|
||||
- Install the updated dependency`ollama_dart: ^0.2.2`
|
||||
- To use the Ollama model, the system must have the Ollama application installed locally with a compatible model.
|
||||
- The interaction with the Ollama model is handled in `lib/services/ollama_services.dart`.
|
||||
- **Recommendation**: Use `ollama3.2:3b` or higher models for better accuracy.
|
||||
- Developers need to switch models by modifying the “`model:''`” parameter in `/apidash/lib/services/ollama_service.dart` to their local Ollama model to interact.
|
||||
- There you go now run `flutter run` to use AI Chatbot in ApiDash.
|
||||
|
||||
|
||||
## Issues
|
||||
1. **Enhance Response Formatting**: Improve the AI to ensure consistent markdown formatting in responses, eliminating plain text outputs.
|
||||
2. **Optimize Structured Outputs**: Fine-tune the AI to generate more organized and structured responses for better usability and clarity.
|
||||
|
||||
|
||||
## Future Enhancements:
|
||||
1. Enable users to integrate their local Ollama models seamlessly through the ChatBot interface for enhanced customization.
|
||||
2. Enable one-click downloading and copying of test codes, ensuring a seamless workflow for developers.
|
||||
3. Implementing a feature to generate test codes dynamically based on API endpoints and user inputs.
|
||||
4. A feature to Integrate with complete system architecture
|
||||
5. Suggesting the best practices from selected type of requests.
|
23
doc/proposals/2025/fosshack/nihal_arch_packaging.md
Normal file
23
doc/proposals/2025/fosshack/nihal_arch_packaging.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Add Arch Linux packaging instructions and CI Pipeline
|
||||
|
||||
Issue - https://github.com/foss42/apidash/issues/545
|
||||
PR - https://github.com/foss42/apidash/pull/594
|
||||
Link - https://fossunited.org/hack/fosshack25/p/e5n4kirnno
|
||||
|
||||
A GitHub action is triggered on new version tags when `pubspec.yaml` changes
|
||||
|
||||
It:
|
||||
- Extracts version from pubspec.yaml
|
||||
- Downloads and generates checksums for the .deb package and LICENSE
|
||||
- Updates the PKGBUILD with new version and checksums
|
||||
- Publishes to AUR using the KSXGitHub/github-actions-deploy-aur action
|
||||
|
||||
The following secrets need to be added to the GitHub repository:
|
||||
|
||||
- `AUR_USERNAME`: Maintainer's AUR username
|
||||
- `AUR_EMAIL`: Maintainer's AUR email address
|
||||
- `AUR_SSH_PRIVATE_KEY`: Maintiner's SSH private key with AUR access
|
||||
|
||||
Adding workflow for `.deb` turned out to be complex than I had thought.
|
||||
I have added the support for arm64 and this will assume `.deb` files are available at release time.
|
||||
If they’re not, it will fail, prompting manual intervention or a separate release process.
|
@ -96,8 +96,6 @@ enum SidebarMenuOption {
|
||||
final String label;
|
||||
}
|
||||
|
||||
enum EnvironmentVariableType { variable, secret }
|
||||
|
||||
final kEnvVarRegEx = RegExp(r'{{([^{}]*)}}');
|
||||
|
||||
enum CodegenLanguage {
|
||||
@ -141,7 +139,8 @@ enum CodegenLanguage {
|
||||
|
||||
enum ImportFormat {
|
||||
curl("cURL"),
|
||||
postman("Postman Collection v2.1");
|
||||
postman("Postman Collection v2.1"),
|
||||
insomnia("Insomnia v4");
|
||||
|
||||
const ImportFormat(this.label);
|
||||
final String label;
|
||||
@ -432,6 +431,7 @@ const kLabelSelect = "Select";
|
||||
const kLabelContinue = "Continue";
|
||||
const kLabelCancel = "Cancel";
|
||||
const kLabelOk = "Ok";
|
||||
const kLabelImport = "Import";
|
||||
const kUntitled = "untitled";
|
||||
// Request Pane
|
||||
const kLabelRequest = "Request";
|
||||
|
@ -12,6 +12,7 @@ class Importer {
|
||||
?.map((t) => (null, t))
|
||||
.toList(),
|
||||
ImportFormat.postman => PostmanIO().getHttpRequestModelList(content),
|
||||
ImportFormat.insomnia => InsomniaIO().getHttpRequestModelList(content),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
export 'environment_model.dart';
|
||||
export 'history_meta_model.dart';
|
||||
export 'history_request_model.dart';
|
||||
export 'request_model.dart';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/environment_model.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/utils/file_utils.dart';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../services/services.dart' show hiveHandler, HiveHandler;
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
|
||||
import 'envvar_indicator.dart';
|
||||
|
||||
class EnvironmentTriggerOptions extends ConsumerWidget {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
class EnvVarIndicator extends StatelessWidget {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'common_widgets.dart';
|
||||
|
||||
class EnvVarPopover extends StatelessWidget {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'dart:math';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:data_table_2/data_table_2.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'dart:math';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:data_table_2/data_table_2.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
@ -1,8 +1,8 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:apidash/models/environment_model.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
|
||||
String getEnvironmentTitle(String? name) {
|
||||
if (name == null || name.trim() == "") {
|
||||
@ -86,6 +85,11 @@ HttpRequestModel substituteHttpRequestModel(
|
||||
value: substituteVariables(param.value, envMap, activeEnvironmentId),
|
||||
);
|
||||
}).toList(),
|
||||
body: substituteVariables(
|
||||
httpRequestModel.body,
|
||||
envMap,
|
||||
activeEnvironmentId,
|
||||
),
|
||||
);
|
||||
return newRequestModel;
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'drag_and_drop_area.dart';
|
||||
import 'dropdown_import_format.dart';
|
||||
import '../consts.dart';
|
||||
|
||||
showImportDialog({
|
||||
required BuildContext context,
|
||||
@ -17,14 +18,15 @@ showImportDialog({
|
||||
return StatefulBuilder(
|
||||
builder: (context, StateSetter setState) {
|
||||
return AlertDialog(
|
||||
contentPadding: const EdgeInsets.all(12),
|
||||
contentPadding: kP12,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Import "),
|
||||
const Text(kLabelImport),
|
||||
kHSpacer8,
|
||||
DropdownButtonImportFormat(
|
||||
importFormat: fmt,
|
||||
onChanged: (format) {
|
||||
@ -38,6 +40,7 @@ showImportDialog({
|
||||
),
|
||||
],
|
||||
),
|
||||
kVSpacer6,
|
||||
DragAndDropArea(
|
||||
onFileDropped: onFileDropped,
|
||||
),
|
||||
|
@ -10,13 +10,14 @@ class SidebarTopMenu extends StatelessWidget {
|
||||
this.splashRadius = 14,
|
||||
this.tooltip,
|
||||
this.shape,
|
||||
this.menuPadding,
|
||||
});
|
||||
final Widget? child;
|
||||
final Offset offset;
|
||||
final double splashRadius;
|
||||
final String? tooltip;
|
||||
final ShapeBorder? shape;
|
||||
|
||||
final EdgeInsets? menuPadding;
|
||||
final Function(SidebarMenuOption)? onSelected;
|
||||
|
||||
@override
|
||||
@ -30,6 +31,7 @@ class SidebarTopMenu extends StatelessWidget {
|
||||
offset: offset,
|
||||
onSelected: onSelected,
|
||||
shape: shape,
|
||||
menuPadding: menuPadding,
|
||||
itemBuilder: (BuildContext context) => SidebarMenuOption.values
|
||||
.map<PopupMenuEntry<SidebarMenuOption>>(
|
||||
(e) => PopupMenuItem<SidebarMenuOption>(
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
import '../consts.dart';
|
||||
|
||||
|
@ -9,6 +9,8 @@ enum APIType {
|
||||
final String abbr;
|
||||
}
|
||||
|
||||
enum EnvironmentVariableType { variable, secret }
|
||||
|
||||
enum HTTPVerb {
|
||||
get("GET"),
|
||||
head("HEAD"),
|
||||
|
@ -1,2 +1,3 @@
|
||||
export 'curl_io.dart';
|
||||
export 'postman_io.dart';
|
||||
export 'insomnia_io.dart';
|
||||
|
117
packages/apidash_core/lib/import_export/insomnia_io.dart
Normal file
117
packages/apidash_core/lib/import_export/insomnia_io.dart
Normal file
@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:insomnia_collection/insomnia_collection.dart';
|
||||
import 'package:seed/seed.dart';
|
||||
import '../consts.dart';
|
||||
import '../models/models.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class InsomniaIO {
|
||||
List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) {
|
||||
content = content.trim();
|
||||
try {
|
||||
final ic = insomniaCollectionFromJsonStr(content);
|
||||
final requests = getRequestsFromInsomniaCollection(ic);
|
||||
|
||||
return requests
|
||||
.map((req) => (req.$1, insomniaResourceToHttpRequestModel(req.$2)))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
debugPrint("$e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
HttpRequestModel insomniaResourceToHttpRequestModel(Resource resource) {
|
||||
HTTPVerb method;
|
||||
try {
|
||||
method = HTTPVerb.values.byName((resource.method ?? "").toLowerCase());
|
||||
} catch (e) {
|
||||
method = kDefaultHttpMethod;
|
||||
}
|
||||
String url = stripUrlParams(resource.url ?? "");
|
||||
List<NameValueModel> headers = [];
|
||||
List<bool> isHeaderEnabledList = [];
|
||||
|
||||
List<NameValueModel> params = [];
|
||||
List<bool> isParamEnabledList = [];
|
||||
|
||||
for (var header in resource.headers ?? <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 resource.parameters ?? <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 =
|
||||
getContentTypeFromContentTypeStr(resource.body?.mimeType) ??
|
||||
kDefaultContentType;
|
||||
|
||||
String? body;
|
||||
List<FormDataModel>? formData;
|
||||
if (resource.body != null && resource.body?.mimeType != null) {
|
||||
if (bodyContentType == ContentType.formdata) {
|
||||
formData = [];
|
||||
for (var fd in resource.body?.params ?? <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 {
|
||||
body = resource.body?.text;
|
||||
}
|
||||
}
|
||||
|
||||
return HttpRequestModel(
|
||||
method: method,
|
||||
url: url,
|
||||
headers: headers,
|
||||
params: params,
|
||||
isHeaderEnabledList: isHeaderEnabledList,
|
||||
isParamEnabledList: isParamEnabledList,
|
||||
body: body,
|
||||
bodyContentType: bodyContentType,
|
||||
formData: formData,
|
||||
);
|
||||
}
|
||||
|
||||
EnvironmentModel insomniaResourceToEnvironmentModel(Resource resource) {
|
||||
List<EnvironmentVariableModel> variables = [];
|
||||
for (var envvar in resource.kvPairData!) {
|
||||
variables.add(EnvironmentVariableModel(
|
||||
key: envvar.name ?? "",
|
||||
value: envvar.value ?? "",
|
||||
enabled: envvar.enabled ?? true,
|
||||
type: envvar.type == "secret"
|
||||
? EnvironmentVariableType.secret
|
||||
: EnvironmentVariableType.variable,
|
||||
));
|
||||
}
|
||||
return EnvironmentModel(
|
||||
id: resource.id!,
|
||||
name: resource.name ?? "",
|
||||
values: variables,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import '../consts.dart';
|
||||
|
||||
part 'environment_model.freezed.dart';
|
||||
|
@ -1,2 +1,3 @@
|
||||
export 'environment_model.dart';
|
||||
export 'http_request_model.dart';
|
||||
export 'http_response_model.dart';
|
||||
|
@ -7,15 +7,7 @@ ContentType? getContentTypeFromHeadersMap(
|
||||
) {
|
||||
if (kvMap != null && kvMap.hasKeyContentType()) {
|
||||
var val = getMediaTypeFromHeaders(kvMap);
|
||||
if (val != null) {
|
||||
if (val.subtype.contains(kSubTypeJson)) {
|
||||
return ContentType.json;
|
||||
} else if (val.type == kTypeMultipart &&
|
||||
val.subtype == kSubTypeFormData) {
|
||||
return ContentType.formdata;
|
||||
}
|
||||
return ContentType.text;
|
||||
}
|
||||
return getContentTypeFromMediaType(val);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -37,3 +29,26 @@ MediaType? getMediaTypeFromContentType(String? contentType) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ContentType? getContentTypeFromMediaType(MediaType? mediaType) {
|
||||
if (mediaType != null) {
|
||||
if (mediaType.subtype.contains(kSubTypeJson)) {
|
||||
return ContentType.json;
|
||||
} else if (mediaType.type == kTypeMultipart &&
|
||||
mediaType.subtype == kSubTypeFormData) {
|
||||
return ContentType.formdata;
|
||||
}
|
||||
return ContentType.text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ContentType? getContentTypeFromContentTypeStr(
|
||||
String? contentType,
|
||||
) {
|
||||
if (contentType != null) {
|
||||
var val = getMediaTypeFromContentType(contentType);
|
||||
return getContentTypeFromMediaType(val);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ dependencies:
|
||||
http_parser: ^4.0.2
|
||||
postman:
|
||||
path: ../postman
|
||||
insomnia_collection:
|
||||
path: ../insomnia_collection
|
||||
seed: ^0.0.3
|
||||
xml: ^6.3.0
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
# melos_managed_dependency_overrides: curl_parser,postman,seed
|
||||
# melos_managed_dependency_overrides: curl_parser,postman,seed,insomnia_collection
|
||||
dependency_overrides:
|
||||
curl_parser:
|
||||
path: ../curl_parser
|
||||
insomnia_collection:
|
||||
path: ../insomnia_collection
|
||||
postman:
|
||||
path: ../postman
|
||||
seed:
|
||||
|
@ -26,13 +26,14 @@ const kP4 = EdgeInsets.all(4);
|
||||
const kP5 = EdgeInsets.all(5);
|
||||
const kP6 = EdgeInsets.all(6);
|
||||
const kP8 = EdgeInsets.all(8);
|
||||
const kP10 = EdgeInsets.all(10);
|
||||
const kP12 = EdgeInsets.all(12);
|
||||
const kPs8 = EdgeInsets.only(left: 8);
|
||||
const kPs2 = EdgeInsets.only(left: 2);
|
||||
const kPe4 = EdgeInsets.only(right: 4);
|
||||
const kPe8 = EdgeInsets.only(right: 8);
|
||||
const kPh20v5 = EdgeInsets.symmetric(horizontal: 20, vertical: 5);
|
||||
const kPh20v10 = EdgeInsets.symmetric(horizontal: 20, vertical: 10);
|
||||
const kP10 = EdgeInsets.all(10);
|
||||
const kPv2 = EdgeInsets.symmetric(vertical: 2);
|
||||
const kPv6 = EdgeInsets.symmetric(vertical: 6);
|
||||
const kPv8 = EdgeInsets.symmetric(vertical: 8);
|
||||
@ -92,6 +93,7 @@ const kHSpacer20 = SizedBox(width: 20);
|
||||
const kHSpacer40 = SizedBox(width: 40);
|
||||
const kVSpacer3 = SizedBox(height: 3);
|
||||
const kVSpacer5 = SizedBox(height: 5);
|
||||
const kVSpacer6 = SizedBox(height: 6);
|
||||
const kVSpacer8 = SizedBox(height: 8);
|
||||
const kVSpacer10 = SizedBox(height: 10);
|
||||
const kVSpacer16 = SizedBox(height: 16);
|
||||
|
30
packages/insomnia_collection/.gitignore
vendored
Normal file
30
packages/insomnia_collection/.gitignore
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
# 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/
|
||||
coverage/
|
3
packages/insomnia_collection/CHANGELOG.md
Normal file
3
packages/insomnia_collection/CHANGELOG.md
Normal file
@ -0,0 +1,3 @@
|
||||
## 0.0.1
|
||||
|
||||
- Implement fromJson object and fromJson String for Insomnia v4 json format
|
201
packages/insomnia_collection/LICENSE
Normal file
201
packages/insomnia_collection/LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2023 Ashita Prasad, Ankit Mahato
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
396
packages/insomnia_collection/README.md
Normal file
396
packages/insomnia_collection/README.md
Normal file
@ -0,0 +1,396 @@
|
||||
# insomnia
|
||||
|
||||
Seamlessly convert Insomnia Collection Format v4 to Dart.
|
||||
|
||||
Helps you bring your APIs stored in Insomnia to Dart and work with them.
|
||||
|
||||
Currently, this package is being used by [API Dash](https://github.com/foss42/apidash), a beautiful open-source cross-platform (macOS, Windows, Linux, Android & iOS) API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. A lightweight alternative to postman & insomnia.
|
||||
|
||||
## Usage
|
||||
|
||||
### Example 1: Insomnia collection JSON string to Insomnia model
|
||||
|
||||
```dart
|
||||
import 'package:insomnia_collection/insomnia_collection.dart';
|
||||
|
||||
void main() {
|
||||
// Example 1: Insomnia collection JSON string to Insomnia model
|
||||
var collectionJsonStr = r'''
|
||||
{
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-05T13:05:11.752Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id":"req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736112258432,
|
||||
"created":1736111908438,
|
||||
"url":"https://food-service-backend.onrender.com/api/users/",
|
||||
"name":"get-with-params",
|
||||
"description":"",
|
||||
"method":"GET",
|
||||
"body":{},
|
||||
"parameters": [
|
||||
{"id":"pair_bf0ae4f4280e440a8a591b64fd4ec4f4","name":"user_id","value":"34","description":"","disabled":false}
|
||||
],
|
||||
"headers":[{"name":"User-Agent","value":"insomnia/10.3.0"}],
|
||||
"authentication":{},
|
||||
"metaSortKey":-1736111908438,
|
||||
"isPrivate":false,
|
||||
"pathParameters":[],
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type":"request"
|
||||
},
|
||||
{
|
||||
"_id":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified":1736082089076,
|
||||
"created":1736082089076,
|
||||
"name":"APIDash-APItests",
|
||||
"description":"These are test endpoints for API Dash",
|
||||
"environment":{},"environmentPropertyOrder":null,
|
||||
"metaSortKey":-1736082080559,
|
||||
"preRequestScript":"",
|
||||
"afterResponseScript":"",
|
||||
"authentication":{},
|
||||
"_type":"request_group"
|
||||
},
|
||||
{"_id":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"parentId":null,
|
||||
"modified":1736082089075,
|
||||
"created":1736082089075,
|
||||
"name":"APIDash-APItests","description":"",
|
||||
"scope":"collection","_type":"workspace"},
|
||||
{
|
||||
"_id":"req_db3c393084f14369bb409afe857e390c",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736082089077,
|
||||
"created":1736082089077,
|
||||
"url":"https://api.apidash.dev/country/codes",
|
||||
"name":"test-get",
|
||||
"description":"",
|
||||
"method":"GET",
|
||||
"body":{},
|
||||
"parameters":[],
|
||||
"headers":[],
|
||||
"authentication":{},
|
||||
"preRequestScript":"",
|
||||
"metaSortKey":-1736082080558,
|
||||
"isPrivate":false,
|
||||
"afterResponseScript":"",
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects":"global",
|
||||
"_type":"request"},
|
||||
{"_id":"req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736082089078,"created":1736082089078,
|
||||
"url":"https://api.apidash.dev/case/lower",
|
||||
"name":"test-post",
|
||||
"description":"",
|
||||
"method":"POST",
|
||||
"body":{"mimeType":"application/json","text":"{\n \"text\": \"Grass is green\"\n}"},
|
||||
"parameters":[],
|
||||
"headers":[{"name":"Content-Type","value":"application/json"}],
|
||||
"authentication":{},
|
||||
"preRequestScript":"",
|
||||
"metaSortKey":-1736082080557,
|
||||
"isPrivate":false,
|
||||
"afterResponseScript":"",
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects":"global",
|
||||
"_type":"request"},
|
||||
{"_id":"req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736082089078,
|
||||
"created":1736082089078,
|
||||
"url":"https://reqres.in/api/users/2",
|
||||
"name":"test-put",
|
||||
"description":"",
|
||||
"method":"PUT",
|
||||
"body":{"mimeType":"application/json",
|
||||
"text":"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"},
|
||||
"parameters":[],
|
||||
"headers":[{"name":"Content-Type","value":"application/json"}],
|
||||
"authentication":{},
|
||||
"preRequestScript":"",
|
||||
"metaSortKey":-1736082080556,
|
||||
"isPrivate":false,
|
||||
"afterResponseScript":"",
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects":"global",
|
||||
"_type":"request"},
|
||||
{
|
||||
"_id":"env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified":1736082095630,"created":1736082095630,
|
||||
"name":"Base Environment",
|
||||
"data":{},"dataPropertyOrder":null,
|
||||
"color":null,
|
||||
"isPrivate":false,
|
||||
"metaSortKey":1736082095630,
|
||||
"environmentType":"kv",
|
||||
"_type":"environment"
|
||||
},
|
||||
{
|
||||
"_id":"jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified":1736082095688,
|
||||
"created":1736082095688,
|
||||
"name":"Default Jar",
|
||||
"cookies":[],
|
||||
"_type":"cookie_jar"
|
||||
}
|
||||
]
|
||||
}
|
||||
''';
|
||||
|
||||
|
||||
|
||||
var collection;
|
||||
try {
|
||||
collection = insomniaCollectionFromJsonStr(collectionJsonStr);
|
||||
|
||||
|
||||
|
||||
print(collection.exportSource);
|
||||
// insomnia.desktop.app:v10.3.0
|
||||
print(collection.resources?[3].name);
|
||||
// test-get
|
||||
print(collection.resources?[3].method);
|
||||
// GET
|
||||
print(collection.resources?[3].url);
|
||||
// https://api.apidash.dev/country/codes
|
||||
} catch (e) {
|
||||
print(e.toString() + 'error from collection');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Example 2: Insomnia collection from JSON
|
||||
|
||||
```dart
|
||||
import 'package:insomnia_collection/insomnia_collection.dart';
|
||||
|
||||
void main() {
|
||||
// Example 2: Insomnia collection from JSON
|
||||
var collectionJson = {
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-05T13:05:11.752Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id": "req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736112258432,
|
||||
"created": 1736111908438,
|
||||
"url": "https://food-service-backend.onrender.com/api/users/",
|
||||
"name": "get-with-params",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [
|
||||
{
|
||||
"id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4",
|
||||
"name": "user_id",
|
||||
"value": "34",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{"name": "User-Agent", "value": "insomnia/10.3.0"}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736111908438,
|
||||
"isPrivate": false,
|
||||
"pathParameters": [],
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082089076,
|
||||
"created": 1736082089076,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "These are test endpoints for API Dash",
|
||||
"environment": {},
|
||||
"environmentPropertyOrder": null,
|
||||
"metaSortKey": -1736082080559,
|
||||
"preRequestScript": "",
|
||||
"afterResponseScript": "",
|
||||
"authentication": {},
|
||||
"_type": "request_group"
|
||||
},
|
||||
{
|
||||
"_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"parentId": null,
|
||||
"modified": 1736082089075,
|
||||
"created": 1736082089075,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "",
|
||||
"scope": "collection",
|
||||
"_type": "workspace"
|
||||
},
|
||||
{
|
||||
"_id": "req_db3c393084f14369bb409afe857e390c",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089077,
|
||||
"created": 1736082089077,
|
||||
"url": "https://api.apidash.dev/country/codes",
|
||||
"name": "test-get",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [],
|
||||
"headers": [],
|
||||
"authentication": {},
|
||||
"preRequestScript": "",
|
||||
"metaSortKey": -1736082080558,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"name": "test-post",
|
||||
"description": "",
|
||||
"method": "POST",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text": "{\n \"text\": \"Grass is green\"\n}"
|
||||
},
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{"name": "Content-Type", "value": "application/json"}
|
||||
],
|
||||
"authentication": {},
|
||||
"preRequestScript": "",
|
||||
"metaSortKey": -1736082080557,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://reqres.in/api/users/2",
|
||||
"name": "test-put",
|
||||
"description": "",
|
||||
"method": "PUT",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text":
|
||||
"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"
|
||||
},
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{"name": "Content-Type", "value": "application/json"}
|
||||
],
|
||||
"authentication": {},
|
||||
"preRequestScript": "",
|
||||
"metaSortKey": -1736082080556,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095630,
|
||||
"created": 1736082095630,
|
||||
"name": "Base Environment",
|
||||
"data": {},
|
||||
"dataPropertyOrder": null,
|
||||
"color": null,
|
||||
"isPrivate": false,
|
||||
"metaSortKey": 1736082095630,
|
||||
"environmentType": "kv",
|
||||
"_type": "environment"
|
||||
},
|
||||
{
|
||||
"_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095688,
|
||||
"created": 1736082095688,
|
||||
"name": "Default Jar",
|
||||
"cookies": [],
|
||||
"_type": "cookie_jar"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var collection2;
|
||||
try {
|
||||
collection2 = InsomniaCollection.fromJson(collectionJson);
|
||||
print(collection2.exportSource);
|
||||
// insomnia.desktop.app:v10.3.0
|
||||
print(collection2.resources?[3].name);
|
||||
// test-get
|
||||
print(collection2.resources?[3].method);
|
||||
// GET
|
||||
print(collection2.resources?[3].url);
|
||||
// https://api.apidash.dev/country/codes
|
||||
} catch (e) {
|
||||
print(e.toString() + 'error from collection2');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Maintainer
|
||||
|
||||
- Ashita Prasad ([GitHub](https://github.com/ashitaprasad), [LinkedIn](https://www.linkedin.com/in/ashitaprasad/), [X](https://x.com/ashitaprasad))
|
||||
- Papa Kofi (contributor) ([GitHub](https://github.com/StormGear))
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the [Apache License 2.0](https://github.com/foss42/apidash/blob/main/packages/insomnia_collection/LICENSE).
|
6
packages/insomnia_collection/analysis_options.yaml
Normal file
6
packages/insomnia_collection/analysis_options.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
analyzer:
|
||||
exclude:
|
||||
- "**/*.g.dart"
|
||||
- "**/*.freezed.dart"
|
||||
errors:
|
||||
invalid_annotation_target: ignore
|
360
packages/insomnia_collection/example/insomnia_example.dart
Normal file
360
packages/insomnia_collection/example/insomnia_example.dart
Normal file
@ -0,0 +1,360 @@
|
||||
import 'package:insomnia_collection/insomnia_collection.dart';
|
||||
|
||||
void main() {
|
||||
// Example 1: Insomnia collection JSON string to Insomnia model
|
||||
var collectionJsonStr = r'''
|
||||
{
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-05T13:05:11.752Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id":"req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736112258432,
|
||||
"created":1736111908438,
|
||||
"url":"https://food-service-backend.onrender.com/api/users/",
|
||||
"name":"get-with-params",
|
||||
"description":"",
|
||||
"method":"GET",
|
||||
"body":{},
|
||||
"parameters": [
|
||||
{"id":"pair_bf0ae4f4280e440a8a591b64fd4ec4f4","name":"user_id","value":"34","description":"","disabled":false}
|
||||
],
|
||||
"headers":[{"name":"User-Agent","value":"insomnia/10.3.0"}],
|
||||
"authentication":{},
|
||||
"metaSortKey":-1736111908438,
|
||||
"isPrivate":false,
|
||||
"pathParameters":[],
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type":"request"
|
||||
},
|
||||
{
|
||||
"_id":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified":1736082089076,
|
||||
"created":1736082089076,
|
||||
"name":"APIDash-APItests",
|
||||
"description":"These are test endpoints for API Dash",
|
||||
"environment":{},"environmentPropertyOrder":null,
|
||||
"metaSortKey":-1736082080559,
|
||||
"preRequestScript":"",
|
||||
"afterResponseScript":"",
|
||||
"authentication":{},
|
||||
"_type":"request_group"
|
||||
},
|
||||
{"_id":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"parentId":null,
|
||||
"modified":1736082089075,
|
||||
"created":1736082089075,
|
||||
"name":"APIDash-APItests","description":"",
|
||||
"scope":"collection","_type":"workspace"},
|
||||
{
|
||||
"_id":"req_db3c393084f14369bb409afe857e390c",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736082089077,
|
||||
"created":1736082089077,
|
||||
"url":"https://api.apidash.dev/country/codes",
|
||||
"name":"test-get",
|
||||
"description":"",
|
||||
"method":"GET",
|
||||
"body":{},
|
||||
"parameters":[],
|
||||
"headers":[],
|
||||
"authentication":{},
|
||||
"preRequestScript":"",
|
||||
"metaSortKey":-1736082080558,
|
||||
"isPrivate":false,
|
||||
"afterResponseScript":"",
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects":"global",
|
||||
"_type":"request"},
|
||||
{"_id":"req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736082089078,"created":1736082089078,
|
||||
"url":"https://api.apidash.dev/case/lower",
|
||||
"name":"test-post",
|
||||
"description":"",
|
||||
"method":"POST",
|
||||
"body":{"mimeType":"application/json","text":"{\n \"text\": \"Grass is green\"\n}"},
|
||||
"parameters":[],
|
||||
"headers":[{"name":"Content-Type","value":"application/json"}],
|
||||
"authentication":{},
|
||||
"preRequestScript":"",
|
||||
"metaSortKey":-1736082080557,
|
||||
"isPrivate":false,
|
||||
"afterResponseScript":"",
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects":"global",
|
||||
"_type":"request"},
|
||||
{"_id":"req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified":1736082089078,
|
||||
"created":1736082089078,
|
||||
"url":"https://reqres.in/api/users/2",
|
||||
"name":"test-put",
|
||||
"description":"",
|
||||
"method":"PUT",
|
||||
"body":{"mimeType":"application/json",
|
||||
"text":"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"},
|
||||
"parameters":[],
|
||||
"headers":[{"name":"Content-Type","value":"application/json"}],
|
||||
"authentication":{},
|
||||
"preRequestScript":"",
|
||||
"metaSortKey":-1736082080556,
|
||||
"isPrivate":false,
|
||||
"afterResponseScript":"",
|
||||
"settingStoreCookies":true,
|
||||
"settingSendCookies":true,
|
||||
"settingDisableRenderRequestBody":false,
|
||||
"settingEncodeUrl":true,
|
||||
"settingRebuildPath":true,
|
||||
"settingFollowRedirects":"global",
|
||||
"_type":"request"},
|
||||
{"_id":"env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified":1736082095630,"created":1736082095630,
|
||||
"name":"Base Environment",
|
||||
"data":{},"dataPropertyOrder":null,
|
||||
"color":null,
|
||||
"isPrivate":false,
|
||||
"metaSortKey":1736082095630,
|
||||
"environmentType":"kv",
|
||||
"_type":"environment"
|
||||
},
|
||||
{
|
||||
"_id":"jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified":1736082095688,
|
||||
"created":1736082095688,
|
||||
"name":"Default Jar",
|
||||
"cookies":[],
|
||||
"_type":"cookie_jar"
|
||||
}
|
||||
]
|
||||
}
|
||||
''';
|
||||
|
||||
var collection;
|
||||
try {
|
||||
collection = insomniaCollectionFromJsonStr(collectionJsonStr);
|
||||
|
||||
print(collection.exportSource);
|
||||
// insomnia.desktop.app:v10.3.0
|
||||
print(collection.resources?[3].name);
|
||||
// test-get
|
||||
print(collection.resources?[3].method);
|
||||
// GET
|
||||
print(collection.resources?[3].url);
|
||||
// https://api.apidash.dev/country/codes
|
||||
} catch (e) {
|
||||
print(e.toString() + 'error from collection');
|
||||
}
|
||||
|
||||
// Example 2: Insomnia collection from JSON
|
||||
var collectionJson = {
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-05T13:05:11.752Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id": "req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736112258432,
|
||||
"created": 1736111908438,
|
||||
"url": "https://food-service-backend.onrender.com/api/users/",
|
||||
"name": "get-with-params",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [
|
||||
{
|
||||
"id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4",
|
||||
"name": "user_id",
|
||||
"value": "34",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{"name": "User-Agent", "value": "insomnia/10.3.0"}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736111908438,
|
||||
"isPrivate": false,
|
||||
"pathParameters": [],
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082089076,
|
||||
"created": 1736082089076,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "These are test endpoints for API Dash",
|
||||
"environment": {},
|
||||
"environmentPropertyOrder": null,
|
||||
"metaSortKey": -1736082080559,
|
||||
"preRequestScript": "",
|
||||
"afterResponseScript": "",
|
||||
"authentication": {},
|
||||
"_type": "request_group"
|
||||
},
|
||||
{
|
||||
"_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"parentId": null,
|
||||
"modified": 1736082089075,
|
||||
"created": 1736082089075,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "",
|
||||
"scope": "collection",
|
||||
"_type": "workspace"
|
||||
},
|
||||
{
|
||||
"_id": "req_db3c393084f14369bb409afe857e390c",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089077,
|
||||
"created": 1736082089077,
|
||||
"url": "https://api.apidash.dev/country/codes",
|
||||
"name": "test-get",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [],
|
||||
"headers": [],
|
||||
"authentication": {},
|
||||
"preRequestScript": "",
|
||||
"metaSortKey": -1736082080558,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"name": "test-post",
|
||||
"description": "",
|
||||
"method": "POST",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text": "{\n \"text\": \"Grass is green\"\n}"
|
||||
},
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{"name": "Content-Type", "value": "application/json"}
|
||||
],
|
||||
"authentication": {},
|
||||
"preRequestScript": "",
|
||||
"metaSortKey": -1736082080557,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://reqres.in/api/users/2",
|
||||
"name": "test-put",
|
||||
"description": "",
|
||||
"method": "PUT",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text":
|
||||
"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"
|
||||
},
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{"name": "Content-Type", "value": "application/json"}
|
||||
],
|
||||
"authentication": {},
|
||||
"preRequestScript": "",
|
||||
"metaSortKey": -1736082080556,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095630,
|
||||
"created": 1736082095630,
|
||||
"name": "Base Environment",
|
||||
"data": {},
|
||||
"dataPropertyOrder": null,
|
||||
"color": null,
|
||||
"isPrivate": false,
|
||||
"metaSortKey": 1736082095630,
|
||||
"environmentType": "kv",
|
||||
"_type": "environment"
|
||||
},
|
||||
{
|
||||
"_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095688,
|
||||
"created": 1736082095688,
|
||||
"name": "Default Jar",
|
||||
"cookies": [],
|
||||
"_type": "cookie_jar"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var collection2;
|
||||
try {
|
||||
collection2 = InsomniaCollection.fromJson(collectionJson);
|
||||
print(collection2.exportSource);
|
||||
// insomnia.desktop.app:v10.3.0
|
||||
print(collection2.resources?[3].name);
|
||||
// test-get
|
||||
print(collection2.resources?[3].method);
|
||||
// GET
|
||||
print(collection2.resources?[3].url);
|
||||
// https://api.apidash.dev/country/codes
|
||||
} catch (e) {
|
||||
print(e.toString() + 'error from collection2');
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
library insomnia_collection;
|
||||
|
||||
export 'models/models.dart';
|
||||
export 'utils/insomnia_utils.dart';
|
192
packages/insomnia_collection/lib/models/insomnia_collection.dart
Normal file
192
packages/insomnia_collection/lib/models/insomnia_collection.dart
Normal file
@ -0,0 +1,192 @@
|
||||
import 'dart:convert';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'insomnia_collection.freezed.dart';
|
||||
part 'insomnia_collection.g.dart';
|
||||
|
||||
InsomniaCollection insomniaCollectionFromJsonStr(String str) =>
|
||||
InsomniaCollection.fromJson(json.decode(str));
|
||||
|
||||
String insomniaCollectionToJsonStr(InsomniaCollection data) =>
|
||||
JsonEncoder.withIndent(' ').convert(data);
|
||||
|
||||
@freezed
|
||||
class InsomniaCollection with _$InsomniaCollection {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory InsomniaCollection({
|
||||
@JsonKey(name: '_type') String? type,
|
||||
@JsonKey(name: '__export_format') num? exportFormat,
|
||||
@JsonKey(name: '__export_date') String? exportDate,
|
||||
@JsonKey(name: '__export_source') String? exportSource,
|
||||
List<Resource>? resources,
|
||||
}) = _InsomniaCollection;
|
||||
|
||||
factory InsomniaCollection.fromJson(Map<String, dynamic> json) =>
|
||||
_$InsomniaCollectionFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Resource with _$Resource {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Resource({
|
||||
@JsonKey(name: '_id') String? id,
|
||||
String? parentId,
|
||||
num? modified,
|
||||
num? created,
|
||||
String? url,
|
||||
String? name,
|
||||
String? description,
|
||||
String? method,
|
||||
Body? body,
|
||||
String? preRequestScript,
|
||||
List<Parameter>? parameters,
|
||||
List<Header>? headers,
|
||||
dynamic authentication,
|
||||
num? metaSortKey,
|
||||
bool? isPrivate,
|
||||
List<dynamic>? pathParameters,
|
||||
String? afterResponseScript,
|
||||
bool? settingStoreCookies,
|
||||
bool? settingSendCookies,
|
||||
bool? settingDisableRenderRequestBody,
|
||||
bool? settingEncodeUrl,
|
||||
bool? settingRebuildPath,
|
||||
String? settingFollowRedirects,
|
||||
dynamic environment,
|
||||
dynamic environmentPropertyOrder,
|
||||
String? scope,
|
||||
dynamic data,
|
||||
dynamic dataPropertyOrder,
|
||||
dynamic color,
|
||||
List<Cookie>? cookies,
|
||||
String? fileName,
|
||||
String? contents,
|
||||
String? contentType,
|
||||
String? environmentType,
|
||||
List<KVPairDatum>? kvPairData,
|
||||
@JsonKey(name: '_type') String? type,
|
||||
}) = _Resource;
|
||||
|
||||
factory Resource.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResourceFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Body with _$Body {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Body({
|
||||
String? mimeType,
|
||||
String? text,
|
||||
List<Formdatum>? params,
|
||||
}) = _Body;
|
||||
|
||||
factory Body.fromJson(Map<String, dynamic> json) => _$BodyFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Formdatum with _$Formdatum {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Formdatum({
|
||||
String? name,
|
||||
String? value,
|
||||
String? type,
|
||||
@JsonKey(name: 'fileName') String? src,
|
||||
}) = _Formdatum;
|
||||
|
||||
factory Formdatum.fromJson(Map<String, dynamic> json) =>
|
||||
_$FormdatumFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Parameter with _$Parameter {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Parameter({
|
||||
String? id,
|
||||
String? name,
|
||||
String? value,
|
||||
String? description,
|
||||
bool? disabled,
|
||||
}) = _Parameter;
|
||||
|
||||
factory Parameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$ParameterFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Header with _$Header {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Header({
|
||||
String? name,
|
||||
String? value,
|
||||
bool? disabled,
|
||||
}) = _Header;
|
||||
|
||||
factory Header.fromJson(Map<String, dynamic> json) => _$HeaderFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Cookie with _$Cookie {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Cookie({
|
||||
String? key,
|
||||
String? value,
|
||||
String? domain,
|
||||
String? path,
|
||||
bool? secure,
|
||||
bool? httpOnly,
|
||||
bool? hostOnly,
|
||||
DateTime? creation,
|
||||
DateTime? lastAccessed,
|
||||
String? sameSite,
|
||||
String? id,
|
||||
}) = _Cookie;
|
||||
|
||||
factory Cookie.fromJson(Map<String, dynamic> json) => _$CookieFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class KVPairDatum with _$KVPairDatum {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory KVPairDatum({
|
||||
String? id,
|
||||
String? name,
|
||||
String? value,
|
||||
String? type,
|
||||
bool? enabled,
|
||||
}) = _KVPairDatum;
|
||||
|
||||
factory KVPairDatum.fromJson(Map<String, dynamic> json) =>
|
||||
_$KVPairDatumFromJson(json);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,249 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'insomnia_collection.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$InsomniaCollectionImpl _$$InsomniaCollectionImplFromJson(Map json) =>
|
||||
_$InsomniaCollectionImpl(
|
||||
type: json['_type'] as String?,
|
||||
exportFormat: json['__export_format'] as num?,
|
||||
exportDate: json['__export_date'] as String?,
|
||||
exportSource: json['__export_source'] as String?,
|
||||
resources: (json['resources'] as List<dynamic>?)
|
||||
?.map((e) => Resource.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$InsomniaCollectionImplToJson(
|
||||
_$InsomniaCollectionImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.type case final value?) '_type': value,
|
||||
if (instance.exportFormat case final value?) '__export_format': value,
|
||||
if (instance.exportDate case final value?) '__export_date': value,
|
||||
if (instance.exportSource case final value?) '__export_source': value,
|
||||
if (instance.resources?.map((e) => e.toJson()).toList() case final value?)
|
||||
'resources': value,
|
||||
};
|
||||
|
||||
_$ResourceImpl _$$ResourceImplFromJson(Map json) => _$ResourceImpl(
|
||||
id: json['_id'] as String?,
|
||||
parentId: json['parentId'] as String?,
|
||||
modified: json['modified'] as num?,
|
||||
created: json['created'] as num?,
|
||||
url: json['url'] as String?,
|
||||
name: json['name'] as String?,
|
||||
description: json['description'] as String?,
|
||||
method: json['method'] as String?,
|
||||
body: json['body'] == null
|
||||
? null
|
||||
: Body.fromJson(Map<String, dynamic>.from(json['body'] as Map)),
|
||||
preRequestScript: json['preRequestScript'] as String?,
|
||||
parameters: (json['parameters'] as List<dynamic>?)
|
||||
?.map((e) => Parameter.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
headers: (json['headers'] as List<dynamic>?)
|
||||
?.map((e) => Header.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
authentication: json['authentication'],
|
||||
metaSortKey: json['metaSortKey'] as num?,
|
||||
isPrivate: json['isPrivate'] as bool?,
|
||||
pathParameters: json['pathParameters'] as List<dynamic>?,
|
||||
afterResponseScript: json['afterResponseScript'] as String?,
|
||||
settingStoreCookies: json['settingStoreCookies'] as bool?,
|
||||
settingSendCookies: json['settingSendCookies'] as bool?,
|
||||
settingDisableRenderRequestBody:
|
||||
json['settingDisableRenderRequestBody'] as bool?,
|
||||
settingEncodeUrl: json['settingEncodeUrl'] as bool?,
|
||||
settingRebuildPath: json['settingRebuildPath'] as bool?,
|
||||
settingFollowRedirects: json['settingFollowRedirects'] as String?,
|
||||
environment: json['environment'],
|
||||
environmentPropertyOrder: json['environmentPropertyOrder'],
|
||||
scope: json['scope'] as String?,
|
||||
data: json['data'],
|
||||
dataPropertyOrder: json['dataPropertyOrder'],
|
||||
color: json['color'],
|
||||
cookies: (json['cookies'] as List<dynamic>?)
|
||||
?.map((e) => Cookie.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
fileName: json['fileName'] as String?,
|
||||
contents: json['contents'] as String?,
|
||||
contentType: json['contentType'] as String?,
|
||||
environmentType: json['environmentType'] as String?,
|
||||
kvPairData: (json['kvPairData'] as List<dynamic>?)
|
||||
?.map(
|
||||
(e) => KVPairDatum.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
type: json['_type'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ResourceImplToJson(_$ResourceImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.id case final value?) '_id': value,
|
||||
if (instance.parentId case final value?) 'parentId': value,
|
||||
if (instance.modified case final value?) 'modified': value,
|
||||
if (instance.created case final value?) 'created': value,
|
||||
if (instance.url case final value?) 'url': value,
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.description case final value?) 'description': value,
|
||||
if (instance.method case final value?) 'method': value,
|
||||
if (instance.body?.toJson() case final value?) 'body': value,
|
||||
if (instance.preRequestScript case final value?)
|
||||
'preRequestScript': value,
|
||||
if (instance.parameters?.map((e) => e.toJson()).toList()
|
||||
case final value?)
|
||||
'parameters': value,
|
||||
if (instance.headers?.map((e) => e.toJson()).toList() case final value?)
|
||||
'headers': value,
|
||||
if (instance.authentication case final value?) 'authentication': value,
|
||||
if (instance.metaSortKey case final value?) 'metaSortKey': value,
|
||||
if (instance.isPrivate case final value?) 'isPrivate': value,
|
||||
if (instance.pathParameters case final value?) 'pathParameters': value,
|
||||
if (instance.afterResponseScript case final value?)
|
||||
'afterResponseScript': value,
|
||||
if (instance.settingStoreCookies case final value?)
|
||||
'settingStoreCookies': value,
|
||||
if (instance.settingSendCookies case final value?)
|
||||
'settingSendCookies': value,
|
||||
if (instance.settingDisableRenderRequestBody case final value?)
|
||||
'settingDisableRenderRequestBody': value,
|
||||
if (instance.settingEncodeUrl case final value?)
|
||||
'settingEncodeUrl': value,
|
||||
if (instance.settingRebuildPath case final value?)
|
||||
'settingRebuildPath': value,
|
||||
if (instance.settingFollowRedirects case final value?)
|
||||
'settingFollowRedirects': value,
|
||||
if (instance.environment case final value?) 'environment': value,
|
||||
if (instance.environmentPropertyOrder case final value?)
|
||||
'environmentPropertyOrder': value,
|
||||
if (instance.scope case final value?) 'scope': value,
|
||||
if (instance.data case final value?) 'data': value,
|
||||
if (instance.dataPropertyOrder case final value?)
|
||||
'dataPropertyOrder': value,
|
||||
if (instance.color case final value?) 'color': value,
|
||||
if (instance.cookies?.map((e) => e.toJson()).toList() case final value?)
|
||||
'cookies': value,
|
||||
if (instance.fileName case final value?) 'fileName': value,
|
||||
if (instance.contents case final value?) 'contents': value,
|
||||
if (instance.contentType case final value?) 'contentType': value,
|
||||
if (instance.environmentType case final value?) 'environmentType': value,
|
||||
if (instance.kvPairData?.map((e) => e.toJson()).toList()
|
||||
case final value?)
|
||||
'kvPairData': value,
|
||||
if (instance.type case final value?) '_type': value,
|
||||
};
|
||||
|
||||
_$BodyImpl _$$BodyImplFromJson(Map json) => _$BodyImpl(
|
||||
mimeType: json['mimeType'] as String?,
|
||||
text: json['text'] as String?,
|
||||
params: (json['params'] as List<dynamic>?)
|
||||
?.map((e) => Formdatum.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$BodyImplToJson(_$BodyImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.mimeType case final value?) 'mimeType': value,
|
||||
if (instance.text case final value?) 'text': value,
|
||||
if (instance.params?.map((e) => e.toJson()).toList() case final value?)
|
||||
'params': value,
|
||||
};
|
||||
|
||||
_$FormdatumImpl _$$FormdatumImplFromJson(Map json) => _$FormdatumImpl(
|
||||
name: json['name'] as String?,
|
||||
value: json['value'] as String?,
|
||||
type: json['type'] as String?,
|
||||
src: json['fileName'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$FormdatumImplToJson(_$FormdatumImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.value case final value?) 'value': value,
|
||||
if (instance.type case final value?) 'type': value,
|
||||
if (instance.src case final value?) 'fileName': value,
|
||||
};
|
||||
|
||||
_$ParameterImpl _$$ParameterImplFromJson(Map json) => _$ParameterImpl(
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
value: json['value'] as String?,
|
||||
description: json['description'] as String?,
|
||||
disabled: json['disabled'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ParameterImplToJson(_$ParameterImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.id case final value?) 'id': value,
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.value case final value?) 'value': value,
|
||||
if (instance.description case final value?) 'description': value,
|
||||
if (instance.disabled case final value?) 'disabled': value,
|
||||
};
|
||||
|
||||
_$HeaderImpl _$$HeaderImplFromJson(Map json) => _$HeaderImpl(
|
||||
name: json['name'] as String?,
|
||||
value: json['value'] as String?,
|
||||
disabled: json['disabled'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$HeaderImplToJson(_$HeaderImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.value case final value?) 'value': value,
|
||||
if (instance.disabled case final value?) 'disabled': value,
|
||||
};
|
||||
|
||||
_$CookieImpl _$$CookieImplFromJson(Map json) => _$CookieImpl(
|
||||
key: json['key'] as String?,
|
||||
value: json['value'] as String?,
|
||||
domain: json['domain'] as String?,
|
||||
path: json['path'] as String?,
|
||||
secure: json['secure'] as bool?,
|
||||
httpOnly: json['httpOnly'] as bool?,
|
||||
hostOnly: json['hostOnly'] as bool?,
|
||||
creation: json['creation'] == null
|
||||
? null
|
||||
: DateTime.parse(json['creation'] as String),
|
||||
lastAccessed: json['lastAccessed'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastAccessed'] as String),
|
||||
sameSite: json['sameSite'] as String?,
|
||||
id: json['id'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$CookieImplToJson(_$CookieImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.key case final value?) 'key': value,
|
||||
if (instance.value case final value?) 'value': value,
|
||||
if (instance.domain case final value?) 'domain': value,
|
||||
if (instance.path case final value?) 'path': value,
|
||||
if (instance.secure case final value?) 'secure': value,
|
||||
if (instance.httpOnly case final value?) 'httpOnly': value,
|
||||
if (instance.hostOnly case final value?) 'hostOnly': value,
|
||||
if (instance.creation?.toIso8601String() case final value?)
|
||||
'creation': value,
|
||||
if (instance.lastAccessed?.toIso8601String() case final value?)
|
||||
'lastAccessed': value,
|
||||
if (instance.sameSite case final value?) 'sameSite': value,
|
||||
if (instance.id case final value?) 'id': value,
|
||||
};
|
||||
|
||||
_$KVPairDatumImpl _$$KVPairDatumImplFromJson(Map json) => _$KVPairDatumImpl(
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
value: json['value'] as String?,
|
||||
type: json['type'] as String?,
|
||||
enabled: json['enabled'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$KVPairDatumImplToJson(_$KVPairDatumImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.id case final value?) 'id': value,
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.value case final value?) 'value': value,
|
||||
if (instance.type case final value?) 'type': value,
|
||||
if (instance.enabled case final value?) 'enabled': value,
|
||||
};
|
102
packages/insomnia_collection/lib/models/insomnia_item.dart
Normal file
102
packages/insomnia_collection/lib/models/insomnia_item.dart
Normal file
@ -0,0 +1,102 @@
|
||||
import 'insomnia_collection.dart';
|
||||
|
||||
enum ResourceType {
|
||||
workspace,
|
||||
environment,
|
||||
request_group,
|
||||
cookie_jar,
|
||||
request,
|
||||
websocket_payload,
|
||||
api_spec
|
||||
}
|
||||
|
||||
class InsomniaItem {
|
||||
const InsomniaItem({
|
||||
this.id,
|
||||
this.type,
|
||||
this.resource,
|
||||
this.children,
|
||||
});
|
||||
|
||||
final String? id;
|
||||
final ResourceType? type;
|
||||
final Resource? resource;
|
||||
final List<InsomniaItem?>? children;
|
||||
|
||||
factory InsomniaItem.fromInsomniaCollection(
|
||||
InsomniaCollection? collection,
|
||||
) {
|
||||
if (collection?.resources == null) {
|
||||
return InsomniaItem();
|
||||
}
|
||||
final resources = collection!.resources!;
|
||||
final resourceMap = <String, Resource?>{for (var v in resources) v.id!: v};
|
||||
Map<String, List<String>> childrenMap = {};
|
||||
for (var item in resources) {
|
||||
if (item.parentId != null && item.id != null) {
|
||||
if (childrenMap.containsKey(item.parentId)) {
|
||||
childrenMap[item.parentId]!.add(item.id!);
|
||||
} else {
|
||||
childrenMap[item.parentId!] = [item.id!];
|
||||
}
|
||||
}
|
||||
}
|
||||
var wksp;
|
||||
for (var item in resources) {
|
||||
if (item.type == ResourceType.workspace.name) {
|
||||
wksp = InsomniaItem(
|
||||
id: item.id,
|
||||
type: ResourceType.workspace,
|
||||
resource: item,
|
||||
children: getInsomniaItemChildren(
|
||||
childrenMap[item.id],
|
||||
childrenMap,
|
||||
resourceMap,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return wksp;
|
||||
}
|
||||
}
|
||||
|
||||
List<InsomniaItem>? getInsomniaItemChildren(
|
||||
List<String>? ids,
|
||||
Map<String, List<String>> childrenMap,
|
||||
Map<String, Resource?> resourceMap,
|
||||
) {
|
||||
if (ids == null) {
|
||||
return null;
|
||||
}
|
||||
List<InsomniaItem> children = [];
|
||||
for (var itemId in ids) {
|
||||
var resource = resourceMap[itemId];
|
||||
ResourceType? type;
|
||||
try {
|
||||
type = ResourceType.values.byName(resource?.type ?? '');
|
||||
} catch (e) {
|
||||
type = null;
|
||||
}
|
||||
if (childrenMap.containsKey(itemId)) {
|
||||
children.add(InsomniaItem(
|
||||
id: itemId,
|
||||
type: type,
|
||||
resource: resource,
|
||||
children: getInsomniaItemChildren(
|
||||
childrenMap[itemId],
|
||||
childrenMap,
|
||||
resourceMap,
|
||||
),
|
||||
));
|
||||
} else {
|
||||
children.add(InsomniaItem(
|
||||
id: itemId,
|
||||
type: type,
|
||||
resource: resource,
|
||||
children: null,
|
||||
));
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
2
packages/insomnia_collection/lib/models/models.dart
Normal file
2
packages/insomnia_collection/lib/models/models.dart
Normal file
@ -0,0 +1,2 @@
|
||||
export 'insomnia_collection.dart';
|
||||
export 'insomnia_item.dart';
|
25
packages/insomnia_collection/lib/utils/insomnia_utils.dart
Normal file
25
packages/insomnia_collection/lib/utils/insomnia_utils.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import '../models/models.dart';
|
||||
|
||||
List<(String?, Resource)> getRequestsFromInsomniaCollection(
|
||||
InsomniaCollection? ic) =>
|
||||
getItemByTypeFromInsomniaCollection(ic, ResourceType.request.name);
|
||||
|
||||
List<(String?, Resource)> getEnvironmentsFromInsomniaCollection(
|
||||
InsomniaCollection? ic) =>
|
||||
getItemByTypeFromInsomniaCollection(ic, ResourceType.environment.name);
|
||||
|
||||
List<(String?, Resource)> getItemByTypeFromInsomniaCollection(
|
||||
InsomniaCollection? ic,
|
||||
String type,
|
||||
) {
|
||||
if (ic?.resources == null || ic!.resources!.length == 0) {
|
||||
return [];
|
||||
}
|
||||
List<(String?, Resource)> requests = [];
|
||||
for (var item in ic.resources!) {
|
||||
if (item.type != null && item.type == type) {
|
||||
requests.add((item.name, item));
|
||||
}
|
||||
}
|
||||
return requests;
|
||||
}
|
25
packages/insomnia_collection/pubspec.yaml
Normal file
25
packages/insomnia_collection/pubspec.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
name: insomnia_collection
|
||||
description: Seamlessly convert Insomnia Collection Format v4 to Dart.
|
||||
version: 0.0.1
|
||||
homepage: https://github.com/foss42/apidash
|
||||
|
||||
topics:
|
||||
- insomnia
|
||||
- api
|
||||
- rest
|
||||
- http
|
||||
- network
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
freezed_annotation: ^2.4.4
|
||||
json_annotation: ^4.9.0
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^2.4.12
|
||||
freezed: ^2.5.7
|
||||
json_serializable: ^6.7.1
|
||||
lints: ^4.0.0
|
||||
test: ^1.24.0
|
@ -0,0 +1,353 @@
|
||||
var collectionApiDashJsonStr = r'''{
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-05T13:05:11.752Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id": "req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736112258432,
|
||||
"created": 1736111908438,
|
||||
"url": "https://food-service-backend.onrender.com/api/users/",
|
||||
"name": "get-with-params",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [
|
||||
{
|
||||
"id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4",
|
||||
"name": "user_id",
|
||||
"value": "34",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/10.3.0"
|
||||
}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736111908438,
|
||||
"isPrivate": false,
|
||||
"pathParameters": [],
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082089076,
|
||||
"created": 1736082089076,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "These are test endpoints for API Dash",
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080559,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"environment": {},
|
||||
"_type": "request_group"
|
||||
},
|
||||
{
|
||||
"_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082089075,
|
||||
"created": 1736082089075,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "",
|
||||
"scope": "collection",
|
||||
"_type": "workspace"
|
||||
},
|
||||
{
|
||||
"_id": "req_db3c393084f14369bb409afe857e390c",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089077,
|
||||
"created": 1736082089077,
|
||||
"url": "https://api.apidash.dev/country/codes",
|
||||
"name": "test-get",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"preRequestScript": "",
|
||||
"parameters": [],
|
||||
"headers": [],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080558,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"name": "test-post",
|
||||
"description": "",
|
||||
"method": "POST",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text": "{\n \"text\": \"Grass is green\"\n}"
|
||||
},
|
||||
"preRequestScript": "",
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080557,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://reqres.in/api/users/2",
|
||||
"name": "test-put",
|
||||
"description": "",
|
||||
"method": "PUT",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text": "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"
|
||||
},
|
||||
"preRequestScript": "",
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080556,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095630,
|
||||
"created": 1736082095630,
|
||||
"name": "Base Environment",
|
||||
"metaSortKey": 1736082095630,
|
||||
"isPrivate": false,
|
||||
"data": {},
|
||||
"environmentType": "kv",
|
||||
"_type": "environment"
|
||||
},
|
||||
{
|
||||
"_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095688,
|
||||
"created": 1736082095688,
|
||||
"name": "Default Jar",
|
||||
"cookies": [],
|
||||
"_type": "cookie_jar"
|
||||
}
|
||||
]
|
||||
}''';
|
||||
|
||||
var collectionApiDashJson = {
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-05T13:05:11.752Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id": "req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736112258432,
|
||||
"created": 1736111908438,
|
||||
"url": "https://food-service-backend.onrender.com/api/users/",
|
||||
"name": "get-with-params",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [
|
||||
{
|
||||
"id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4",
|
||||
"name": "user_id",
|
||||
"value": "34",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{"name": "User-Agent", "value": "insomnia/10.3.0"}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736111908438,
|
||||
"isPrivate": false,
|
||||
"pathParameters": [],
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082089076,
|
||||
"created": 1736082089076,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "These are test endpoints for API Dash",
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080559,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"environment": {},
|
||||
"_type": "request_group"
|
||||
},
|
||||
{
|
||||
"_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082089075,
|
||||
"created": 1736082089075,
|
||||
"name": "APIDash-APItests",
|
||||
"description": "",
|
||||
"scope": "collection",
|
||||
"_type": "workspace"
|
||||
},
|
||||
{
|
||||
"_id": "req_db3c393084f14369bb409afe857e390c",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089077,
|
||||
"created": 1736082089077,
|
||||
"url": "https://api.apidash.dev/country/codes",
|
||||
"name": "test-get",
|
||||
"description": "",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"preRequestScript": "",
|
||||
"parameters": [],
|
||||
"headers": [],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080558,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"name": "test-post",
|
||||
"description": "",
|
||||
"method": "POST",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text": "{\n \"text\": \"Grass is green\"\n}"
|
||||
},
|
||||
"preRequestScript": "",
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{"name": "Content-Type", "value": "application/json"}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080557,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
"parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
"modified": 1736082089078,
|
||||
"created": 1736082089078,
|
||||
"url": "https://reqres.in/api/users/2",
|
||||
"name": "test-put",
|
||||
"description": "",
|
||||
"method": "PUT",
|
||||
"body": {
|
||||
"mimeType": "application/json",
|
||||
"text":
|
||||
"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"
|
||||
},
|
||||
"preRequestScript": "",
|
||||
"parameters": [],
|
||||
"headers": [
|
||||
{"name": "Content-Type", "value": "application/json"}
|
||||
],
|
||||
"authentication": {},
|
||||
"metaSortKey": -1736082080556,
|
||||
"isPrivate": false,
|
||||
"afterResponseScript": "",
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095630,
|
||||
"created": 1736082095630,
|
||||
"name": "Base Environment",
|
||||
"metaSortKey": 1736082095630,
|
||||
"isPrivate": false,
|
||||
"data": {},
|
||||
"environmentType": "kv",
|
||||
"_type": "environment"
|
||||
},
|
||||
{
|
||||
"_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
"parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
"modified": 1736082095688,
|
||||
"created": 1736082095688,
|
||||
"name": "Default Jar",
|
||||
"cookies": [],
|
||||
"_type": "cookie_jar"
|
||||
}
|
||||
]
|
||||
};
|
29
packages/insomnia_collection/test/insomnia_test.dart
Normal file
29
packages/insomnia_collection/test/insomnia_test.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:insomnia_collection/insomnia_collection.dart';
|
||||
import 'collection_examples/collection_apidash.dart';
|
||||
import 'models/collection_apidash_model.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Insomnia tests', () {
|
||||
test('Insomnia collection from Json String', () {
|
||||
expect(
|
||||
insomniaCollectionFromJsonStr(collectionApiDashJsonStr),
|
||||
collectionApiDashModel,
|
||||
);
|
||||
});
|
||||
|
||||
test('Insomnia collection from Json', () {
|
||||
expect(
|
||||
InsomniaCollection.fromJson(collectionApiDashJson),
|
||||
collectionApiDashModel,
|
||||
);
|
||||
});
|
||||
|
||||
test('Insomnia collection to Json String', () {
|
||||
expect(
|
||||
insomniaCollectionToJsonStr(collectionApiDashModel),
|
||||
collectionApiDashJsonStr,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
import 'package:insomnia_collection/models/models.dart';
|
||||
|
||||
var collectionApiDashModel = InsomniaCollection(
|
||||
type: "export",
|
||||
exportFormat: 4,
|
||||
exportDate: "2025-01-05T13:05:11.752Z",
|
||||
exportSource: "insomnia.desktop.app:v10.3.0",
|
||||
resources: [
|
||||
Resource(
|
||||
id: "req_15f4d64ca3084a92a0680e29a958c9da",
|
||||
parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
modified: 1736112258432,
|
||||
created: 1736111908438,
|
||||
url: "https://food-service-backend.onrender.com/api/users/",
|
||||
name: "get-with-params",
|
||||
description: "",
|
||||
method: "GET",
|
||||
body: Body(),
|
||||
parameters: [
|
||||
Parameter(
|
||||
id: "pair_bf0ae4f4280e440a8a591b64fd4ec4f4",
|
||||
name: "user_id",
|
||||
value: "34",
|
||||
description: "",
|
||||
disabled: false,
|
||||
)
|
||||
],
|
||||
headers: [
|
||||
Header(
|
||||
name: "User-Agent",
|
||||
value: "insomnia/10.3.0",
|
||||
)
|
||||
],
|
||||
authentication: {},
|
||||
metaSortKey: -1736111908438,
|
||||
isPrivate: false,
|
||||
pathParameters: [],
|
||||
afterResponseScript: null,
|
||||
settingSendCookies: true,
|
||||
settingStoreCookies: true,
|
||||
settingDisableRenderRequestBody: false,
|
||||
settingEncodeUrl: true,
|
||||
settingRebuildPath: true,
|
||||
settingFollowRedirects: "global",
|
||||
type: "request",
|
||||
),
|
||||
Resource(
|
||||
id: "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
parentId: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
modified: 1736082089076,
|
||||
created: 1736082089076,
|
||||
name: "APIDash-APItests",
|
||||
description: "These are test endpoints for API Dash",
|
||||
environment: {},
|
||||
environmentPropertyOrder: null,
|
||||
metaSortKey: -1736082080559,
|
||||
isPrivate: false,
|
||||
afterResponseScript: "",
|
||||
authentication: {},
|
||||
type: "request_group",
|
||||
),
|
||||
Resource(
|
||||
id: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
parentId: null,
|
||||
modified: 1736082089075,
|
||||
created: 1736082089075,
|
||||
name: "APIDash-APItests",
|
||||
description: "",
|
||||
scope: "collection",
|
||||
type: "workspace",
|
||||
),
|
||||
Resource(
|
||||
id: "req_db3c393084f14369bb409afe857e390c",
|
||||
parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
modified: 1736082089077,
|
||||
created: 1736082089077,
|
||||
url: "https://api.apidash.dev/country/codes",
|
||||
name: "test-get",
|
||||
description: "",
|
||||
method: "GET",
|
||||
body: Body(),
|
||||
parameters: [],
|
||||
headers: [],
|
||||
preRequestScript: "",
|
||||
authentication: {},
|
||||
metaSortKey: -1736082080558,
|
||||
isPrivate: false,
|
||||
afterResponseScript: "",
|
||||
settingSendCookies: true,
|
||||
settingStoreCookies: true,
|
||||
settingDisableRenderRequestBody: false,
|
||||
settingEncodeUrl: true,
|
||||
settingRebuildPath: true,
|
||||
settingFollowRedirects: "global",
|
||||
type: "request",
|
||||
),
|
||||
Resource(
|
||||
id: "req_ba718bbacd094e95a30ef3f07baa4e42",
|
||||
parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
modified: 1736082089078,
|
||||
created: 1736082089078,
|
||||
url: "https://api.apidash.dev/case/lower",
|
||||
name: "test-post",
|
||||
description: "",
|
||||
method: "POST",
|
||||
body: Body(
|
||||
mimeType: "application/json",
|
||||
text: "{\n \"text\": \"Grass is green\"\n}",
|
||||
),
|
||||
parameters: [],
|
||||
headers: [
|
||||
Header(
|
||||
name: "Content-Type",
|
||||
value: "application/json",
|
||||
)
|
||||
],
|
||||
preRequestScript: "",
|
||||
authentication: {},
|
||||
metaSortKey: -1736082080557,
|
||||
isPrivate: false,
|
||||
afterResponseScript: "",
|
||||
settingSendCookies: true,
|
||||
settingStoreCookies: true,
|
||||
settingDisableRenderRequestBody: false,
|
||||
settingEncodeUrl: true,
|
||||
settingRebuildPath: true,
|
||||
settingFollowRedirects: "global",
|
||||
type: "request",
|
||||
),
|
||||
Resource(
|
||||
id: "req_24cff90fc3c74e71a567f61d3f8e8cc1",
|
||||
parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd",
|
||||
modified: 1736082089078,
|
||||
created: 1736082089078,
|
||||
url: "https://reqres.in/api/users/2",
|
||||
name: "test-put",
|
||||
description: "",
|
||||
method: "PUT",
|
||||
body: Body(
|
||||
mimeType: "application/json",
|
||||
text:
|
||||
"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"),
|
||||
parameters: [],
|
||||
headers: [
|
||||
Header(
|
||||
name: "Content-Type",
|
||||
value: "application/json",
|
||||
)
|
||||
],
|
||||
preRequestScript: "",
|
||||
authentication: {},
|
||||
metaSortKey: -1736082080556,
|
||||
isPrivate: false,
|
||||
afterResponseScript: "",
|
||||
settingSendCookies: true,
|
||||
settingStoreCookies: true,
|
||||
settingDisableRenderRequestBody: false,
|
||||
settingEncodeUrl: true,
|
||||
settingRebuildPath: true,
|
||||
settingFollowRedirects: "global",
|
||||
type: "request",
|
||||
),
|
||||
Resource(
|
||||
id: "env_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
parentId: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
modified: 1736082095630,
|
||||
created: 1736082095630,
|
||||
name: "Base Environment",
|
||||
data: {},
|
||||
dataPropertyOrder: null,
|
||||
color: null,
|
||||
isPrivate: false,
|
||||
metaSortKey: 1736082095630,
|
||||
environmentType: "kv",
|
||||
type: "environment",
|
||||
),
|
||||
Resource(
|
||||
id: "jar_9d818b2866dffc9831640d91a516ea3986e16bda",
|
||||
parentId: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a",
|
||||
modified: 1736082095688,
|
||||
created: 1736082095688,
|
||||
name: "Default Jar",
|
||||
cookies: [],
|
||||
type: "cookie_jar",
|
||||
),
|
||||
]);
|
@ -708,6 +708,13 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.3.0"
|
||||
insomnia_collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
path: "packages/insomnia_collection"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
integration_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
@ -1,9 +1,5 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart'
|
||||
show
|
||||
EnvironmentModel,
|
||||
EnvironmentVariableModel,
|
||||
EnvironmentVariableSuggestion;
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
|
||||
/// Global environment model
|
||||
const globalEnvironment = EnvironmentModel(
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
import 'environment_models.dart';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/screens/common_widgets/env_trigger_options.dart';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_indicator.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_indicator.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_popover.dart';
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/utils/envvar_utils.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
@ -211,10 +210,12 @@ void main() {
|
||||
NameValueModel(name: "num", value: "{{num}}"),
|
||||
],
|
||||
);
|
||||
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
|
||||
String? activeEnvironmentId = "activeEnvId";
|
||||
const expected = HttpRequestModel(
|
||||
url: "api.apidash.dev/humanize/social",
|
||||
@ -227,7 +228,10 @@ void main() {
|
||||
);
|
||||
expect(
|
||||
substituteHttpRequestModel(
|
||||
httpRequestModel, envMap, activeEnvironmentId),
|
||||
httpRequestModel,
|
||||
envMap,
|
||||
activeEnvironmentId,
|
||||
),
|
||||
expected);
|
||||
});
|
||||
|
||||
@ -260,6 +264,40 @@ void main() {
|
||||
httpRequestModel, envMap, activeEnvironmentId),
|
||||
expected);
|
||||
});
|
||||
|
||||
test(
|
||||
"Testing substituteHttpRequestModel with environment variables in body",
|
||||
() {
|
||||
const httpRequestModel = HttpRequestModel(
|
||||
url: "{{url}}/humanize/social",
|
||||
headers: [
|
||||
NameValueModel(name: "Authorization", value: "Bearer {{token}}"),
|
||||
],
|
||||
params: [
|
||||
NameValueModel(name: "num", value: "{{num}}"),
|
||||
],
|
||||
body: "The API key is {{token}} and the number is {{num}}",
|
||||
);
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
String? activeEnvironmentId = "activeEnvId";
|
||||
const expected = HttpRequestModel(
|
||||
url: "api.apidash.dev/humanize/social",
|
||||
headers: [
|
||||
NameValueModel(name: "Authorization", value: "Bearer token"),
|
||||
],
|
||||
params: [
|
||||
NameValueModel(name: "num", value: "8940000"),
|
||||
],
|
||||
body: "The API key is token and the number is 8940000",
|
||||
);
|
||||
expect(
|
||||
substituteHttpRequestModel(
|
||||
httpRequestModel, envMap, activeEnvironmentId),
|
||||
expected);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getEnvironmentTriggerSuggestions function", () {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/widgets/popup_menu_env.dart';
|
||||
|
||||
void main() {
|
||||
|
Reference in New Issue
Block a user