Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/include graphql in 2.1.0 schema #7

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "postman_collection"
version = "0.2.0"
authors = ["Sebastian Mandrean <[email protected]>"]
version = "0.3.0"
authors = ["Sebastian Mandrean <[email protected]>", "Marlon Brandão de Sousa <[email protected]>"]
description = "A Postman Collection serialization & deserialization library."
edition = "2021"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add the following to your `Cargo.toml` file:

```toml
[dependencies]
postman_collection = "0.1"
postman_collection = "0.3"
```

Use
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ mod tests {
// Just tests if the deserialization does not blow up. But does not test correctness
#[test]
fn can_deserialize() {
for entry in glob("/tests/fixtures/collection/*.json").expect("Failed to read glob pattern")
for entry in glob("tests/fixtures/collection/*.json").expect("Failed to read glob pattern")
{
let entry = entry.unwrap();
let path = entry.as_path();
Expand All @@ -198,7 +198,7 @@ mod tests {
.collect();
let mut invalid_diffs = Vec::new();

for entry in glob("/tests/fixtures/collection/*.json").expect("Failed to read glob pattern")
for entry in glob("tests/fixtures/collection/*.json").expect("Failed to read glob pattern")
{
let entry = entry.unwrap();
let path = entry.as_path();
Expand Down
32 changes: 31 additions & 1 deletion src/v2_1_0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
pub struct Spec {
Expand All @@ -24,6 +25,10 @@ pub struct Spec {
/// Represents authentication helpers provided by Postman
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Auth {
/// The attributes for API Key Authentication.
#[serde(rename = "apikey")]
pub apikey: Option<Vec<AuthAttribute>>,

/// The attributes for [AWS
/// Auth](http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html).
#[serde(rename = "awsv4")]
Expand All @@ -44,6 +49,10 @@ pub struct Auth {
#[serde(rename = "digest")]
pub digest: Option<Vec<AuthAttribute>>,

/// The attributes for [Akamai EdgeGrid Authentication](https://developer.akamai.com/legacy/introduction/Client_Auth.html).
#[serde(rename = "edgegrid")]
pub edgegrid: Option<Vec<AuthAttribute>>,

/// The attributes for [Hawk Authentication](https://github.com/hueniverse/hawk)
#[serde(rename = "hawk")]
pub hawk: Option<Vec<AuthAttribute>>,
Expand Down Expand Up @@ -400,6 +409,10 @@ pub struct Body {
#[serde(rename = "formdata")]
pub formdata: Option<Vec<FormParameter>>,

/// as per postman specification, the only information provided for the graphql field is that it is a json object
#[serde(rename = "graphql")]
pub graphql: Option<Value>,

/// Postman stores the type of data associated with this request in this field.
#[serde(rename = "mode")]
pub mode: Option<Mode>,
Expand All @@ -409,6 +422,10 @@ pub struct Body {

#[serde(rename = "urlencoded")]
pub urlencoded: Option<Vec<UrlEncodedParameter>>,

/// Additional configurations and options set for various body modes
#[serde(rename = "options")]
pub options: Option<serde_json::value::Value>,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
Expand Down Expand Up @@ -482,7 +499,7 @@ pub struct Certificate {

/// A list of Url match pattern strings, to identify Urls this certificate can be used for.
#[serde(rename = "matches")]
pub matches: Option<Vec<Option<serde_json::Value>>>,
pub matches: Option<Vec<String>>,

/// A name for the certificate for user reference
#[serde(rename = "name")]
Expand Down Expand Up @@ -584,6 +601,10 @@ pub struct ResponseClass {
#[serde(rename = "responseTime")]
pub response_time: Option<ResponseTime>,

/// Set of timing information related to request and response in milliseconds
#[serde(rename = "timings")]
pub timings: Option<serde_json::value::Value>,

/// The response status, e.g: '200 OK'
#[serde(rename = "status")]
pub status: Option<String>,
Expand Down Expand Up @@ -765,6 +786,9 @@ pub enum ResponseTime {

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub enum AuthType {
#[serde(rename = "apikey")]
Apikey,

#[serde(rename = "awsv4")]
Awsv4,

Expand All @@ -777,6 +801,9 @@ pub enum AuthType {
#[serde(rename = "digest")]
Digest,

#[serde(rename = "edgegrid")]
Edgegrid,

#[serde(rename = "hawk")]
Hawk,

Expand Down Expand Up @@ -822,6 +849,9 @@ pub enum Mode {
#[serde(rename = "file")]
File,

#[serde(rename = "graphql")]
Graphql,

#[serde(rename = "formdata")]
Formdata,

Expand Down
57 changes: 57 additions & 0 deletions tests/fixtures/collection/graphql-query-v2.1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"info": {
"name": "GraphQL test schema",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"description": "GraphQL APIs are an efficient alternative to the rest APIs. They allow fetch customized responses or retrieve data of nested or multiple resources through a single API request. This example is based on Contentstack GraphQL Postman Collection at https://raw.githubusercontent.com/contentstack/contentstack-postman-collections/collections/graphql-collection.json."
},
"item": [
{
"name": "Get a List of Assets",
"request": {
"method": "POST",
"header": [
{
"key": "access_token",
"value": "{{access_token}}",
"disabled": false
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "query {\n all_assets(\n locale: \"en-us\"\n ) {\n total\n items {\n title\n url\n file_size\n }\n }\n}",
"variables": null
}
},
"description": "sample query graph",
"url": {
"protocol": "https",
"host": "{{base_url}}",
"path": "/list",
"query": [
{
"key": "environment",
"value": "{{environment}}"
},
{
"key": "limit",
"value": "",
"disabled": true
},
{
"key": "skip",
"value": "",
"disabled": true
},
{
"key": "skip_content_type_uids",
"value": "",
"disabled": true
}
]
}
}
}
],
"event": []
}
70 changes: 56 additions & 14 deletions tests/fixtures/schema/postman-collection-v2.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"$ref": "#/definitions/auth"
}
]
},
"protocolProfileBehavior": {
"$ref": "#/definitions/protocol-profile-behavior"
}
},
"required": [
Expand Down Expand Up @@ -70,10 +73,12 @@
"type": {
"type": "string",
"enum": [
"apikey",
"awsv4",
"basic",
"bearer",
"digest",
"edgegrid",
"hawk",
"noauth",
"oauth1",
Expand All @@ -82,6 +87,14 @@
]
},
"noauth": {},
"apikey": {
"type": "array",
"title": "API Key Authentication",
"description": "The attributes for API Key Authentication.",
"items": {
"$ref": "#/definitions/auth-attribute"
}
},
"awsv4": {
"type": "array",
"title": "AWS Signature v4",
Expand Down Expand Up @@ -114,6 +127,14 @@
"$ref": "#/definitions/auth-attribute"
}
},
"edgegrid": {
"type": "array",
"title": "EdgeGrid Authentication",
"description": "The attributes for [Akamai EdgeGrid Authentication](https://developer.akamai.com/legacy/introduction/Client_Auth.html).",
"items": {
"$ref": "#/definitions/auth-attribute"
}
},
"hawk": {
"type": "array",
"title": "Hawk Authentication",
Expand Down Expand Up @@ -173,7 +194,7 @@
"matches": {
"description": "A list of Url match pattern strings, to identify Urls this certificate can be used for.",
"type": "array",
"item": {
"items": {
"type": "string",
"description": "An Url match pattern string"
}
Expand Down Expand Up @@ -450,6 +471,9 @@
"$ref": "#/definitions/auth"
}
]
},
"protocolProfileBehavior": {
"$ref": "#/definitions/protocol-profile-behavior"
}
},
"required": [
Expand Down Expand Up @@ -490,22 +514,20 @@
}
},
"protocolProfileBehavior": {
"type": "object",
"title": "Protocol Profile Behavior",
"description": "Set of configurations used to alter the usual behavior of sending the request",
"properties": {
"disableBodyPruning": {
"type": "boolean",
"default": false,
"description": "Disable body pruning for GET, COPY, HEAD, PURGE and UNLOCK request methods."
}
}
"$ref": "#/definitions/protocol-profile-behavior"
}
},
"required": [
"request"
]
},
"protocol-profile-behavior": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Protocol Profile Behavior",
"$id": "#/definitions/protocol-profile-behavior",
"description": "Set of configurations used to alter the usual behavior of sending the request"
},
"proxy-config": {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "#/definitions/proxy-config",
Expand Down Expand Up @@ -623,12 +645,16 @@
"raw",
"urlencoded",
"formdata",
"file"
"file",
"graphql"
]
},
"raw": {
"type": "string"
},
"graphql": {
"type": "object"
},
"urlencoded": {
"type": "array",
"items": {
Expand Down Expand Up @@ -659,7 +685,7 @@
"items": {
"type": "object",
"title": "FormParameter",
"oneOf": [
"anyOf": [
{
"properties": {
"key": {
Expand Down Expand Up @@ -696,6 +722,7 @@
},
"src": {
"type": [
"array",
"string",
"null"
]
Expand Down Expand Up @@ -744,6 +771,10 @@
}
}
},
"options": {
"type": "object",
"description": "Additional configurations and options set for various body modes."
},
"disabled": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -785,6 +816,14 @@
],
"description": "The time taken by the request to complete. If a number, the unit is milliseconds. If the response is manually created, this can be set to `null`."
},
"timings": {
"title": "Response Timings",
"description": "Set of timing information related to request and response in milliseconds",
"type": [
"object",
"null"
]
},
"header": {
"title": "Headers",
"oneOf": [
Expand Down Expand Up @@ -819,7 +858,10 @@
}
},
"body": {
"type": "string",
"type": [
"null",
"string"
],
"description": "The raw text of the response."
},
"status": {
Expand Down