Skip to content

Commit

Permalink
implemented almost all the objects from the openapi spec
Browse files Browse the repository at this point in the history
  • Loading branch information
RazMag committed Nov 21, 2023
1 parent 21f0e14 commit 389bf26
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 67 deletions.
17 changes: 17 additions & 0 deletions cherrybomb-oas/src/new_oas/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// https://spec.openapis.org/oas/v3.1.0#components-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Components {
pub schemas: Option<HashMap<String, Schema>>,
pub responses: Option<HashMap<String, RelRef>>,
pub parameters: Option<HashMap<String, RelRef>>,
pub examples: Option<HashMap<String, RelRef>>,
pub request_bodies: Option<HashMap<String, RelRef>>,
pub headers: Option<HashMap<String, RelRef>>,
pub security_schemes: Option<HashMap<String, RelRef>>,
pub links: Option<HashMap<String, RelRef>>,
pub callbacks: Option<HashMap<String, RelRef>>,
pub extensions: Option<HashMap<String, Value>>,
}
13 changes: 13 additions & 0 deletions cherrybomb-oas/src/new_oas/encoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde_json::Value;

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Encoding {
pub content_type: Option<String>,
pub headers: Option<HashMap<String, RelRef>>,
pub style: Option<String>,
pub explode: Option<bool>,
pub allow_reserved: Option<bool>,
pub extensions: Option<HashMap<String, Value>>,
}
1 change: 1 addition & 0 deletions cherrybomb-oas/src/new_oas/external_docs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};

// https://spec.openapis.org/oas/v3.1.0#external-documentation-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct ExternalDocs {
pub description: Option<String>,
Expand Down
2 changes: 2 additions & 0 deletions cherrybomb-oas/src/new_oas/info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};

// https://spec.openapis.org/oas/v3.1.0#info-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct Info {
pub title: String,
Expand All @@ -9,6 +10,7 @@ pub struct Info {
pub contact: Option<Contact>,
pub license: Option<License>,
pub version: String,
pub extensions: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
Expand Down
14 changes: 14 additions & 0 deletions cherrybomb-oas/src/new_oas/media_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::new_oas::schema::Schema;

// https://spec.openapis.org/oas/v3.1.0#media-type-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct MediaType {
pub schema: Option<Schema>,
pub example: Option<Value>,
pub examples: Option<HashMap<String, RelRef>>,
pub encoding: Option<HashMap<String, crate::new_oas::encoding::Encoding>>,
pub extensions: Option<HashMap<String, Value>>,
}
9 changes: 9 additions & 0 deletions cherrybomb-oas/src/new_oas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ mod paths;
mod open_api;
mod security;
mod external_docs;
mod responses;
mod parameter;
mod operation;
mod components;
mod tag;
mod schema;
mod media_type;
mod encoding;
mod request_body;
3 changes: 2 additions & 1 deletion cherrybomb-oas/src/new_oas/open_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};

// https://spec.openapis.org/oas/v3.1.0#openapi-object
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct OpenAPI {
pub openapi: String,
Expand All @@ -12,7 +13,7 @@ pub struct OpenAPI {
pub webhooks: Option<HashMap<String,RelRef>>,
pub components: Option<crate::new_oas::components::Components>,
pub security: Option<Vec<crate::new_oas::security::Security>>,
pub tags: Option<Vec<crate::new_oas::tags::Tag>>,
pub tags: Option<Vec<crate::new_oas::tag::Tag>>,
pub external_docs: Option<crate::new_oas::external_docs::ExternalDocs>,
pub extensions: Option<HashMap<String, serde_json::Value>>,
}
23 changes: 23 additions & 0 deletions cherrybomb-oas/src/new_oas/operation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde::{Deserialize,Serialize};
use std::collections::HashMap;

// https://spec.openapis.org/oas/v3.1.0#operation-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Operation {
pub tags: Option<Vec<String>>,
pub summary: Option<String>,
pub description: Option<String>,
#[serde(rename = "externalDocs")]
pub external_docs: Option<crate::new_oas::external_docs::ExternalDocs>,
#[serde(rename = "operationId")]
pub operation_id: Option<String>,
pub parameters: Option<Vec<RelRef>>,
#[serde(rename = "requestBody")]
pub request_body: Option<RelRef>,
pub responses: Option<crate::new_oas::responses::Responses>,
pub callbacks: Option<HashMap<String, RelRef>>,
pub deprecated: Option<bool>,
pub security: Option<Vec<crate::new_oas::security::Security>>,
pub servers: Option<Vec<crate::new_oas::server::Server>>,
}

33 changes: 33 additions & 0 deletions cherrybomb-oas/src/new_oas/parameter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use serde::{Deserialize,Serialize};
use serde_json::Value;
use std::collections::HashMap;

