diff --git a/Cargo.lock b/Cargo.lock index fc3dfe7..4ef0923 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,16 +271,15 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] @@ -310,9 +309,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -320,9 +319,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.71" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" dependencies = [ "backtrace", ] @@ -488,20 +487,19 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.11" +version = "4.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" +checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.11" +version = "4.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" +checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" dependencies = [ "anstream", "anstyle", @@ -511,9 +509,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", "proc-macro2", @@ -523,9 +521,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "colorchoice" @@ -975,9 +973,9 @@ dependencies = [ [[package]] name = "indoc" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "761cde40c27e2a9877f8c928fd248b7eec9dd48623dd514b256858ca593fbba7" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" [[package]] name = "instant" @@ -1072,6 +1070,8 @@ dependencies = [ "include_dir", "indexmap 2.0.0", "indoc", + "libninja_commercial", + "libninja_hir", "libninja_mir", "ln-core", "ln-macro", @@ -1097,10 +1097,38 @@ dependencies = [ "url", ] +[[package]] +name = "libninja_commercial" +version = "0.1.0" +dependencies = [ + "anyhow", + "convert_case 0.6.0", + "indoc", + "libninja_mir", + "ln-core", + "ln-macro", + "openapiv3-extended", + "proc-macro2", + "quote", + "serde_json", +] + +[[package]] +name = "libninja_hir" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "convert_case 0.6.0", + "openapiv3-extended", + "serde_json", +] + [[package]] name = "libninja_mir" version = "0.1.0" dependencies = [ + "libninja_hir", "proc-macro2", "quote", ] @@ -1126,6 +1154,7 @@ dependencies = [ "convert_case 0.6.0", "include_dir", "indexmap 2.0.0", + "libninja_hir", "libninja_mir", "openapiv3-extended", "proc-macro2", @@ -1637,9 +1666,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.100" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", diff --git a/Cargo.toml b/Cargo.toml index d9468e6..1cdb997 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "macro", "core", "mir", + "hir" ] exclude = [ "commercial", diff --git a/core/Cargo.toml b/core/Cargo.toml index 262f20f..fe2fa21 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -20,6 +20,7 @@ syn = "2.0" libninja_mir = { path = "../mir" } include_dir = "0.7.3" tera = "1.19.0" +libninja_hir = { path = "../hir" } [dev-dependencies] serde_yaml = "0.9.25" \ No newline at end of file diff --git a/core/src/extractor.rs b/core/src/extractor.rs index b36f38a..e3abe68 100644 --- a/core/src/extractor.rs +++ b/core/src/extractor.rs @@ -2,23 +2,21 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use anyhow::{anyhow, Result}; use convert_case::{Case, Casing}; -use openapiv3::{APIKeyLocation, OpenAPI, Operation, PathItem, ReferenceOr, Schema, SchemaReference, SecurityRequirement, SecurityScheme, StatusCode}; +use openapiv3::{OpenAPI, ReferenceOr, Schema}; use openapiv3 as oa; use tracing_ez::{span, warn}; -use mir::{Doc, Name, NewType}; +use ::hir::{AuthLocation, AuthorizationParameter, AuthorizationStrategy, DocFormat, HirSpec, Language, Location, Operation, Record, Ty, Parameter, Doc}; pub use record::*; -pub use resolution::{schema_to_ty, schema_ref_to_ty, schema_ref_to_ty_already_resolved}; +pub use resolution::{schema_ref_to_ty, schema_ref_to_ty_already_resolved, schema_to_ty}; pub use resolution::*; - -use crate::{mir2, Language, LibraryOptions}; -use crate::mir2::{AuthLocation, AuthorizationParameter, AuthorizationStrategy, DocFormat, Location, MirSpec, Record, Ty}; +use mir::NewType; mod resolution; mod record; /// You might need to call add_operation_models after this -pub fn extract_spec(spec: &OpenAPI) -> Result { +pub fn extract_spec(spec: &OpenAPI) -> Result { let operations = extract_api_operations(spec)?; let schemas = extract_records(spec)?; let servers = extract_servers(spec)?; @@ -26,7 +24,7 @@ pub fn extract_spec(spec: &OpenAPI) -> Result { let api_docs_url = extract_api_docs_link(spec); - let mut s = MirSpec { + let mut s = HirSpec { operations, schemas, servers, @@ -57,7 +55,7 @@ pub fn extract_request_schema<'a>( Ok(content.schema.as_ref().unwrap().resolve(spec)) } -pub fn extract_param(param: &ReferenceOr, spec: &OpenAPI) -> Result { +pub fn extract_param(param: &ReferenceOr, spec: &OpenAPI) -> Result { span!("extract_param", param = ?param); let param = param.resolve(spec)?; let data = param.parameter_data_ref(); @@ -66,9 +64,9 @@ pub fn extract_param(param: &ReferenceOr, spec: &OpenAPI) -> Resu .ok_or_else(|| anyhow!("No schema for parameter: {:?}", param))?; let ty = schema_ref_to_ty(param_schema_ref, spec); let schema = param_schema_ref.resolve(spec); - Ok(mir2::Parameter { + Ok(Parameter { doc: None, - name: Name::new(&data.name), + name: data.name.to_string(), optional: !data.required, location: param.into(), ty, @@ -78,9 +76,9 @@ pub fn extract_param(param: &ReferenceOr, spec: &OpenAPI) -> Resu pub fn extract_inputs<'a>( operation: &'a oa::Operation, - item: &'a PathItem, + item: &'a oa::PathItem, spec: &'a OpenAPI, -) -> Result> { +) -> Result> { let mut inputs = operation .parameters .iter() @@ -99,15 +97,15 @@ pub fn extract_inputs<'a>( Ok(schema) => schema, }; - if let oa::SchemaKind::Type(oa::Type::Array(oa::ArrayType{ items, .. })) = &schema.schema_kind { + if let oa::SchemaKind::Type(oa::Type::Array(oa::ArrayType { items, .. })) = &schema.schema_kind { let ty = if let Some(items) = items { schema_ref_to_ty(&items.unbox(), spec) } else { Ty::Any }; let ty = Ty::Array(Box::new(ty)); - inputs.push(mir2::Parameter { - name: Name::new("body"), + inputs.push(Parameter { + name: "body".to_string(), ty, optional: false, doc: None, @@ -119,8 +117,9 @@ pub fn extract_inputs<'a>( let ty = schema_ref_to_ty(param, spec); let param: &Schema = param.resolve(spec); let optional = is_optional(name, param, schema); - mir2::Parameter { - name: name.into(), + let name = name.to_string(); + Parameter { + name, ty, optional, doc: None, @@ -134,8 +133,8 @@ pub fn extract_inputs<'a>( } } } else { - inputs.push(mir2::Parameter { - name: Name::new("body"), + inputs.push(Parameter { + name: "body".to_string(), ty: Ty::Any, optional: false, doc: None, @@ -149,7 +148,9 @@ pub fn extract_inputs<'a>( pub fn extract_response_success<'a>( operation: &'a oa::Operation, spec: &'a OpenAPI, -) -> Option<&'a ReferenceOr> { +) -> Option<&'a ReferenceOr> { + use openapiv3::StatusCode; + let response = operation .responses .responses @@ -169,7 +170,7 @@ pub fn extract_response_success<'a>( .and_then(|media| media.schema.as_ref()) } -pub fn extract_operation_doc(operation: &Operation, format: DocFormat) -> Option { +pub fn extract_operation_doc(operation: &oa::Operation, format: DocFormat) -> Option { let mut doc_pieces = vec![]; if let Some(summary) = operation.summary.as_ref() { if !summary.is_empty() { @@ -199,7 +200,7 @@ pub fn extract_operation_doc(operation: &Operation, format: DocFormat) -> Option } } -pub fn extract_schema_docs(schema: &Schema) -> Option { +pub fn extract_schema_docs(schema: &oa::Schema) -> Option { schema .schema_data .description @@ -230,7 +231,7 @@ pub fn make_name_from_method_and_url(method: &str, url: &str) -> String { format!("{method}{name}{last_group}") } -pub fn extract_api_operations(spec: &OpenAPI) -> Result> { +pub fn extract_api_operations(spec: &OpenAPI) -> Result> { spec.operations() .map(|(path, method, operation, item)| { let name = match &operation.operation_id { @@ -245,8 +246,8 @@ pub fn extract_api_operations(spec: &OpenAPI) -> Result> { None => Ty::Unit, Some(r) => schema_ref_to_ty(r, spec), }; - Ok(mir2::Operation { - name: name.into(), + Ok(Operation { + name, doc, parameters, ret, @@ -287,39 +288,36 @@ fn extract_api_docs_link(spec: &OpenAPI) -> Option { spec.external_docs.as_ref().map(|e| e.url.clone()) } -fn remove_unused(spec: &mut MirSpec) { - let mut used = HashSet::new(); +/// Remove from the HirSpec anything that appears to be unused +fn remove_unused(spec: &mut HirSpec) { + let mut used: HashSet = HashSet::new(); for (_name, schema) in spec.schemas.iter() { for field in schema.fields() { if let Some(name) = &field.ty.inner_model() { - used.insert(name.0.clone()); + used.insert(name.to_string()); }; } } for operation in spec.operations.iter() { if let Some(name) = &operation.ret.inner_model() { - used.insert(name.0.clone()); + used.insert(name.to_string()); }; for param in operation.parameters.iter() { if let Some(name) = ¶m.ty.inner_model() { - used.insert(name.0.clone()); + used.insert(name.to_string()); }; } } spec.schemas.retain(|name, _| used.contains(name) || name.ends_with("Webhook")); } -fn sanitize_spec(spec: &mut MirSpec) { +fn sanitize_spec(spec: &mut HirSpec) { // skip alias structs - let optional_short_circuit: HashMap = spec.schemas.iter() + let optional_short_circuit: HashMap = spec.schemas.iter() .filter(|(_, r)| r.optional()) .filter_map(|(_, r)| { - let Record::TypeAlias(alias, field) = r else { - return None; - }; - let Ty::Model(resolved) = &field.ty else { - return None; - }; + let Record::TypeAlias(alias, field) = r else { return None; }; + let Ty::Model(resolved) = &field.ty else { return None; }; Some((alias.clone(), resolved.clone())) }) .collect(); @@ -331,7 +329,7 @@ fn sanitize_spec(spec: &mut MirSpec) { let Some(rename_to) = optional_short_circuit.get(name) else { continue; }; - field.ty = mir2::Ty::Model(rename_to.clone()); + field.ty = Ty::model(rename_to); field.optional = true; } } @@ -342,15 +340,15 @@ fn sanitize_spec(spec: &mut MirSpec) { // that are only unused recursively. E.g. A -> B. A is removed on first pass, B // but B isn't. On second pass, B is removed. remove_unused(spec); - } -pub fn spec_defines_auth(spec: &MirSpec) -> bool { +pub fn spec_defines_auth(spec: &HirSpec) -> bool { !spec.security.is_empty() } -fn extract_security_fields(_name: &str, requirement: &SecurityRequirement, spec: &OpenAPI) -> Result> { +fn extract_security_fields(_name: &str, requirement: &oa::SecurityRequirement, spec: &OpenAPI) -> Result> { + use openapiv3::{SecurityScheme, APIKeyLocation}; let security_schemas = &spec.components.as_ref().unwrap().security_schemes; let mut fields = vec![]; for (name, _scopes) in requirement { @@ -431,7 +429,7 @@ pub fn extract_security_strategies(spec: &OpenAPI) -> Vec strats } -pub fn extract_newtype(name: &str, schema: &Schema, spec: &OpenAPI) -> NewType { +pub fn extract_newtype(name: &str, schema: &oa::Schema, spec: &OpenAPI) -> NewType { let ty = schema_to_ty(schema, spec); NewType { @@ -442,21 +440,21 @@ pub fn extract_newtype(name: &str, schema: &Schema, spec: &OpenAPI) -> NewType String { +fn get_name(schema_ref: oa::SchemaReference) -> String { match schema_ref { - SchemaReference::Schema { schema } => schema, - SchemaReference::Property { property, .. } => property + oa::SchemaReference::Schema { schema } => schema, + oa::SchemaReference::Property { property, .. } => property } } /// Add the models for operations that have structs for their required params. /// E.g. linkTokenCreate has >3 required params, so it has a struct. -pub fn add_operation_models(sourcegen: Language, mut spec: MirSpec) -> Result { +pub fn add_operation_models(sourcegen: Language, mut spec: HirSpec) -> Result { let mut new_schemas = vec![]; for op in &spec.operations { if op.use_required_struct(sourcegen) { - new_schemas.push((op.required_struct_name().0, Record::Struct(op.required_struct(sourcegen)))); + new_schemas.push((op.required_struct_name(), Record::Struct(op.required_struct(sourcegen)))); } } spec.schemas.extend(new_schemas); diff --git a/core/src/extractor/record.rs b/core/src/extractor/record.rs index 4f3aece..7b1c98a 100644 --- a/core/src/extractor/record.rs +++ b/core/src/extractor/record.rs @@ -1,17 +1,19 @@ +use std::collections::{BTreeMap, HashMap}; + +use anyhow::Result; +use indexmap::IndexMap; /// Records are the "model"s of the MIR world. model is a crazy overloaded word though. -use openapiv3::{ObjectType, OpenAPI, ReferenceOr, Schema, SchemaData, SchemaKind, SchemaReference, StatusCode, StringType, Type}; -use mir::{Doc, Name}; -use std::collections::{BTreeMap, HashMap}; +use openapiv3::{ObjectType, OpenAPI, ReferenceOr, Schema, SchemaData, SchemaKind, SchemaReference, StringType, Type}; use tracing_ez::warn; -use crate::{extractor, mir2}; -use crate::extractor::{schema_to_ty, schema_ref_to_ty_already_resolved}; -use crate::mir2::{MirField, Record, StrEnum, Struct}; -use indexmap::IndexMap; -use anyhow::Result; + +use hir::{Doc, HirField, Record, StrEnum, Struct, NewType}; + +use crate::extractor; use crate::child_schemas::ChildSchemas; +use crate::extractor::{schema_ref_to_ty_already_resolved, schema_to_ty}; -fn properties_to_fields(properties: &IndexMap>, schema: &Schema, spec: &OpenAPI) -> BTreeMap { +fn properties_to_fields(properties: &IndexMap>, schema: &Schema, spec: &OpenAPI) -> BTreeMap { properties .iter() .map(|(name, field_schema_ref)| { @@ -22,7 +24,7 @@ fn properties_to_fields(properties: &IndexMap>, sche field_schema, ); let optional = extractor::is_optional(name, field_schema, schema); - (Name::new(name), MirField { + (name.clone(), HirField { ty, optional, doc: extractor::extract_schema_docs(field_schema), @@ -46,18 +48,19 @@ pub fn effective_length(all_of: &[ReferenceOr]) -> usize { } pub fn create_record(name: &str, schema: &Schema, spec: &OpenAPI) -> Record { + let name = name.to_string(); match &schema.schema_kind { // The base case, a regular object SchemaKind::Type(Type::Object(ObjectType { properties, .. })) => { let fields = properties_to_fields(properties, schema, spec); - Record::Struct(Struct { name: Name::new(name), fields, nullable: schema.schema_data.nullable }) + Record::Struct(Struct { name, fields, nullable: schema.schema_data.nullable }) } // An enum SchemaKind::Type(Type::String(StringType { enumeration, .. })) if !enumeration.is_empty() => { Record::Enum(StrEnum { - name: Name::new(name), + name, variants: enumeration .iter() .map(|s| s.to_string()) @@ -67,19 +70,19 @@ pub fn create_record(name: &str, schema: &Schema, spec: &OpenAPI) -> Record { // A newtype with multiple fields SchemaKind::AllOf { all_of } => { if effective_length(all_of) == 1 { - Record::TypeAlias(Name::new(name), MirField { + Record::TypeAlias(name, HirField { ty: schema_ref_to_ty_already_resolved(&all_of[0], spec, schema), optional: schema.schema_data.nullable, - ..MirField::default() + ..HirField::default() }) } else { - create_record_from_all_of(name, all_of, &schema.schema_data, spec) + create_record_from_all_of(&name, all_of, &schema.schema_data, spec) } } // Default case, a newtype with a single field - _ => Record::NewType(mir2::NewType { - name: Name::new(name), - fields: vec![MirField { + _ => Record::NewType(NewType { + name, + fields: vec![HirField { ty: schema_to_ty(schema, spec), optional: schema.schema_data.nullable, doc: None, @@ -91,7 +94,7 @@ pub fn create_record(name: &str, schema: &Schema, spec: &OpenAPI) -> Record { } -fn create_field(field_schema_ref: &ReferenceOr, spec: &OpenAPI) -> MirField { +fn create_field(field_schema_ref: &ReferenceOr, spec: &OpenAPI) -> HirField { let field_schema = field_schema_ref.resolve(spec); let ty = schema_ref_to_ty_already_resolved( field_schema_ref, @@ -101,7 +104,7 @@ fn create_field(field_schema_ref: &ReferenceOr, spec: &OpenAPI) -> MirFi let optional = field_schema.schema_data.nullable; let example = field_schema.schema_data.example.clone(); let doc = field_schema.schema_data.description.clone().map(Doc); - MirField { ty, optional, doc, example, flatten: false } + HirField { ty, optional, doc, example, flatten: false } } fn create_record_from_all_of(name: &str, all_of: &[ReferenceOr], schema_data: &SchemaData, spec: &OpenAPI) -> Record { @@ -113,7 +116,7 @@ fn create_record_from_all_of(name: &str, all_of: &[ReferenceOr], schema_ let name = extractor::get_name(schema_ref); let mut field = create_field(schema, spec); field.flatten = true; - fields.insert(Name(name), field); + fields.insert(name, field); } ReferenceOr::Item(item) => { match item.properties() { @@ -123,7 +126,7 @@ fn create_record_from_all_of(name: &str, all_of: &[ReferenceOr], schema_ if !item.required(name) { field.optional = true; } - fields.insert(Name::new(name), field); + fields.insert(name.to_string(), field); } } None => { @@ -135,7 +138,7 @@ fn create_record_from_all_of(name: &str, all_of: &[ReferenceOr], schema_ } Record::Struct(Struct { nullable: schema_data.nullable, - name: Name::new(name), + name: name.to_string(), fields, }) } @@ -147,7 +150,7 @@ pub fn extract_records(spec: &OpenAPI) -> Result> { spec.add_child_schemas(&mut schema_lookup); for (name, schema) in schema_lookup { let rec = create_record(&name, schema, spec); - let name = rec.name().0.clone(); + let name = rec.name().to_string(); result.insert(name, rec); } Ok(result) @@ -155,7 +158,8 @@ pub fn extract_records(spec: &OpenAPI) -> Result> { #[cfg(test)] mod tests { - use openapiv3::{OpenAPI, ReferenceOr, Schema, SchemaData, SchemaKind}; + use openapiv3::{OpenAPI, Schema, SchemaData, SchemaKind}; + use crate::extractor::record::create_record_from_all_of; #[test] diff --git a/core/src/extractor/resolution.rs b/core/src/extractor/resolution.rs index 5d758e7..7bca465 100644 --- a/core/src/extractor/resolution.rs +++ b/core/src/extractor/resolution.rs @@ -1,7 +1,7 @@ use openapiv3::{ArrayType, OpenAPI, ReferenceOr, Schema, SchemaKind, SchemaReference}; use tracing_ez::warn; -use crate::mir2::Ty; +use hir::Ty; use openapiv3 as oa; @@ -34,11 +34,11 @@ pub fn schema_to_ty(schema: &Schema, spec: &OpenAPI) -> Ty { SchemaKind::Type(oa::Type::String(s)) => { match s.format.as_str() { "decimal" => Ty::Currency { - serialization: crate::mir2::DecimalSerialization::String, + serialization: hir::DecimalSerialization::String, }, - "integer" => Ty::Integer { serialization: crate::mir2::IntegerSerialization::String }, + "integer" => Ty::Integer { serialization: hir::IntegerSerialization::String }, "date" => Ty::Date { - serialization: crate::mir2::DateSerialization::Iso8601, + serialization: hir::DateSerialization::Iso8601, }, "date-time" => Ty::DateTime, _ => Ty::String, @@ -49,13 +49,13 @@ pub fn schema_to_ty(schema: &Schema, spec: &OpenAPI) -> Ty { let null_as_zero = schema.schema_data.extensions.get("x-null-as-zero") .and_then(|v| v.as_bool()).unwrap_or(false); if null_as_zero { - return Ty::Integer { serialization: crate::mir2::IntegerSerialization::NullAsZero }; + return Ty::Integer { serialization: hir::IntegerSerialization::NullAsZero }; } match schema.schema_data.extensions.get("x-format").and_then(|s| s.as_str()) { Some("date") => Ty::Date { - serialization: crate::mir2::DateSerialization::Integer, + serialization: hir::DateSerialization::Integer, }, - _ => Ty::Integer { serialization: crate::mir2::IntegerSerialization::Simple }, + _ => Ty::Integer { serialization: hir::IntegerSerialization::Simple }, } } SchemaKind::Type(oa::Type::Boolean {}) => Ty::Boolean, diff --git a/core/src/lib.rs b/core/src/lib.rs index 25594fc..3f67049 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,15 +1,12 @@ +#![allow(unused)] + +pub use extractor::extract_spec; +pub use fs::*; +pub use options::*; +pub use template::*; + pub mod fs; -pub mod mir2; -mod lang; mod options; pub mod extractor; mod template; -pub mod child_schemas; - -pub use options::*; -pub use lang::Language; - -pub use fs::*; -pub use mir2::MirSpec; -pub use extractor::extract_spec; -pub use template::*; \ No newline at end of file +pub mod child_schemas; \ No newline at end of file diff --git a/core/src/options.rs b/core/src/options.rs index 10eb457..6dcadb8 100644 --- a/core/src/options.rs +++ b/core/src/options.rs @@ -1,7 +1,8 @@ use std::path::PathBuf; use convert_case::{Case, Casing}; -use mir::{literal, Name, Literal}; -use crate::Language; +use mir::{literal, Literal}; +use hir::Language; + #[derive(Debug, Clone, Default)] pub struct LibraryConfig { @@ -46,20 +47,20 @@ impl LibraryOptions { )) } - pub fn client_name(&self) -> Name { - Name(format!("{} Client", self.service_name)) + pub fn client_name(&self) -> String { + format!("{} Client", self.service_name) } - pub fn async_client_name(&self) -> Name { - Name(format!("Async {} Client", self.service_name)) + pub fn async_client_name(&self) -> String { + format!("Async {} Client", self.service_name) } - pub fn authenticator_name(&self) -> Name { - Name(format!("{} Authentication", self.service_name)) + pub fn authenticator_name(&self) -> String { + format!("{} Authentication", self.service_name) } - pub fn bare_client_name(&self) -> Name { - Name::new("Client") + pub fn bare_client_name(&self) -> String { + "Client".to_string() } pub fn env_var(&self, name: &str) -> Literal { @@ -90,11 +91,11 @@ impl OutputOptions { ) } - pub fn client_name(&self) -> Name { + pub fn client_name(&self) -> String { self.library_options.client_name() } - pub fn async_client_name(&self) -> Name { + pub fn async_client_name(&self) -> String { self.library_options.async_client_name() } } diff --git a/core/src/template.rs b/core/src/template.rs index 800a479..a96f734 100644 --- a/core/src/template.rs +++ b/core/src/template.rs @@ -1,13 +1,16 @@ -use crate::{MirSpec, OutputOptions, write_file}; use tera::Context; +use hir::HirSpec; + +use crate::{OutputOptions, write_file}; + pub static TEMPLATE_DIR: include_dir::Dir<'_> = include_dir::include_dir!("$CARGO_MANIFEST_DIR/template"); pub fn copy_templates( opts: &OutputOptions, tera: &tera::Tera, - context: &tera::Context, + context: &Context, ) -> anyhow::Result<()> { let project_template = opts.library_options.language.to_string(); TEMPLATE_DIR @@ -50,7 +53,7 @@ pub fn prepare_templates() -> tera::Tera { } /// Create context for j2 files. -pub fn create_context(opts: &OutputOptions, mir_spec: &MirSpec) -> tera::Context { +pub fn create_context(opts: &OutputOptions, mir_spec: &HirSpec) -> tera::Context { let mut context = Context::new(); context.insert("package_name", &opts.library_options.package_name); context.insert("github_repo", &opts.qualified_github_repo); @@ -63,7 +66,7 @@ pub fn create_context(opts: &OutputOptions, mir_spec: &MirSpec) -> tera::Context name = opts.library_options.service_name ), ); - context.insert("env_vars", &mir_spec.env_vars(&opts.library_options)); + context.insert("env_vars", &mir_spec.env_vars(&opts.library_options.service_name)); if let Some(url) = &mir_spec.api_docs_url { context.insert("api_docs_url", url); } @@ -71,5 +74,5 @@ pub fn create_context(opts: &OutputOptions, mir_spec: &MirSpec) -> tera::Context } pub fn get_template_file(path: &str) -> &'static str { - TEMPLATE_DIR.get_file(path).unwrap().contents_utf8().unwrap() + TEMPLATE_DIR.get_file(path).expect(&format!("{} not found in TEMPLATE_DIR", path)).contents_utf8().unwrap() } diff --git a/hir/src/doc.rs b/hir/src/doc.rs new file mode 100644 index 0000000..0acf0a4 --- /dev/null +++ b/hir/src/doc.rs @@ -0,0 +1,22 @@ +#[derive(Debug, Clone)] +pub struct Doc(pub String); + +impl Doc { + pub fn new(s: &str) -> Self { + Self(s.to_string()) + } +} + +pub fn doc>(s: S) -> Option { + let s = s.into(); + if s.is_empty() { + None + } else { + Some(Doc(s)) + } +} + +pub enum DocFormat { + Markdown, + Rst, +} diff --git a/core/src/lang.rs b/hir/src/lang.rs similarity index 87% rename from core/src/lang.rs rename to hir/src/lang.rs index 4ff3b53..bb3cca9 100644 --- a/core/src/lang.rs +++ b/hir/src/lang.rs @@ -1,8 +1,7 @@ use anyhow::Result; -use serde::{Deserialize, Serialize}; use clap::ValueEnum; -#[derive(Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Debug, ValueEnum)] +#[derive(Eq, PartialEq, Copy, Clone, Debug, ValueEnum)] pub enum Language { Rust, Python, @@ -34,4 +33,4 @@ impl std::str::FromStr for Language { _ => Err(anyhow::anyhow!("Unknown generator: {}", s)), } } -} +} \ No newline at end of file diff --git a/core/src/mir2.rs b/hir/src/lib.rs similarity index 83% rename from core/src/mir2.rs rename to hir/src/lib.rs index 8d6bd3e..4a2b210 100644 --- a/core/src/mir2.rs +++ b/hir/src/lib.rs @@ -4,11 +4,14 @@ use std::collections::BTreeMap; use std::fmt::{Debug, Formatter}; use std::iter::{empty, Iterator, once}; use std::string::{String, ToString}; + use anyhow::Result; use convert_case::{Case, Casing}; +pub use doc::*; +mod doc; +mod lang; +pub use lang::*; -use crate::{LibraryOptions, Language}; -pub use mir::{Doc, Name}; use openapiv3 as oa; #[derive(Debug, Clone, Copy, PartialEq)] @@ -39,13 +42,12 @@ pub enum Ty { Boolean, Array(Box), // OpenAPI name for the model. Hasn't been converted to a language type (e.g. cased, sanitized) - Model(Name), + Model(String), Unit, Date { serialization: DateSerialization }, DateTime, Currency { serialization: DecimalSerialization }, Any, - // TODO add a union type and an enum type } impl Default for Ty { @@ -61,7 +63,7 @@ impl Ty { } } - pub fn inner_model(&self) -> Option<&Name> { + pub fn inner_model(&self) -> Option<&String> { match self { Ty::Model(name) => Some(name), Ty::Array(ty) => ty.inner_model(), @@ -97,14 +99,14 @@ impl Ty { } pub fn model(s: &str) -> Self { - Ty::Model(Name::new(s)) + Ty::Model(s.to_string()) } } /// Parameter is an input to an OpenAPI operation. #[derive(Debug, Clone)] pub struct Parameter { - pub name: Name, + pub name: String, pub ty: Ty, pub location: Location, pub optional: bool, @@ -115,15 +117,15 @@ pub struct Parameter { impl Parameter { pub fn to_key(&self) -> ParamKey { if self.ty.is_iterable() && self.location == Location::Query { - ParamKey::RepeatedKey(self.name.0.clone()) + ParamKey::RepeatedKey(self.name.clone()) } else { - ParamKey::Key(self.name.0.clone()) + ParamKey::Key(self.name.clone()) } } pub fn path(name: &str, ty: Ty) -> Self { Self { - name: Name(name.to_string()), + name: name.to_string(), ty, location: Location::Path, optional: false, @@ -203,13 +205,9 @@ pub struct AuthorizationStrategy { pub fields: Vec, } -pub enum DocFormat { - Markdown, - Rst, -} #[derive(Debug, Default, Clone)] -pub struct MirField { +pub struct HirField { pub ty: Ty, pub optional: bool, pub doc: Option, @@ -219,41 +217,41 @@ pub struct MirField { #[derive(Debug, Clone)] pub struct Struct { - pub name: Name, + pub name: String, pub nullable: bool, - pub fields: BTreeMap, + pub fields: BTreeMap, } #[derive(Debug, Clone)] pub struct NewType { - pub name: Name, - pub fields: Vec, + pub name: String, + pub fields: Vec, } #[derive(Debug, Clone)] pub struct TypeAlias { - pub name: Name, + pub name: String, pub ty: Ty, pub optional: bool, } #[derive(Debug, Clone)] pub struct StrEnum { - pub name: Name, + pub name: String, pub variants: Vec, } -// an object type in the HIR +/// an object type in the HIR #[derive(Debug, Clone)] pub enum Record { Struct(Struct), NewType(NewType), - TypeAlias(Name, MirField), + TypeAlias(String, HirField), Enum(StrEnum), } impl Record { - pub fn name(&self) -> &Name { + pub fn name(&self) -> &str { match self { Record::Struct(s) => &s.name, Record::Enum(e) => &e.name, @@ -271,7 +269,7 @@ impl Record { } } - pub fn fields(&self) -> Box + '_> { + pub fn fields(&self) -> Box + '_> { match self { Record::Struct(s) => Box::new(s.fields.values()), Record::Enum(_) => Box::new(empty()), @@ -280,7 +278,7 @@ impl Record { } } - pub fn fields_mut(&mut self) -> Box + '_> { + pub fn fields_mut(&mut self) -> Box + '_> { match self { Record::Struct(s) => Box::new(s.fields.iter_mut().map(|(_, f)| f)), Record::Enum(_) => Box::new(empty()), @@ -307,7 +305,7 @@ impl Record { } #[derive(Debug, Clone)] -pub struct MirSpec { +pub struct HirSpec { pub operations: Vec, pub schemas: BTreeMap, @@ -326,14 +324,23 @@ pub enum ServerStrategy { /// There's multiple choices Env, } +impl ServerStrategy { + pub fn env_var_for_strategy(&self, service_name: &str) -> Option { + match self { + ServerStrategy::BaseUrl => Some(format!("{}_BASE_URL", service_name.to_case(Case::ScreamingSnake))), + ServerStrategy::Single(_) => None, + ServerStrategy::Env => Some(format!("{}_ENV", service_name.to_case(Case::ScreamingSnake))), + } + } +} -impl MirSpec { - pub fn get_record(&self, name: &Name) -> Result<&Record> { - self.schemas.get(&name.0).ok_or_else(|| anyhow::anyhow!("No record named {}", name.0)) +impl HirSpec { + pub fn get_record(&self, name: &str) -> Result<&Record> { + self.schemas.get(name).ok_or_else(|| anyhow::anyhow!("No record named {}", name)) } pub fn get_operation(&self, name: &str) -> Result<&Operation> { - self.operations.iter().find(|o| o.name.0 == name).ok_or_else(|| anyhow::anyhow!("No operation named {}", name)) + self.operations.iter().find(|o| o.name == name).ok_or_else(|| anyhow::anyhow!("No operation named {}", name)) } pub fn server_strategy(&self) -> ServerStrategy { @@ -351,20 +358,14 @@ impl MirSpec { self.security.len() > 1 } - pub fn env_vars(&self, opt: &LibraryOptions) -> Vec { + pub fn env_vars(&self, service_name: &str) -> Vec { let mut env_vars = vec![]; - match self.server_strategy() { - ServerStrategy::Single(_) => {} - ServerStrategy::BaseUrl => { - env_vars.push(opt.env_var("base_url").0); - } - ServerStrategy::Env => { - env_vars.push(opt.env_var("env").0); - } + if let Some(env) = self.server_strategy().env_var_for_strategy(service_name) { + env_vars.push(env); } for strategy in &self.security { for param in &strategy.fields { - env_vars.push(param.env_var_for_service(&opt.service_name)); + env_vars.push(param.env_var_for_service(service_name)); } } env_vars @@ -377,7 +378,7 @@ impl MirSpec { #[derive(Debug, Clone)] pub struct Operation { - pub name: Name, + pub name: String, pub doc: Option, pub parameters: Vec, pub ret: Ty, @@ -388,19 +389,19 @@ pub struct Operation { impl Operation { // Mostly for Go pub fn flat_package_name(&self) -> String { - self.name.0.to_case(Case::Flat) + self.name.to_case(Case::Flat) } pub fn file_name(&self) -> String { - self.name.0.to_case(Case::Snake) + self.name.to_case(Case::Snake) } - pub fn request_struct_name(&self) -> Name { - Name(format!("{}Request", self.name.0)) + pub fn request_struct_name(&self) -> String { + format!("{}Request", self.name) } - pub fn required_struct_name(&self) -> Name { - Name(format!("{}Required", self.name.0)) + pub fn required_struct_name(&self) -> String { + format!("{}Required", self.name) } pub fn crowded_args(&self) -> bool { @@ -443,8 +444,8 @@ impl Operation { match generator { Language::Golang if self.crowded_args() => { vec![Parameter { - name: Name::new("args"), - ty: Ty::Model(Name::new("Required")), + name: "args".to_string(), + ty: Ty::model("Required"), location: Location::Body, optional: false, doc: None, @@ -453,7 +454,7 @@ impl Operation { } _ if self.use_required_struct(generator) => { vec![Parameter { - name: Name::new("args"), + name: "args".to_string(), ty: Ty::Model(self.required_struct_name()), location: Location::Body, optional: false, @@ -498,7 +499,7 @@ impl Operation { impl Default for Operation { fn default() -> Self { Self { - name: Name::new(""), + name: "".to_string(), doc: None, parameters: Vec::new(), ret: Ty::Unit, @@ -508,7 +509,7 @@ impl Default for Operation { } } -impl From<&Parameter> for MirField { +impl From<&Parameter> for HirField { fn from(p: &Parameter) -> Self { Self { ty: p.ty.clone(), @@ -518,4 +519,5 @@ impl From<&Parameter> for MirField { flatten: false, } } -} \ No newline at end of file +} + diff --git a/libninja/Cargo.toml b/libninja/Cargo.toml index 96fdb17..5e3becc 100644 --- a/libninja/Cargo.toml +++ b/libninja/Cargo.toml @@ -10,8 +10,7 @@ default-run = "libninja" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -integration = [] -actix = ["actix-web"] +commercial = ["libninja_commercial"] [dependencies] anyhow = { version = "1.0.71", features = ["backtrace"] } @@ -26,7 +25,7 @@ tokio = { version = "1.29.1", features = ["full"] } openapiv3-extended = { version = "3" } convert_case = "0.6.0" prettyplease = "0.2" -clap = { version = "4.3.11", features = ["derive"] } +clap = { version = "4.4.10", features = ["derive"] } tera = "1.19.0" include_dir = "0.7.3" regex = "1.9.0" @@ -44,6 +43,8 @@ indexmap = "2.0" ln-macro = { path = "../macro" } ln-core = { path = "../core" } libninja_mir = { path = "../mir" } +libninja_hir = { path = "../hir" } +libninja_commercial = { path = "../commercial" , optional = true } [dev-dependencies] env_logger = "0.10.0" diff --git a/libninja/examples/petstore-server.rs b/libninja/examples/petstore-server.rs deleted file mode 100644 index 1d4f8f6..0000000 --- a/libninja/examples/petstore-server.rs +++ /dev/null @@ -1,77 +0,0 @@ -#[cfg(feature = "actix")] -mod inner { - use actix_web::middleware::Logger; - use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; - use serde::{Deserialize, Serialize}; - - #[derive(Serialize, Deserialize)] - pub struct Pet { - pub id: u32, - pub name: String, - pub tag: String, - } - - pub fn pets() -> Vec { - vec![ - Pet { - id: 1, - name: "Rust".to_string(), - tag: "Rust".to_string(), - }, - Pet { - id: 2, - name: "Python".to_string(), - tag: "Python".to_string(), - }, - Pet { - id: 3, - name: "Typescript".to_string(), - tag: "Typescript".to_string(), - }, - ] - } - - #[derive(Debug, Serialize, Deserialize)] - pub struct ListPetsParams { - pub limit: Option, - } - - #[get("/pets")] - async fn list_pets(query: web::Query) -> impl Responder { - println!("{:?}", query); - HttpResponse::Ok().json(pets()) - } - - #[post("/pets")] - async fn create_pet(_req_body: String) -> impl Responder { - HttpResponse::Created() - } - - #[get("/pets/{id}")] - async fn get_pet_by_id(path: web::Path<(u32,)>) -> impl Responder { - let pet = pets().into_iter().find(|p| p.id == path.0); - HttpResponse::Ok().json(pet) - } - - #[actix_web::main] - async fn main() -> std::io::Result<()> { - let port = 5000; - env_logger::init(); - println!("Listening on http://localhost:{port}"); - HttpServer::new(|| { - App::new() - .wrap(Logger::default()) - .service(list_pets) - .service(create_pet) - .service(get_pet_by_id) - }) - .bind(("127.0.0.1", port))? - .run() - .await - } -} - -fn main() { - #[cfg(feature = "actix")] - inner::main().unwrap(); -} diff --git a/libninja/src/bin/libninja.rs b/libninja/src/bin/libninja.rs index e99dcd5..1caf979 100644 --- a/libninja/src/bin/libninja.rs +++ b/libninja/src/bin/libninja.rs @@ -5,7 +5,8 @@ use anyhow::Result; use convert_case::{Case, Casing}; use clap::{Args, Parser, Subcommand}; use libninja::generate_library_using_spec_at_path; -use ln_core::{Language, OutputOptions, LibraryOptions}; +use ln_core::{OutputOptions, LibraryOptions}; +use hir::Language; use libninja::rust::generate_rust_library; use std::path::Path; use libninja::command::*; diff --git a/libninja/src/lang.rs b/libninja/src/commercial.rs similarity index 69% rename from libninja/src/lang.rs rename to libninja/src/commercial.rs index 4b5e031..d726507 100644 --- a/libninja/src/lang.rs +++ b/libninja/src/commercial.rs @@ -1,6 +1,7 @@ use openapiv3::OpenAPI; use anyhow::{anyhow, Result}; -use ln_core::{mir2, LibraryOptions, OutputOptions}; +use ln_core::{LibraryOptions, OutputOptions}; +use hir::{HirSpec, Operation}; #[cfg(feature = "commercial")] pub mod python { @@ -15,11 +16,11 @@ pub mod python { Err(anyhow!("Commercial features are not enabled")) } - pub fn generate_sync_example(operation: &mir2::Operation, opt: &LibraryOptions, spec: &mir2::MirSpec) -> Result { + pub fn generate_sync_example(operation: &Operation, opt: &LibraryOptions, spec: &HirSpec) -> Result { Err(anyhow!("Commercial features are not enabled")) } - pub fn generate_async_example(operation: &mir2::Operation, opt: &LibraryOptions, spec: &mir2::MirSpec) -> Result { + pub fn generate_async_example(operation: &Operation, opt: &LibraryOptions, spec: &HirSpec) -> Result { Err(anyhow!("Commercial features are not enabled")) } } @@ -37,7 +38,7 @@ pub mod go { Err(anyhow!("Commercial features are not enabled")) } - pub fn generate_example(operation: &mir2::Operation, opt: &LibraryOptions, spec: &mir2::MirSpec) -> Result { + pub fn generate_example(operation: &Operation, opt: &LibraryOptions, spec: &HirSpec) -> Result { Err(anyhow!("Commercial features are not enabled")) } } @@ -55,7 +56,7 @@ pub mod typescript { Err(anyhow!("Commercial features are not enabled")) } - pub fn generate_example(operation: &mir2::Operation, opt: &LibraryOptions, spec: &mir2::MirSpec) -> Result { + pub fn generate_example(operation: &Operation, opt: &LibraryOptions, spec: &HirSpec) -> Result { Err(anyhow!("Commercial features are not enabled")) } } \ No newline at end of file diff --git a/libninja/src/lib.rs b/libninja/src/lib.rs index 9aaa49e..6d66674 100644 --- a/libninja/src/lib.rs +++ b/libninja/src/lib.rs @@ -13,11 +13,12 @@ pub use openapiv3; use serde::{Deserialize, Serialize}; use serde_yaml::Value; -use lang::*; -use ln_core::{Language, LibraryConfig, LibraryOptions, MirSpec, OutputOptions}; +use commercial::*; +use ln_core::{LibraryConfig, LibraryOptions, OutputOptions}; use ln_core::extractor::{extract_api_operations, extract_spec}; use ln_core::extractor::add_operation_models; use ln_core::fs::open; +use hir::{Language, HirSpec}; pub use repo::*; pub mod custom; @@ -26,7 +27,7 @@ pub mod util; pub mod command; mod modify; pub mod repo; -mod lang; +mod commercial; pub fn read_spec(path: impl AsRef, service_name: &str) -> Result { let path = path.as_ref(); @@ -104,7 +105,7 @@ pub fn generate_examples( typescript, go, }; - map.insert(operation.name.0.clone(), examples); + map.insert(operation.name.clone(), examples); } Ok(map) } diff --git a/libninja/src/rust.rs b/libninja/src/rust.rs index 501ecfd..cb9499c 100644 --- a/libninja/src/rust.rs +++ b/libninja/src/rust.rs @@ -14,10 +14,11 @@ use format::format_code; use ln_core::{copy_files, copy_templates, create_context, get_template_file, prepare_templates}; use ::mir::{Visibility, Import, File}; use ln_core::fs; +use hir::{HirSpec, IntegerSerialization, DateSerialization}; -use crate::{add_operation_models, extract_spec, LibraryOptions, MirSpec, OutputOptions, util}; +use crate::{add_operation_models, extract_spec, LibraryOptions, OutputOptions, util}; pub use crate::rust::codegen::generate_example; -use crate::rust::codegen::ToRustCode; +use crate::rust::codegen::{sanitize_filename, ToRustCode}; use crate::rust::io::write_rust_file_to_path; use crate::rust::lower_mir::{generate_model_rs, generate_single_model_file}; use crate::rust::request::{build_request_struct, generate_request_model_rs}; @@ -44,8 +45,8 @@ impl Extras { } } -pub fn calculate_extras(spec: &MirSpec) -> Extras { - use ln_core::mir2::Ty; +pub fn calculate_extras(spec: &HirSpec) -> Extras { + use hir::Ty; let mut null_as_zero = false; let mut date_serialization = false; let mut currency = false; @@ -54,13 +55,13 @@ pub fn calculate_extras(spec: &MirSpec) -> Extras { for (_, record) in &spec.schemas { for field in record.fields() { match &field.ty { - Ty::Integer { serialization: ln_core::mir2::IntegerSerialization::NullAsZero } => { + Ty::Integer { serialization: IntegerSerialization::NullAsZero } => { null_as_zero = true; } - Ty::Integer { serialization: ln_core::mir2::IntegerSerialization::String } => { + Ty::Integer { serialization: IntegerSerialization::String } => { option_i64_str = true; } - Ty::Date { serialization: ln_core::mir2::DateSerialization::Integer } => { + Ty::Date { serialization: DateSerialization::Integer } => { integer_date_serialization = true; date_serialization = true; } @@ -124,7 +125,7 @@ pub fn generate_rust_library(spec: OpenAPI, opts: OutputOptions) -> Result<()> { Ok(()) } -fn write_model_module(mir_spec: &MirSpec, opts: &OutputOptions) -> Result<()> { +fn write_model_module(mir_spec: &HirSpec, opts: &OutputOptions) -> Result<()> { let config = &opts.library_options.config; let src_path = opts.dest_path.join("src"); @@ -133,14 +134,14 @@ fn write_model_module(mir_spec: &MirSpec, opts: &OutputOptions) -> Result<()> { fs::create_dir_all(src_path.join("model"))?; for (name, record) in &mir_spec.schemas { let file = generate_single_model_file(name, record, mir_spec, config); - let name = name.to_filename(); + let name = sanitize_filename(name); write_rust_file_to_path(&src_path.join("model").join(name).with_extension("rs"), file)?; } Ok(()) } /// Generates the client code for a given OpenAPI specification. -fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &OutputOptions) -> Result<()> { +fn write_lib_rs(mir_spec: &HirSpec, extras: &Extras, spec: &OpenAPI, opts: &OutputOptions) -> Result<()> { let src_path = opts.dest_path.join("src"); let name = &opts.library_options.service_name; let mut struct_Client = client::struct_Client(mir_spec, &opts.library_options); @@ -162,7 +163,7 @@ fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &Outp let lib_rs_template = if template_path.exists() { fs::read_to_string(template_path)? } else { - let s = get_template_file("rust/src/mir"); + let s = get_template_file("rust/src/lib.rs"); formatdoc!( r#" //! [`{client}`](struct.{client}.html) is the main entry point for this library. @@ -197,7 +198,7 @@ fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &Outp } -fn write_request_module(spec: &MirSpec, opts: &OutputOptions) -> Result<()> { +fn write_request_module(spec: &HirSpec, opts: &OutputOptions) -> Result<()> { let src_path = opts.dest_path.join("src"); let client_name = opts.library_options.client_name().to_rust_struct(); let mut imports = vec![]; @@ -293,7 +294,7 @@ fn bump_deps(current_manifest: &mut cargo_toml::Manifest, from_other: &cargo_tom Ok(()) } -fn write_examples(spec: &MirSpec, opts: &OutputOptions) -> Result { +fn write_examples(spec: &HirSpec, opts: &OutputOptions) -> Result { let example_path = opts.dest_path.join("examples"); let _ = fs::remove_dir_all(&example_path); diff --git a/libninja/src/rust/client.rs b/libninja/src/rust/client.rs index e651ebc..4a6fdc9 100644 --- a/libninja/src/rust/client.rs +++ b/libninja/src/rust/client.rs @@ -1,23 +1,18 @@ -use ln_core::mir2::{AuthLocation, AuthorizationStrategy, DocFormat, Location, Parameter, ServerStrategy}; -use ln_core::extractor::{extract_response_success, extract_security_strategies, spec_defines_auth}; -use crate::rust::codegen::{ToRustCode}; -use ln_core::{extractor, Language, LibraryOptions, MirSpec, mir2}; use convert_case::{Case, Casing}; -use mir::{Doc, field, Function, Ident, Name}; -use mir::{Class, Field, FnArg, Visibility}; -use openapiv3::{ - APIKeyLocation, OpenAPI, Operation, ReferenceOr, RequestBody, Schema, SchemaKind, - SecurityRequirement, SecurityScheme, StatusCode, -}; +use openapiv3::OpenAPI; use proc_macro2::TokenStream; -use quote::{format_ident, quote, ToTokens}; -use regex::Captures; -use ln_macro::rfunction; +use quote::{quote, ToTokens}; + +use hir::{AuthLocation, AuthorizationStrategy, DocFormat, Location, Parameter, ServerStrategy, Doc, HirSpec, Language, Operation}; +use mir::{field, Function, Ident}; +use mir::{Class, Field, FnArg, Visibility}; +use ln_core::LibraryOptions; + +use crate::rust::codegen::ToRustCode; use crate::rust::codegen::ToRustIdent; use crate::rust::codegen::ToRustType; - -fn build_Client_from_env(spec: &MirSpec, opt: &LibraryOptions) -> Function { +fn build_Client_from_env(spec: &HirSpec, opt: &LibraryOptions) -> Function { let declare_url = match spec.server_strategy() { ServerStrategy::Single(url) => quote! { .base_url(#url) @@ -64,7 +59,7 @@ fn build_Client_from_env(spec: &MirSpec, opt: &LibraryOptions) -> Function Class { +pub fn struct_Client(mir_spec: &HirSpec, opt: &LibraryOptions) -> Class { let auth_struct_name = opt.authenticator_name().to_rust_struct(); let mut instance_fields = vec![ @@ -84,7 +79,7 @@ pub fn struct_Client(mir_spec: &MirSpec, opt: &LibraryOptions) -> Class TokenStream { +pub fn build_api_client_method(operation: &Operation) -> TokenStream { let use_struct = operation.use_required_struct(Language::Rust); let fn_args = if use_struct { @@ -143,7 +138,7 @@ pub fn build_api_client_method(operation: &mir2::Operation) -> TokenStream { } } -pub fn impl_ServiceClient_paths(spec: &MirSpec) -> Vec { +pub fn impl_ServiceClient_paths(spec: &HirSpec) -> Vec { let mut result = vec![]; for operation in &spec.operations { result.push(build_api_client_method(operation)); @@ -157,7 +152,7 @@ pub fn authenticate_variant( ) -> TokenStream { let auth_struct = opt.authenticator_name().to_rust_struct(); - let variant_name = Name::new(&req.name).to_rust_struct(); + let variant_name = req.name.to_rust_struct(); let fields = req .fields .iter() @@ -196,7 +191,7 @@ pub fn authenticate_variant( } } -pub fn build_Client_authenticate(mir_spec: &MirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { +pub fn build_Client_authenticate(mir_spec: &HirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { let authenticate_variant = mir_spec.security .iter() .map(|req| authenticate_variant(req, opt)) @@ -238,7 +233,7 @@ fn build_new_fn(security: bool, opt: &LibraryOptions) -> TokenStream { } } -pub fn impl_Client(mir_spec: &mir2::MirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { +pub fn impl_Client(mir_spec: &HirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { let client_struct_name = opt.client_name().to_rust_struct(); let path_fns = impl_ServiceClient_paths(mir_spec); @@ -277,7 +272,7 @@ pub fn impl_Client(mir_spec: &mir2::MirSpec, spec: &OpenAPI, opt: &LibraryOption } } -pub fn struct_Authentication(mir_spec: &MirSpec, opt: &LibraryOptions) -> TokenStream { +pub fn struct_Authentication(mir_spec: &HirSpec, opt: &LibraryOptions) -> TokenStream { let auth_struct_name = opt.authenticator_name().to_rust_struct(); let variants = mir_spec.security.iter().map(|strategy| { @@ -296,7 +291,7 @@ pub fn struct_Authentication(mir_spec: &MirSpec, opt: &LibraryOptions) -> TokenS } } -fn build_Authentication_from_env(mir_spec: &MirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { +fn build_Authentication_from_env(mir_spec: &HirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { let first_variant = mir_spec.security.first() .unwrap(); let fields = first_variant @@ -325,7 +320,7 @@ fn build_Authentication_from_env(mir_spec: &MirSpec, spec: &OpenAPI, opt: &Libra } } -pub fn impl_Authentication(mir_spec: &MirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { +pub fn impl_Authentication(mir_spec: &HirSpec, spec: &OpenAPI, opt: &LibraryOptions) -> TokenStream { let auth_struct_name = opt.authenticator_name().to_rust_struct(); let from_env = build_Authentication_from_env(mir_spec, spec, opt); diff --git a/libninja/src/rust/codegen.rs b/libninja/src/rust/codegen.rs index d707c50..f4f1074 100644 --- a/libninja/src/rust/codegen.rs +++ b/libninja/src/rust/codegen.rs @@ -6,20 +6,51 @@ use quote::{quote, TokenStreamExt}; use regex::{Captures, Regex}; use syn::Path; -use mir::{ArgIdent, Class, Doc, Field, File, Function, Ident, Import, ImportItem, Literal, Visibility}; +use mir::{ArgIdent, Class, Field, File, Function, Ident, Import, ImportItem, Literal, Visibility}; pub use typ::*; pub use example::*; pub use ident::*; use ln_core::extractor::is_primitive; -use ln_core::mir2; - -use ln_core::mir2::{MirSpec, Name, NewType, Parameter, ParamKey, Record, StrEnum, Struct, Ty}; +use hir::{HirSpec, NewType, Parameter, ParamKey, Record, StrEnum, Struct, Ty, Doc, HirField}; use crate::rust::format; mod example; mod ident; mod typ; +pub trait ToRustIdent { + fn to_rust_struct(&self) -> Ident; + fn to_rust_ident(&self) -> Ident; +} + +impl ToRustIdent for String { + fn to_rust_struct(&self) -> Ident { + sanitize_struct(self) + } + + fn to_rust_ident(&self) -> Ident { + sanitize_ident(self) + } +} + +impl ToRustIdent for &str { + fn to_rust_struct(&self) -> Ident { + sanitize_struct(self) + } + + fn to_rust_ident(&self) -> Ident { + sanitize_ident(self) + } +} + +pub fn sanitize_filename(s: &str) -> String { + sanitize(s) +} + +pub fn sanitize_ident(s: &str) -> Ident { + Ident(sanitize(s)) +} + /// Use this for codegen structs: Function, Class, etc. pub trait ToRustCode { fn to_rust_code(self) -> TokenStream; @@ -251,10 +282,10 @@ impl ToRustCode for Option { } } -pub fn to_rust_example_value(ty: &Ty, name: &Name, spec: &MirSpec, use_ref_value: bool) -> Result { +pub fn to_rust_example_value(ty: &Ty, name: &str, spec: &HirSpec, use_ref_value: bool) -> Result { let s = match ty { Ty::String => { - let s = format!("your {}", name.0.to_case(Case::Lower)); + let s = format!("your {}", name.to_case(Case::Lower)); if use_ref_value { quote!(#s) } else { @@ -279,7 +310,7 @@ pub fn to_rust_example_value(ty: &Ty, name: &Name, spec: &MirSpec, use_ref_value } Ty::Model(model) => { let record = spec.get_record(model)?; - let force_not_ref = model.0.ends_with("Required"); + let force_not_ref = model.ends_with("Required"); match record { Record::Struct(Struct { name: _name, fields, nullable }) => { let fields = fields.iter().map(|(name, field)| { @@ -302,11 +333,11 @@ pub fn to_rust_example_value(ty: &Ty, name: &Name, spec: &MirSpec, use_ref_value } Record::Enum(StrEnum { name, variants }) => { let variant = variants.first().unwrap(); - let variant = Name::new(variant).to_rust_struct(); + let variant = variant.to_rust_struct(); let model = model.to_rust_struct(); quote!(#model::#variant) } - Record::TypeAlias(name, mir2::MirField { ty, optional, .. }) => { + Record::TypeAlias(name, HirField { ty, optional, .. }) => { let ty = to_rust_example_value(ty, name, spec, force_not_ref)?; if *optional { quote!(Some(#ty)) @@ -375,7 +406,8 @@ fn rewrite_names(s: &str) -> String { .replace('.', "_") } -fn sanitize(s: &str) -> String { +fn sanitize(s: impl AsRef) -> String { + let s = s.as_ref(); let original = s; let s = rewrite_names(s); let regex = Regex::new("[a-z]_[0-9]").unwrap(); @@ -397,18 +429,19 @@ fn sanitize(s: &str) -> String { s } -fn sanitize_struct(s: &str) -> String { +fn sanitize_struct(s: impl AsRef) -> Ident { + let s = s.as_ref(); let original = s; let s = rewrite_names(s); let mut s = s.to_case(Case::Pascal); if is_restricted(&s) { s += "Struct" } - assert_valid_ident(&s, original); - s + assert_valid_ident(&s, &original); + Ident(s) } -pub fn assert_valid_ident(s: &str, original: &str) { +fn assert_valid_ident(s: &str, original: &str) { if s.chars().next().map(|c| c.is_numeric()).unwrap_or_default() { panic!("Numeric identifier: {}", original) } @@ -425,19 +458,19 @@ pub fn formatted_code(code: impl ToRustCode) -> String { #[cfg(test)] mod tests { - use mir::{Ident, import, Import, Name}; + use mir::{Ident, import, Import}; use crate::rust::codegen::{ToRustCode, ToRustIdent}; #[test] fn test_to_ident() { - assert_eq!(Name::new("meta/root").to_rust_ident().0, "meta_root"); + assert_eq!("meta/root".to_rust_ident().0, "meta_root"); } #[test] fn test_to_ident1() { assert_eq!( - Name::new("get-phone-checks-v0.1").to_rust_ident().0, + "get-phone-checks-v0.1".to_rust_ident().0, "get_phone_checks_v0_1" ); } @@ -481,8 +514,8 @@ pub fn is_restricted(s: &str) -> bool { ["type", "use", "ref", "self", "match", "final"].contains(&s) } -pub fn serde_rename(one: &str, two: &str) -> TokenStream { - if one != two { +pub fn serde_rename(one: &str, two: &Ident) -> TokenStream { + if one != &two.0 { quote!(#[serde(rename = #one)]) } else { TokenStream::new() diff --git a/libninja/src/rust/codegen/example.rs b/libninja/src/rust/codegen/example.rs index 699692f..5ed5fe3 100644 --- a/libninja/src/rust/codegen/example.rs +++ b/libninja/src/rust/codegen/example.rs @@ -1,26 +1,27 @@ use proc_macro2::TokenStream; use quote::quote; + +use hir::{HirSpec, Language, Operation, Parameter}; use ln_macro::rfunction; use mir::{File, Import}; -use crate::{Language, LibraryOptions, }; -use ln_core::{mir2, mir2::{MirSpec, Parameter}}; -use crate::rust::codegen; -use crate::rust::codegen::ident::ToRustIdent; + +use crate::LibraryOptions; use crate::rust::codegen::{to_rust_example_value, ToRustCode}; +use crate::rust::codegen::ToRustIdent; use crate::rust::format::format_code; pub trait ToRustExample { - fn to_rust_example(&self, spec: &MirSpec) -> anyhow::Result; + fn to_rust_example(&self, spec: &HirSpec) -> anyhow::Result; } impl ToRustExample for Parameter { - fn to_rust_example(&self, spec: &MirSpec) -> anyhow::Result { + fn to_rust_example(&self, spec: &HirSpec) -> anyhow::Result { to_rust_example_value(&self.ty, &self.name, spec, false) } } -pub fn generate_example(operation: &mir2::Operation, opt: &LibraryOptions, spec: &MirSpec) -> anyhow::Result { +pub fn generate_example(operation: &Operation, opt: &LibraryOptions, spec: &HirSpec) -> anyhow::Result { let args = operation.function_args(Language::Rust); let declarations = args.iter().map(|p| { let ident = p.name.to_rust_ident(); diff --git a/libninja/src/rust/codegen/ident.rs b/libninja/src/rust/codegen/ident.rs index f3423d0..d7ab6ec 100644 --- a/libninja/src/rust/codegen/ident.rs +++ b/libninja/src/rust/codegen/ident.rs @@ -1,50 +1,11 @@ -use convert_case::{Case, Casing}; -use mir::{Ident, Name}; -use crate::rust::codegen; - -pub trait ToRustIdent { - fn to_rust_struct(&self) -> Ident; - fn to_filename(&self) -> String; - fn to_rust_ident(&self) -> Ident; -} - -impl ToRustIdent for Name { - fn to_rust_struct(&self) -> Ident { - Ident(codegen::sanitize_struct(&self.0)) - } - - fn to_filename(&self) -> String { - sanitize_filename(&self.0) - } - - fn to_rust_ident(&self) -> Ident { - Ident(codegen::sanitize(&self.0)) - } -} - - -impl ToRustIdent for String { - fn to_rust_struct(&self) -> Ident { - Ident(codegen::sanitize_struct(self.as_str())) - } - - fn to_filename(&self) -> String { - sanitize_filename(self.as_str()) - } - - fn to_rust_ident(&self) -> Ident { - Ident(codegen::sanitize(self.as_str())) - } -} - -fn sanitize_filename(s: &str) -> String { - codegen::sanitize(s) -} +use mir::Ident; +use crate::rust::codegen; #[cfg(test)] mod tests { use super::*; + use crate::rust::codegen::{ToRustIdent, sanitize_filename}; #[test] fn test_filename() { diff --git a/libninja/src/rust/codegen/typ.rs b/libninja/src/rust/codegen/typ.rs index e80c2d3..30f695f 100644 --- a/libninja/src/rust/codegen/typ.rs +++ b/libninja/src/rust/codegen/typ.rs @@ -1,7 +1,7 @@ use proc_macro2::TokenStream; use quote::quote; -use ln_core::mir2::Ty; -use crate::rust::codegen::ident::ToRustIdent; +use hir::Ty; +use crate::rust::codegen::ToRustIdent; /// Use this to generate Rust code types. pub trait ToRustType { diff --git a/libninja/src/rust/lower_mir.rs b/libninja/src/rust/lower_mir.rs index 4c70df8..bfdcba5 100644 --- a/libninja/src/rust/lower_mir.rs +++ b/libninja/src/rust/lower_mir.rs @@ -1,35 +1,28 @@ -use std::collections::{BTreeSet, HashSet}; -use clap::builder::Str; -use convert_case::{Case, Casing}; -use openapiv3::{OpenAPI, ReferenceOr, Schema}; -use openapiv3::{SchemaKind, StringType, Type}; -use proc_macro2::{Span, TokenStream}; -use quote::{quote, ToTokens}; -use tracing_ez::{info, span}; +use std::collections::BTreeSet; -use ::mir::{Field, File, Ident, Import, import, Name, Visibility}; -use ::mir as model; +use convert_case::Casing; +use proc_macro2::TokenStream; +use quote::{quote, ToTokens}; -use ln_core::{extractor, mir2, MirSpec}; -use ln_core::mir2::{DateSerialization, IntegerSerialization, MirField, NewType, Record, StrEnum, Struct, Ty, TypeAlias}; -use ln_core::mir2::AuthLocation::Token; -use ln_core::extractor::schema_ref_to_ty; +use hir::{DateSerialization, DecimalSerialization, HirField, HirSpec, IntegerSerialization, NewType, Record, StrEnum, Struct, Ty, TypeAlias}; use ln_core::LibraryConfig; +use mir::{Field, File, Ident, Import, import, Visibility}; + use crate::rust::codegen; -use crate::rust::codegen::{ToRustCode}; +use crate::rust::codegen::{sanitize_filename, ToRustCode}; use crate::rust::codegen::ToRustIdent; use crate::rust::codegen::ToRustType; pub trait FieldExt { - fn decorators(&self, name: &Name, config: &LibraryConfig) -> Vec; + fn decorators(&self, name: &str, config: &LibraryConfig) -> Vec; } -impl FieldExt for MirField { - fn decorators(&self, name: &Name, config: &LibraryConfig) -> Vec { +impl FieldExt for HirField { + fn decorators(&self, name: &str, config: &LibraryConfig) -> Vec { let mut decorators = Vec::new(); let rust_ident = name.to_rust_ident(); - if rust_ident.0 != name.0 { - let name = &name.0; + if rust_ident.0 != name { + let name = &name; if self.flatten { decorators.push(quote! { #[serde(flatten)] @@ -81,7 +74,7 @@ impl FieldExt for MirField { } } } - Ty::Currency { serialization: mir2::DecimalSerialization::String } => { + Ty::Currency { serialization: DecimalSerialization::String } => { if self.optional { decorators.push(quote! { #[serde(with = "rust_decimal::serde::str_option")] @@ -101,9 +94,10 @@ impl FieldExt for MirField { pub trait StructExt { fn implements_default(&self) -> bool; fn derive_default(&self) -> TokenStream; - fn model_fields<'a>(&'a self, config: &'a LibraryConfig) -> Box> + 'a>; + fn model_fields<'a>(&'a self, config: &'a LibraryConfig) -> Box> + 'a>; fn ref_target(&self) -> Option; } + impl StructExt for Struct { fn implements_default(&self) -> bool { @@ -118,7 +112,7 @@ impl StructExt for Struct { } } - fn model_fields<'a>(&'a self, config: &'a LibraryConfig) -> Box> + 'a> { + fn model_fields<'a>(&'a self, config: &'a LibraryConfig) -> Box> + 'a> { Box::new(self.fields.iter().map(|(name, field)| { let decorators = field.decorators(name, config); let ty = field.ty.to_rust_type(); @@ -132,13 +126,13 @@ impl StructExt for Struct { } _ => {} } - model::Field { + Field { name: name.clone(), ty, visibility: Visibility::Public, decorators, optional, - ..model::Field::default() + ..Field::default() } })) } @@ -172,12 +166,13 @@ impl RecordExt for Record { } /// Generate a model.rs file that just imports from dependents. -pub fn generate_model_rs(spec: &MirSpec, config: &LibraryConfig) -> File { - let imports = spec.schemas.keys().map(|name| { - Import::new(&name.to_filename(), vec!["*"]).public() +pub fn generate_model_rs(spec: &HirSpec, config: &LibraryConfig) -> File { + let imports = spec.schemas.keys().map(|name: &String| { + let fname = sanitize_filename(&name); + Import::new(&fname, vec!["*"]).public() }).collect(); let code = spec.schemas.keys().map(|name| { - let name = Ident::new(&name.to_filename()); + let name = Ident(sanitize_filename(name)); quote! { mod #name; } @@ -190,7 +185,7 @@ pub fn generate_model_rs(spec: &MirSpec, config: &LibraryConfig) -> File File { +pub fn generate_single_model_file(name: &str, record: &Record, spec: &HirSpec, config: &LibraryConfig) -> File { let mut imports = vec![ import!("serde", Serialize, Deserialize), ]; @@ -208,8 +203,8 @@ pub fn generate_single_model_file(name: &str, record: &Record, spec: &MirSpec, c } pub struct RefTarget { - name: Name, - ty: mir2::Ty, + name: String, + ty: Ty, } pub fn create_sumtype_struct(schema: &Struct, config: &LibraryConfig) -> TokenStream { @@ -256,10 +251,10 @@ fn create_enum_struct(e: &StrEnum) -> TokenStream { let original_name = s.to_string(); let mut s = original_name.clone(); if !s.is_empty() && s.chars().next().unwrap().is_numeric() { - s = format!("{}{}", e.name.0, s); + s = format!("{}{}", e.name, s); } - let name = Name::new(&s).to_rust_struct(); - let serde_attr = codegen::serde_rename(&original_name, &name.to_string()); + let name = s.to_rust_struct(); + let serde_attr = codegen::serde_rename(&original_name, &name); quote! { #serde_attr #name @@ -286,7 +281,7 @@ pub fn create_newtype_struct(schema: &NewType) -> TokenStream { } } -pub fn create_typealias(name: &Name, schema: &MirField) -> TokenStream { +pub fn create_typealias(name: &str, schema: &HirField) -> TokenStream { let name = name.to_rust_struct(); let mut ty = schema.ty.to_rust_type(); if schema.optional { @@ -308,18 +303,20 @@ pub fn create_struct(record: &Record, config: &LibraryConfig) -> TokenStream { #[cfg(test)] mod tests { - use ln_core::mir2::{MirField, Name, Ty}; + use hir::{HirField, Ty}; + use crate::rust::format::format_code; + use super::*; #[test] fn test_struct_newtype() { - let name = Name::new("NewType"); + let name = "NewType".to_string(); let schema = NewType { name, - fields: vec![MirField { + fields: vec![HirField { ty: Ty::String, - ..MirField::default() + ..HirField::default() }], }; let code = create_newtype_struct(&schema); diff --git a/libninja/src/rust/request.rs b/libninja/src/rust/request.rs index 122ae47..aad9439 100644 --- a/libninja/src/rust/request.rs +++ b/libninja/src/rust/request.rs @@ -1,21 +1,15 @@ use std::default::Default; -use anyhow::Result; use convert_case::{Case, Casing}; -use indoc::formatdoc; -use openapiv3::{ArrayType, OpenAPI, Operation, SchemaKind, Type}; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use regex::Captures; -use ln_core::mir2::{Parameter, Location, Ty}; -use ln_core::{extractor, Language, }; -use ln_core::extractor::{extract_response_success, schema_ref_to_ty, spec_defines_auth}; -use ln_core::mir2; +use hir::{Doc, HirSpec, Operation}; +use hir::{doc, Location, Parameter, Ty, Language}; +use ln_core::extractor::spec_defines_auth; use ln_core::LibraryOptions; -use ln_core::OutputOptions; -use mir::{Doc, doc, Ident, Name}; -use mir::{Class, Field, FnArg, Function, Visibility}; +use mir::{Class, Field, FnArg, Function, Ident, Visibility}; use crate::rust::codegen::ToRustCode; use crate::rust::codegen::ToRustIdent; @@ -83,7 +77,7 @@ pub fn assign_inputs_to_request(inputs: &[Parameter]) -> TokenStream { } } -pub fn build_url(operation: &mir2::Operation) -> TokenStream { +pub fn build_url(operation: &Operation) -> TokenStream { let inputs = operation .parameters .iter() @@ -111,7 +105,7 @@ pub fn build_url(operation: &mir2::Operation) -> TokenStream { } } -pub fn authorize_request(spec: &mir2::MirSpec) -> TokenStream { +pub fn authorize_request(spec: &HirSpec) -> TokenStream { if spec_defines_auth(spec) { quote! { r = self.http_client.authenticate(r); @@ -121,7 +115,7 @@ pub fn authorize_request(spec: &mir2::MirSpec) -> TokenStream { } } -pub fn build_send_function(operation: &mir2::Operation, spec: &mir2::MirSpec) -> Function { +pub fn build_send_function(operation: &Operation, spec: &HirSpec) -> Function { let assign_inputs = assign_inputs_to_request(&operation.parameters); let auth = authorize_request(spec); let response = operation.ret.to_rust_type(); @@ -183,7 +177,7 @@ pub fn build_struct_fields( /// Build the various "builder" methods for optional parameters for a request struct pub fn build_request_struct_builder_methods( - operation: &mir2::Operation, + operation: &Operation, ) -> Vec> { operation.parameters.iter().filter(|a| a.optional).map(|a| { let name = a.name.to_rust_ident(); @@ -228,15 +222,15 @@ pub fn build_request_struct_builder_methods( } pub fn build_request_struct( - operation: &mir2::Operation, - spec: &mir2::MirSpec, + operation: &Operation, + spec: &HirSpec, opt: &LibraryOptions, ) -> Vec> { let mut instance_fields = build_struct_fields(&operation.parameters, false); instance_fields.insert( 0, Field { - name: Name::new("http_client"), + name: "http_client".to_string(), ty: { let c = opt.client_name().to_rust_struct(); quote! { &'a #c } @@ -295,7 +289,7 @@ That method takes required values as arguments. Set optional values using builde result } -pub fn build_request_structs(spec: &mir2::MirSpec, opt: &LibraryOptions) -> Vec> { +pub fn build_request_structs(spec: &HirSpec, opt: &LibraryOptions) -> Vec> { let mut result = vec![]; for operation in &spec.operations { result.extend(build_request_struct(operation, spec, opt)); @@ -303,7 +297,7 @@ pub fn build_request_structs(spec: &mir2::MirSpec, opt: &LibraryOptions) -> Vec< result } -pub fn generate_request_model_rs(spec: &mir2::MirSpec, opt: &LibraryOptions) -> TokenStream { +pub fn generate_request_model_rs(spec: &HirSpec, opt: &LibraryOptions) -> TokenStream { let classes = build_request_structs(spec, opt); let mut request_structs = classes .into_iter() diff --git a/libninja/src/util.rs b/libninja/src/util.rs index 095a664..5c020e4 100644 --- a/libninja/src/util.rs +++ b/libninja/src/util.rs @@ -11,7 +11,7 @@ use ln_core::fs; use ln_core::OutputOptions; pub use mir::build_struct; -use crate::{MirSpec, }; +use crate::{HirSpec, }; pub fn code_sample(path: &Path) -> Option { match path.read_dir() { diff --git a/libninja/tests/all_of/main.rs b/libninja/tests/all_of/main.rs index 1d0e44f..84a6825 100644 --- a/libninja/tests/all_of/main.rs +++ b/libninja/tests/all_of/main.rs @@ -2,7 +2,8 @@ use openapiv3::{OpenAPI, ReferenceOr, Schema}; use pretty_assertions::assert_eq; /// Tests that the `allOf` keyword is handled correctly. -use ln_core::{LibraryConfig, mir2}; +use ln_core::{LibraryConfig}; +use hir::Record; const TRANSACTION: &str = include_str!("transaction.yaml"); const TRANSACTION_RS: &str = include_str!("transaction.rs"); @@ -11,14 +12,14 @@ const RESTRICTION_BACS: &str = include_str!("restriction_bacs.yaml"); const RESTRICTION_BACS_RS: &str = include_str!("restriction_bacs.rs"); -fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> mir2::Record { +fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> Record { let schema = serde_yaml::from_str::(schema).unwrap(); let mut record = ln_core::extractor::create_record(name, &schema, spec); record.clear_docs(); record } -fn formatted_code(record: mir2::Record) -> String { +fn formatted_code(record: Record) -> String { let config = LibraryConfig::default(); let code = libninja::rust::lower_mir::create_struct(&record, &config); libninja::rust::format::format_code(code).unwrap() diff --git a/libninja/tests/integration/basic/link_create_token.rs b/libninja/tests/basic/link_create_token.rs similarity index 99% rename from libninja/tests/integration/basic/link_create_token.rs rename to libninja/tests/basic/link_create_token.rs index 9021078..5248823 100644 --- a/libninja/tests/integration/basic/link_create_token.rs +++ b/libninja/tests/basic/link_create_token.rs @@ -7,14 +7,14 @@ async fn main() { let language = "your language"; let response = client .link_token_create(client_name, language) - .webhook("your webhook") .access_token("your access token") - .link_customization_name("your link customization name") - .redirect_uri("your redirect uri") .android_package_name("your android package name") .institution_id("your institution id") + .link_customization_name("your link customization name") + .redirect_uri("your redirect uri") .user_token("your user token") + .webhook("your webhook") .await .unwrap(); println!("{:#?}", response); -} +} \ No newline at end of file diff --git a/libninja/tests/integration/basic/main.rs b/libninja/tests/basic/main.rs similarity index 78% rename from libninja/tests/integration/basic/main.rs rename to libninja/tests/basic/main.rs index 3a8c5a5..dcd3f70 100644 --- a/libninja/tests/integration/basic/main.rs +++ b/libninja/tests/basic/main.rs @@ -1,11 +1,12 @@ -use ocg::extractor::{extract_api_operations, extract_inputs, extract_spec}; -use ocg::options::{LibraryConfig, LibraryOptions}; -use ocg::{generate_library, OutputOptions, rust}; -use ocg::lang::Language; +use std::fs::File; + +use anyhow::Result; +use hir::Language; +use libninja::{generate_library, rust}; +use ln_core::extractor::{extract_api_operations, extract_inputs, extract_spec}; +use ln_core::{LibraryConfig, LibraryOptions, OutputOptions}; use openapiv3::OpenAPI; use pretty_assertions::assert_eq; -use anyhow::Result; -use std::fs::File; const BASIC: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/spec/basic.yaml"); const RECURLY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/spec/recurly.yaml"); @@ -18,7 +19,7 @@ pub fn test_required_args() { let spec: OpenAPI = serde_yaml::from_reader(yaml).unwrap(); let (operation, path) = spec.get_operation("linkTokenCreate").unwrap(); let inputs = extract_inputs(&operation, path, &spec).unwrap(); - assert_eq!(inputs[8].name.0, "user_token"); + assert_eq!(inputs[8].name, "user_token"); assert_eq!(inputs[8].optional, true); } @@ -32,17 +33,18 @@ fn test_generate_example() -> Result<()> { package_name: "plaid".to_string(), service_name: "Plaid".to_string(), package_version: "0.1.0".to_string(), - generator: Language::Rust, + language: Language::Rust, + build_examples: false, config: Default::default(), }; let operations = extract_api_operations(&spec).unwrap(); let operation = operations .iter() - .find(|o| o.name.0 == "linkTokenCreate") + .find(|o| o.name == "linkTokenCreate") .unwrap(); - let spec = extract_spec(&spec, &opt).unwrap(); - let example = rust::example::generate_example(&operation, &opt, &spec)?; + let spec = extract_spec(&spec).unwrap(); + let example = rust::generate_example(&operation, &opt, &spec)?; assert_eq!(example, EXAMPLE); Ok(()) } diff --git a/libninja/tests/integration.rs b/libninja/tests/integration.rs deleted file mode 100644 index bf21c53..0000000 --- a/libninja/tests/integration.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(feature = "integration")] -mod integration { - #[path = "basic/main.rs"] - mod basic; - #[path = "full_lifecycle/main.rs"] - mod full_lifecyle; -} \ No newline at end of file diff --git a/libninja/tests/integration/full_lifecycle/main.rs b/libninja/tests/integration/full_lifecycle/main.rs deleted file mode 100644 index 35fb341..0000000 --- a/libninja/tests/integration/full_lifecycle/main.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(unused)] -use ocg::CreateEnvironment; -use anyhow::Result; -use std::path::Path; - -const POSTMAN: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/integration/full_lifecycle/postman.yaml"); - - -#[tokio::test] -#[cfg(feature = "integration")] -async fn test_lifecycle() -> Result<()> { - let test_repo_name = "test-postman-rs"; - let repo = format!("libninjacom/{test_repo_name}"); - let res = (|| async { - let token = env!("GH_TOKEN").to_string(); - - let temp = tempfile::tempdir()?; - let env = CreateEnvironment { - repo: repo.clone(), - gh_token: token.clone(), - homepage: "https://docs.rs/postman/".to_string(), - service: "Postman".to_string(), - dir: temp.path().display().to_string(), - tags: "openapi,rust,postman".to_string(), - }; - ::ocg::create_repo(env.clone()).await?; - - std::fs::remove_dir_all(temp.path().join(test_repo_name))?; - // Create it again because this is effectively idempotent. - ::ocg::create_repo(env.clone()).await?; - - eprintln!("Generating library..."); - ::ocg::generate_library_using_spec_at_path(&Path::new(POSTMAN), ::ocg::OutputOptions { - library_options: ::ocg::LibraryOptions { - package_name: "postman".to_string(), - service_name: "Postman".to_string(), - language: ::ocg::Language::Rust, - package_version: "0.1.0".to_string(), - config: ::ocg::LibraryConfig::default(), - }, - qualified_github_repo: env.repo, - dest_path: temp.path().join(test_repo_name), - })?; - - println!("Pushing repo..."); - ::ocg::push_repo(::ocg::PushEnvironment { - repo: test_repo_name.to_string(), - gh_token: token.clone(), - dir: temp.path().display().to_string(), - version: "0.1.0".to_string(), - }).await?; - Ok(()) - })().await; - - ocg::repo::delete_repo(&repo).await?; - res -} \ No newline at end of file diff --git a/libninja/tests/integration/full_lifecycle/postman.yaml b/libninja/tests/integration/full_lifecycle/postman.yaml deleted file mode 100644 index b4dd158..0000000 --- a/libninja/tests/integration/full_lifecycle/postman.yaml +++ /dev/null @@ -1,8286 +0,0 @@ -openapi: 3.0.3 -info: - title: Postman API - description: | - The Postman API lets you programmatically access data stored in Postman account with ease. - - ## Getting started - - The easiest way to get started with the Postman API is to [fork this collection](https://learning.postman.com/docs/collaborating-in-postman/version-control/#creating-a-fork) to your own workspace. You can then use Postman to send requests. - - ## Overview - - 1. You must use a valid API Key to send requests to the API endpoints. You can get your API key from Postman's [integrations dashboard](https://go.postman.co/settings/me/api-keys). - 1. The API has access rate limits. - 1. The API only responds to HTTPS-secured communications. Any requests sent via HTTP return an HTTP `301` redirect to the corresponding HTTPS resources. - 1. The API returns requests responses in [JSON format](https://en.wikipedia.org/wiki/JSON). When an API request returns an error, it is sent in the JSON response as an `"error": {}` key. - 1. The request method (verb) determines the nature of action you intend to perform. A request made using the `GET` method implies that you want to fetch something from Postman, and `POST` implies you want to save something new to Postman. - 1. API calls respond with the appropriate [HTTP status codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) for all requests. Within the Postman client, when a response is received, the status code is highlighted and is accompanied by a help text that indicates the possible meaning of the response code. A `200 OK` indicates success, while an HTTP `4XX` or HTTP `5XX` response code indicates an error from the requesting client or our API servers, respectively. - 1. Individual resources in your Postman account are accessible using its unique ID (`uid`) value. The `uid` is a simple concatenation of the resource owner's user ID and the resource's ID. For example, a collection's `uid` is `{{owner_id}}-{{collection_id}}` value. - - ## Authentication - - An API key is required to be sent as part of every request to the Postman API, in the form of an `X-Api-Key` request header. To get a Postman API key, you can generate one in the [**API keys**](https://postman.postman.co/settings/me/api-keys) section in your Postman account settings. - - An API key tells the API server that the received request from you. Everything that you have access to in Postman is accessible with your API key. - - For ease of use in Postman, you can store your API key as the `postman_api_key` [environment variable](https://www.getpostman.com/docs/environments). The Postman API [collection](https://www.getpostman.com/docs/collections) will automatically use it to make API calls. - - ### API Key related error response - - If an API key is missing, malformed, or invalid, you will receive an HTTP `401 Unauthorized` response code and the following JSON response: - - ```json - { - "error": { - "name": "AuthenticationError", - "message": "Invalid API Key. Every request requires a valid API Key to be sent." - } - } - ``` - - ### Using the API key as a query parameter - - Each request that accepts API key as `X-Api-Key` request header also accepts the key when it is sent as the `apikey` query parameter. - - An API key sent as part of the header has a higher priority when you send the key as both a request header and a query parameter. - - ## Rate Limits - - API access rate limits apply at a per-API key basis in unit time. Access to the API using an API key is limited to **60 requests per minute**. In addition, every API response is accompanied by the following set of headers to identify the status of your use: - - | Header | Description | - | ------ | ----------- | - | `X-RateLimit-Limit` | The maximum number of requests that the consumer is permitted to make per minute. | - | `X-RateLimit-Remaining` | The number of requests remaining in the current rate limit window. | - | `X-RateLimit-Reset` | The time at which the current rate limit window resets in UTC epoch seconds. | - - Once you reach the rate limit you will receive a response similar to the following HTTP `429 Too Many Requests` response: - - ```json - { - "error": { - "name": "rateLimitError", - "message": "Rate Limit exceeded. Please retry at 1465452702843" - } - } - ``` - - In the event you receive an HTTP `503` response from our servers, it indicates that we have had an unexpected spike in API access traffic. This is usually operational within the next five minutes. If the outage persists or you receive any other form of an HTTP `5XX` error, [contact support](https://support.postman.com/hc/en-us/requests/new/). - - ## Support - - For help regarding accessing the Postman API, you can: - - - Visit [Postman Support](https://support.postman.com/hc/en-us) or our [Community and Support](https://www.postman.com/community/) sites. - - Reach out to the [Postman community](https://community.postman.com/). - - Submit a help request to [Postman support](https://support.postman.com/hc/en-us/requests/new/). - - ## Policies - - - [Postman Terms of Service](http://postman.com/legal/terms/) - - [Postman Privacy Policy](https://www.postman.com/legal/privacy-policy/) - version: "1.0" - termsOfService: http://postman.com/legal/terms/ - contact: - name: Postman Support - email: help@postman.com - url: https://www.postman.com/community/ - license: - name: Apache 2.0 - url: https://www.apache.org/licenses/LICENSE-2.0.html - x-api-id: postman_api_key - x-audience: Developers - x-newrelic-app-id: - - 1162449093 -servers: - - url: https://api.getpostman.com -security: - - PostmanApiKey: [] -paths: - /apis: - get: - summary: Get all APIs - description: Gets information about all APIs. - operationId: getAllApis - tags: - - API - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - apis: - type: array - items: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API was created. - example: '2022-06-09T14:48:45.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API was updated. - example: '2022-06-09T19:50:49.000Z' - createdBy: - type: string - description: The user who created the API. - example: '12345678' - description: - type: string - description: The API's description. - example: This is a test API. - id: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - name: - type: string - description: The API's name. - example: Test API - summary: - type: string - description: The API's summary. - example: Test API. - examples: - Get All APIs: - value: - apis: - - createdAt: '2022-06-09T14:48:45.000Z' - updatedAt: '2022-06-09T19:50:49.000Z' - id: 5360b75f-447e-467c-9299-12fd6c92450d - name: Test API - summary: Test API. - description: This is a test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - - createdAt: '2022-06-22T16:51:28.000Z' - updatedAt: '2022-06-22T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public API A - summary: Public Test A. - description: This is a public test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - - createdAt: '2022-06-30T16:51:28.000Z' - updatedAt: '2022-06-30T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public Test API B - summary: Public Test B - description: This is another public test API. - createdBy: '87654321' - updatedBy: '87654321' - isPublic: false - Get Public APIs: - value: - apis: - - createdAt: '2022-06-09T14:48:45.000Z' - updatedAt: '2022-06-09T19:50:49.000Z' - id: 5360b75f-447e-467c-9299-12fd6c92450d - name: Test API - summary: Test API. - description: This is a test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - - createdAt: '2022-06-22T16:51:28.000Z' - updatedAt: '2022-06-22T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public API A - summary: Public Test A. - description: This is a public test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - Get APIs in a Date Range: - value: - apis: - - createdAt: '2022-06-09T14:48:45.000Z' - updatedAt: '2022-06-09T19:50:49.000Z' - id: 5360b75f-447e-467c-9299-12fd6c92450d - name: Test API - summary: Test API. - description: This is a test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - Filter APIs by Name: - value: - apis: - - createdAt: '2022-06-22T16:51:28.000Z' - updatedAt: '2022-06-22T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public API A - summary: Public Test A. - description: This is a public test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - - createdAt: '2022-06-30T16:51:28.000Z' - updatedAt: '2022-06-30T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public Test API B - summary: Public Test B - description: This is another public test API. - createdBy: '87654321' - updatedBy: '87654321' - isPublic: false - Sort by updatedAt: - value: - apis: - - createdAt: '2022-06-09T14:48:45.000Z' - updatedAt: '2022-06-09T19:50:49.000Z' - id: 5360b75f-447e-467c-9299-12fd6c92450d - name: Test API - summary: Test API. - description: This is a test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - - createdAt: '2022-06-22T16:51:28.000Z' - updatedAt: '2022-06-22T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public API A - summary: Public Test A. - description: This is a public test API. - createdBy: '12345678' - updatedBy: '12345678' - isPublic: true - - createdAt: '2022-06-30T16:51:28.000Z' - updatedAt: '2022-06-30T16:51:28.000Z' - id: 69ce25ea-2914-426e-ae34-af558b6777e6 - name: Public Test API B - summary: Public Test B - description: This is another public test API. - createdBy: '87654321' - updatedBy: '87654321' - isPublic: false - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - name: workspace - in: query - schema: - type: string - format: uuid - description: Return only APIs that are inside the given workspace. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - - name: since - in: query - schema: - type: string - format: date-time - description: Return only APIs updated at and after this time, in ISO 8601 UTC format. - example: '2022-06-01T00:00:00.000Z' - - name: until - in: query - schema: - type: string - format: date-time - description: Return only APIs updated at and before this time, in ISO 8601 UTC format. - example: '2022-06-15T00:00:00.000Z' - - name: createdBy - in: query - schema: - type: string - description: Return only APIs created by the given user ID. - example: '12345678' - - name: updatedBy - in: query - schema: - type: string - description: Return only APIs updated by the given user ID. - example: '12345678' - - name: isPublic - in: query - schema: - type: boolean - description: If true, return only public APIs; if false, return only private APIs. - example: true - - name: name - in: query - schema: - type: string - description: Return only APIs whose name includes the given value. Matching is not case-sensitive. - example: Test 123 - - name: summary - in: query - schema: - type: string - description: Return only APIs whose summary includes the given value. Matching is not case-sensitive. - example: Test API. - - name: description - in: query - schema: - type: string - description: Return only APIs whose description includes the given value. Matching is not case-sensitive. - example: This is a test API. - - name: sort - in: query - schema: - type: string - description: | - Sort the results by the given value. - - If you use this query parameter, you must also use the `direction` parameter. - example: updatedAt - - name: direction - in: query - schema: - type: string - enum: - - asc - - desc - description: | - Sort in ascending (`asc`) or descending (`desc`) order. Matching is not case-sensitive. - - If you use this query parameter, you must also use the `sort` parameter. - example: asc - post: - summary: Create an API - description: Creates an API. - operationId: createApi - tags: - - API - requestBody: - content: - application/json: - schema: - type: object - properties: - api: - type: object - properties: - name: - type: string - description: The API's name. - example: Test API - summary: - type: string - description: A short summary of the API. - example: Test API Schema - description: - type: string - description: A description of the API. - example: This is a test API. - example: - api: - name: Test API - summary: Test API Schema - description: This is a test API. - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - api: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API was created. - example: '2022-06-15T00:00:00.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API was last updated. - example: '2022-06-15T00:00:00.000Z' - id: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - name: - type: string - description: The API's name. - example: Test API - summary: - type: string - description: The API's short summary. - example: Test API Schema - createdBy: - type: string - description: The user ID of the user who created the API. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API. - example: '12345678' - description: - type: string - description: The API's description. - example: This is a test API. - example: - api: - createdAt: '2022-06-15T00:00:00.000Z' - updatedAt: '2022-06-15T00:00:00.000Z' - createdBy: '12345678' - description: This is a test API. - id: 387c2863-6ee3-4a56-8210-225f774edade - name: Test API - summary: Test API. - '400': - $ref: '#/components/responses/paramMissingError' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /apis/{apiId}: - get: - summary: Get an API - description: Gets information about an API. - operationId: singleApi - tags: - - API - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - api: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API was created. - example: '2022-06-09T14:48:45.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API was updated. - example: '2022-06-09T19:50:49.000Z' - id: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - name: - type: string - description: The API's name. - example: Test API - summary: - type: string - nullable: true - description: The API's short summary. - example: Test API. - description: - type: string - nullable: true - description: The API's description. - example: This is a test API. - createdBy: - type: string - description: The user ID of the user who created the API. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API. - example: '12345678' - team: - type: string - description: The API's assigned team. - example: '1234' - isPublic: - type: boolean - description: If true, the API is public. - example: true - versions: - type: array - description: Information about the API's version. - items: - type: object - properties: - id: - type: string - description: The API version's ID. - format: uuid - example: 16bb367e-fafb-4ef3-933b-ee3d971866fb - name: - type: string - description: The API version's name. - example: v1 - language: - type: string - description: The API version's schema file language. - example: json - content: - type: string - description: The API's stringified schema file. - example: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - relations: - type: array - description: Information about the API version's relations. - items: - type: object - properties: - id: - type: string - description: The relation's ID. - format: uuid - example: 66b88a55-9e52-41b0-8577-7b6798ff5bee - model: - type: string - description: The type of relation model. - example: schema - type: - type: string - description: The type of relation. - example: schema - modelId: - type: string - description: The model's ID. - format: uuid - example: 5a07383e-e604-4793-a48a-b6bb3019abc6 - example: - api: - createdAt: '2022-06-09T14:48:45.000Z' - updatedAt: '2022-06-09T19:50:49.000Z' - id: 5360b75f-447e-467c-9299-12fd6c92450d - name: Test API - summary: Test API. - description: This is a test API. - createdBy: '12345678' - updatedBy: '12345678' - team: '1234' - isPublic: true - versions: - - id: a9879d02-74bf-425a-bbec-6d27aa135507 - name: v1 - schemas: - - id: 16bb367e-fafb-4ef3-933b-ee3d971866fb - type: openapi3 - language: json - content: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - relations: - - id: 66b88a55-9e52-41b0-8577-7b6798ff5bee - model: schema - type: schema - modelId: 5a07383e-e604-4793-a48a-b6bb3019abc6 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update an API - description: Updates an API. - operationId: updateAnApi - tags: - - API - requestBody: - content: - application/json: - schema: - type: object - properties: - api: - type: object - properties: - name: - type: string - description: The API's name. - example: Test API A - summary: - type: string - description: A summary of the API. - example: Test API A Schema - description: - type: string - description: The description of the API. - example: This is Test API A. - example: - api: - name: Test API A - summary: Test API A Schema - description: This is Test API A. - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - api: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API was created. - example: '2022-06-15T00:00:00.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API was last updated. - example: '2022-06-15T00:00:00.000Z' - id: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - name: - type: string - description: The API's name. - example: Test API A - summary: - type: string - description: The API's short summary. - example: Test API A Schema - description: - type: string - description: The API's description. - example: This is Test API A. - createdBy: - type: string - description: The user ID of the user who created the API. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API. - example: '12345678' - example: - api: - createdAt: '2022-06-15T00:00:00.000Z' - updatedAt: '2022-06-15T00:00:00.000Z' - id: 5360b75f-447e-467c-9299-12fd6c92450d - name: Test API A - summary: Test API A Schema - description: This is Test API A. - createdBy: '12345678' - updatedBy: '12345678' - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete an API - description: Deletes an API. - operationId: deleteAnApi - tags: - - API - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - api: - type: object - properties: - id: - type: string - format: uuid - description: The deleted API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - example: - api: - id: 5360b75f-447e-467c-9299-12fd6c92450d - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - /apis/{apiId}/versions: - get: - summary: Get all API versions - description: Gets information about an API's versions. - operationId: getAllApiVersions - tags: - - API - - API Version - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - versions: - type: array - items: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API version was created. - example: '2022-06-30T16:46:35.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API version was last updated. - example: '2022-06-30T19:53:14.000Z' - id: - type: string - format: uuid - description: The API version's ID. - example: a9879d02-74bf-425a-bbec-6d27aa135507 - name: - type: string - description: The API version's name. - example: 'v1' - summary: - type: string - nullable: true - description: The API version's short summary. - example: This is a test API. - stage: - type: string - description: The [API version's status](https://learning.postman.com/docs/designing-and-developing-your-api/versioning-an-api/api-statuses/). - example: Planning - visibility: - type: string - description: The API version's visibility. - example: public - createdBy: - type: string - description: The user ID of the user who created the API version. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API version. - example: '12345678' - repositoryIntegration: - type: object - description: Information about the API version's repository integration. - nullable: true - properties: - lastCommit: - type: string - description: The SHA of the last commit to the repository. - example: e30e201cbe08983997b42c8e6fa2d45a6e8ea5ed - lastSyncedWithRepoAt: - type: string - description: The date and time at which the last repository sync occurred. - format: date-time - example: '2022-07-12T14:59:12.477Z' - lastRevision: - type: string - nullable: true - example: ~ - api: - type: string - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - example: - versions: - - createdAt: '2022-06-30T16:46:35.000Z' - updatedAt: '2022-06-30T19:53:14.000Z' - id: a9879d02-74bf-425a-bbec-6d27aa135507 - name: v1 - summary: This is a test API. - stage: Planning - visibility: public - createdBy: '12345678' - updatedBy: '12345678' - repositoryIntegration: - lastCommit: e30e201cbe08983997b42c8e6fa2d45a6e8ea5ed - lastSyncedWithRepoAt: '2022-07-12T14:59:12.477Z' - lastRevision: - api: 387c2863-6ee3-4a56-8210-225f774edade - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - post: - summary: Create an API version - description: Creates a new API version. - operationId: createApiVersion - tags: - - API - - API Version - requestBody: - content: - application/json: - schema: - type: object - properties: - version: - type: object - properties: - name: - type: string - description: The API version's name. - example: '1.0' - source: - type: object - description: The API version source information to copy to the created API version. - properties: - id: - type: string - example: The API version ID to use as the source for the created API version. - relations: - type: object - description: The API version source's relation types to copy to the new API version. - properties: - documentation: - type: boolean - default: false - description: If true, copy the source API version's documentation. - example: true - environment: - type: boolean - default: false - description: If true, copy the source API version's environment. - example: true - mock: - type: boolean - default: false - description: If true, copy the source API version's mock. - example: true - monitor: - type: boolean - default: false - description: If true, copy the source API version's monitor. - example: true - schema: - type: boolean - default: false - description: If true, copy the source API version's schema. - example: true - example: - version: - name: v2 - source: - id: a9879d02-74bf-425a-bbec-6d27aa135507 - schema: true - relations: - documentation: true - environment: true - mock: true - monitor: true - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - version: - type: object - properties: - id: - type: string - format: uuid - description: The API version's ID. - example: 8421a1f3-3262-4d47-a597-7005bf4c1564 - name: - type: string - description: The API version's name. - example: v1 - api: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - example: - version: - id: 8421a1f3-3262-4d47-a597-7005bf4c1564 - name: v2 - api: 387c2863-6ee3-4a56-8210-225f774edade - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - /apis/{apiId}/versions/{apiVersionId}: - get: - summary: Get an API version - description: Gets information about an API version. - operationId: getAnApiVersion - tags: - - API - - API Version - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - version: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API version was created. - example: '2022-06-30T16:46:35.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API version was last updated. - example: '2022-06-30T19:53:14.000Z' - id: - type: string - format: uuid - description: The API version's ID. - example: a9879d02-74bf-425a-bbec-6d27aa135507 - name: - type: string - description: The API version's name. - example: "v1" - summary: - type: string - nullable: true - description: The API version's short summary. - example: This is a test API. - stage: - type: string - description: The [API version's status](https://learning.postman.com/docs/designing-and-developing-your-api/versioning-an-api/api-statuses/). - example: Planning - visibility: - type: string - description: The API version's visibility. - example: public - createdBy: - type: string - description: The user ID of the user who created the API version. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API version. - example: '12345678' - repositoryIntegration: - type: object - description: Information about the API version's repository integration. - nullable: true - properties: - lastCommit: - type: string - description: The SHA of the last commit to the repository. - example: e30e201cbe08983997b42c8e6fa2d45a6e8ea5ed - lastSyncedWithRepoAt: - type: string - description: The date and time at which the last repository sync occurred. - format: date-time - example: '2022-07-12T14:59:12.477Z' - lastRevision: - type: string - nullable: true - example: ~ - api: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - schema: - type: array - description: A list of the API version's schema IDs. - items: - type: string - example: 16bb367e-fafb-4ef3-933b-ee3d971866fb - example: - version: - createdAt: '2022-06-09T14:48:45.000Z' - updatedAt: '2022-06-09T19:50:49.000Z' - id: a9879d02-74bf-425a-bbec-6d27aa135507 - name: v1 - summary: Test API. - stage: Planning - visibility: public - createdBy: '12345678' - updatedBy: '12345678' - repositoryIntegration: - lastRevision: - api: 387c2863-6ee3-4a56-8210-225f774edade - schema: - - 16bb367e-fafb-4ef3-933b-ee3d971866fb - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update an API version - description: Updates an API version. - operationId: updateAnApiVersion - tags: - - API - - API Version - requestBody: - content: - application/json: - schema: - type: object - properties: - version: - type: object - properties: - name: - type: string - description: The API version's name. - example: 'v2' - example: - version: - name: v2 - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - version: - type: object - properties: - createdAt: - type: string - format: date-time - description: The date and time at which the API version was created. - example: '2022-06-30T16:46:35.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API version was last updated. - example: '2022-06-30T19:53:14.000Z' - id: - type: string - format: uuid - description: The API version's ID. - example: a9879d02-74bf-425a-bbec-6d27aa135507 - name: - type: string - description: The API version's name. - example: 'v2' - summary: - type: string - nullable: true - description: The API version's short summary. - example: This is a test API. - stage: - type: string - description: The [API version's status](https://learning.postman.com/docs/designing-and-developing-your-api/versioning-an-api/api-statuses/). - example: Planning - visibility: - type: string - description: The API version's visibility. - example: public - createdBy: - type: string - description: The user ID of the user who created the API version. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API version. - example: '12345678' - repositoryIntegration: - type: object - description: Information about the API version's repository integration. - nullable: true - properties: - lastCommit: - type: string - description: The SHA of the last commit to the repository. - example: e30e201cbe08983997b42c8e6fa2d45a6e8ea5ed - lastSyncedWithRepoAt: - type: string - description: The date and time at which the last repository sync occurred. - format: date-time - example: '2022-07-12T14:59:12.477Z' - lastRevision: - type: string - nullable: true - example: ~ - api: - type: string - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - example: - version: - createdAt: '2022-06-30T16:46:35.000Z' - updatedAt: '2022-06-30T19:53:14.000Z' - id: a9879d02-74bf-425a-bbec-6d27aa135507 - name: v2 - summary: This is a test API. - stage: Planning - visibility: public - createdBy: '12345678' - updatedBy: '12345678' - repositoryIntegration: - lastCommit: e30e201cbe08983997b42c8e6fa2d45a6e8ea5ed - lastSyncedWithRepoAt: "2022-07-12T14:59:12.477Z" - api: 387c2863-6ee3-4a56-8210-225f774edade - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete an API version - description: Deletes an API version. - operationId: deleteAnApiVersion - tags: - - API - - API Version - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - version: - type: object - properties: - id: - type: string - description: The deleted API version's ID. - example: a9879d02-74bf-425a-bbec-6d27aa135507 - example: - version: - id: a9879d02-74bf-425a-bbec-6d27aa135507 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/contracttest: - get: - summary: Get contract test relations - deprecated: true - description: This endpoint is **deprecated**. Use the `/apis/{apiId}/versions/{apiVersionId}/test` endpoint. - operationId: getContractTestRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - contracttest: - type: array - description: The API version's contract test relations. - items: - type: object - properties: - id: - type: string - description: The contract test relation ID. - example: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: - type: string - description: The contract test's name. - example: Contract Test - updatedAt: - type: string - format: date-time - description: The date and time at which the contract test was last updated. - example: '2019-08-29T10:18:11.000Z' - collectionId: - type: string - description: The related collection's ID. - example: 7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745 - example: - contracttest: - - id: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: Contract Test - updatedAt: '2019-08-29T10:18:11.000Z' - collectionId: 7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/documentation: - get: - summary: Get documentation relations - description: Gets an API version's documentation relations. - operationId: getDocumentationRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - documentation: - type: array - description: The API version's documentation relations. - items: - type: object - properties: - id: - type: string - description: The documentation relation ID. - example: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: - type: string - description: The related documentation's name. - example: Test Collection - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T20:31:06.000Z' - collectionId: - type: string - description: The related documentation's ID. - example: 12345678-203ec937-0c09-42e4-b1d1-553bd4ea9e42 - example: - documentation: - - id: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: Test Collection - updatedAt: '2022-07-08T20:31:06.000Z' - collectionId: 12345678-203ec937-0c09-42e4-b1d1-553bd4ea9e42 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/environment: - get: - summary: Get environment relations - description: Gets an API version's environment relations. - operationId: getEnvironmentRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - environment: - type: array - description: The API version's environment relations. - items: - type: object - properties: - id: - type: string - description: The environment relation ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The related environment's name. - example: Test Environment - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T20:31:30.000Z' - environmentId: - type: string - description: The related environment's ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - example: - environment: - - id: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Environment - updatedAt: '2022-07-08T20:31:30.000Z' - environmentId: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/integrationtest: - get: - summary: Get integration test relations - deprecated: true - description: This endpoint is **deprecated**. Use the `/apis/{apiId}/versions/{apiVersionId}/test` endpoint. - operationId: getIntegrationTestRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - integrationtest: - type: array - description: The API version's integration test relations. - items: - type: object - properties: - id: - type: string - description: The integration test relation ID. - example: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: - type: string - description: The integration test's name. - example: C test - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2019-08-29T10:18:11.000Z' - collectionId: - type: string - description: The related collection's ID. - example: 7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745 - example: - integrationtest: - - id: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: C test - updatedAt: '2019-08-29T10:18:11.000Z' - collectionId: 12345678-a8bcd149-2b01-4b4c-8c14-c7d05be77745 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/mock: - get: - summary: Get mock server relations - description: Gets an API version's mock server relations. - operationId: getMockServerRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: array - description: The API version's mock server relations. - items: - type: object - properties: - id: - type: string - description: The mock server relation ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - name: - type: string - description: The related mock server's name. - example: Test Mock - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-10T05:00:25.066Z' - mockId: - type: string - format: uuid - description: The related mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - example: - mock: - - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - name: Test Mock - updatedAt: '2022-07-25T20:48:13.000Z' - mockId: e3d951bf-873f-49ac-a658-b2dcb91d3289 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/monitor: - get: - summary: Get monitor relations - description: Gets an API version's monitor relations. - operationId: getMonitorRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - monitor: - type: array - description: The API version's monitor relations. - items: - type: object - properties: - id: - type: string - description: The monitor relation ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The related monitor's name. - example: Test Monitor - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-10T05:00:25.066Z' - monitorId: - type: string - format: uuid - description: The related monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - example: - monitor: - - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - monitorId: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - updatedAt: '2022-07-10T05:00:25.066Z' - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/relations: - get: - summary: Get all linked relations - description: Gets all of an API version's relations. - operationId: getLinkedRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - relations: - type: object - description: The API version's relations. - properties: - schema: - type: object - description: The API version's schema relations. - properties: - additionalProperties: - type: object - description: Information about the schema. The object's name is the schema relation's ID. - properties: - id: - type: string - description: The schema relation ID. - example: 16bb367e-fafb-4ef3-933b-ee3d971866fb - documentation: - type: object - description: The API version's documentation relations. - properties: - additionalProperties: - type: object - description: Information about the documentation. The object's name is the documentation relation's ID. - properties: - id: - type: string - description: The documentation relation ID. - example: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: - type: string - description: The related documentation's name. - example: Test Collection - createdAt: - type: string - format: date-time - description: The date and time at which the documentation relation was created. - example: '2022-07-08T20:31:06.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T20:31:06.000Z' - environment: - type: object - description: The API version's environment relations. - properties: - additionalProperties: - type: object - description: Information about the environment. The object's name is the environment relation's ID. - properties: - id: - type: string - description: The environment relation ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The related environment's name. - example: Test Environment - createdAt: - type: string - format: date-time - description: The date and time at which the environment relation was created. - example: '2022-07-08T20:31:06.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T20:31:06.000Z' - monitor: - type: object - description: The API version's monitor relations. - properties: - additionalProperties: - type: object - description: Information about the monitor. The object's name is the monitor relation's ID. - properties: - id: - type: string - description: The monitor relation ID. - example: 1ecfedca-f067-4920-8a53-ec3ec0f416bf - name: - type: string - description: The related monitor's name. - example: Test Monitor - createdAt: - type: string - format: date-time - description: The date and time at which the monitor relation was created. - example: '2022-07-08T20:31:30.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T20:31:30.000Z' - mock: - type: object - description: The API version's mock server relations. - properties: - additionalProperties: - type: object - description: Information about the mock server. The object's name is the mock server relation's ID. - properties: - id: - type: string - description: The mock server relation ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - name: - type: string - description: The related mock server's name. - example: Test Mock - createdAt: - type: string - format: date-time - description: The date and time at which the mock server relation was created. - example: '2022-07-10T05:00:25.066Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-10T05:00:25.066Z' - url: - type: string - format: url - description: The mock server's URL. - example: 'https://4ccd755f-2c80-481b-a262-49b55e12f5e1.mock-beta.pstmn.io' - test: - type: object - description: The API version's test relations. - properties: - additionalProperties: - type: object - description: Information about the test. The object's name is the test relation's ID. - properties: - id: - type: string - description: The test relation ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The related test's name. - example: Test Collection - createdAt: - type: string - format: date-time - description: The date and time at which the mock server relation was created. - example: '2022-07-08T18:32:49.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T18:32:49.000Z' - contracttest: - type: object - deprecated: true - description: | - **Deprecated. Use the `test` response.** The API version's contract test relations. - properties: - additionalProperties: - type: object - description: Information about the contract test. The object's name is the contract test relation's ID. - properties: - id: - type: string - description: The contract test relation ID. - example: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: - type: string - description: The contract test's name. - example: Contract Test - createdAt: - type: string - format: date-time - description: The date and time at which the contract test relation was created. - example: '2019-08-29T10:18:11.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was last updated. - example: '2019-08-29T10:18:11.000Z' - integrationtest: - type: object - deprecated: true - description: | - **Deprecated. Use the `test` response.** The API version's contract test relations. - properties: - additionalProperties: - type: object - description: Information about the integration test. The object's name is the integration test relation's ID. - properties: - id: - type: string - description: The integration test relation ID. - example: 521b0486-ab91-4d3a-9189-43c9380a0533 - name: - type: string - description: The integration test's name. - example: Integration Test - createdAt: - type: string - format: date-time - description: The date and time at which the integration test relation was created. - example: '2019-08-29T10:18:11.000Z' - updatedAt: - type: string - description: The date and time at which the relation was last updated. - example: '2019-08-29T11:40:39.000Z' - example: - relations: - schema: - 16bb367e-fafb-4ef3-933b-ee3d971866fb: - id: 16bb367e-fafb-4ef3-933b-ee3d971866fb - documentation: - 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2: - id: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: Test Collection - createdAt: '2022-07-08T16:38:54.000Z' - updatedAt: '2022-07-08T16:38:54.000Z' - environment: - 12345678-5daabc50-8451-43f6-922d-96b403b4f28e: - id: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Environment - createdAt: '2022-07-08T16:27:56.000Z' - updatedAt: '2022-07-08T17:14:18.000Z' - monitor: - 1ecfedca-f067-4920-8a53-ec3ec0f416bf: - id: 1ecfedca-f067-4920-8a53-ec3ec0f416bf - name: Test Monitor - createdAt: '2022-07-08T16:40:33.000Z' - updatedAt: '2022-07-10T05:00:25.066Z' - mock: - e3d951bf-873f-49ac-a658-b2dcb91d3289: - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - name: Test Mock - createdAt: '2022-07-08T16:26:51.000Z' - updatedAt: '2022-07-08T16:26:50.000Z' - url: https://04f3b440-665d-4066-a3db-9d87e566858e.mock.pstmn.io - test: - 12ece9e1-2abf-4edc-8e34-de66e74114d2: - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - createdAt: '2022-07-08T18:32:49.000Z' - updatedAt: '2022-07-08T18:32:23.000Z' - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - post: - summary: Create relations - description: Creates a new relation for an API version. This endpoint accepts multiple relation arrays in a single call. - operationId: createRelations - tags: - - API - - Relations - requestBody: - content: - application/json: - schema: - type: object - properties: - documentation: - type: array - description: A list of collection UID values with which to create an API version relation. - items: - type: string - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: - type: array - description: A list of environment UID values with which to create an API version relation. - items: - type: string - example: 5daabc50-8451-43f6-922d-96b403b4f28e - mock: - type: array - description: A list of mock ID values with which to create an API version relation. - items: - type: string - example: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitor: - type: array - description: A list of monitor ID values with which to create an API version relation. - items: - type: string - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - test: - type: array - description: A list collection UID values with which to create an API version relation. - items: - type: string - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - contracttest: - type: array - deprecated: true - description: | - **Deprecated. Use the `test` property.** A list of collection UID values with which to create an API version relation. - items: - type: string - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - testsuite: - type: array - deprecated: true - description: | - **Deprecated. Use the `test` property.** A list of collection UID values with which to create an API version relation. - items: - type: string - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - documentation: - - 12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: - - 5daabc50-8451-43f6-922d-96b403b4f28e - mock: - - 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitor: - - 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - test: - - 12ece9e1-2abf-4edc-8e34-de66e74114d2 - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - documentation: - type: array - description: A list of the documentation relation IDs. - items: - type: string - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: - type: array - description: A list of the API version's related environment UID values. - items: - type: string - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - mock: - type: array - description: A list of the API version's related mock ID values. - items: - type: string - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitor: - type: array - description: A list of the API version's related monitor ID values. - items: - type: string - example: 1ecfedca-f067-4920-8a53-ec3ec0f416bf - test: - type: array - description: A list of the test relation IDs. - items: - type: string - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - contracttest: - type: array - deprecated: true - description: | - **Deprecated. Use the `test` response.** A list of the API version's related collection ID values. - items: - type: string - example: 5bcece87-ca4b-4e75-a967-2a6845626164 - testsuite: - type: array - deprecated: true - description: | - **Deprecated. Use the `test` response.** A list of the API version's related collection ID values. - items: - type: string - example: e525fa71-035e-4620-acda-ce878524f1e7 - example: - documentation: - - 12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: - - 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - mock: - - e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitor: - - 1ecfedca-f067-4920-8a53-ec3ec0f416bf - test: - - 12ece9e1-2abf-4edc-8e34-de66e74114d2 - '400': - $ref: '#/components/responses/invalidParamsError' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/schemas: - post: - summary: Create a schema - description: Creates an API definition. - operationId: createSchema - tags: - - API - - Schema - requestBody: - content: - application/json: - schema: - type: object - properties: - schema: - type: object - properties: - language: - type: string - description: | - The API definition's language. One of: - - OpenAPI and RAML — `json` or `yaml` - - GraphQL — `graphql` - - WSDL — `xml` - - Protobuf — `proto` - example: json - enum: - - json - - yaml - - graphql - - xml - - proto - schema: - type: string - description: The API definition's contents. - example: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - type: - type: string - description: The API definition's type. - enum: - - openapi3_1 - - openapi3 - - openapi2 - - openapi1 - - raml - - raml1 - - wsdl1 - - wsdl2 - - graphql - - proto2 - - graphql - - proto3 - example: openapi3 - example: - schema: - language: json - schema: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - type: openapi3 - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - schema: - type: object - description: Information about the created API definition. - properties: - language: - type: string - description: The API definition's language. - example: json - type: - type: string - description: The API definition's type. - example: openapi3 - id: - type: string - format: uuid - description: The API definition's ID. - example: e3b3a0b7-34d5-4fc5-83e0-118bd9e8c822 - createdBy: - type: string - description: The user ID of the user who created the API definition. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API definition. - example: '12345678' - createdAt: - type: string - format: date-time - description: The date and time at which the API definition was created. - example: '2021-05-22T13:17:07.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API definition was last updated. - example: '2021-05-22T13:17:07.000Z' - apiVersion: - type: string - description: The API version's ID. - format: uuid - example: ad810c39-df60-434e-a76f-a2192cd8d81f - example: - schema: - language: json - type: openapi3 - id: e3b3a0b7-34d5-4fc5-83e0-118bd9e8c822 - createdBy: '12345678' - updatedBy: '12345678' - createdAt: '2021-05-22T13:17:07.000Z' - updatedAt: '2021-05-22T13:17:07.000Z' - apiVersion: ad810c39-df60-434e-a76f-a2192cd8d81f - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceAlreadyExists - message: - type: string - description: The error message. - example: A schema already exists for this API Version - example: - error: - name: instanceAlreadyExists - message: A schema already exists for this API Version - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/schemas/{schemaId}: - get: - summary: Get a schema - description: Gets information about an API's definition. - operationId: getSchema - tags: - - API - - Schema - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - schema: - type: object - description: Information about the created API definition. - properties: - id: - type: string - description: The API definition's ID. - example: 16bb367e-fafb-4ef3-933b-ee3d971866fb - type: - type: string - description: The API definition's type. - example: openapi3 - language: - type: string - description: The API definition's language. - example: json - createdAt: - type: string - format: date-time - description: The date and time at which the API definition was created. - example: '2022-07-01T20:12:31.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API definition was last updated. - example: '2022-07-01T20:13:04.000Z' - createdBy: - type: string - description: The user ID of the user who created the API definition. - example: '12345678' - updatedBy: - type: string - example: '12345678' - schema: - type: string - example: "{\n \"openapi\": \"3.0.0\",\n \"info\": null,\n \"version\": \"v1.0\",\n \"title\": \"API\",\n \"servers\": [\n {\n \"url\": \"http://localhost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"Returns details about a particular user\",\n \"operationId\": \"listUser\",\n \"tags\": [\n \"user\"\n ],\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"description\": \"ID of the user\",\n \"required\": true,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Details about a user by ID\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"\\\\'#/components/schemas/User\\\\'\"\n }\n }\n }\n },\n \"default\": {\n \"description\": \"Unexpected error\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"\\\\'#/components/schemas/Error\\\\'\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - apiVersion: - type: string - description: The API version's ID. - example: ad810c39-df60-434e-a76f-a2192cd8d81f - example: - schema: - id: 16bb367e-fafb-4ef3-933b-ee3d971866fb - type: openapi3 - language: json - createdAt: "2022-07-01T20:12:31.000Z" - updatedAt: "2022-07-01T20:13:04.000Z" - createdBy: "12345678" - updatedBy: "12345678" - schema: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - apiVersion: a9879d02-74bf-425a-bbec-6d27aa135507 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update a schema - description: Updates an API definition. - operationId: updateSchema - tags: - - API - - Schema - requestBody: - content: - application/json: - schema: - type: object - properties: - schema: - type: object - properties: - language: - type: string - description: | - The API definition's language. One of: - - OpenAPI and RAML — `json` or `yaml` - - GraphQL — `graphql` - - WSDL — `xml` - - Protobuf — `proto` - example: yaml - enum: - - json - - yaml - - graphql - - xml - - proto - schema: - type: string - description: The API definition's contents. - example: "openapi: 3.0.0\ninfo:\n version: 1.0.0\n title: Test API\nservers:\n - url: http://localhost:3000\npaths:\n /user:\n get:\n summary: List all users\n operationId: listUser\n tags:\n - user\n parameters:\n - name: id\n in: query\n required: true\n description: The user's ID.\n example: 1234\n schema:\n type: integer\n format: int32\n responses:\n '200':\n description: Information about the user.\n headers:\n x-next:\n description: A link to the next page of responses.\n schema:\n type: string\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/User' \ncomponents:\n schemas:\n User:\n type: object\n required:\n - id\n - name\n properties:\n id:\n type: integer\n format: int32\n Error:\n type: object\n required:\n - code\n - message\n properties:\n code:\n type: integer\n format: int32\n message:\n type: string\n" - type: - type: string - description: The API definition's type. - enum: - - openapi3_1 - - openapi3 - - openapi2 - - openapi1 - - raml - - raml1 - - wsdl1 - - wsdl2 - - graphql - - proto2 - - graphql - - proto3 - example: openapi3 - example: - schema: - language: yaml - schema: "openapi: 3.0.0\ninfo:\n version: 1.0.0\n title: Test API\nservers:\n - url: http://localhost:3000\npaths:\n /user:\n get:\n summary: List all users\n operationId: listUser\n tags:\n - user\n parameters:\n - name: id\n in: query\n required: true\n description: The user's ID.\n example: 1234\n schema:\n type: integer\n format: int32\n responses:\n '200':\n description: Information about the user.\n headers:\n x-next:\n description: A link to the next page of responses.\n schema:\n type: string\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/User' \ncomponents:\n schemas:\n User:\n type: object\n required:\n - id\n - name\n properties:\n id:\n type: integer\n format: int32\n Error:\n type: object\n required:\n - code\n - message\n properties:\n code:\n type: integer\n format: int32\n message:\n type: string\n" - type: openapi3 - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - schema: - type: object - properties: - id: - type: string - description: The API definition's ID. - example: e3b3a0b7-34d5-4fc5-83e0-118bd9e8c822 - language: - type: string - description: The API definition's language. - example: yaml - apiVersion: - type: string - example: ad810c39-df60-434e-a76f-a2192cd8d81f - type: - type: string - description: The API definition's type. - example: openapi3 - createdBy: - type: string - description: The user ID of the user who created the API definition. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the API definition. - example: '12345678' - createdAt: - type: string - format: date-time - description: The date and time at which the API definition was created. - example: '2021-05-22T13:17:07.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the API definition was last updated. - example: '2021-05-22T13:17:07.000Z' - example: - schema: - id: 16bb367e-fafb-4ef3-933b-ee3d971866fb - language: yaml - apiVersion: a9879d02-74bf-425a-bbec-6d27aa135507 - type: openapi3 - createdBy: '12345678' - updatedBy: '12345678' - createdAt: '2021-05-22T13:17:07.000Z' - updatedAt: '2021-05-22T13:17:07.000Z' - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - - $ref: "#/components/parameters/schemaId" - /apis/{apiId}/versions/{apiVersionId}/schemas/{schemaId}/collections: - post: - summary: Create collection from a schema - description: Creates a collection and links it to an API as one or multiple relations. - operationId: createCollectionFromSchema - tags: - - API - - Schema - requestBody: - content: - application/json: - schema: - type: object - required: - - name - - relations - properties: - name: - type: string - description: The name of the collection. - example: Test Collection - relations: - type: array - description: A list of collection relations. - items: - type: object - properties: - type: - type: string - description: | - The type of relation to create with the collection. - - **Note:** - - The `contracttest`, `integrationtest`, and `testsuite` values are deprecated. - example: documentation - enum: - - documentation - example: - name: Test Collection - relations: - - type: documentation - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - description: Information about the collection. - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - relations: - type: array - description: Information about the collection's relations. - items: - type: object - properties: - id: - type: string - description: The relation's ID. - example: 4b40f06a-5a6a-448f-bfcd-a6dbcb68da22 - type: - type: string - description: The type of relation. - example: documentation - example: - collection: - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - relations: - - type: documentation - id: d86b6c97-fdf9-4c37-825a-49b0223913c7 - '400': - $ref: '#/components/responses/invalidParamsError' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/apiId' - - $ref: '#/components/parameters/apiVersionId' - - $ref: '#/components/parameters/schemaId' - - $ref: '#/components/parameters/workspaceQueryId' - /apis/{apiId}/versions/{apiVersionId}/test: - get: - summary: Get all test relations - description: Gets all of an API version's test relations. - operationId: getTestRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - test: - type: array - description: The API version's test relations. - items: - type: object - properties: - id: - type: string - format: uuid - description: The test relation ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The related test's name. - example: Test Collection - updatedAt: - type: string - format: date-time - description: The date and time at which the relation was updated. - example: '2022-07-08T18:32:23.000Z' - collectionId: - type: string - description: The related test's ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - test: - - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - updatedAt: '2022-07-08T18:32:23.000Z' - collectionId: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/testsuite: - get: - summary: Get test suite relations - deprecated: true - description: This endpoint is **deprecated**. Use the `/apis/{apiId}/versions/{apiVersionId}/test` endpoint. - operationId: getTestSuiteRelations - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - testsuite: - type: array - items: - type: object - properties: - collectionId: - type: string - description: The collection ID. - example: 7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745 - id: - type: string - format: uuid - example: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: - type: string - example: C test - updatedAt: - type: string - example: '2019-08-29T10:18:11.000Z' - example: - testsuite: - - collectionId: 7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745 - id: 2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2 - name: C test - updatedAt: '2019-08-29T10:18:11.000Z' - - collectionId: 7332157-a8bcd143-2b01-4b12-8c14-c7d05be77725 - id: 521b0486-ab91-4d3a-9189-43c9380a0533 - name: C1 - updatedAt: '2019-08-29T11:40:39.000Z' - '400': - $ref: '#/components/responses/instanceNotFoundApi' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/apiId" - - $ref: "#/components/parameters/apiVersionId" - /apis/{apiId}/versions/{apiVersionId}/{relationType}/{entityId}/syncWithSchema: - put: - summary: Sync API relations with definition - description: Syncs an API version's relation with the API's definition. - operationId: syncRelationsWithSchema - tags: - - API - - Relations - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - success: - type: boolean - description: If true, the sync succeeded. - example: true - example: - success: true - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: validationFailed - message: - type: string - description: The error message. - example: Unable to validate. Only the OpenAPI 3.0 schema format is supported. - examples: - Validation Failed: - value: - error: - name: validationFailed - message: Unable to validate. Only the OpenAPI 3.0 schema format is supported. - Invalid Relation: - value: - error: - name: invalidRelationTypeError - message: The provided relation type is invalid. - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/apiId' - - $ref: '#/components/parameters/apiVersionId' - - $ref: '#/components/parameters/relationType' - - $ref: '#/components/parameters/entityId' - /collections: - get: - summary: Get all collections - description: Gets all of your [collections](https://www.getpostman.com/docs/collections). The response includes all of your subscribed collections. - operationId: allCollections - tags: - - Collections - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collections: - type: array - items: - type: object - description: Information about the collection. - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The collection's name. - example: Test Collection - owner: - type: string - description: The owner of the collection. - example: '12345678' - createdAt: - type: string - format: date-time - description: The collection's creation date and time. - example: '2022-01-13T10:21:46.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the collection was last updated. - example: '2022-01-13T10:21:46.000Z' - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - fork: - type: object - description: If the collection is [forked](https://learning.postman.com/docs/collaborating-in-postman/version-control/#forking-postman-entities), the fork's information. - properties: - label: - type: string - description: The fork's label. - example: Test Fork - createdAt: - type: string - format: date-time - description: The fork's creation date and time. - example: '2022-06-16T19:51:44.069Z' - from: - type: string - description: The unique ID of the fork's source collection. - example: 12345678-f2f0cb8f-609d-443f-913c-9831187c326e - isPublic: - type: boolean - description: If true, the collection is publicly available. - example: false - example: - collections: - - id: dac5eac9-148d-a32e-b76b-3edee9da28f7 - name: Cloud API - owner: '12345678' - createdAt: '2022-04-12T10:29:46.000Z' - updatedAt: '2022-04-12T10:29:56.000Z' - uid: 12345678-dac5eac9-148d-a32e-b76b-3edee9da28f7 - isPublic: true - - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - owner: '12345678' - createdAt: '2022-01-13T10:21:46.000Z' - updatedAt: '2022-02-12T11:29:56.000Z' - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - isPublic: false - fork: - label: Test Fork - createdAt: '2022-06-16T19:51:44.069Z' - from: 12345678-f2f0cb8f-609d-443f-913c-9831187c326e - - id: f695cab7-6878-eb55-7943-ad88e1ccfd65 - name: Postman Echo - owner: '12345678' - createdAt: '2021-04-11T09:18:26.000Z' - updatedAt: '2022-05-01T15:29:32.000Z' - uid: 12345678-f695cab7-6878-eb55-7943-ad88e1ccfd65 - isPublic: true - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - post: - summary: Create a collection - description: | - Creates a collection using the [Postman Collection v2 schema format](https://schema.postman.com/json/collection/v2.1.0/docs/index.html). - - **Note:** - - - For a complete list of available property values for this endpoint, use the following references available in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json): - - `info` object — Use the `definitions.info` entry. - - `item` object — Use the `definitions.items` entry. - - For all other possible values, refer to the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - operationId: createCollection - tags: - - Collections - requestBody: - content: - application/json: - schema: - type: object - properties: - collection: - type: object - description: For a complete list of values, refer to the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - required: - - info - properties: - info: - type: object - required: - - name - - schema - description: An object that contains basic information about the collection. For a complete list of values, refer to the `definitions.info` entry in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - properties: - description: - type: string - description: The collection's description. - example: This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client. - name: - type: string - description: The collection's name. - example: Test Collection - schema: - type: string - format: url - description: A URL to the collection's schema. - example: https://schema.getpostman.com/json/collection/v2.1.0/collection.json - item: - type: array - description: Information about the collection's HTTP requests and responses. For a complete list of values, refer to the `definitions.item` entry in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - items: - required: - - request - type: object - properties: - request: - type: object - description: The collection's request information. For a complete list of values, refer to the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). If you pass an empty object for this value, the system defaults to an untitled GET request. - example: - collection: - info: - name: Test Collection - description: This collection makes a request to the Postman Echo service to get - a list of request headers sent by an HTTP client. - schema: https://schema.getpostman.com/json/collection/v2.1.0/collection.json - item: - - name: Test GET Response - event: - - listen: test - script: - id: 7d2334fc-a84a-4c3d-b26c-7529afa4c0ae - exec: - - pm.test("Status code is 200", function () { - - " pm.response.to.have.status(200);" - - "});" - type: text/javascript - request: - url: https://echo.getpostman.com/headers - method: GET - header: - - key: Content-Type - value: application/json - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The collection's name. - example: Test Collection - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - collection: - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: malformedRequestError - message: - type: string - description: The error message. - example: Found 1 errors with the supplied collection. - details: - type: array - description: Information about the error. - items: - type: string - examples: - Bad Request: - value: - error: - name: instanceFoundError - message: The specified item already exists. - details: - item: collection - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - Malformed Request: - value: - error: - name: malformedRequestError - message: Found 1 errors with the supplied collection. - details: - - ": must have required property 'info'" - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /collections/fork/{collectionUid}: - post: - summary: Create a fork - description: Creates a [fork](https://learning.postman.com/docs/collaborating-in-postman/version-control/#creating-a-fork) from an existing collection into a workspace. - operationId: createAFork - tags: - - Collections - requestBody: - content: - application/json: - schema: - type: object - properties: - label: - type: string - description: The fork's label. - example: Test Fork - example: - label: Test Fork - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - description: Information about the forked collection. - properties: - id: - type: string - format: uuid - description: The forked collection's ID. - example: 09547fef-a9a5-4e00-998b-aa563e8db69a - name: - type: string - description: The collection's name. - example: Test Collection - fork: - type: object - description: Information about the collection's fork. - properties: - label: - type: string - description: The fork's label. - example: Test Fork - createdAt: - type: string - format: date-time - description: The fork's creation date and time. - example: '2022-06-16T19:51:44.069Z' - from: - type: string - format: uid - description: The unique ID of fork's source collection. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: - type: string - format: uid - description: The forked collection's unique ID. - example: 12345678-09547fef-a9a5-4e00-998b-aa563e8db69a - example: - collection: - id: 09547fef-a9a5-4e00-998b-aa563e8db69a - name: Test Collection - fork: - label: Test Fork - createdAt: '2022-06-16T19:51:44.069Z' - from: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: 12345678-09547fef-a9a5-4e00-998b-aa563e8db69a - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundCollection' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - name: workspace - in: query - required: true - schema: - type: string - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - description: The workspace ID in which to fork the collection. - parameters: - - $ref: "#/components/parameters/collectionUid" - /collections/merge: - post: - summary: Merge a fork - description: Merges a forked collection back into its destination collection. - operationId: mergeAFork - tags: - - Collections - requestBody: - content: - application/json: - schema: - type: object - properties: - destination: - type: string - format: uid - description: The destination collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - source: - type: string - format: uid - description: The forked collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - strategy: - type: string - description: | - The fork's merge strategy: - - - `deleteSource` — The system deletes the forked collection after a successful merge into the destination collection. - - `updateSourceWithDestination` — The system only merges the forked collection into the destination collection. - enum: - - deleteSource - - updateSourceWithDestination - default: updateSourceWithDestination - example: deleteSource - example: - strategy: deleteSource - source: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - destination: 12345678-09547fef-a9a5-4e00-998b-aa563e8db69a - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - properties: - id: - type: string - format: uuid - description: The source collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: - type: string - format: uid - description: The source collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - collection: - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundCollection' - '500': - $ref: '#/components/responses/internalServerError' - /collections/{collectionUid}: - get: - summary: Get a collection - description: Gets information about a collection. For a complete list of this endpoint's possible values, use the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - operationId: singleCollection - tags: - - Collections - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - description: For a complete list of this endpoint's possible values, use the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - properties: - info: - type: object - description: An object that contains basic information about the collection. - properties: - _postman_id: - type: string - description: The collection's Postman ID. - example: f2e66c2e-5297-e4a5-739e-20cbb90900e3 - description: - type: string - description: The collection's description. - example: This is a sample collection that makes a tiny request to Postman Echo service to get the list of request headers sent by a HTTP client. - name: - type: string - description: The collection's name. - example: Test Collection - schema: - type: string - format: url - description: A URL to the collection's schema. - example: https://schema.getpostman.com/json/collection/v2.1.0/collection.json - items: - type: array - items: - type: object - properties: - request: - type: object - description: The collection's request information. For a complete list of values, refer to the `definitions.request` entry in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). If you pass an empty object for this value, the system defaults to an untitled GET request. - example: - collection: - info: - name: Test Collection - description: This is a test collection that makes a tiny request to Postman Echo service to get the list of request headers sent by a HTTP client. - _postman_id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - schema: https://schema.getpostman.com/json/collection/v2.0.0/collection.json - updatedAt: '2022-06-16T20:21:13.000Z' - fork: - label: Test Fork - createdAt: '2022-06-16T19:51:44.069Z' - from: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - item: - - name: Test GET Response - id: 82ee981b-e19f-962a-401e-ea34ebfb4848 - event: - - listen: test - script: - id: 7d2334fc-a84a-4c3d-b26c-7529afa4c0ae - exec: - - pm.test("Status code is 200", function () { - - " pm.response.to.have.status(200);" - - "});" - type: text/javascript - request: - url: https://echo.getpostman.com/headers - method: GET - header: - - key: Content-Type - value: application/json - response: [] - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: We could not find the collection you are looking for - example: - error: - name: instanceNotFoundError - message: We could not find the collection you are looking for - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update a collection - description: | - Updates a collection using the [Postman Collection v2 schema format](https://schema.postman.com/json/collection/v2.1.0/docs/index.html). - - > Use caution when using this endpoint. The system will **replace** the existing collection with the values passed in the request body. - - **Note:** - - - For a complete list of available property values for this endpoint, use the following references available in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json): - - `info` object — Use the `definitions.info` entry. - - `item` object — Use the `definitions.items` entry. - - For all other possible values, refer to the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - operationId: updateCollection - tags: - - Collections - requestBody: - content: - application/json: - schema: - type: object - properties: - collection: - type: object - description: For a complete list of values, refer to the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - required: - - info - properties: - info: - type: object - required: - - name - - schema - description: An object that contains basic information about the collection. For a complete list of values, refer to the `definitions.info` entry in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - properties: - description: - type: string - description: The collection's description. - example: This collection makes a request to the Postman Echo service to get a list of request headers sent by an HTTP client. - name: - type: string - description: The collection's name. - example: Test Collection - schema: - type: string - format: url - description: A URL to the collection's schema. - example: https://schema.getpostman.com/json/collection/v2.1.0/collection.json - item: - type: array - description: Information about the collection's HTTP requests and responses. For a complete list of values, refer to the `definitions.item` entry in the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). - items: - required: - - request - type: object - properties: - request: - type: object - description: The collection's request information. For a complete list of values, refer to the [collection.json schema file](https://schema.postman.com/json/collection/v2.1.0/collection.json). If you pass an empty object for this value, the system defaults to an untitled GET request. - example: - collection: - info: - name: Test Collection - description: This collection makes a request to the Postman Echo service to get - a list of request headers sent by an HTTP client. - schema: https://schema.getpostman.com/json/collection/v2.1.0/collection.json - item: - - name: Test POST Response - event: - - listen: test - script: - id: 7d2334fc-a84a-4c3d-b26c-7529afa4c0ae - exec: - - pm.test("Status code is 200", function () { - - " pm.response.to.have.status(200);" - - "});" - type: text/javascript - request: - url: https://echo.getpostman.com/headers - method: POST - header: - - key: Content-Type - value: application/json - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The collection's name. - example: Test Collection - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - collection: - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: malformedRequestError - message: - type: string - description: The error message. - example: Found 2 errors with the supplied collection. - details: - type: array - description: Information about the error. - items: - type: string - example: - - ": must have required property 'item'" - - "info: must have required property 'schema'" - examples: - Malformed Request: - value: - error: - name: malformedRequestError - message: Found 2 errors with the supplied collection. - details: - - ": must have required property 'item'" - - 'info: must have required property ''schema''' - Collection ID Mismatch: - value: - error: - name: collectionMismatchError - message: The collection ID in the path does not match the collection ID in the request body. - '401': - $ref: '#/components/responses/Unauthorized' - '403': - $ref: '#/components/responses/forbiddenError' - '404': - $ref: '#/components/responses/instanceNotFoundCollection' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete a collection - description: Deletes a collection. - operationId: deleteCollection - tags: - - Collections - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collection: - type: object - description: Information about the deleted collection. - properties: - id: - type: string - format: uuid - description: The deleted collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: - type: string - format: uid - description: The deleted collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - collection: - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundCollection' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/collectionUid" - /environments: - get: - summary: Get all environments - description: Gets information about all of your [environments](https://learning.postman.com/docs/sending-requests/managing-environments/). - operationId: allEnvironments - tags: - - Environments - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - environments: - type: array - items: - type: object - properties: - id: - type: string - format: uuid - description: The environment's ID. - example: 5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The environment's name. - example: Test Environment - createdAt: - type: string - format: date-time - description: The date and time at which the environment was created. - example: '2020-09-23T14:31:18.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the environment was last updated. - example: '2020-12-04T14:13:40.000Z' - owner: - type: string - description: The environment owner's ID. - example: '12345678' - uid: - type: string - format: uid - description: The environment's unique ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - isPublic: - type: boolean - description: If true, the environment is public. - example: false - example: - environments: - - id: 5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Environment - createdAt: '2020-09-23T14:31:18.000Z' - updatedAt: '2020-12-04T14:13:40.000Z' - owner: '12345678' - uid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - isPublic: false - - id: 7d786cc8-142b-4d62-b5a5-872afc37ad16 - name: Environment Scanner - createdAt: '2020-02-04T19:34:23.000Z' - updatedAt: '2020-08-12T13:34:06.000Z' - owner: '12345678' - uid: 12345678-7d786cc8-142b-4d62-b5a5-872afc37ad16 - isPublic: false - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundEnvironment' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - post: - summary: Create an environment - description: Creates an environment. - operationId: createEnvironment - tags: - - Environments - requestBody: - content: - application/json: - schema: - type: object - properties: - environment: - type: object - required: - - name - properties: - name: - type: string - description: The environment's name. - example: Test Environment - values: - type: array - description: The environment's key-value pairs. - items: - type: object - properties: - key: - type: string - description: The key name. - example: variable_1 - value: - type: string - description: The `key` property's value. - example: The variable_1 value. - example: - environment: - name: Test Environment - values: - - key: variable_1 - value: The variable_1 value. - - key: variable_2 - value: The variable_2 value. - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - environment: - type: object - properties: - id: - type: string - format: uuid - description: The environment's ID. - example: 5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The environment's name. - example: Test Environment - uid: - type: string - format: uid - description: The environment's unique ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - example: - environment: - id: 5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Environment - uid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - example: malformedRequestError - message: - type: string - example: Found 1 errors with the supplied environment. - details: - type: array - items: - type: string - example: ": must have required property 'environment'" - example: - error: - name: malformedRequestError - message: Found 1 errors with the supplied environment. - details: - - ": must have required property 'environment'" - '401': - $ref: '#/components/responses/Unauthorized' - '403': - $ref: '#/components/responses/forbiddenError' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /environments/{environmentUid}: - get: - summary: Get an environment - description: Gets information about an environment. - operationId: singleEnvironment - tags: - - Environments - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - environment: - type: object - properties: - id: - type: string - format: uuid - description: The environment's ID. - example: 5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The environment's name. - example: Test Environment - owner: - type: string - description: The ID of environment's owner. - example: '12345678' - createdAt: - type: string - format: date-time - description: The date and time at which the environment was created. - example: '2020-11-05T13:59:22.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the environment was last updated. - example: '2020-11-05T13:59:23.000Z' - values: - type: array - description: Information about the environment's key-pair values. - items: - type: object - properties: - enabled: - type: boolean - description: If true, the value is enabled. - example: true - key: - type: string - description: The key name. - example: apiKey - value: - type: string - description: The `key` property's value. - example: PMAK-1234-5678-0987-6543 - type: - type: string - description: The key-value pair type. - example: secret - isPublic: - type: boolean - description: If true, the environment is public. - example: false - example: - environment: - id: 5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Environment - owner: '12345678' - createdAt: '2020-11-05T13:59:22.000Z' - updatedAt: '2020-11-05T13:59:23.000Z' - values: - - key: apiKey - value: PMAK-1234-5678-0987-6543 - enabled: true - type: secret - isPublic: false - '400': - $ref: '#/components/responses/instanceNotFoundEnvironment' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update an environment - description: Updates an environment. - operationId: updateEnvironment - tags: - - Environments - requestBody: - content: - application/json: - schema: - type: object - properties: - environment: - type: object - properties: - name: - type: string - description: The environment's name. - example: Test A Environment - values: - type: array - description: The environment's key-value pairs. - items: - type: object - properties: - key: - type: string - description: The key name. - example: variable_a - value: - type: string - description: The `key` property's value. - example: The variable's value. - example: - environment: - name: Test A Environment - values: - - key: variable_a - value: The variable's value. - - key: variable_b - value: The variable's value. - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - environment: - type: object - properties: - id: - type: string - example: 5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - example: Test A Environment - uid: - type: string - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - example: - environment: - id: 5daabc50-8451-43f6-922d-96b403b4f28e - name: Test A Environment - uid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: malformedRequestError - message: - type: string - description: The error message. - example: 'Invalid type: null (expected object) at environment.values.0' - example: - error: - name: malformedRequestError - message: 'Invalid type: null (expected object) at environment.values.0' - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete an environment - description: Deletes an environment. - operationId: deleteEnvironment - tags: - - Environments - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - environment: - type: object - properties: - id: - type: string - format: uuid - description: The deleted environment's ID. - example: 4dfb28a4-9a6c-4ce4-b31a-17c26a8b2cce - uid: - type: string - format: uid - description: The deleted environment's unique ID. - example: 5852-4dfb28a4-9a6c-4ce4-b31a-17c26a8b2cce - example: - environment: - id: 5daabc50-8451-43f6-922d-96b403b4f28e - uid: 1234567-5daabc50-8451-43f6-922d-96b403b4f28e - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundEnvironment' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/environmentUid' - /import/exported: - post: - summary: Import an exported Postman data dump file - deprecated: true - description: | - **This endpoint is deprecated.** - - Imports exported Postman data. This endpoint only accepts [export data dump files](https://postman.postman.co/me/export). - - For more information, read our [Exporting data dumps](https://learning.postman.com/docs/getting-started/importing-and-exporting-data/#exporting-data-dumps) documentation. - operationId: importExportedData - tags: - - Import - requestBody: - content: - multipart/form-data: - schema: - type: object - required: - - type - - input - properties: - type: - type: string - description: The `file` type value. - enum: - - file - example: file - input: - type: string - description: A file containing a valid user's export .zip file. - format: binary - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collections: - type: array - items: - type: object - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The collection's name. - example: Test API - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - collections: - - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test API - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: paramMissingError - message: - type: string - description: The error message. - example: The request body is missing a value for the type parameter. Check your request and try again. - details: - type: object - description: Information about the error. - properties: - param: - type: string - description: The parameter name. - example: type - examples: - Invalid Parameters: - value: - error: - name: invalidParamsError - message: The request body has invalid values for the type parameter. Value must - be one of file, string, json - details: - param: type - Missing Parameter: - value: - error: - name: paramMissingError - message: The request body is missing a value for the type parameter. Check your request and try again. - details: - param: type - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - /import/openapi: - post: - summary: Import an OpenAPI definition - description: Imports an OpenAPI definition into Postman as a new [Postman Collection](https://learning.postman.com/docs/getting-started/creating-the-first-collection/). - operationId: importExternalApiSpecification - tags: - - Import - requestBody: - content: - application/json: - schema: - oneOf: - - $ref: '#/components/schemas/jsonSchema' - - $ref: '#/components/schemas/jsonStringified' - examples: - Import a Stringified OpenAPI Definition: - value: - type: string - input: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - Import an OpenAPI Definition: - value: - type: json - input: - openapi: 3.0.0 - info: - version: 1.0.0 - title: Test API - servers: - - url: http://locahost:3000 - paths: - "/user": - get: - summary: List all users - operationId: listUser - parameters: - - name: id - in: query - required: true - description: The user's ID. - example: 1234 - schema: - type: integer - format: int32 - responses: - '200': - description: Information about the user. - headers: - x-next: - description: A link to the next page of responses. - schema: - type: string - content: - application/json: - schema: - type: object - required: - - id - - name - properties: - id: - type: integer - format: int64 - name: - type: string - tag: - type: string - multipart/form-data: - schema: - $ref: '#/components/schemas/importExportFile' - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - collections: - type: array - items: - type: object - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The collection's name. - example: Test Collection - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - collections: - - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environments: [] - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: invalidParamsError - message: - type: string - description: The error message. - example: The request body has invalid values for the type parameter. Value must be one of file, string, json - details: - type: object - description: Information about the error. - properties: - param: - type: string - description: The parameter name. - example: type - examples: - Invalid Parameters: - value: - error: - name: invalidParamsError - message: The request body has invalid values for the type parameter. Value must be one of file, string, json - details: - param: type - Missing Parameters: - value: - error: - name: paramMissingError - message: The request body is missing a value for the type parameter. Check your - request and try again. - details: - param: type - Malformed Request: - value: - error: - name: invalidSchemaError - message: Specification must contain a semantic version number of the OAS specification - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /me: - get: - summary: Get authenticated user - description: Gets information about the authenticated user. - operationId: apiKeyOwner - tags: - - User - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - user: - type: object - description: Information about the authenticated user. - properties: - avatar: - type: string - description: The user's avatar image URL. - format: url - example: https://example.com/user/r5u9qpvmujfjf6lbqmga.jpg - email: - type: string - format: email - description: The user's email address. - example: taylor.lee@example.com - fullName: - type: string - description: The user's full name. - example: Taylor Lee - id: - type: number - description: The user's Postman ID. - example: 12345678 - isPublic: - type: boolean - description: If true, the user's information is publicly available. - example: true - username: - type: string - description: The user's username. - example: taylor-lee - operations: - type: array - description: Information about operations and their usage limits. - items: - type: object - properties: - limit: - type: number - description: The operation's limit value. - example: 1000000 - name: - type: string - description: The operation's name. - example: mock_usage - overage: - type: number - description: The operation's overage value. - example: 0 - usage: - type: number - description: The operation's current usage value. - example: 110276 - example: - user: - id: 12345678 - username: taylor-lee - email: taylor.lee@example.com - fullName: Taylor Lee - avatar: https://example.com/user/r5u9qpvmujfjf6lbqmga.jpg - isPublic: true - operations: - - name: mock_usage - limit: 1000000 - usage: 110276 - overage: 0 - - name: monitor_request_runs - limit: 10000000 - usage: 1141750 - overage: 0 - - name: api_usage - limit: 1000000 - usage: 16240 - overage: 0 - - name: custom_domains - limit: 25 - usage: 25 - overage: 0 - - name: serverless_requests - limit: 10000 - usage: 0 - overage: 0 - - name: integrations - limit: 5000 - usage: 1018 - overage: 0 - - name: cloud_agent_requests - limit: 1000000 - usage: 1615 - overage: 0 - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - /mocks: - get: - summary: Get all mock servers - description: Gets all mock servers. - operationId: allMocks - tags: - - Mocks - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mocks: - type: array - items: - type: object - description: Information about the mock servers. - properties: - collection: - type: string - description: The mock's associated collection unique ID. - example: 12345678-39fee52f-b806-3ffa-1173-00a6f5b183dc - config: - type: object - description: Information about the mock server's configuration. - properties: - delay: - type: object - nullable: true - description: Information about the mock server's simulated network delay settings. This returns a null value if there are no configured network delay settings. - properties: - type: - type: string - description: | - The type of simulated delay value: - - - `fixed` — The delay value is a fixed value. - example: fixed - enum: - - fixed - preset: - type: string - description: | - The simulated fixed network delay value: - - - `1` — 2G (300 ms). - - `2` — 3G (100 ms). - - The object does not return this value for custom delay values. - example: "2" - enum: - - "1" - - "2" - duration: - type: integer - description: The configured delay, in milliseconds. - example: 100 - headers: - type: array - description: A list of the mock server's headers. - items: - type: string - example: [] - matchBody: - type: boolean - description: If true, match the request body. - example: false - matchQueryParams: - type: boolean - description: If true, match query parameters. - example: true - matchWildcards: - type: boolean - description: If true, use wildcard matching. - example: true - createdAt: - type: string - format: date-time - description: The date and time at which the mock server was created. - example: '2022-06-09T19:00:39.000Z' - environment: - type: string - description: The mock server's environment. - example: 1679925-0b9e9f15-3208-a2b1-22e0-d58392f01524 - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - isPublic: - type: boolean - description: If true, the mock server is public. - example: false - mockUrl: - type: string - format: url - description: The mock server URL. - example: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: - type: string - description: The mock server's name. - example: Test Mock - owner: - type: string - description: The ID of mock server's owner. - example: '12345678' - uid: - type: string - format: uid - description: The mock server's unique ID. - example: 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 - updatedAt: - type: string - format: date-time - description: The date and time at which the mock server was last updated. - example: '2022-06-09T19:00:39.000Z' - example: - mocks: - - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: '12345678' - uid: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - mockUrl: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: Test Mock - config: - headers: [] - matchBody: false - matchQueryParams: true - matchWildcards: true - delay: - type: fixed - duration: 140000 - serverResponseId: - createdAt: '2022-07-25T20:54:30.000Z' - updatedAt: '2022-07-25T20:54:30.000Z' - isPublic: false - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - post: - summary: Create a mock server - description: Creates a mock server in a collection. - operationId: createMock - tags: - - Mocks - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - mock: - type: object - required: - - collection - properties: - collection: - type: string - description: The mock's associated collection unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: - type: string - description: The mock server's environment. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The mock server's name. - example: Test Mock - example: - mock: - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Mock - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: object - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: - type: string - description: The ID of mock server's owner. - example: '12345678' - uid: - type: string - format: uid - description: The mock server's unique ID. - example: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - collection: - type: string - description: The mock's associated collection unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - mockUrl: - type: string - format: url - description: The mock server URL. - example: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - config: - type: object - description: Information about the mock server's configuration. - properties: - delay: - type: object - nullable: true - description: Information about the mock server's simulated network delay settings. This returns a null value if there are no configured network delay settings. - properties: - type: - type: string - description: | - The type of simulated delay value: - - - `fixed` — The delay value is a fixed value. - example: fixed - enum: - - fixed - preset: - type: string - description: | - The simulated fixed network delay value: - - - `1` — 2G (300 ms). - - `2` — 3G (100 ms). - - The object does not return this value for custom delay values. - example: "2" - enum: - - "1" - - "2" - duration: - type: integer - description: The configured delay, in milliseconds. - example: 100 - headers: - type: array - description: A list of the mock server's headers. - items: - type: string - example: [] - matchBody: - type: boolean - description: If true, match the request body. - example: false - matchQueryParams: - type: boolean - description: If true, match query parameters. - example: true - matchWildcards: - type: boolean - description: If true, use wildcard matching. - example: true - createdAt: - type: string - format: date-time - description: The date and time at which the mock server was created. - example: '2022-06-09T19:00:39.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the mock server was last updated. - example: '2022-06-09T19:00:39.000Z' - environment: - type: string - description: The mock's associated environment unique ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - example: - mock: - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: '12345678' - uid: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - mockUrl: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: Test Mock - config: - headers: [] - matchBody: false - matchQueryParams: true - matchWildcards: true - delay: - serverResponseId: - createdAt: '2022-06-09T19:00:39.000Z' - updatedAt: '2022-06-09T19:00:39.000Z' - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: paramMissingError - message: - type: string - description: The error message. - example: Parameter is missing in the request. - details: - type: object - description: Information about the error. - properties: - param: - type: array - description: Information about the missing parameter. - items: - type: string - example: collection - example: - error: - name: paramMissingError - message: Parameter is missing in the request. - details: - param: - - collection - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /mocks/{mockUid}: - get: - summary: Get a mock server - description: Gets information about a mock server. - operationId: singleMock - tags: - - Mocks - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: object - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: - type: string - description: The ID of mock server's owner. - example: '12345678' - uid: - type: string - format: uid - description: The mock server's unique ID. - example: 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 - collection: - type: string - description: The mock's associated collection unique ID. - example: 12345678-39fee52f-b806-3ffa-1173-00a6f5b183dc - mockUrl: - type: string - format: url - description: The mock server URL. - example: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: - type: string - description: The mock server's name. - example: Test Mock - config: - type: object - description: Information about the mock server's configuration. - properties: - headers: - type: array - description: A list of the mock server's headers. - items: {} - matchBody: - type: boolean - description: If true, match the request body. - example: false - matchQueryParams: - type: boolean - description: If true, match query parameters. - example: true - matchWildcards: - type: boolean - description: If true, use wildcard matching. - example: true - serverResponseId: - type: string - nullable: true - format: uuid - description: The server response's ID. - example: ~ - createdAt: - type: string - format: date-time - description: The date and time at which the mock server was created. - example: '2022-06-09T19:00:39.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the mock server was last updated. - example: '2022-06-09T19:00:39.000Z' - isPublic: - type: boolean - description: If true, the mock server is public. - example: false - environment: - type: string - description: The mock server's environment. - example: 1679925-0b9e9f15-3208-a2b1-22e0-d58392f01524 - example: - mock: - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: '12345678' - uid: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - mockUrl: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: Test Mock - config: - headers: [] - matchBody: false - matchQueryParams: true - matchWildcards: true - delay: - type: fixed - duration: 140000 - serverResponseId: ~ - createdAt: '2022-07-25T20:54:30.000Z' - updatedAt: '2022-07-25T20:54:30.000Z' - isPublic: false - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMock' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update a mock server - description: Updates a mock server. - operationId: updateMock - tags: - - Mocks - requestBody: - content: - application/json: - schema: - type: object - properties: - mock: - type: object - properties: - name: - type: string - description: The mock server's name. - example: Test Mock - environment: - type: string - format: uuid - description: The associated environment's ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - description: - type: string - description: The mock server's description. - example: This is a test mock server. - private: - type: boolean - description: If true, the mock server is set private. - example: false - versionTag: - type: string - description: The API's version tag ID. - example: abf07d3d-f8ec-47d4-8015-9fe83078b4ec - config: - type: object - description: The mock server's configuration settings. - properties: - serverResponseId: - type: string - nullable: true - description: | - The server response ID. This sets the given server response as the default response for each request. - - To deactivate a server response, pass a null value. - example: 9a291bbe-dc0a-44ba-a3c8-6dbd06a61460 - examples: - Update a Mock: - value: - mock: - name: Test Mock - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19 - description: This is a test mock server. - private: false - versionTag: abf07d3d-f8ec-47d4-8015-9fe83078b4ec - Activate a Mock's Server Response: - value: - mock: - config: - serverResponseId: 9a291bbe-dc0a-44ba-a3c8-6dbd06a61460 - Deactivate a Mock's Server Response: - value: - mock: - config: - serverResponseId: - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: object - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: - type: string - description: The ID of mock server's owner. - example: '12345678' - uid: - type: string - format: uid - description: The mock server's unique ID. - example: 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 - collection: - type: string - description: The mock's associated collection unique ID. - example: 12345678-39fee52f-b806-3ffa-1173-00a6f5b183dc - mockUrl: - type: string - format: url - description: The mock server URL. - example: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: - type: string - description: The mock server's name. - example: Test Mock - config: - type: object - description: Information about the mock server's configuration. - properties: - headers: - type: array - description: A list of the mock server's headers. - items: {} - matchBody: - type: boolean - description: If true, match the request body. - example: false - matchQueryParams: - type: boolean - description: If true, match query parameters. - example: true - matchWildcards: - type: boolean - description: If true, use wildcard matching. - example: true - createdAt: - type: string - format: date-time - description: The date and time at which the mock server was created. - example: '2022-06-09T19:00:39.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the mock server was last updated. - example: '2022-06-09T19:00:39.000Z' - environment: - type: string - description: The mock server's environment. - example: 1679925-0b9e9f15-3208-a2b1-22e0-d58392f01524 - example: - mock: - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - owner: '12345678' - uid: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - mockUrl: https://e3d951bf-873f-49ac-a658-b2dcb91d3289.mock.pstmn.io - name: Test Mock - config: - headers: [] - matchBody: false - matchQueryParams: true - matchWildcards: true - createdAt: '2022-06-09T19:38:06.000Z' - updatedAt: '2022-06-13T18:55:25.000Z' - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMock' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete a mock server - description: Deletes a mock server. - operationId: deleteMock - tags: - - Mocks - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: object - description: Information about the mock server. - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - uid: - type: string - format: uid - description: The mock server's unique ID. - example: 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 - example: - mock: - id: e782b64e-406b-4a6c-8fe9-9ebe84aeb706 - uid: 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: JobTemplate 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 does not exist - examples: - Not Found: - value: - error: - name: instanceNotFoundError - message: JobTemplate 12345678-e782b64e-406b-4a6c-8fe9-9ebe84aeb706 does not exist - Parameter Missing: - value: - error: - name: paramMissingError - message: Only the name and description of a mock can be updated. - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMock' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/mockUid" - /mocks/{mockUid}/publish: - post: - summary: Publish a mock server - description: Publishes a mock server. Publishing a mock server sets its **Access Control** configuration setting to public. - operationId: publishMock - tags: - - Mocks - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: object - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - example: - mock: - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: mockAlreadyPublishedError - message: - type: string - description: The error message. - example: This mock is already public. - example: - error: - name: mockAlreadyPublishedError - message: This mock is already public. - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMock' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/mockUid" - /mocks/{mockUid}/unpublish: - delete: - summary: Unpublish a mock server - description: Unpublishes a mock server. Unpublishing a mock server sets its **Access Control** configuration setting to private. - operationId: unpublishMock - tags: - - Mocks - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - mock: - type: object - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - example: - mock: - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: mockAlreadyUnpublishedError - message: - type: string - description: The error message. - example: This mock has already been deleted. - example: - error: - name: mockAlreadyUnpublishedError - message: This mock has already been deleted. - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMock' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/mockUid" - /monitors: - get: - summary: Get all monitors - description: Gets all monitors. - operationId: allMonitors - tags: - - Monitors - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - monitors: - type: array - items: - type: object - properties: - id: - type: string - format: uuid - description: The monitor's description. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The monitor's name. - example: Test Monitor - owner: - type: string - description: The ID of the monitor's owner. - example: '12345678' - uid: - type: string - format: uid - description: The monitor's unique ID. - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - example: - monitors: - - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - uid: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - owner: 12345678 - - id: 1e6b6cb7-f13d-4000-acb7-0695757174a8 - name: Postman Echo Monitor - uid: 87654321-1e6b6cb7-f13d-4000-acb7-0695757174a8 - owner: 87654321 - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - post: - summary: Create a monitor - description: Creates a monitor. - operationId: createMonitor - tags: - - Monitors - requestBody: - content: - application/json: - schema: - type: object - properties: - monitor: - type: object - properties: - collection: - type: string - description: The monitor's associated collection unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: - type: string - description: The monitor's associated environment unique ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The monitor's name. - example: Test Monitor - schedule: - type: object - description: Information about the monitor's schedule. - properties: - cron: - type: string - description: | - The monitor's run frequency, based on the given cron pattern. For example: - - | Frequency | Pattern | - | --------- | ------- | - | Every 5 minutes | `*/5 * * * *` | - | Every 30 minutes | `*/30 * * * *` | - | Every hour | `0 */1 * * *` | - | Every 6 hours | `0 */6 * * *` | - | Every day at 5 pm | `0 17 * * *` | - | Every Monday at 12 pm | `0 12 * * MON` | - | Every weekday (Mon — Fri) at 6 am | `0 6 * * MON-FRI` | - - At this time you can only create monitors with limited schedules. For information about the available schedules, see our [Postman Monitors](https://monitor.getpostman.com) collection. - example: '0 0 * * *' - timezone: - type: string - description: The monitor's [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). - example: America/Chicago - example: - monitor: - name: Test Monitor - schedule: - cron: 0 0 * * * - timezone: America/Chicago - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environment: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - monitor: - type: object - properties: - id: - type: string - format: uuid - description: The monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The monitor's name. - example: Test Monitor - uid: - type: string - format: uid - description: The monitor's unique ID. - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - example: - monitor: - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - uid: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - example: paramMissingError - message: - type: string - example: Parameter is missing in the request. - details: - type: object - description: Information about the error. - examples: - Missing Parameter: - value: - error: - error: - name: paramMissingError - message: Parameter is missing in the request. - details: - param: - - name - Invalid Timezone: - value: - error: - name: invalidParamsError - message: The request had invalid parameters - details: - param: schedule.timezone - Invalid Environment UID: - value: - error: - name: invalidUidError - message: The specified uid is invalid. - details: - param: environment - uid: 5daabc50-8451-43f6-922d-96b403b4f28e - Invalid Cron Pattern: - value: - error: - name: cronPatternNotAllowedError - message: The specified cron pattern is not allowed. Please check https://monitor.getpostman.com - for the allowed schedules. - details: - pattern: '* * * * *' - '401': - $ref: '#/components/responses/Unauthorized' - '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: forbiddenError - message: - type: string - description: The error description. - example: You need read access to this collection in order to perform this action. - example: - error: - name: forbiddenError - message: You need read access to this collection in order to perform this action. - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /monitors/{monitorUid}: - get: - summary: Get a monitor - description: Gets information about a monitor. - operationId: singleMonitor - tags: - - Monitors - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - monitor: - type: object - properties: - id: - type: string - format: uuid - description: The monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The monitor's name. - example: Test Monitor - uid: - type: string - description: The monitor's unique ID. - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - owner: - type: number - description: The ID of monitor's owner. - example: 12345678 - collectionUid: - type: string - description: The monitor's associated collection unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environmentUid: - type: string - description: The monitor's associated environment unique ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - distribution: - type: array - items: {} - lastRun: - type: object - description: Information about the monitor's previous run. - properties: - finishedAt: - type: string - format: date-time - description: The date and time at which the monitor's previous run completed. - example: '2022-06-17T18:39:53.707Z' - startedAt: - type: string - format: date-time - description: The date and time at which the monitor's previous run started. - example: '2022-06-17T18:39:52.852Z' - stats: - type: object - description: Information about the monitor's stats. - properties: - assertions: - type: object - description: Information about the monitor's assertions. - properties: - failed: - type: number - description: The number of failures. - example: 1 - total: - type: number - description: The total number of assertions. - example: 8 - requests: - type: object - description: Information about the monitor's requests. - properties: - total: - type: number - description: The total number of requests. - example: 4 - status: - type: string - description: The monitor's status after its last run. - example: failed - notifications: - type: object - description: Information about the monitor's notification settings. - properties: - onError: - type: array - items: - type: object - properties: - email: - type: string - format: email - description: The email address of the user to notify on monitor error. - example: taylor.lee@example.com - onFailure: - type: array - items: - type: object - properties: - email: - type: string - format: email - description: The email address of the user to notify on monitor failure. - example: taylor.lee@example.com - options: - type: object - description: Information about the monitor's option settings. - properties: - followRedirects: - type: boolean - description: If true, follow redirects enabled. - example: true - requestDelay: - type: number - description: The monitor's request delay value. - example: 0 - requestTimeout: - type: number - description: The monitor's request timeout value. - example: 3000 - strictSSL: - type: boolean - description: If true, strict SSL enabled. - example: true - schedule: - type: object - description: Information about the monitor's schedule. - properties: - cron: - type: string - description: The monitor's cron frequency value. - example: '0 0 * * * *' - nextRun: - type: string - format: date-time - description: The date and time of monitor's next scheduled run. - example: '2022-06-18T05:00:00.000Z' - timezone: - type: string - description: The monitor's timezone. - example: America/Chicago - example: - monitor: - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - uid: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - owner: 12345678 - collectionUid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environmentUid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - options: - strictSSL: true - followRedirects: true - requestTimeout: 3000 - requestDelay: 0 - notifications: - onError: - - email: taylor.lee@example.com - onFailure: - - email: taylor.lee@example.com - distribution: [] - schedule: - cron: 0 0 0 * * * - timezone: America/Chicago - nextRun: '2022-06-18T05:00:00.000Z' - lastRun: - status: failed - startedAt: '2022-06-17T18:39:52.852Z' - finishedAt: '2022-06-17T18:39:53.707Z' - stats: - assertions: - total: 8 - failed: 1 - requests: - total: 4 - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMonitor' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update a monitor - description: Updates a monitor. - operationId: updateMonitor - tags: - - Monitors - requestBody: - content: - application/json: - schema: - type: object - properties: - monitor: - type: object - properties: - name: - type: string - description: The monitor's name. - example: Test Monitor - schedule: - type: object - description: Information about the monitor's schedule. - properties: - cron: - description: | - The monitor's run frequency, based on the given cron pattern. For example: - - | Frequency | Pattern | - | --------- | ------- | - | Every 5 minutes | `*/5 * * * *` | - | Every 30 minutes | `*/30 * * * *` | - | Every hour | `0 */1 * * *` | - | Every 6 hours | `0 */6 * * *` | - | Every day at 5 pm | `0 17 * * *` | - | Every Monday at 12 pm | `0 12 * * MON` | - | Every weekday (Mon — Fri) at 6 am | `0 6 * * MON-FRI` | - - At this time you can only create monitors with limited schedules. For information about the available schedules, see our [Postman Monitors](https://monitor.getpostman.com) collection. - example: '*/5 * * * *' - timezone: - type: string - description: The monitor's [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). - example: America/Chicago - example: - monitor: - name: Test Monitor - schedule: - cron: '*/5 * * * *' - timezone: America/Chicago - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - monitor: - type: object - properties: - id: - type: string - format: uuid - description: The monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The monitor's name. - example: Test Monitor - uid: - type: string - format: uid - description: The monitor's unique ID. - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - example: - monitor: - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - uid: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundMonitor' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete a monitor - description: Deletes a monitor. - operationId: deleteMonitor - tags: - - Monitors - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - monitor: - type: object - properties: - id: - type: string - format: uuid - description: The monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - uid: - type: string - format: uid - description: The monitor's unique ID. - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - example: - monitor: - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - uid: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: JobTemplate 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 does not exist - example: - error: - name: instanceNotFoundError - message: JobTemplate 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 does not exist - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/monitorUid" - /monitors/{monitorUid}/run: - post: - summary: Run a monitor - description: Runs a monitor and returns its run results. - operationId: runAMonitor - tags: - - Monitors - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - run: - type: object - description: Information about the monitor run. - properties: - info: - type: object - description: Information about the monitor. - properties: - jobId: - type: string - format: uuid - description: The monitor's run job ID. - example: 1ecee76a-e14e-47c0-bddc-256bf690c407 - collectionUid: - type: string - format: uuid - description: The monitor's associated collection ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environmentUid: - type: string - format: uuid - description: The monitor's associated environment ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - monitorId: - type: string - format: uuid - description: The monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The monitor's name. - example: Test Monitor - status: - type: string - description: The monitor run's status. - example: success - startedAt: - type: string - format: date-time - description: The date and time at which the monitor run began. - example: '2022-06-17T19:50:04.019Z' - finishedAt: - type: string - format: date-time - description: The date and time at which the monitor's run completed. - example: '2022-06-17T19:50:06.439Z' - stats: - type: object - description: Information about the monitor run's stats. - properties: - assertions: - type: object - description: The monitor run's assertions stats. - properties: - total: - type: number - description: The total number of assertions. - example: 0 - failed: - type: number - description: The number of assertion failures. - example: 0 - requests: - type: object - description: The monitor run's request stats. - properties: - total: - type: number - description: The total number of requests. - example: 1 - failed: - type: number - description: The number of request failures. - example: 0 - executions: - type: array - description: Information about the monitor run's executions. - items: - type: object - properties: - id: - type: number - description: The execution ID. - example: 1 - item: - type: object - description: Information about the executed item. - properties: - name: - type: string - description: The executed item's name. - example: Sample POST Request - request: - type: object - description: Information about the monitor run's requests. - properties: - method: - type: string - description: The request method. - example: POST - url: - type: string - format: url - description: The request's URL. - example: http://echo.getpostman.com/post - body: - type: object - description: Information about the request body. - properties: - contentLength: - type: number - description: The request body's content length value. - example: 0 - mode: - type: string - description: The request body's media type (mode). - example: raw - headers: - type: object - description: Information about the request headers, such as Content-Type, Accept, encoding, and other information. - properties: - accept: - type: string - description: The Accept header value. - example: '*/*' - accept-encoding: - type: string - description: The Accept header's encoding value. - example: 'gzip, deflate, br' - content-length: - type: number - description: The header content length. - example: 0 - content-type: - type: string - description: The header's Content-Type value. - example: application/json - timestamp: - type: string - description: The date and time of the request. - example: "2016-12-04T14:30:26.025Z" - response: - type: object - description: Information about the monitor run's response. - properties: - body: - type: object - description: Information about the response body. - properties: - contentLength: - type: number - description: The response's Content-Length value. - example: 298 - code: - type: number - description: The response's HTTP status code. - example: 200 - headers: - type: object - description: Information about the response headers, such as Content-Type, Accept, encoding, and other information. - properties: - connection: - type: string - description: The header's connection type. - example: keep-alive - content-encoding: - type: string - description: The header's encoding value. - example: gzip - content-type: - type: string - description: The header's Content-Type value. - example: application/json - date: - type: string - format: date-time - description: The date and time of the header. - example: "Sun, 04 Dec 2016 14:30:26 GMT" - transfer-encoding: - type: string - description: The header's transfer encoding value. - example: chunked - responseSize: - type: number - description: The response size. - example: 298 - responseTime: - type: number - description: The response time. - example: 26 - failures: - type: array - description: If the monitor run failed, information about the run's failures. - items: - type: object - example: [] - examples: - Successful Response: - value: - run: - info: - jobId: 1ecee76a-e14e-47c0-bddc-256bf690c407 - monitorId: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - collectionUid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environmentUid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - status: success - startedAt: '2022-06-17T19:50:04.019Z' - finishedAt: '2022-06-17T19:50:06.439Z' - stats: - assertions: - total: 0 - failed: 0 - requests: - total: 1 - failed: 0 - executions: - - id: 1 - item: - name: Sample POST Request - request: - method: POST - url: http://echo.getpostman.com/post - headers: - Content-Type: application/json - User-Agent: PostmanRuntime/7.29.0 - Accept: "*/*" - Cache-Control: no-cache - Postman-Token: - Host: echo.getpostman.com - Accept-Encoding: gzip, deflate, br - Connection: keep-alive - Content-Length: '0' - body: - contentLength: 0 - timestamp: '2022-06-17T19:50:06.186Z' - response: - code: 200 - body: - contentLength: 50 - responseTime: 49 - responseSize: 50 - headers: - Date: Fri, 17 Jun 2022 19:50:06 GMT - Content-Type: text/plain - Content-Length: '50' - Connection: keep-alive - Server: - failures: [] - Monitor Run Failed: - value: - run: - info: - jobId: 1ecee76a-e14e-47c0-bddc-256bf690c407 - monitorId: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - collectionUid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environmentUid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - status: failed - startedAt: '2022-06-17T20:00:41.659Z' - finishedAt: '2022-06-17T20:00:42.693Z' - stats: - assertions: - total: 1 - failed: 1 - requests: - total: 1 - failed: 0 - executions: - - id: 1 - item: - name: Sample POST Request - request: - method: POST - url: http://echo.getpostman.com/post - headers: - Content-Type: application/json - User-Agent: PostmanRuntime/7.29.0 - Accept: "*/*" - Cache-Control: no-cache - Postman-Token: - Host: echo.getpostman.com - Accept-Encoding: gzip, deflate, br - Connection: keep-alive - Content-Length: '0' - body: - contentLength: 0 - timestamp: '2022-06-17T20:00:42.423Z' - response: - code: 200 - body: - contentLength: 50 - responseTime: 15 - responseSize: 50 - headers: - Date: Fri, 17 Jun 2022 20:00:42 GMT - Content-Type: text/plain - Content-Length: '50' - Connection: keep-alive - Server: - failures: [] - Monitor Run with Errors: - value: - run: - info: - jobId: 1ecee76a-e14e-47c0-bddc-256bf690c407 - monitorId: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - collectionUid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environmentUid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - status: error - startedAt: '2022-06-17T20:04:47.183Z' - finishedAt: '2022-06-17T20:04:48.858Z' - stats: - assertions: - total: 4 - failed: 2 - requests: - total: 4 - failed: 3 - executions: - - id: 1 - item: - name: Sample GET Request - request: - method: GET - url: https://example.com/search?format=json&state=&city=&country= - headers: - User-Agent: PostmanRuntime/7.29.0 - Accept: "*/*" - Cache-Control: no-cache - Postman-Token: - Host: example.com - Accept-Encoding: gzip, deflate, br - Connection: keep-alive - body: - contentLength: 0 - timestamp: '2022-06-17T20:04:47.926Z' - response: - code: 200 - body: - contentLength: 2 - responseTime: 257 - responseSize: 2 - headers: - Server: - Date: Fri, 17 Jun 2022 20:04:47 GMT - Content-Type: application/json; charset=UTF-8 - Transfer-Encoding: chunked - Connection: keep-alive - Keep-Alive: - Access-Control-Allow-Origin: "*" - Access-Control-Allow-Methods: OPTIONS,GET - errors: - - name: TypeError - message: Cannot read property 'lat' of undefined - failures: - - executionId: 1 - name: TypeError - message: Cannot read property 'lat' of undefined - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/monitorUid" - /scim/v2/ResourceTypes: - get: - summary: Get resource types - description: Gets all the resource types supported by Postman's SCIM API. - operationId: getResourceTypes - tags: - - SCIM 2.0 - Identity - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: array - items: - type: object - properties: - schemas: - type: array - description: A list of SCIM schema resource URIs. - items: - type: string - example: - - urn:ietf:params:scim:schemas:core:2.0:ResourceType - id: - type: string - description: The resource's ID. - example: User - name: - type: string - description: The resource's friendly name. - example: User - endpoint: - type: string - description: The resource's endpoint. - example: /Users - description: - type: string - description: The resource's description. - example: User Account - schema: - type: string - description: The resource's schema URI. - example: urn:ietf:params:scim:schemas:core:2.0:User - schemaExtensions: - type: array - description: Information about the resource's schema extensions. - items: - type: object - properties: - schema: - type: string - description: The resource extension's URI. - example: urn:ietf:params:scim:schemas:extension:enterprise:2.0:User - required: - type: boolean - description: If true, the resource must include this schema extension. - example: true - example: - - schemas: - - urn:ietf:params:scim:schemas:core:2.0:ResourceType - id: User - name: User - endpoint: /Users - description: User Account - schema: urn:ietf:params:scim:schemas:core:2.0:User - schemaExtensions: - - schema: urn:ietf:params:scim:schemas:extension:enterprise:2.0:User - required: true - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - /scim/v2/ServiceProviderConfig: - get: - summary: Get service provider configuration - description: Gets the Postman SCIM API configuration information. This includes a list of supported operations. - operationId: serviceProviderConfig - tags: - - SCIM 2.0 - Identity - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: A list of schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig - documentationUri: - type: string - format: url - description: A link to the URI's documentation. - example: "https://learning.postman.com/docs/administration/managing-your-team/configuring-scim" - patch: - type: object - properties: - supported: - type: boolean - example: true - bulk: - type: object - properties: - maxOperations: - type: number - example: 0 - maxPayloadSize: - type: number - example: 0 - supported: - type: boolean - example: false - filter: - type: object - properties: - maxResults: - type: number - example: 100 - supported: - type: boolean - example: true - changePassword: - type: object - properties: - supported: - type: boolean - example: false - sort: - type: object - properties: - supported: - type: boolean - example: false - authenticationSchemes: - type: array - description: A list of authentication schemes. - items: - type: object - description: Information about the scheme. - properties: - description: - type: string - description: The scheme's description. - example: Authentication scheme using the OAuth Bearer Token Standard - name: - type: string - description: The scheme's friendly name. - example: OAuth Bearer Token - specUri: - type: string - format: url - description: A link to the scheme's specification documentation. - example: http://www.rfc-editor.org/info/rfc6750 - type: - type: string - description: The scheme's type. - example: oauthbearertoken - etag: - type: object - properties: - supported: - type: boolean - example: false - meta: - type: object - properties: - resourceType: - type: string - example: ServiceProviderConfig - location: - type: string - format: url - example: https://api.getpostman.com/scim/v2/ServiceProviderConfig - example: - schemas: - - urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig - documentationUri: https://learning.postman.com/docs/administration/managing-your-team/configuring-scim - patch: - supported: true - bulk: - supported: false - maxOperations: 0 - maxPayloadSize: 0 - filter: - supported: true - maxResults: 100 - changePassword: - supported: false - sort: - supported: false - etag: - supported: false - authenticationSchemes: - - name: OAuth Bearer Token - description: Authentication scheme using the OAuth Bearer Token Standard - specUri: http://www.rfc-editor.org/info/rfc6750 - type: oauthbearertoken - meta: - resourceType: ServiceProviderConfig - location: https://api.getpostman.com/scim/v2/ServiceProviderConfig - '401': - $ref: '#/components/responses/scimUnauthorized' - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - /scim/v2/Users: - get: - summary: Get all user resources - description: Gets information about all Postman team members. - operationId: fetchAllUserResource - tags: - - SCIM 2.0 - Identity - - User Provisioning - parameters: - - name: startIndex - in: query - schema: - type: number - default: 1 - description: The index entry by which to begin the list of returned results. - example: 1 - - name: count - in: query - schema: - type: number - default: 100 - description: Limit the number of results returned in a single response. - example: 50 - - name: filter - in: query - schema: - type: string - description: Filter results by a specific word or phrase. - example: userName eq "taylor-lee%40example.com" - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - Resources: - type: array - description: A list of user resources. - items: - $ref: '#/components/schemas/scimUserResource' - itemsPerPage: - type: number - description: The number of items per response page. - example: 2 - schemas: - type: array - items: - type: string - description: The schemas URI. - example: urn:ietf:params:scim:api:messages:2.0:ListResponse - startIndex: - type: number - description: The index entry by which the returned results begin. - example: 1 - totalResults: - type: number - description: The total number of results found. - example: 1000 - examples: - Successful Response: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:ListResponse - totalResults: 1000 - startIndex: 1 - itemsPerPage: 2 - Resources: - - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - id: 405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - userName: taylor-lee@example.com - name: - givenName: Taylor - familyName: Lee - externalId: '12345678' - active: true - meta: - resourceType: User - created: '2021-02-22T04:24:13.000Z' - lastModified: '2021-02-22T04:24:13.000Z' - - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - id: 123775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - userName: alex-cruz@example.com - name: - givenName: Alex - familyName: Cruz - externalId: '87654321' - active: true - meta: - resourceType: User - created: '2021-02-22T04:24:13.000Z' - lastModified: '2021-02-22T04:24:13.000Z' - No Results Found: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:ListResponse - totalResults: 0 - startIndex: 1 - itemsPerPage: 0 - Resources: [] - Filter Results: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:ListResponse - totalResults: 1000 - startIndex: 1 - itemsPerPage: 1 - Resources: - - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - id: 405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - userName: taylor-lee@example.com - name: - givenName: Taylor - familyName: Lee - externalId: '12345678' - active: true - meta: - resourceType: User - created: '2021-02-22T04:24:13.000Z' - lastModified: '2021-02-22T04:24:13.000Z' - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - example: You've used filter(s) that Postman doesn't support. - status: - type: string - example: '400' - examples: - Bad Request: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: This Postman team doesn't exist anymore. - status: '400' - Using Incorrect Filter: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: You've used filter(s) that Postman doesn't support. - status: '400' - '401': - $ref: '#/components/responses/scimUnauthorized' - '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - example: Your API key was generated by a Team Admin who is no longer on your team. Use an API key generated by a Team Admin. - status: - type: string - example: '403' - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Your API key was generated by a Team Admin who is no longer on your team. - Use an API key generated by a Team Admin. - status: '403' - '429': - description: Too Many Requests - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - example: That's 300 attempts in less than a minute. Wait for a minute and then try again. - status: - type: number - example: 429 - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: That's 300 attempts in less than a minute. Wait for a minute and then try again. - status: 429 - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - post: - summary: Create a user - description: | - Creates a new user account in Postman and adds the user to your organization's Postman team. If the account does not already exist, this also activates the user so they can authenticate in to your Postman team. - - If the account already exists, the system sends the user an [email invite](https://learning.postman.com/docs/administration/managing-your-team/managing-your-team/#inviting-users) to join the Postman team. The user joins the team once they accept the invite. - - By default, the system assigns new users the developer role. You can [update user roles in Postman](https://learning.postman.com/docs/administration/managing-your-team/managing-your-team/#managing-team-roles). - operationId: createUser - tags: - - SCIM 2.0 - Identity - - User Provisioning - requestBody: - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URI. - items: - type: string - example: urn:ietf:params:scim:schemas:core:2.0:User - userName: - type: string - description: The user's username. - example: taylor-lee@example.com - active: - type: boolean - description: If true, activates the user. This lets them authenticate in to your Postman team. - example: true - externalId: - type: string - description: The user's external ID. - example: "12345678" - groups: - type: array - description: A list of groups to which to assign the user to. - items: - type: string - example: Test Group - locale: - type: string - description: The user's IETF locale. - example: en-US - name: - type: object - description: Information about the user's name. - properties: - givenName: - type: string - description: The user's first name. - example: Taylor - familyName: - type: string - description: The user's last name. - example: Lee - example: - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - userName: taylor-lee@example.com - name: - givenName: Taylor - familyName: Lee - displayName: Taylor Lee - locale: en-US - groups: - - Test Group - active: true - responses: - '201': - description: Created - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema URI. - items: - type: string - example: urn:ietf:params:scim:schemas:core:2.0:User - id: - type: string - description: The user's SCIM ID. - example: 405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - userName: - type: string - format: email - description: The user's username. - example: taylor-lee@example.com - name: - type: object - properties: - givenName: - type: string - description: The user's first name. - example: Taylor - familyName: - type: string - description: The user's last name. - example: Lee - externalId: - type: string - description: The user's external ID. - example: "12345678" - active: - type: boolean - description: If true, the user is active. - example: true - meta: - type: object - description: The response's non-standard meta information. - properties: - created: - type: string - format: date-time - description: The date and time at which the user was created. - example: "2021-02-22T04:24:13.000Z" - lastModified: - type: string - format: date-time - description: The date and time at which the user was last modified. - example: "2021-02-22T04:24:13.000Z" - resourceType: - type: string - description: The SCIM resource type. - enum: - - User - example: User - example: - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - id: 405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - userName: taylor-lee@example.com - name: - givenName: Test - familyName: User - externalId: '12345678' - active: true - meta: - resourceType: User - created: '2021-02-22T04:24:13.000Z' - lastModified: '2021-02-22T04:24:13.000Z' - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: A list of SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - scimType: - type: string - description: The SCIM type. - example: invalidSyntax - detail: - type: string - description: Information about the error. - example: This Postman team doesn't exist anymore. - status: - type: string - description: The HTTP status code. - example: '400' - examples: - Invalid Syntax: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - scimType: invalidSyntax - detail: The request body seems to be incomplete or have unsupported characters. - status: '400' - Invalid Team: - value: - detail: This Postman team doesn't exist anymore. - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - status: '400' - Not Enterprise: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Only Postman teams on the Enterprise plan can use SCIM provisioning. Upgrade your plan. - status: '400' - No Slots Available: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: No slots available on your Postman team. Purchase or free up slots to invite more members. For help, contact Team Admins or members with a Billing role. - status: '400' - '401': - $ref: '#/components/responses/scimUnauthorized' - '403': - $ref: '#/components/responses/scimForbidden' - '409': - description: Conflict - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - scimType: - type: string - description: The SCIM type. - example: uniqueness - detail: - type: string - description: Information about the error. - example: This person is already a member of the team. - status: - type: string - description: The HTTP status code. - example: '409' - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - scimType: uniqueness - detail: This person is already a member of the team. - status: '409' - '429': - $ref: '#/components/responses/scimTooManyRequests' - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - /scim/v2/Users/{userId}: - get: - summary: Get user resource - description: Gets information about a Postman team member. - operationId: fetchUserResource - tags: - - SCIM 2.0 - Identity - - User Provisioning - responses: - '200': - $ref: '#/components/responses/scimUserResource' - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - description: The error schema URI. - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: This Postman team doesn't exist anymore. - status: - type: string - description: The error status code. - example: '400' - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: This Postman team doesn't exist anymore. - status: '400' - '401': - $ref: '#/components/responses/scimUnauthorized' - '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - description: The error schema URI. - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: Your API key was generated by a Team Admin who is no longer on your team. Use an API key generated by a Team Admin. - status: - type: string - description: The error status code. - example: '403' - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Your API key was generated by a Team Admin who is no longer on your team. - Use an API key generated by a Team Admin. - status: '403' - '404': - $ref: '#/components/responses/scimUserNotFound' - '429': - description: Too Many Requests - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - description: The error schema URI. - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: That's 300 attempts in less than a minute. Wait for a minute and then try again. - status: - type: number - description: The error status code. - example: 429 - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: That's 300 attempts in less than a minute. Wait for a minute and then try again. - status: 429 - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - put: - summary: Update a user - description: | - Updates a user's first and last name in Postman. - - **Note:** - - You can only use the SCIM API to update a user's first and last name. You cannot update any other user attributes with the API. - operationId: updateUserInformation - tags: - - SCIM 2.0 - Identity - - User Provisioning - requestBody: - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URI. - items: - type: string - example: urn:ietf:params:scim:schemas:core:2.0:User - name: - type: object - description: Information about the user's name. - properties: - givenName: - type: string - description: The user's first name. - example: Taylor - familyName: - type: string - description: The user's last name. - example: Lee - example: - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - name: - givenName: Taylor - familyName: Lee - responses: - '200': - $ref: '#/components/responses/scimUserResource' - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: A list of SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - scimType: - type: string - description: The SCIM type. - example: invalidSyntax - detail: - type: string - description: Information about the error. - example: This Postman team doesn't exist anymore. - status: - type: string - description: The HTTP status code. - example: '400' - examples: - Bad Request: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Couldn't update this team member's username. Try again — it should work next time around. - status: '400' - Invalid Team: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: This Postman team doesn't exist anymore. - status: '400' - Invalid Syntax: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - scimType: invalidSyntax - detail: The request body seems to be incomplete or have unsupported characters. - status: '400' - '401': - $ref: '#/components/responses/scimUnauthorized' - '403': - $ref: '#/components/responses/scimForbidden' - '404': - $ref: '#/components/responses/scimUserNotFound' - '429': - $ref: '#/components/responses/scimTooManyRequests' - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - patch: - summary: Update a user's state - description: | - Updates a user's active state in Postman. - - ### Reactivating users - - By setting the `active` property from `false` to `true`, this reactivates an account. This allows the account to authenticate in to Postman and adds the account back on to your Postman team. - operationId: updateUserState - tags: - - SCIM 2.0 - Identity - - User Provisioning - requestBody: - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URI. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:PatchOp - Operations: - type: array - description: Information about the user update operation. - items: - type: object - properties: - op: - type: string - description: The operation to perform. - enum: - - replace - example: replace - value: - type: object - description: The performed operation's value. - properties: - active: - type: boolean - description: | - Sets the user's `active` state: - - `true` — Activates the user. This lets them authenticate in to your Postman team. - - `false` — Removes the user from your Postman team and deactivates the account. This blocks the user from authenticating in to Postman. - example: true - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:PatchOp - Operations: - - op: replace - value: - active: true - responses: - '200': - $ref: '#/components/responses/scimUserResource' - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - example: Team doesn't exist. - status: - type: string - example: '400' - examples: - Bad Request: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - scimType: invalidSyntax - detail: You've used operation that Postman doesn't support. - status: '400' - Invalid Team: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Team doesn't exist. - status: '400' - '401': - $ref: '#/components/responses/scimUnauthorized' - '403': - $ref: '#/components/responses/scimForbidden' - '404': - $ref: '#/components/responses/scimUserNotFound' - '429': - $ref: '#/components/responses/scimTooManyRequests' - '500': - $ref: '#/components/responses/scimInternalErrorUserUpdate' - parameters: - - $ref: "#/components/parameters/userId" - /security/api-validation: - post: - summary: Schema security validation - description: | - Performs a security analysis on the given definition and returns any issues. This can help you understand their impact and provides solutions to help you resolve the errors. You can include this endpoint to your CI/CD process to automate schema validation. - - For more information, read our [API definition warnings](https://learning.postman-beta.com/docs/api-governance/api-definition/api-definition-warnings/) documentation. - - **Note:** - - The maximum allowed size of the definition is 10 MB. - operationId: schemaSecurityValidation - tags: - - API Security - requestBody: - content: - application/json: - schema: - type: object - properties: - schema: - type: object - required: - - language - - schema - - type - properties: - language: - type: string - description: The definition format. - enum: - - json - - yaml - example: json - schema: - type: string - description: The stringified definition. - example: "{\"openapi\":\"3.0.0\",\"info\":{\"version\":\"1\",\"title\":\"temp\",\"license\":{\"name\":\"MIT\"}},\"servers\":[{\"url\":\"https://petstore.swagger.io/v1\"}],\"paths\":{\"/user\":{\"get\":{\"summary\":\"Details about a user\",\"operationId\":\"listUser\",\"tags\":[\"user\"],\"parameters\":[{\"name\":\"id\",\"in\":\"query\",\"description\":\"ID of the user\",\"required\":true,\"schema\":{\"type\":\"integer\",\"format\":\"int32\"}}],\"responses\":{\"200\":{\"description\":\"Details about a user\",\"headers\":{\"x-next\":{\"description\":\"A link to the next page of responses\",\"schema\":{\"type\":\"string\"}}},\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/User\"}}}},\"default\":{\"description\":\"unexpected error\",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Error\"}}}}}}}},\"components\":{\"schemas\":{\"User\":{\"type\":\"object\",\"required\":[\"id\",\"name\"],\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}}},\"Error\":{\"type\":\"object\",\"required\":[\"code\",\"message\"],\"properties\":{\"code\":{\"type\":\"integer\",\"format\":\"int32\"},\"message\":{\"type\":\"string\"}}}},\"securitySchemes\":{\"BasicAuth\":{\"type\":\"http\",\"scheme\":\"basic\"}}},\"security\":[{\"BasicAuth\":[]}]}" - type: - type: string - description: The definition type. - enum: - - openapi3 - - openapi2 - example: openapi3 - example: - schema: - type: openapi3 - language: json - schema: "{\"openapi\":\"3.0.0\",\"info\":{\"version\":\"1\",\"title\":\"temp\",\"license\":{\"name\":\"MIT\"}},\"servers\":[{\"url\":\"https://petstore.swagger.io/v1\"}],\"paths\":{\"/user\":{\"get\":{\"summary\":\"Details about a user\",\"operationId\":\"listUser\",\"tags\":[\"user\"],\"parameters\":[{\"name\":\"id\",\"in\":\"query\",\"description\":\"ID of the user\",\"required\":true,\"schema\":{\"type\":\"integer\",\"format\":\"int32\"}}],\"responses\":{\"200\":{\"description\":\"Details about a user\",\"headers\":{\"x-next\":{\"description\":\"A link to the next page of responses\",\"schema\":{\"type\":\"string\"}}},\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/User\"}}}},\"default\":{\"description\":\"unexpected error\",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Error\"}}}}}}}},\"components\":{\"schemas\":{\"User\":{\"type\":\"object\",\"required\":[\"id\",\"name\"],\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}}},\"Error\":{\"type\":\"object\",\"required\":[\"code\",\"message\"],\"properties\":{\"code\":{\"type\":\"integer\",\"format\":\"int32\"},\"message\":{\"type\":\"string\"}}}},\"securitySchemes\":{\"BasicAuth\":{\"type\":\"http\",\"scheme\":\"basic\"}}},\"security\":[{\"BasicAuth\":[]}]}" - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - warnings: - type: array - description: | - Information about each issue discovered in the security analysis. Each object includes the warning's severity and category, the location of the issue, data paths, and other information. This returns an empty object if there are no issues present in the schema. - - If there are issues, this returns the `possibleFixUrl` response in each warning object. This provides a link to documentation you can use to resolve the warning. - items: - type: object - additionalProperties: true - example: {} - examples: - No Warnings Found: - value: - warnings: [] - Successful Response with Warnings: - value: - warnings: - - severity: MEDIUM - message: HTTP authentication scheme is using an unknown scheme. - location: - start: - line: 1 - column: 1116 - end: - line: 1 - column: 1118 - dataPath: - - components - - securitySchemes - - BasicAuth - - scheme - possibleFixUrl: https://go.pstmn.io/openapi3-security-warnings#http-authentication-scheme-is-using-an-unknown-scheme - category: - name: Broken User Authentication - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: Invalid schema - message: - type: string - description: The error message. - example: Provided schema type is not supported. - examples: - Invalid Schema: - value: - error: - name: Invalid schema - reason: Provided schema type is not supported. - Payload Too Large: - value: - error: - message: request entity too large - name: PayloadTooLargeError - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - /webhooks: - description: The `/webhooks` endpoint lets you manage webhooks. - post: - summary: Create a webhook - description: Creates a webhook that triggers a collection with a custom payload. You can get the webhook's URL from the `webhookUrl` property in the endpoint's response. - operationId: createWebhook - tags: - - Webhooks - requestBody: - content: - application/json: - schema: - type: object - properties: - webhook: - type: object - properties: - collection: - type: string - format: uid - description: The collection UID to trigger when calling this webhook. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The webhook's name. On success, the system creates a new monitor with this name in the **Monitors** tab. - example: Test Webhook - example: - webhook: - name: Test Webhook - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - responses: - '200': - description: 'Successful Response' - content: - application/json: - schema: - type: object - properties: - webhook: - type: object - description: Information about the webhook. - properties: - id: - type: string - format: uuid - description: The webhook's ID. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: - type: string - description: The webhook's name. - example: Test Webhook - collection: - type: string - format: uid - description: The unique ID of the webhook's associated collection. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - webhookUrl: - type: string - format: url - description: The webhook's URL. - example: https://newman-api.getpostman.com/run/12345678/267a6e99-b6da-407c-a96f-03be2d6282fb - uid: - type: string - format: uid - description: The webhook's unique ID. - example: 12345678-1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - example: - webhook: - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: Test Webhook - collection: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - webhookUrl: https://newman-api.getpostman.com/run/12345678/267a6e99-b6da-407c-a96f-03be2d6282fb - uid: 12345678-1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: '#/components/parameters/workspaceQueryId' - /workspaces: - get: - summary: Get all workspaces - description: | - Gets all [workspaces](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/). The response includes your workspaces and any workspaces that you have access to. - - **Note:** - - This endpoint's response contains the visibility field. Visibility determines who can access the workspace: - - - `only-me` — Applies to the **My Workspace** workspace. - - `personal` — Only you can access the workspace. - - `team` — All team members can access the workspace. - - `private-team` — Only invited team members can access the workspace. - - `public` — Everyone can access the workspace. - operationId: allWorkspaces - tags: - - Workspaces - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - workspaces: - type: array - items: - type: object - description: Information about the workspace. - properties: - id: - type: string - format: uuid - description: The workspace's ID. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: - type: string - description: The workspace's name. - example: Test Workspace - type: - type: string - description: The type of workspace. - enum: - - personal - - team - example: personal - visibility: - type: string - description: | - The team's visibility in Postman: - - - `only-me` — Applies to the **My Workspace** workspace. - - `personal` — Only you can access the workspace. - - `team` — All team members can access the workspace. - - `private-team` — Only invited team members can access the workspace. - - `public` — Everyone can access the workspace. - enum: - - only-me - - personal - - team - - private-team - - public - example: private-team - examples: - Successful Response: - value: - workspaces: - - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: Test Workspace - type: personal - visibility: personal - - id: f8801e9e-03a4-4c7b-b31e-5db5cd771696 - name: Team Workspace - type: team - visibility: private-team - Filter by Type: - value: - workspaces: - - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: Test Workspace - type: personal - visibility: personal - '401': - $ref: '#/components/responses/Unauthorized' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - name: type - required: false - in: query - description: | - The type of workspace to filter the response by: - - - `team` — Return only team workspaces. - - `personal` — Return only personal workspaces. - schema: - type: string - example: team - post: - summary: Create a workspace - description: | - Creates a new [workspace](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/). - - ### Important: - - We **deprecated** linking collections or environments between workspaces. We do **not** recommend that you do this. - - If you have a linked collection or environment, note the following: - - - The endpoint does **not** create a clone of a collection or environment. - - Any changes you make to a linked collection or environment changes them in **all** workspaces. - - If you delete a collection or environment linked between workspaces, the system deletes it in **all** the workspaces. - operationId: createWorkspace - tags: - - Workspaces - requestBody: - content: - application/json: - schema: - type: object - properties: - workspace: - type: object - description: Information about the workspace. - required: - - name - - type - properties: - name: - type: string - description: The workspace's name. - example: Test Workspace - type: - type: string - description: | - The type of workspace: - - - `personal` — A personal workspace. - - `team` — A team workspace. - enum: - - personal - - team - example: personal - description: - type: string - description: The workspace's description. - example: This is a test personal workspace. - example: - workspace: - name: Test Workspace - type: personal - description: This is a test personal workspace. - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - workspace: - type: object - description: Information about the created workspace. - properties: - id: - type: string - format: uuid - description: The workspace's ID. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: - type: string - description: The workspace's name. - example: Test Workspace - example: - workspace: - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: Test Workspace - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundDatabase' - '500': - $ref: '#/components/responses/internalServerError' - /workspaces/{workspaceId}: - get: - summary: Get a workspace - description: | - Gets information about a workspace. - - **Note:** - - This endpoint's response contains the `visibility` field. [Visibility](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#changing-workspace-visibility) determines who can access the workspace: - - - `only-me` — Applies to the **My Workspace** workspace. - - `personal` — Only you can access the workspace. - - `team` — All team members can access the workspace. - - `private-team` — Only invited team members can access the workspace. - - `public` — Everyone can access the workspace. - operationId: singleWorkspace - tags: - - Workspaces - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - workspace: - type: object - description: Information about the workspace. - properties: - id: - type: string - format: uuid - description: The workspace's ID. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: - type: string - description: The workspace's name. - example: Team Workspace - type: - type: string - description: The type of workspace. - enum: - - personal - - team - example: personal - description: - type: string - description: The workspace's description. - example: The Test team workspace. - visibility: - type: string - description: | - The workspace's visibility. [Visibility](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#changing-workspace-visibility) determines who can access the workspace: - - - `only-me` — Applies to the **My Workspace** workspace. - - `personal` — Only you can access the workspace. - - `team` — All team members can access the workspace. - - `private-team` — Only invited team members can access the workspace. - - `public` — Everyone can access the workspace. - enum: - - only-me - - personal - - team - - private-team - - public - example: private-team - createdBy: - type: string - description: The user ID of the user who created the workspace. - example: '12345678' - updatedBy: - type: string - description: The user ID of the user who last updated the workspace. - example: '12345678' - createdAt: - type: string - format: date-time - description: The date and time at which the workspace was created. - example: '2022-07-06T16:18:32.000Z' - updatedAt: - type: string - format: date-time - description: The date and time at which the workspace was last updated. - example: '2022-07-06T20:55:13.000Z' - collections: - type: array - description: The workspace's collections. - items: - type: object - description: Information about the collection. - properties: - id: - type: string - format: uuid - description: The collection's ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: - type: string - description: The collection's name. - example: Test Collection - uid: - type: string - format: uid - description: The collection's unique ID. - example: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environments: - type: array - description: The workspace's environments. - items: - type: object - description: Information about the environment. - properties: - id: - type: string - format: uuid - description: The environment's ID. - example: 5daabc50-8451-43f6-922d-96b403b4f28e - name: - type: string - description: The environment's name. - example: Test Environment - uid: - type: string - format: uid - description: The environment's unique ID. - example: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - mocks: - type: array - description: The workspace's mock servers. - items: - type: object - description: Information about the mock server. - properties: - id: - type: string - format: uuid - description: The mock server's ID. - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - name: - type: string - description: The mock server's name. - example: Test Mock - uid: - type: string - format: uid - description: The mock server's unique ID. - example: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitors: - type: array - description: The workspace's monitors. - items: - type: object - description: Information about the monitor. - properties: - id: - type: string - format: uuid - description: The monitor's ID. - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: - type: string - description: The monitor's name. - example: Test Environment - uid: - type: string - format: uid - description: The monitor's unique ID. - example: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - apis: - type: array - description: The workspace's APIs. - items: - type: object - description: Information about the API. - properties: - id: - type: string - format: uuid - description: The API's ID. - example: 387c2863-6ee3-4a56-8210-225f774edade - name: - type: string - description: The API's name. - example: Test API - uid: - type: string - format: uid - description: The API's unique ID. - example: 12345678-387c2863-6ee3-4a56-8210-225f774edade - example: - workspace: - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: Team Workspace - type: team - description: The Test team workspace. - visibility: private-team - createdBy: '12345678' - updatedBy: '12345678' - createdAt: '2022-07-06T16:18:32.000Z' - updatedAt: '2022-07-06T20:55:13.000Z' - collections: - - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - name: Test Collection - uid: 12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2 - environments: - - id: 5daabc50-8451-43f6-922d-96b403b4f28e - name: Test Environment - uid: 12345678-5daabc50-8451-43f6-922d-96b403b4f28e - mocks: - - id: e3d951bf-873f-49ac-a658-b2dcb91d3289 - name: Test Mock - uid: 12345678-e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitors: - - id: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - name: Test Monitor - uid: 12345678-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - apis: - - id: 387c2863-6ee3-4a56-8210-225f774edade - name: Test API - uid: 12345678-387c2863-6ee3-4a56-8210-225f774edade - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundDatabase' - '500': - $ref: '#/components/responses/internalServerError' - put: - summary: Update a workspace - description: | - Updates a workspace. - - **Note:** - - You can change a workspace's type from `personal` to `team`, but you **cannot** change a workspace from `team` to `personal`. - - ### Important: - - We **deprecated** linking collections or environments between workspaces. We do **not** recommend that you do this. - - If you have a linked collection or environment, note the following: - - - The endpoint does **not** create a clone of a collection or environment. - - Any changes you make to a linked collection or environment changes them in **all** workspaces. - - If you delete a collection or environment linked between workspaces, the system deletes it in **all** the workspaces. - operationId: updateWorkspace - tags: - - Workspaces - requestBody: - content: - application/json: - schema: - type: object - properties: - workspace: - type: object - properties: - name: - type: string - description: The workspace's name. - example: Test Workspace - type: - type: string - description: | - The type of workspace: - - - `personal` — A personal workspace. - - `team` — A team workspace. - enum: - - team - - personal - example: team - description: - type: string - description: The workspace's description. - example: This is a test team workspace. - example: - workspace: - name: Test Workspace - description: This is a test team workspace. - type: team - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - workspace: - type: object - description: Information about the updated workspace. - properties: - id: - type: string - format: uuid - description: The workspace's ID. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: - type: string - description: The workspace's name. - example: Test Workspace - example: - workspace: - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - name: Test Workspace - '400': - description: Bad Request - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: invalidUIDError - message: - type: string - description: The error message. - example: The ID provided is not a valid UID. - example: - error: - name: invalidUIDError - message: The ID provided is not a valid UID. - '401': - $ref: '#/components/responses/Unauthorized' - '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: forbiddenError - message: - type: string - description: The error message. - example: You do not have access to update this workspace. - example: - error: - name: forbiddenError - message: You do not have access to update this workspace. - '404': - $ref: '#/components/responses/instanceNotFoundWorkspace' - '500': - $ref: '#/components/responses/internalServerError' - delete: - summary: Delete a workspace - description: | - Deletes an existing workspace. - - ### Important: - - If you delete a workspace that has a linked collection or environment with another workspace, this will delete the collection and environment in **all** workspaces. - operationId: deleteWorkspace - tags: - - Workspaces - responses: - '200': - description: Successful Response - content: - application/json: - schema: - type: object - properties: - workspace: - type: object - description: Information about the deleted workspace. - properties: - id: - type: string - format: uuid - description: The workspace's ID. - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - example: - workspace: - id: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/instanceNotFoundWorkspace' - '500': - $ref: '#/components/responses/internalServerError' - parameters: - - $ref: "#/components/parameters/workspaceId" -components: - securitySchemes: - PostmanApiKey: - type: apiKey - in: header - name: x-api-key - responses: - forbiddenError: - description: Forbidden - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: forbiddenError - message: - type: string - description: The error message - example: You do not have enough permissions to perform this action. - example: - error: - name: forbiddenError - message: You do not have enough permissions to perform this action. - instanceNotFoundApi: - description: Instance Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: We could not find the API you are looking for - example: - error: - name: instanceNotFoundError - message: We could not find the API you are looking for - instanceNotFoundDatabase: - description: Instance Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: Instance not found in the database. - example: - error: - name: instanceNotFoundError - message: Instance not found in the database. - instanceNotFoundEnvironment: - description: Instance Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: We could not find the environment you are looking for - example: - error: - name: instanceNotFoundError - message: We could not find the environment you are looking for - instanceNotFoundCollection: - description: Instance Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: The specified item does not exist. - details: - type: object - description: Information about the error. - properties: - item: - type: string - description: The instance item. - example: collection - id: - type: string - format: uuid - description: The collection ID. - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - example: - error: - name: instanceNotFoundError - message: The specified item does not exist. - details: - item: collection - id: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - instanceNotFoundMock: - description: Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: The specified mock does not exist. - details: - type: array - description: Information about the error. - items: - type: string - example: {} - example: - error: - name: instanceNotFoundError - message: The specified mock does not exist. - details: {} - instanceNotFoundMonitor: - description: Instance Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: The specified monitor does not exist. - example: - error: - name: instanceNotFoundError - message: The specified monitor does not exist. - instanceNotFoundWorkspace: - description: Instance Not Found - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: instanceNotFoundError - message: - type: string - description: The error message. - example: The specified workspace does not exist. - example: - error: - name: instanceNotFoundError - message: The specified workspace does not exist. - internalServerError: - description: Internal Server Error - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: serverError - message: - type: string - description: The error message. - example: An error has occurred on the server. - example: - error: - name: serverError - message: An error has occurred on the server. - invalidParamsError: - description: Invalid Parameters - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: invalidParamsError - message: - type: string - description: The error message. - example: The specified parameter is in an invalid format - paramMissingError: - description: Parameter Missing - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error name. - example: paramMissingError - message: - type: string - description: The error message. - example: Parameter is missing in the request. - scimInternalErrorUserUpdate: - description: Internal Server Error - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: Couldn't update this team member's information. Try again — it should work next time around. - status: - type: string - description: The HTTP status code. - example: '500' - examples: - Cannot Update User: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Couldn't update this team member's information. Try again — it should work next time around. - status: '500' - Cannot Add Team Members: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Unable to add members to the team. Try again — it should work next time around. - status: '500' - scimForbidden: - description: Forbidden - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: Your API key was generated by a Team Admin who is no longer on your team. Use an API key generated by a Team Admin. - status: - type: string - description: The HTTP status code. - example: '403' - examples: - Forbidden: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: This person isn't a member of the team. - status: '403' - Invalid API Key: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Your API key was generated by a Team Admin who is no longer on your team. Use an API key generated by a Team Admin. - status: '403' - Admin Action Not Allowed: - value: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: The admin is not allowed to perform this action. - status: '403' - scimTooManyRequests: - description: Too Many Requests - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: That's 180 attempts in less than a minute. Wait for a minute and then try again. - status: - type: number - description: The HTTP status code. - example: 429 - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: That's 180 attempts in less than a minute. Wait for a minute and then try again. - status: 429 - scimUserNotFound: - description: Not Found - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: This person isn't a member of the team. - status: - type: string - description: The HTTP status code. - example: '404' - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: This person isn't a member of the team. - status: '404' - scimUnauthorized: - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: The SCIM schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:api:messages:2.0:Error - detail: - type: string - description: Information about the error. - example: Unable to access the team. Check if you have entered a valid API key. - status: - type: string - description: The HTTP status code. - example: '401' - example: - schemas: - - urn:ietf:params:scim:api:messages:2.0:Error - detail: Unable to access the team. Check if you have entered a valid API key. - status: '401' - scimUserResource: - description: Successful Response - content: - application/json: - schema: - type: object - properties: - schemas: - type: array - description: A list of schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:schemas:core:2.0:User - id: - type: string - description: The team member's SCIM ID. - example: '405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99' - userName: - type: string - description: The team member's SCIM username. - example: taylor-lee@example.com - name: - type: object - description: Information about the Postman team member. - properties: - givenName: - type: string - description: The team member's first name. - example: Taylor - familyName: - type: string - description: The team member's last name. - example: Lee - externalId: - type: string - description: The team member's external ID. - example: '12345678' - active: - type: boolean - description: If true, the team member is active. - example: true - meta: - type: object - properties: - resourceType: - type: string - description: The resource type. - example: User - created: - type: string - format: date-time - description: The date and time at which the team member was created. - example: '2021-02-22T04:24:13.000Z' - lastModified: - type: string - format: date-time - description: The date and time at which the team member was last modified. - example: '2021-02-22T04:24:13.000Z' - example: - schemas: - - urn:ietf:params:scim:schemas:core:2.0:User - id: 405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - userName: taylor-lee@example.com - name: - givenName: Taylor - familyName: Lee - externalId: '12345678' - active: true - meta: - resourceType: User - created: '2021-02-22T04:24:13.000Z' - lastModified: '2021-02-22T04:24:13.000Z' - Unauthorized: - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - error: - type: object - properties: - name: - type: string - description: The error message. - example: AuthenticationError - message: - type: string - description: The error message. - example: Invalid API Key. Every request requires a valid API Key to be sent. - example: - error: - name: AuthenticationError - message: Invalid API Key. Every request requires a valid API Key to be sent. - schemas: - scimUserResource: - description: The SCIM user resource object. - type: object - properties: - schemas: - type: array - description: A list of schema resource URIs. - items: - type: string - example: urn:ietf:params:scim:schemas:core:2.0:User - id: - type: string - description: The team member's SCIM ID. - example: '405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99' - userName: - type: string - description: The team member's SCIM username. - example: taylor-lee@example.com - name: - type: object - description: Information about the Postman team member. - properties: - givenName: - type: string - description: The team member's first name. - example: Taylor - familyName: - type: string - description: The team member's last name. - example: Lee - externalId: - type: string - description: The team member's external ID. - example: '12345678' - active: - type: boolean - description: If true, the team member is active. - example: true - meta: - type: object - properties: - resourceType: - type: string - description: The resource type. - example: User - created: - type: string - format: date-time - description: The date and time at which the team member was created. - example: '2021-02-22T04:24:13.000Z' - lastModified: - type: string - format: date-time - description: The date and time at which the team member was last modified. - example: '2021-02-22T04:24:13.000Z' - importExportFile: - type: object - required: - - type - - input - properties: - type: - type: string - description: The `file` type value. - enum: - - file - example: file - input: - type: string - description: A file containing a valid user's export .zip file. - format: binary - jsonSchema: - type: object - properties: - type: - type: string - description: The OpenAPI definition type. - enum: - - json - example: json - input: - type: object - description: An object that contains a valid JSON OpenAPI definition. For more information, read the [OpenAPI documentation](https://swagger.io/docs/specification/basic-structure/). - properties: {} - jsonStringified: - type: object - properties: - type: - type: string - description: The OpenAPI definition type. - enum: - - json - example: json - input: - type: string - description: The stringified OpenAPI definition. - example: "{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Test API\"\n },\n \"servers\": [\n {\n \"url\": \"http://locahost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"List all users\",\n \"operationId\": \"listUser\",\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"required\": true,\n \"description\": \"The user's ID.\",\n \"example\": 1234,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Information about the user.\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses.\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/User\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}" - parameters: - apiId: - name: apiId - in: path - required: true - description: The API's ID. - schema: - type: string - format: uuid - example: 387c2863-6ee3-4a56-8210-225f774edade - apiVersionId: - name: apiVersionId - in: path - required: true - description: The API version's ID. - schema: - type: string - format: uuid - example: a9879d02-74bf-425a-bbec-6d27aa135507 - collectionUid: - name: collectionUid - in: path - required: true - description: The collection's ID. - schema: - type: string - format: uuid - example: 12ece9e1-2abf-4edc-8e34-de66e74114d2 - entityId: - name: entityId - in: path - required: true - description: | - The entity's ID value - - - For `documentation` and `test` — The collection UID value. - - For `environment` — The environment UID value. - - For `mock` — The mock ID value. - - For `monitor` — The monitor ID value. - schema: - type: string - format: uuid - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - environmentUid: - name: environmentUid - in: path - required: true - description: The environment's ID. - schema: - type: string - format: uuid - example: 5daabc50-8451-43f6-922d-96b403b4f28e - mockUid: - name: mockUid - in: path - required: true - description: The mock's ID. - schema: - type: string - format: uuid - example: e3d951bf-873f-49ac-a658-b2dcb91d3289 - monitorUid: - name: monitorUid - in: path - required: true - description: The monitor's ID. - schema: - type: string - format: uuid - example: 1e6b6cc1-c760-48e0-968f-4bfaeeae9af1 - relationType: - name: relationType - in: path - required: true - description: The relation type. - schema: - type: string - enum: - - documentation - - test - - mock - - monitor - example: mock - schemaId: - name: schemaId - in: path - required: true - description: The schema's ID. - schema: - type: string - format: uuid - example: 16bb367e-fafb-4ef3-933b-ee3d971866fb - userId: - name: userId - in: path - required: true - description: The user's SCIM ID. - schema: - type: string - example: 405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99 - workspaceId: - name: workspaceId - in: path - required: true - description: The workspace's ID. - schema: - type: string - format: uuid - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 - workspaceQueryId: - name: workspaceId - required: false - in: query - description: | - The workspace's ID. - - If you do not include this query parameter, the system defaults to the **My Workspace** workspace. - schema: - type: string - format: uuid - example: 1f0df51a-8658-4ee8-a2a1-d2567dfa09a9 -tags: - - name: Collections - description: The `/collections` endpoints let you manage your [collections](https://learning.postman.com/docs/sending-requests/intro-to-collections/). - - name: Environments - description: The `/environments` endpoints let you manage your [environments](https://learning.postman.com/docs/sending-requests/managing-environments/). - - name: Mocks - description: The `/mocks` endpoints let you manage your [mock servers](https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/setting-up-mock/). - - name: Monitors - description: The `/monitors` endpoints let you manage your [monitors](https://learning.postman.com/docs/monitoring-your-api/intro-monitors/). - - name: Workspaces - description: The `/workspaces` endpoints let you manage your [workspaces](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/). - - name: User - description: The `/me` endpoints let you manage information about the authenticated user. - - name: Import - description: The `/import` endpoints let you manage [importing and exporting](https://learning.postman.com/docs/getting-started/importing-and-exporting-data/) Postman data. - - name: API - description: The `/apis` endpoints let you manage your APIs. - - name: API Version - description: The API version endpoints let you manage your [API's versions](https://learning.postman.com/docs/designing-and-developing-your-api/versioning-an-api/versioning-an-api-overview/). - - name: Schema - description: The Schema endpoints let you manage your API's schemas. - - name: Relations - description: The Relations endpoints let you manage your API's relations. [Relations](https://learning.postman.com/docs/designing-and-developing-your-api/developing-an-api/) are an API's connections to items such as documentation, tests, environments, mocks, and monitors. - - name: Webhooks - description: The `/webhooks` endpoints let you manage [custom webhooks](https://learning.postman.com/docs/running-collections/collection-webhooks/). - - name: SCIM 2.0 - Identity - description: | - Postman supports [SCIM](https://en.wikipedia.org/wiki/System_for_Cross-domain_Identity_Management) (System for Cross-domain Identity Management), which allows you to automate the provisioning of your team. You can deploy Postman at scale across your organization and control access to it with your identity provider. - - **Note:** - - - You **must** be a [Postman Team admin](http://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#team-roles) to enable SCIM. - - SCIM provisioning is only available with a Postman **Enterprise** [pricing plan](https://www.postman.com/pricing). - - ### Enabling SCIM provisioning in Postman - - You must [configure SSO](https://learning.postman.com/docs/administration/sso/admin-sso/) and [enable SCIM](http://learning.postman.com/docs/administration/managing-your-team/configuring-scim/#enabling-scim-provisioning) for your Postman team to use these endpoints. - - **Important:** - - To use SCIM, you must have only **one** SSO method configured. If you have more than one SSO method enabled, you **cannot** generate an SCIM API key. - - ### SCIM provisioning limitations - - You can only deactivate users with the SCIM API. You **cannot** permanently delete users with the API. - - ### Rate limits - - For your organization's team, Postman applies per-minute rate limits across all SCIM API endpoints. This helps ensure that you have the best experience using Postman's SCIM API. The rate limits apply as follows: - - - **Write (POST, PUT, PATCH)** — 180 requests per minute. - - **Read (GET)** — 300 requests per minute. - - If your requests are limited, the API will return an HTTP `429 Too Many Requests` response status code. - - name: User Provisioning - description: | - The `/scim/v2/Users` endpoint lets you provision and manage your Postman users. - - **Note:** - - You can only deactivate users with the SCIM API. You **cannot** permanently delete users with the API. - - ### Provisioning users with the SCIM API - - - You can only deactivate users with the SCIM API. You cannot permanently delete users with the API. - - Users created with the SCIM API are automatically created in Postman: - - If the account's email ID does not exist, the user is also added to their organization's Postman team. - - If the account's email ID already exists, the system sends the user an email invite to join the Postman team. After they accept the invite, the are added to the team. - - By default, new users are given the developer role in Postman. Postman user roles cannot be updated via the SCIM API. You must manage user and group roles in Postman. - - name: API Security - description: The API Security endpoints let you manage the [security of your API](https://learning.postman.com/docs/api-governance/api-definition/api-definition-warnings/). API security includes ensuring you follow security and format warnings and schema validation. - diff --git a/libninja/tests/regression/main.rs b/libninja/tests/regression/main.rs index f807c29..8e11718 100644 --- a/libninja/tests/regression/main.rs +++ b/libninja/tests/regression/main.rs @@ -1,11 +1,12 @@ -use openapiv3::{OpenAPI, ReferenceOr, Schema}; -use ln_core::{mir2, mir2::Record}; +use openapiv3::{OpenAPI, Schema}; + +use hir::Record; use libninja::rust::lower_mir::StructExt; const LINK_TOKEN_CREATE: &str = include_str!("link_token_create.yaml"); -fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> mir2::Record { +fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> Record { let schema = serde_yaml::from_str::(schema).unwrap(); let mut record = ln_core::extractor::create_record(name, &schema, spec); record.clear_docs(); diff --git a/macro/src/lib.rs b/macro/src/lib.rs index e9b9c5e..d93ce53 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -11,6 +11,10 @@ use function::{Arg, Tags}; use crate::function::{parse_intro, parse_args, parse_return} ; +/// Define a function where the body is a string. The fn interface definition is reminiscent of Python, +/// but because it creates a mir::Function, it will compile down into whatever language we target. +/// The body has to be valid code for the target language though. We don't have a MIR for the AST - +/// nor would making one make sense (languages don't have mutually compatible ASTs) #[proc_macro] pub fn function(item: TokenStream) -> TokenStream { let mut toks = item.into_iter().peekable(); @@ -57,6 +61,7 @@ pub fn function(item: TokenStream) -> TokenStream { } +/// like function, but for Rust #[proc_macro] pub fn rfunction(item: TokenStream) -> TokenStream { let mut toks = item.into_iter().peekable(); diff --git a/mir/Cargo.toml b/mir/Cargo.toml index 2c0d954..eaf7dd1 100644 --- a/mir/Cargo.toml +++ b/mir/Cargo.toml @@ -9,4 +9,5 @@ path = "src/lib.rs" [dependencies] quote = "1.0.29" -proc-macro2 = "1.0.63" \ No newline at end of file +proc-macro2 = "1.0.63" +libninja_hir = { path = "../hir" } \ No newline at end of file diff --git a/mir/src/lib.rs b/mir/src/lib.rs index 1264a1d..1aafa8e 100644 --- a/mir/src/lib.rs +++ b/mir/src/lib.rs @@ -9,19 +9,15 @@ use core::option::Option::None; use quote::TokenStreamExt; pub use function::{ArgIdent, FnArg, FnArgTreatment, Function, build_struct, build_dict}; +use hir::Doc; mod function; mod r#macro; -/// Non-localized -#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord, Default)] -pub struct Name(pub String); - /// Localized string -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)] pub struct Ident(pub String); - impl std::fmt::Display for Ident { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) @@ -41,27 +37,10 @@ impl Default for Visibility { } } -#[derive(Debug, Clone)] -pub struct Doc(pub String); - -impl Doc { - pub fn new(s: &str) -> Self { - Self(s.to_string()) - } -} - -pub fn doc>(s: S) -> Option { - let s = s.into(); - if s.is_empty() { - None - } else { - Some(Doc(s)) - } -} #[derive(Debug, Default)] pub struct Field { - pub name: Name, + pub name: String, pub ty: T, pub default: Option, pub visibility: Visibility, @@ -328,23 +307,4 @@ impl From for proc_macro2::TokenStream { tok.append(proc_macro2::Ident::new(&val.0, proc_macro2::Span::call_site())); tok } -} - -impl Name { - pub fn new(name: &str) -> Self { - Self(name.to_string()) - } -} - - -impl From for Name { - fn from(s: String) -> Self { - Self(s) - } -} - -impl From<&String> for Name { - fn from(s: &String) -> Self { - Self(s.clone()) - } } \ No newline at end of file diff --git a/mir/src/macro.rs b/mir/src/macro.rs index ea66e58..378cd75 100644 --- a/mir/src/macro.rs +++ b/mir/src/macro.rs @@ -57,7 +57,7 @@ macro_rules! arg { macro_rules! field { (pub(crate) $name:ident : $ty:expr) => { ::mir::Field { - name: ::mir::Name::new(stringify!($name)), + name: stringify!($name).to_string(), ty: ($ty).into(), visibility: ::mir::Visibility::Crate, ..Field::default() @@ -65,7 +65,7 @@ macro_rules! field { }; (pub $name:ident : $ty:expr) => { ::mir::Field { - name: ::mir::Name::new(stringify!($name)), + name: stringify!($name).to_string(), ty: ($ty).into(), visibility: ::mir::Visibility::Public, ..Field::default() @@ -73,7 +73,7 @@ macro_rules! field { }; ($name:ident : $ty:expr) => { ::mir::Field { - name: ::mir::Name::new(stringify!($name)), + name: stringify!($name).to_string(), ty: ($ty).into(), ..Field::default() }