// https://spec.openapis.org/oas/v3.1.0#parameter-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Parameter{
pub name: String,
#[serde(rename = "in")]
pub in_: String,
pub description: Option<String>,
pub required: Option<bool>,
pub deprecated: Option<bool>,
#[serde(rename = "allowEmptyValue")]
pub allow_empty_value: Option<bool>,
pub style: Option<String>,
pub explode: Option<bool>,
#[serde(rename = "allowReserved")]
pub allow_reserved: Option<bool>,
pub schema: Option<Schema>,
pub example: Option<Value>,
pub examples: Option<HashMap<String, RelRef>>,
pub content: Option<HashMap<String, MediaType>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct MediaType {
pub schema: Option<Schema>,
pub example: Option<Value>,
pub examples: Option<HashMap<String, RelRef>>,
pub encoding: Option<HashMap<String, Encoding>>,
}

68 changes: 2 additions & 66 deletions cherrybomb-oas/src/new_oas/paths.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde_json::Value;
use crate::new_oas::operation::Operation;

// https://spec.openapis.org/oas/v3.1.0#paths-object
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Paths {
#[serde(flatten)]
Expand All @@ -25,71 +27,5 @@ pub struct PathItem {
pub servers: Option<Vec<crate::new_oas::server::Server>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Operation {
pub tags: Option<Vec<String>>,
pub summary: Option<String>,
pub description: Option<String>,
#[serde(rename = "externalDocs")]
pub external_docs: Option<crate::new_oas::external_docs::ExternalDocs>,
#[serde(rename = "operationId")]
pub operation_id: Option<String>,
pub parameters: Option<Vec<RelRef>>,
#[serde(rename = "requestBody")]
pub request_body: Option<RelRef>,
pub responses: Option<Responses>,
pub callbacks: Option<HashMap<String, RelRef>>,
pub deprecated: Option<bool>,
pub security: Option<Vec<crate::new_oas::security::Security>>,
pub servers: Option<Vec<crate::new_oas::server::Server>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Parameter{
pub name: String,
#[serde(rename = "in")]
pub in_: String,
pub description: Option<String>,
pub required: Option<bool>,
pub deprecated: Option<bool>,
#[serde(rename = "allowEmptyValue")]
pub allow_empty_value: Option<bool>,
pub style: Option<String>,
pub explode: Option<bool>,
#[serde(rename = "allowReserved")]
pub allow_reserved: Option<bool>,
pub schema: Option<Schema>,
pub example: Option<Value>,
pub examples: Option<HashMap<String, RelRef>>,
pub content: Option<HashMap<String, MediaType>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Responses {
#[serde(rename = "default")]
pub default: Option<RelRef>,
pub responses: Option<HashMap<String, RelRef>>,
pub extensions: Option<HashMap<String, Value>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Response {
pub description: String,
pub headers: Option<HashMap<String, RelRef>>,
pub content: Option<HashMap<String, MediaType>>,
pub links: Option<HashMap<String, RelRef>>,
pub extensions: Option<HashMap<String, Value>>,
}



#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct MediaType {
pub schema: Option<Schema>,
pub example: Option<Value>,
pub examples: Option<HashMap<String, RelRef>>,
pub encoding: Option<HashMap<String, Encoding>>,
}



12 changes: 12 additions & 0 deletions cherrybomb-oas/src/new_oas/request_body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde_json::Value;

// https://spec.openapis.org/oas/v3.1.0#request-body-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct RequestBody {
pub description: Option<String>,
pub content: HashMap<String, crate::new_oas::media_type::MediaType>,
pub required: Option<bool>,
pub extensions: Option<HashMap<String, Value>>,
}
20 changes: 20 additions & 0 deletions cherrybomb-oas/src/new_oas/responses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// https://spec.openapis.org/oas/v3.1.0#responses-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Responses {
#[serde(rename = "default")]
pub default: Option<RelRef>,
pub responses: Option<HashMap<String, RelRef>>,
pub extensions: Option<HashMap<String, Value>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Response {
pub description: String,
pub headers: Option<HashMap<String, RelRef>>,
pub content: Option<HashMap<String, MediaType>>,
pub links: Option<HashMap<String, RelRef>>,
pub extensions: Option<HashMap<String, Value>>,
}
10 changes: 10 additions & 0 deletions cherrybomb-oas/src/new_oas/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde_json::Value;

// https://spec.openapis.org/oas/v3.1.0#schema-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Schema{


}
1 change: 1 addition & 0 deletions cherrybomb-oas/src/new_oas/security.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};

// https://spec.openapis.org/oas/v3.1.0#security-requirement-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Security {
pub security: Option<HashMap<String, Vec<String>>>,
Expand Down
1 change: 1 addition & 0 deletions cherrybomb-oas/src/new_oas/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// https://spec.openapis.org/oas/v3.1.0#server-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct Server {
#[serde(rename(deserialize = "url"))]
Expand Down
10 changes: 10 additions & 0 deletions cherrybomb-oas/src/new_oas/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};

// https://spec.openapis.org/oas/v3.1.0#tag-object
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Tag {
pub name: String,
pub description: Option<String>,
pub external_docs: Option<crate::new_oas::external_docs::ExternalDocs>,
pub extensions: Option<serde_json::Value>,
}

0 comments on commit 389bf26

Please sign in to comment.