feat(import): complete OpenAPI onboarding and verify delivery
This commit is contained in:
1 parent
bb3e376767
commit
e93de7015a
244 files changed
+57020
-5139
No files matched your search
@@ -13,5 +13,6 @@ crank-schema = { path = "../crank-schema" }
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde_yaml.workspace = true
|
||||
sha2.workspace = true
|
||||
thiserror.workspace = true
|
||||
url.workspace = true
|
||||
@@ -0,0 +1,650 @@
|
||||
//! Bounded, no-materialization preflight for JSON/YAML source documents.
|
||||
//!
|
||||
//! `serde_yaml` materializes alias expansions into owned `Value` trees, so the
|
||||
//! existing post-decode `validate_value_limits` runs too late: a small source
|
||||
//! with few aliases can expand to many MiB before the limit is observed. This
|
||||
//! module walks the same logical, alias-expanded structure with a
|
||||
//! `serde::de::Visitor` that stores no values, strings, keys or collection
|
||||
//! entries, charging an aggregate expanded string/key budget as it goes.
|
||||
//!
|
||||
//! Semantics preserved:
|
||||
//! - the preflight is permissive about duplicate mapping keys, non-finite
|
||||
//! numbers, tags and non-standard keys; the existing strict/legacy
|
||||
//! materializers decide those (so their errors are unchanged);
|
||||
//! - each JSON or YAML parse attempt uses fresh per-document counters, while
|
||||
//! the shared aggregate budget is not reset and is committed only after a
|
||||
//! document fully passes, so an abandoned fallback attempt cannot be
|
||||
//! charged twice;
|
||||
//! - a budget failure is reported as `ImportParseError::LimitExceeded`, while
|
||||
//! syntax/duplicate/conversion failures stay `InvalidDocument`.
|
||||
|
||||
use serde::de::{
|
||||
self, DeserializeSeed, Deserializer, EnumAccess, IgnoredAny, MapAccess, SeqAccess,
|
||||
VariantAccess, Visitor,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use super::model::{ExternalDocumentSnapshot, NormalizationConfig};
|
||||
use super::normalize::ImportParseError;
|
||||
|
||||
/// Internal hard ceiling for expanded string/key bytes in one document set.
|
||||
/// This is deliberately not a `NormalizationConfig` field.
|
||||
const HARD_EXPANDED_BYTES_CAP: u64 = 64 * 1024 * 1024;
|
||||
/// Aggregate allowance per unit of the applicable raw byte limit.
|
||||
const EXPANSION_FACTOR: u64 = 16;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) struct ShapeLimits {
|
||||
pub max_nodes: u64,
|
||||
pub max_depth: u64,
|
||||
pub max_collection_items: u64,
|
||||
pub max_scalar_bytes: u64,
|
||||
}
|
||||
|
||||
impl ShapeLimits {
|
||||
pub(super) fn from_config(config: &NormalizationConfig) -> Self {
|
||||
Self {
|
||||
max_nodes: config.max_nodes as u64,
|
||||
max_depth: config.max_depth as u64,
|
||||
max_collection_items: config.max_collection_items as u64,
|
||||
max_scalar_bytes: config.max_scalar_bytes as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `min(16 * max(raw_limit, max_scalar_bytes), 64 MiB)` with checked overflow.
|
||||
pub(super) fn allowance(
|
||||
raw_limit: usize,
|
||||
max_scalar_bytes: usize,
|
||||
) -> Result<u64, ImportParseError> {
|
||||
let base = (raw_limit as u64).max(max_scalar_bytes as u64);
|
||||
match base.checked_mul(EXPANSION_FACTOR) {
|
||||
Some(value) => Ok(value.min(HARD_EXPANDED_BYTES_CAP)),
|
||||
None => Err(ImportParseError::LimitExceeded),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared expanded-byte budget across one document set. `used` is only
|
||||
/// advanced after a document passes preflight.
|
||||
pub(super) struct AggregateBudget {
|
||||
limit: u64,
|
||||
used: u64,
|
||||
}
|
||||
|
||||
impl AggregateBudget {
|
||||
pub(super) fn empty() -> Self {
|
||||
Self { limit: 0, used: 0 }
|
||||
}
|
||||
|
||||
pub(super) fn reserve(&mut self, allowance: u64) -> Result<(), ImportParseError> {
|
||||
self.limit = self
|
||||
.limit
|
||||
.checked_add(allowance)
|
||||
.ok_or(ImportParseError::LimitExceeded)?
|
||||
.min(HARD_EXPANDED_BYTES_CAP);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct State {
|
||||
shape: ShapeLimits,
|
||||
allowance: u64,
|
||||
bytes: u64,
|
||||
nodes: u64,
|
||||
exceeded: bool,
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn new(shape: ShapeLimits, allowance: u64) -> Self {
|
||||
Self {
|
||||
shape,
|
||||
allowance,
|
||||
bytes: 0,
|
||||
nodes: 0,
|
||||
exceeded: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn preflight_document(
|
||||
document: &str,
|
||||
shape: ShapeLimits,
|
||||
allowance: u64,
|
||||
aggregate: &mut AggregateBudget,
|
||||
) -> Result<(), ImportParseError> {
|
||||
match attempt_json(document, shape, allowance, aggregate) {
|
||||
Attempt::Ok => return Ok(()),
|
||||
Attempt::Budget => return Err(ImportParseError::LimitExceeded),
|
||||
Attempt::Syntax => {}
|
||||
}
|
||||
match attempt_yaml(document, shape, allowance, aggregate) {
|
||||
Attempt::Ok => Ok(()),
|
||||
Attempt::Budget => Err(ImportParseError::LimitExceeded),
|
||||
Attempt::Syntax => Err(ImportParseError::InvalidDocument),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn preflight_single(
|
||||
document: &str,
|
||||
shape: ShapeLimits,
|
||||
raw_limit: usize,
|
||||
) -> Result<(), ImportParseError> {
|
||||
let allowance = allowance(raw_limit, shape.max_scalar_bytes as usize)?;
|
||||
let mut aggregate = AggregateBudget::empty();
|
||||
aggregate.reserve(allowance)?;
|
||||
preflight_document(document, shape, allowance, &mut aggregate)
|
||||
}
|
||||
|
||||
/// Preflights a primary document using `config.max_bytes`.
|
||||
pub(super) fn preflight_primary(
|
||||
document: &str,
|
||||
config: &NormalizationConfig,
|
||||
) -> Result<(), ImportParseError> {
|
||||
preflight_single(document, ShapeLimits::from_config(config), config.max_bytes)
|
||||
}
|
||||
|
||||
/// Preflights a primary document and its supplied external snapshots as one
|
||||
/// set with a shared aggregate budget. Raw byte/alias guards remain the
|
||||
/// caller's responsibility.
|
||||
pub(super) fn preflight_bundle(
|
||||
primary: &str,
|
||||
snapshots: &[ExternalDocumentSnapshot],
|
||||
config: &NormalizationConfig,
|
||||
) -> Result<(), ImportParseError> {
|
||||
let shape = ShapeLimits::from_config(config);
|
||||
let primary_allowance = allowance(config.max_bytes, config.max_scalar_bytes)?;
|
||||
let external_allowance =
|
||||
allowance(config.max_external_document_bytes, config.max_scalar_bytes)?;
|
||||
let mut aggregate = AggregateBudget::empty();
|
||||
aggregate.reserve(primary_allowance)?;
|
||||
for _ in snapshots {
|
||||
aggregate.reserve(external_allowance)?;
|
||||
}
|
||||
preflight_document(primary, shape, primary_allowance, &mut aggregate)?;
|
||||
for snapshot in snapshots {
|
||||
preflight_document(
|
||||
&snapshot.document,
|
||||
shape,
|
||||
external_allowance,
|
||||
&mut aggregate,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Preflights a raw bundle where every document shares `config.max_bytes`.
|
||||
pub(super) fn preflight_raw_bundle(
|
||||
documents: &[&str],
|
||||
config: &NormalizationConfig,
|
||||
) -> Result<(), ImportParseError> {
|
||||
let shape = ShapeLimits::from_config(config);
|
||||
let allowance = allowance(config.max_bytes, config.max_scalar_bytes)?;
|
||||
let mut aggregate = AggregateBudget::empty();
|
||||
for _ in documents {
|
||||
aggregate.reserve(allowance)?;
|
||||
}
|
||||
for document in documents {
|
||||
preflight_document(document, shape, allowance, &mut aggregate)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
enum Attempt {
|
||||
Ok,
|
||||
Budget,
|
||||
Syntax,
|
||||
}
|
||||
|
||||
fn attempt_json(
|
||||
document: &str,
|
||||
shape: ShapeLimits,
|
||||
allowance: u64,
|
||||
aggregate: &mut AggregateBudget,
|
||||
) -> Attempt {
|
||||
let mut state = State::new(shape, allowance);
|
||||
let mut de = serde_json::Deserializer::from_str(document);
|
||||
let seed = Seed {
|
||||
state: &mut state,
|
||||
aggregate,
|
||||
depth: 0,
|
||||
mode: Mode::Value,
|
||||
};
|
||||
let result = match seed.deserialize(&mut de) {
|
||||
Ok(()) => de.end(),
|
||||
Err(error) => Err(error),
|
||||
};
|
||||
finish(result, &state, aggregate)
|
||||
}
|
||||
|
||||
fn attempt_yaml(
|
||||
document: &str,
|
||||
shape: ShapeLimits,
|
||||
allowance: u64,
|
||||
aggregate: &mut AggregateBudget,
|
||||
) -> Attempt {
|
||||
let mut state = State::new(shape, allowance);
|
||||
let seed = Seed {
|
||||
state: &mut state,
|
||||
aggregate,
|
||||
depth: 0,
|
||||
mode: Mode::Value,
|
||||
};
|
||||
let result = seed.deserialize(serde_yaml::Deserializer::from_str(document));
|
||||
finish(result, &state, aggregate)
|
||||
}
|
||||
|
||||
fn finish<E>(result: Result<(), E>, state: &State, aggregate: &mut AggregateBudget) -> Attempt {
|
||||
if result.is_err() {
|
||||
return if state.exceeded {
|
||||
Attempt::Budget
|
||||
} else {
|
||||
Attempt::Syntax
|
||||
};
|
||||
}
|
||||
match aggregate.used.checked_add(state.bytes) {
|
||||
Some(total) if total <= aggregate.limit => {
|
||||
aggregate.used = total;
|
||||
Attempt::Ok
|
||||
}
|
||||
_ => Attempt::Budget,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Mode {
|
||||
Value,
|
||||
Key,
|
||||
}
|
||||
|
||||
struct Seed<'a> {
|
||||
state: &'a mut State,
|
||||
aggregate: &'a mut AggregateBudget,
|
||||
depth: u64,
|
||||
mode: Mode,
|
||||
}
|
||||
|
||||
impl<'de, 'a> DeserializeSeed<'de> for Seed<'a> {
|
||||
type Value = ();
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<(), D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_any(Probe {
|
||||
state: self.state,
|
||||
aggregate: self.aggregate,
|
||||
depth: self.depth,
|
||||
mode: self.mode,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct Probe<'a> {
|
||||
state: &'a mut State,
|
||||
aggregate: &'a mut AggregateBudget,
|
||||
depth: u64,
|
||||
mode: Mode,
|
||||
}
|
||||
|
||||
impl<'a> Probe<'a> {
|
||||
fn fail<E: de::Error>(&mut self) -> E {
|
||||
self.state.exceeded = true;
|
||||
E::custom("normalization decode budget exceeded")
|
||||
}
|
||||
|
||||
/// Charges expanded string/key bytes and the per-scalar limit. Returns an
|
||||
/// internal error that the caller turns into `fail()`.
|
||||
fn charge(&mut self, len: u64) -> Result<(), ()> {
|
||||
if len > self.state.shape.max_scalar_bytes {
|
||||
return Err(());
|
||||
}
|
||||
self.state.bytes = self.state.bytes.checked_add(len).ok_or(())?;
|
||||
if self.state.bytes > self.state.allowance {
|
||||
return Err(());
|
||||
}
|
||||
let total = self
|
||||
.aggregate
|
||||
.used
|
||||
.checked_add(self.state.bytes)
|
||||
.ok_or(())?;
|
||||
if total > self.aggregate.limit {
|
||||
return Err(());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn enter_value<E: de::Error>(&mut self) -> Result<(), E> {
|
||||
if self.depth > self.state.shape.max_depth {
|
||||
return Err(self.fail());
|
||||
}
|
||||
match self.state.nodes.checked_add(1) {
|
||||
Some(nodes) => self.state.nodes = nodes,
|
||||
None => return Err(self.fail()),
|
||||
}
|
||||
if self.state.nodes > self.state.shape.max_nodes {
|
||||
return Err(self.fail());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Bounds depth for composite keys without counting a value node, so
|
||||
/// ordinary scalar mapping keys keep their existing accounting.
|
||||
fn check_depth<E: de::Error>(&mut self) -> Result<(), E> {
|
||||
if self.depth > self.state.shape.max_depth {
|
||||
return Err(self.fail());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn charge_scalar<E: de::Error>(&mut self, len: usize) -> Result<(), E> {
|
||||
if self.charge(len as u64).is_err() {
|
||||
return Err(self.fail());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn value_or_scalar<E: de::Error>(&mut self, len: Option<usize>) -> Result<(), E> {
|
||||
if self.mode == Mode::Value {
|
||||
self.enter_value::<E>()?;
|
||||
}
|
||||
match len {
|
||||
Some(len) => self.charge_scalar::<E>(len),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a> Visitor<'de> for Probe<'a> {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
formatter.write_str("a JSON- or YAML-compatible value")
|
||||
}
|
||||
|
||||
fn visit_bool<E: de::Error>(mut self, _value: bool) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_i64<E: de::Error>(mut self, _value: i64) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_u64<E: de::Error>(mut self, _value: u64) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_i128<E: de::Error>(mut self, _value: i128) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_u128<E: de::Error>(mut self, _value: u128) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_f64<E: de::Error>(mut self, _value: f64) -> Result<(), E> {
|
||||
// Non-finite numbers are deliberately accepted here; the materializer
|
||||
// decides their validity.
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_char<E: de::Error>(mut self, value: char) -> Result<(), E> {
|
||||
self.value_or_scalar(Some(value.len_utf8()))
|
||||
}
|
||||
|
||||
fn visit_str<E: de::Error>(mut self, value: &str) -> Result<(), E> {
|
||||
self.value_or_scalar(Some(value.len()))
|
||||
}
|
||||
|
||||
fn visit_string<E: de::Error>(mut self, value: String) -> Result<(), E> {
|
||||
self.value_or_scalar(Some(value.len()))
|
||||
}
|
||||
|
||||
fn visit_bytes<E: de::Error>(mut self, value: &[u8]) -> Result<(), E> {
|
||||
self.value_or_scalar(Some(value.len()))
|
||||
}
|
||||
|
||||
fn visit_byte_buf<E: de::Error>(mut self, value: Vec<u8>) -> Result<(), E> {
|
||||
self.value_or_scalar(Some(value.len()))
|
||||
}
|
||||
|
||||
fn visit_unit<E: de::Error>(mut self) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_none<E: de::Error>(mut self) -> Result<(), E> {
|
||||
self.value_or_scalar(None)
|
||||
}
|
||||
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<(), D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Seed {
|
||||
state: self.state,
|
||||
aggregate: self.aggregate,
|
||||
depth: self.depth,
|
||||
mode: self.mode,
|
||||
}
|
||||
.deserialize(deserializer)
|
||||
}
|
||||
|
||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<(), D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Seed {
|
||||
state: self.state,
|
||||
aggregate: self.aggregate,
|
||||
depth: self.depth + 1,
|
||||
mode: self.mode,
|
||||
}
|
||||
.deserialize(deserializer)
|
||||
}
|
||||
|
||||
fn visit_seq<A>(mut self, mut seq: A) -> Result<(), A::Error>
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
{
|
||||
match self.mode {
|
||||
Mode::Value => self.enter_value::<A::Error>()?,
|
||||
Mode::Key => self.check_depth::<A::Error>()?,
|
||||
}
|
||||
let collection_limit = self.state.shape.max_collection_items;
|
||||
if seq
|
||||
.size_hint()
|
||||
.is_some_and(|hint| hint as u64 > collection_limit)
|
||||
{
|
||||
return Err(self.fail());
|
||||
}
|
||||
let mut count: u64 = 0;
|
||||
while seq
|
||||
.next_element_seed(Seed {
|
||||
state: &mut *self.state,
|
||||
aggregate: &mut *self.aggregate,
|
||||
depth: self.depth + 1,
|
||||
mode: Mode::Value,
|
||||
})?
|
||||
.is_some()
|
||||
{
|
||||
count += 1;
|
||||
if count > self.state.shape.max_collection_items {
|
||||
return Err(self.fail());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_map<A>(mut self, mut map: A) -> Result<(), A::Error>
|
||||
where
|
||||
A: MapAccess<'de>,
|
||||
{
|
||||
match self.mode {
|
||||
Mode::Value => self.enter_value::<A::Error>()?,
|
||||
Mode::Key => self.check_depth::<A::Error>()?,
|
||||
}
|
||||
let collection_limit = self.state.shape.max_collection_items;
|
||||
if map
|
||||
.size_hint()
|
||||
.is_some_and(|hint| hint as u64 > collection_limit)
|
||||
{
|
||||
return Err(self.fail());
|
||||
}
|
||||
let mut count: u64 = 0;
|
||||
while map
|
||||
.next_key_seed(Seed {
|
||||
state: &mut *self.state,
|
||||
aggregate: &mut *self.aggregate,
|
||||
depth: self.depth + 1,
|
||||
mode: Mode::Key,
|
||||
})?
|
||||
.is_some()
|
||||
{
|
||||
count += 1;
|
||||
if count > self.state.shape.max_collection_items {
|
||||
return Err(self.fail());
|
||||
}
|
||||
map.next_value_seed(Seed {
|
||||
state: &mut *self.state,
|
||||
aggregate: &mut *self.aggregate,
|
||||
depth: self.depth + 1,
|
||||
mode: Mode::Value,
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_enum<A>(self, data: A) -> Result<(), A::Error>
|
||||
where
|
||||
A: EnumAccess<'de>,
|
||||
{
|
||||
// Tagged values are traversed permissively and bounded; the
|
||||
// materializer keeps the final say on tag semantics.
|
||||
let (_variant, variant) = data.variant_seed(PhantomData::<IgnoredAny>)?;
|
||||
variant.newtype_variant_seed(Seed {
|
||||
state: self.state,
|
||||
aggregate: self.aggregate,
|
||||
depth: self.depth + 1,
|
||||
mode: self.mode,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn shape(
|
||||
max_nodes: u64,
|
||||
max_depth: u64,
|
||||
max_collection_items: u64,
|
||||
max_scalar_bytes: u64,
|
||||
) -> ShapeLimits {
|
||||
ShapeLimits {
|
||||
max_nodes,
|
||||
max_depth,
|
||||
max_collection_items,
|
||||
max_scalar_bytes,
|
||||
}
|
||||
}
|
||||
|
||||
fn wide() -> ShapeLimits {
|
||||
shape(1_000, 64, 1_000, 1_000)
|
||||
}
|
||||
|
||||
fn run(
|
||||
document: &str,
|
||||
shape: ShapeLimits,
|
||||
allowance: u64,
|
||||
limit: u64,
|
||||
) -> Result<(), ImportParseError> {
|
||||
let mut aggregate = AggregateBudget::empty();
|
||||
aggregate.limit = limit;
|
||||
preflight_document(document, shape, allowance, &mut aggregate)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_aggregate_boundary_is_inclusive() {
|
||||
let shape = wide();
|
||||
assert!(run("\"abc\"", shape, 3, 3).is_ok());
|
||||
assert_eq!(
|
||||
run("\"abc\"", shape, 2, 3),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_depth_collection_and_node_limits_fail_before_materialization() {
|
||||
let scalar = shape(1_000, 64, 1_000, 2);
|
||||
assert_eq!(
|
||||
run("\"abc\"", scalar, 1_000, 1_000),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
|
||||
let depth = shape(1_000, 1, 1_000, 1_000);
|
||||
assert_eq!(
|
||||
run("{\"a\":{\"b\":1}}", depth, 1_000, 1_000),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
|
||||
let collection = shape(1_000, 64, 1, 1_000);
|
||||
assert_eq!(
|
||||
run("[1,2]", collection, 1_000, 1_000),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
|
||||
let nodes = shape(1, 64, 1_000, 1_000);
|
||||
assert_eq!(
|
||||
run("{\"a\":1}", nodes, 1_000, 1_000),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mapping_keys_do_not_consume_value_nodes() {
|
||||
let node_limited = shape(3, 64, 1_000, 1_000);
|
||||
assert!(run("{\"a\":1,\"b\":2}", node_limited, 1_000, 1_000).is_ok());
|
||||
let stricter = shape(2, 64, 1_000, 1_000);
|
||||
assert_eq!(
|
||||
run("{\"a\":1,\"b\":2}", stricter, 1_000, 1_000),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn composite_mapping_keys_are_depth_bounded() {
|
||||
// A mapping used as a mapping key, whose own key is again a mapping,
|
||||
// must not evade `max_depth`; the fix increases key-child depth.
|
||||
let document = "? {? {a: b}: c}\n: value\n";
|
||||
let shallow = shape(1_000, 1, 1_000, 1_000);
|
||||
assert_eq!(
|
||||
run(document, shallow, 1_000, 1_000),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
let deep = shape(1_000, 64, 1_000, 1_000);
|
||||
assert!(run(document, deep, 1_000, 1_000).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_aggregate_is_not_reset_between_documents() {
|
||||
let shape = wide();
|
||||
let mut aggregate = AggregateBudget::empty();
|
||||
aggregate.limit = 7;
|
||||
assert!(preflight_document("\"abcd\"", shape, 5, &mut aggregate).is_ok());
|
||||
assert_eq!(
|
||||
preflight_document("\"efgh\"", shape, 5, &mut aggregate),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reserve_caps_and_allowance_is_overflow_safe() {
|
||||
let mut aggregate = AggregateBudget::empty();
|
||||
aggregate.reserve(HARD_EXPANDED_BYTES_CAP).unwrap();
|
||||
aggregate.reserve(HARD_EXPANDED_BYTES_CAP).unwrap();
|
||||
assert_eq!(aggregate.limit, HARD_EXPANDED_BYTES_CAP);
|
||||
assert_eq!(
|
||||
allowance(usize::MAX, usize::MAX),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,6 @@ pub(super) fn invalid_path_item() -> ImportFinding {
|
||||
severity: ImportFindingSeverity::Error,
|
||||
message: "Path Item имеет неверную структуру и не был интерпретирован.".to_owned(),
|
||||
operation_key: None,
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,10 @@ pub fn candidate_from_operation(
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
status: String::new(),
|
||||
source_location: operation.source_location.clone(),
|
||||
security_requirements: Default::default(),
|
||||
security_schemes: Default::default(),
|
||||
security_schemes: BTreeMap::new(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
suggested_name: name,
|
||||
suggested_display_name: display_name,
|
||||
|
||||
@@ -1,70 +1,444 @@
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::rest::{
|
||||
model::{ImportFinding, SourceLocation},
|
||||
recommendations::document_finding,
|
||||
};
|
||||
|
||||
pub(super) fn collect_secret_like_examples(
|
||||
value: &Value,
|
||||
pub(super) const REDACTED_LITERAL: &str = "[REDACTED]";
|
||||
|
||||
/// Redacts credential-like literals before they enter the normalized tree,
|
||||
/// while retaining stable source locations for review findings.
|
||||
pub(super) fn redact_secret_like_literals(
|
||||
value: &mut Value,
|
||||
pointer: &str,
|
||||
inside_example: bool,
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<SourceLocation>>,
|
||||
) {
|
||||
let declared_names = credential_names(std::iter::once(&*value));
|
||||
redact_secret_like_literals_with_names(value, pointer, &declared_names, findings, locations);
|
||||
}
|
||||
|
||||
pub(super) fn redact_secret_like_literals_with_names(
|
||||
value: &mut Value,
|
||||
pointer: &str,
|
||||
declared_names: &CredentialNames,
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<SourceLocation>>,
|
||||
) {
|
||||
visit(
|
||||
value,
|
||||
pointer,
|
||||
VisitContext {
|
||||
in_secret_example: false,
|
||||
sensitive_parameter_schema: false,
|
||||
force_redact: false,
|
||||
declared_names,
|
||||
},
|
||||
findings,
|
||||
locations,
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct CredentialNames {
|
||||
header: BTreeSet<String>,
|
||||
query: BTreeSet<String>,
|
||||
cookie: BTreeSet<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct VisitContext<'a> {
|
||||
in_secret_example: bool,
|
||||
sensitive_parameter_schema: bool,
|
||||
force_redact: bool,
|
||||
declared_names: &'a CredentialNames,
|
||||
}
|
||||
|
||||
impl CredentialNames {
|
||||
fn contains(&self, location: &str, name: &str) -> bool {
|
||||
let names = match location.to_ascii_lowercase().as_str() {
|
||||
"header" => &self.header,
|
||||
"query" => &self.query,
|
||||
"cookie" => &self.cookie,
|
||||
_ => return false,
|
||||
};
|
||||
names.contains(&name.to_ascii_lowercase())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn credential_names<'a>(roots: impl IntoIterator<Item = &'a Value>) -> CredentialNames {
|
||||
let mut names = CredentialNames::default();
|
||||
for root in roots {
|
||||
collect_credential_names(root, &mut names);
|
||||
}
|
||||
names
|
||||
}
|
||||
|
||||
fn collect_credential_names(value: &Value, names: &mut CredentialNames) {
|
||||
match value {
|
||||
Value::Object(fields) => {
|
||||
if fields.get("type").and_then(Value::as_str) == Some("apiKey")
|
||||
&& let (Some(location), Some(name)) = (
|
||||
fields.get("in").and_then(Value::as_str),
|
||||
fields.get("name").and_then(Value::as_str),
|
||||
)
|
||||
{
|
||||
let destination = match location.to_ascii_lowercase().as_str() {
|
||||
"header" => Some(&mut names.header),
|
||||
"query" => Some(&mut names.query),
|
||||
"cookie" => Some(&mut names.cookie),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(destination) = destination {
|
||||
destination.insert(name.to_ascii_lowercase());
|
||||
}
|
||||
}
|
||||
for child in fields.values() {
|
||||
collect_credential_names(child, names);
|
||||
}
|
||||
}
|
||||
Value::Array(items) => {
|
||||
for child in items {
|
||||
collect_credential_names(child, names);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit(
|
||||
value: &mut Value,
|
||||
pointer: &str,
|
||||
context: VisitContext<'_>,
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<SourceLocation>>,
|
||||
) {
|
||||
if context.force_redact
|
||||
|| value
|
||||
.as_str()
|
||||
.is_some_and(|text| url_has_secret_named(text, context.declared_names))
|
||||
|| (context.in_secret_example && value.as_str() == Some(REDACTED_LITERAL))
|
||||
|| (context.in_secret_example && scalar_looks_secret(value))
|
||||
{
|
||||
redact(value, context.force_redact, context.declared_names);
|
||||
findings.push(document_finding(
|
||||
"secret_like_example",
|
||||
"В исходном документе обнаружено значение, похожее на секрет; оно удалено из импортируемых данных.",
|
||||
));
|
||||
locations.push(Some(SourceLocation {
|
||||
pointer: pointer.to_owned(),
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
match value {
|
||||
Value::Object(fields) => {
|
||||
let sensitive_parameter =
|
||||
fields
|
||||
.get("in")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|location| {
|
||||
["header", "query", "cookie"]
|
||||
.iter()
|
||||
.any(|allowed| location.eq_ignore_ascii_case(allowed))
|
||||
})
|
||||
&& fields
|
||||
.get("name")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|name| {
|
||||
is_sensitive_name(name)
|
||||
|| fields.get("in").and_then(Value::as_str).is_some_and(
|
||||
|location| context.declared_names.contains(location, name),
|
||||
)
|
||||
});
|
||||
for (key, child) in fields {
|
||||
let child_pointer = format!(
|
||||
"{pointer}/{}",
|
||||
super::normalize_coverage::escape_pointer(key)
|
||||
);
|
||||
collect_secret_like_examples(
|
||||
let key_lower = key.to_ascii_lowercase();
|
||||
let in_example = context.in_secret_example
|
||||
|| matches!(
|
||||
key_lower.as_str(),
|
||||
"default"
|
||||
| "example"
|
||||
| "examples"
|
||||
| "x-example"
|
||||
| "x-examples"
|
||||
| "bearerformat"
|
||||
| "x-format-hint"
|
||||
);
|
||||
let sensitive_header_definition = pointer.ends_with("/headers")
|
||||
&& (is_sensitive_name(key) || context.declared_names.contains("header", key));
|
||||
let parameter_value = (sensitive_parameter || sensitive_header_definition)
|
||||
&& matches!(
|
||||
key_lower.as_str(),
|
||||
"example" | "examples" | "x-example" | "x-examples"
|
||||
);
|
||||
let parameter_schema = context.sensitive_parameter_schema
|
||||
|| sensitive_header_definition
|
||||
|| (sensitive_parameter && key_lower == "schema");
|
||||
let parent_is_secret_property =
|
||||
pointer.rsplit('/').next().is_some_and(is_sensitive_name);
|
||||
// Names in schema/scheme maps and security requirements are
|
||||
// identifiers, not credential values. Traverse their metadata
|
||||
// and redact the actual defaults/examples instead.
|
||||
let identifier_map = (child.is_object()
|
||||
&& (pointer.ends_with("/properties")
|
||||
|| pointer.ends_with("/headers")
|
||||
|| pointer == "/components/schemas"
|
||||
|| pointer == "/definitions"
|
||||
|| pointer == "/components/securitySchemes"
|
||||
|| pointer == "/securityDefinitions"))
|
||||
|| (child.is_array()
|
||||
&& pointer.rsplit_once('/').is_some_and(|(parent, index)| {
|
||||
parent.ends_with("/security") && index.parse::<usize>().is_ok()
|
||||
}));
|
||||
let force_child = (is_sensitive_name(key) && !identifier_map)
|
||||
|| (matches!(key_lower.as_str(), "default" | "example" | "examples")
|
||||
&& parent_is_secret_property)
|
||||
|| parameter_value
|
||||
|| (sensitive_parameter
|
||||
&& matches!(key_lower.as_str(), "default" | "example" | "examples"))
|
||||
|| (parameter_schema
|
||||
&& matches!(key_lower.as_str(), "default" | "example" | "examples"));
|
||||
visit(
|
||||
child,
|
||||
&child_pointer,
|
||||
inside_example || matches!(key.as_str(), "example" | "examples"),
|
||||
VisitContext {
|
||||
in_secret_example: in_example,
|
||||
sensitive_parameter_schema: parameter_schema,
|
||||
force_redact: force_child,
|
||||
..context
|
||||
},
|
||||
findings,
|
||||
locations,
|
||||
);
|
||||
}
|
||||
}
|
||||
Value::Array(items) => {
|
||||
for (index, child) in items.iter().enumerate() {
|
||||
collect_secret_like_examples(
|
||||
for (index, child) in items.iter_mut().enumerate() {
|
||||
visit(
|
||||
child,
|
||||
&format!("{pointer}/{index}"),
|
||||
inside_example,
|
||||
VisitContext {
|
||||
force_redact: false,
|
||||
..context
|
||||
},
|
||||
findings,
|
||||
locations,
|
||||
);
|
||||
}
|
||||
}
|
||||
Value::String(value) if inside_example && looks_secret_like(pointer, value) => {
|
||||
findings.push(document_finding(
|
||||
"secret_like_example",
|
||||
"Example содержит значение, похожее на секрет, и не включается в executable contract.",
|
||||
));
|
||||
locations.push(Some(SourceLocation {
|
||||
pointer: pointer.to_owned(),
|
||||
}));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn looks_secret_like(pointer: &str, value: &str) -> bool {
|
||||
let pointer = pointer.to_ascii_lowercase();
|
||||
fn is_sensitive_name(name: &str) -> bool {
|
||||
let lower = name.to_ascii_lowercase();
|
||||
if lower.starts_with('/')
|
||||
|| matches!(
|
||||
lower.as_str(),
|
||||
"url"
|
||||
| "tokenurl"
|
||||
| "authorizationurl"
|
||||
| "refreshurl"
|
||||
| "openidconnecturl"
|
||||
| "clientcredentials"
|
||||
| "authorizationcode"
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let compact = lower.replace(['-', '_'], "");
|
||||
[
|
||||
"token",
|
||||
"secret",
|
||||
"password",
|
||||
"credential",
|
||||
"authorization",
|
||||
"apikey",
|
||||
"accesskey",
|
||||
"ciphertext",
|
||||
"privatekey",
|
||||
"passwd",
|
||||
]
|
||||
.iter()
|
||||
.any(|marker| compact.contains(marker))
|
||||
}
|
||||
|
||||
fn scalar_looks_secret(value: &Value) -> bool {
|
||||
let Value::String(value) = value else {
|
||||
return false;
|
||||
};
|
||||
let value = value.to_ascii_lowercase();
|
||||
[
|
||||
"token",
|
||||
"secret",
|
||||
"password",
|
||||
"credential",
|
||||
"authorization",
|
||||
"api_key",
|
||||
"apikey",
|
||||
"authorization",
|
||||
]
|
||||
.iter()
|
||||
.any(|marker| pointer.contains(marker) || value.contains(marker))
|
||||
.any(|marker| value.contains(marker))
|
||||
|| value.starts_with("bearer ")
|
||||
|| value.starts_with("sk-")
|
||||
|| looks_like_jwt(&value)
|
||||
}
|
||||
|
||||
fn looks_like_jwt(value: &str) -> bool {
|
||||
let mut segments = value.split('.');
|
||||
let (Some(header), Some(payload), Some(signature), None) = (
|
||||
segments.next(),
|
||||
segments.next(),
|
||||
segments.next(),
|
||||
segments.next(),
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
header.starts_with("eyj")
|
||||
&& !payload.is_empty()
|
||||
&& signature.len() >= 8
|
||||
&& [header, payload, signature].iter().all(|segment| {
|
||||
segment
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-'))
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn url_has_secret(value: &str) -> bool {
|
||||
url_has_secret_named(value, &CredentialNames::default())
|
||||
}
|
||||
|
||||
fn url_has_secret_named(value: &str, declared_names: &CredentialNames) -> bool {
|
||||
url_userinfo(value).is_some()
|
||||
|| query_has_secret_parameter(value, &declared_names.query)
|
||||
|| fragment_has_secret_parameter(value)
|
||||
}
|
||||
|
||||
fn fragment_has_secret_parameter(value: &str) -> bool {
|
||||
let Some((_, fragment)) = value.split_once('#') else {
|
||||
return false;
|
||||
};
|
||||
if fragment.starts_with('/') {
|
||||
return false;
|
||||
}
|
||||
url::form_urlencoded::parse(fragment.as_bytes()).any(|(name, _)| is_sensitive_name(&name))
|
||||
}
|
||||
|
||||
fn redact_url_fragment(value: &str) -> String {
|
||||
let Some((base, fragment)) = value.split_once('#') else {
|
||||
return value.to_owned();
|
||||
};
|
||||
if fragment.starts_with('/') || !fragment.contains('=') {
|
||||
return value.to_owned();
|
||||
}
|
||||
let redacted = fragment
|
||||
.split('&')
|
||||
.map(|pair| {
|
||||
let (name, parameter_value) = pair.split_once('=').unwrap_or((pair, ""));
|
||||
let decoded_name = url::form_urlencoded::parse(format!("{name}=").as_bytes())
|
||||
.next()
|
||||
.map(|(name, _)| name.into_owned())
|
||||
.unwrap_or_default();
|
||||
if is_sensitive_name(&decoded_name) {
|
||||
format!("{name}={REDACTED_LITERAL}")
|
||||
} else if pair.contains('=') {
|
||||
format!("{name}={parameter_value}")
|
||||
} else {
|
||||
name.to_owned()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("&");
|
||||
format!("{base}#{redacted}")
|
||||
}
|
||||
|
||||
fn url_userinfo(value: &str) -> Option<(&str, &str, &str)> {
|
||||
let (scheme, rest) = value
|
||||
.split_once("://")
|
||||
.or_else(|| value.strip_prefix("//").map(|rest| ("", rest)))?;
|
||||
let (authority, suffix) = rest
|
||||
.find(['/', '?', '#'])
|
||||
.map_or((rest, ""), |index| (&rest[..index], &rest[index..]));
|
||||
let (userinfo, host) = authority.split_once('@')?;
|
||||
if userinfo.is_empty() || host.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some((scheme, host, suffix))
|
||||
}
|
||||
|
||||
fn query_has_secret_parameter(value: &str, declared_query_names: &BTreeSet<String>) -> bool {
|
||||
let Some((_, query)) = value.split_once('?') else {
|
||||
return false;
|
||||
};
|
||||
let query = query.split('#').next().unwrap_or(query);
|
||||
url::form_urlencoded::parse(query.as_bytes()).any(|(name, _)| {
|
||||
is_sensitive_name(&name) || declared_query_names.contains(&name.to_ascii_lowercase())
|
||||
})
|
||||
}
|
||||
|
||||
fn redact(value: &mut Value, force: bool, declared_names: &CredentialNames) {
|
||||
if force
|
||||
|| !value
|
||||
.as_str()
|
||||
.is_some_and(|text| url_has_secret_named(text, declared_names))
|
||||
{
|
||||
*value = Value::String(REDACTED_LITERAL.to_owned());
|
||||
return;
|
||||
}
|
||||
if let Value::String(text) = value {
|
||||
if force {
|
||||
*text = REDACTED_LITERAL.to_owned();
|
||||
return;
|
||||
}
|
||||
let mut sanitized = text.clone();
|
||||
if let Some((scheme, host, suffix)) = url_userinfo(&sanitized) {
|
||||
sanitized = if scheme.is_empty() {
|
||||
format!("//{host}{suffix}")
|
||||
} else {
|
||||
format!("{scheme}://{host}{suffix}")
|
||||
};
|
||||
}
|
||||
if query_has_secret_parameter(&sanitized, &declared_names.query)
|
||||
&& let Some((base, query)) = sanitized.split_once('?')
|
||||
{
|
||||
let (query, fragment) = query
|
||||
.split_once('#')
|
||||
.map_or((query, None), |(query, fragment)| (query, Some(fragment)));
|
||||
let redacted = query
|
||||
.split('&')
|
||||
.map(|pair| {
|
||||
let (name, value) = pair.split_once('=').unwrap_or((pair, ""));
|
||||
let decoded_name = url::form_urlencoded::parse(format!("{name}=").as_bytes())
|
||||
.next()
|
||||
.map(|(name, _)| name.into_owned())
|
||||
.unwrap_or_default();
|
||||
if is_sensitive_name(&decoded_name)
|
||||
|| declared_names
|
||||
.query
|
||||
.contains(&decoded_name.to_ascii_lowercase())
|
||||
{
|
||||
format!("{name}={REDACTED_LITERAL}")
|
||||
} else if pair.contains('=') {
|
||||
format!("{name}={value}")
|
||||
} else {
|
||||
name.to_owned()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("&");
|
||||
sanitized = match fragment {
|
||||
Some(fragment) => format!("{base}?{redacted}#{fragment}"),
|
||||
None => format!("{base}?{redacted}"),
|
||||
};
|
||||
}
|
||||
*text = redact_url_fragment(&sanitized);
|
||||
} else {
|
||||
*value = Value::String(REDACTED_LITERAL.to_owned());
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,39 @@
|
||||
mod decode_budget;
|
||||
mod http_methods;
|
||||
mod legacy_mapping;
|
||||
mod legacy_payload;
|
||||
mod legacy_schema;
|
||||
mod mapping;
|
||||
mod metadata_findings;
|
||||
pub mod model;
|
||||
mod naming;
|
||||
mod normalize;
|
||||
mod normalize_coverage;
|
||||
mod normalize_finding_validation;
|
||||
mod normalize_limits;
|
||||
mod normalize_preview;
|
||||
mod normalize_projection;
|
||||
mod normalize_schema;
|
||||
mod normalize_security;
|
||||
mod openapi3;
|
||||
mod openapi3_findings;
|
||||
mod openapi3_legacy;
|
||||
mod parser_findings;
|
||||
mod payload;
|
||||
mod recommendations;
|
||||
mod reference;
|
||||
mod reference_budget;
|
||||
mod schema;
|
||||
mod security;
|
||||
mod security_literals;
|
||||
mod source_safety;
|
||||
mod strict_decode;
|
||||
mod swagger2;
|
||||
mod swagger2_findings;
|
||||
mod swagger2_legacy;
|
||||
|
||||
pub use model::{
|
||||
ExternalDocumentSnapshot, HISTORICAL_NORMALIZER_VERSION, HISTORICAL_PROJECTION_VERSION,
|
||||
ImportFinding, ImportFindingSeverity, ImportGroupPreview, ImportOperationCandidate,
|
||||
ImportPreview, ImportSourcePreview, NORMALIZER_VERSION, NormalizationConfig, NormalizedFinding,
|
||||
NormalizedIr, NormalizedOperation, NormalizedParameter, NormalizedReference,
|
||||
NormalizedRequestBodyVariant, NormalizedResponseVariant, NormalizedSchema,
|
||||
ImportFinding, ImportFindingSeverity, ImportGroupPreview, ImportNameConflict,
|
||||
ImportOperationCandidate, ImportPreview, ImportSourcePreview, NORMALIZER_VERSION,
|
||||
NormalizationConfig, NormalizedFinding, NormalizedIr, NormalizedOperation, NormalizedParameter,
|
||||
NormalizedReference, NormalizedRequestBodyVariant, NormalizedResponseVariant, NormalizedSchema,
|
||||
NormalizedSchemaConstraints, NormalizedSchemaKind, NormalizedSecurityRequirements,
|
||||
NormalizedSecurityScheme, NormalizedSecuritySchemeKind, PROJECTION_VERSION,
|
||||
ResolvedReferenceEdge, ResolvedReferenceGraph, ResolvedReferenceNode, RestImportCandidate,
|
||||
@@ -42,7 +45,9 @@ pub use model::{
|
||||
pub use normalize::{
|
||||
ImportParseError, external_reference_uris, normalize_verified_bundle,
|
||||
normalize_verified_document, preview_document, preview_document_legacy_v1, preview_from_ir,
|
||||
reference_uris, validate_normalized_ir,
|
||||
reference_uris, validate_document_source_safe, validate_normalized_ir,
|
||||
};
|
||||
pub use payload::operation_draft_from_candidate;
|
||||
pub use security_literals::{SecretLiteralFinding, scan_secret_literals};
|
||||
pub use source_safety::{
|
||||
validate_document_bundle_source_safe, validate_resolved_bundle_source_safe,
|
||||
};
|
||||
@@ -10,7 +10,7 @@ use serde_json::Value;
|
||||
/// deliberately travel with an import job: changing either contract must not
|
||||
/// silently reinterpret a pending preview.
|
||||
pub const NORMALIZER_VERSION: &str = "normalized-ir-v5";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v5";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v6";
|
||||
pub const HISTORICAL_NORMALIZER_VERSION: &str = "normalized-ir-v4";
|
||||
pub const HISTORICAL_PROJECTION_VERSION: &str = "preview-v4";
|
||||
|
||||
@@ -496,6 +496,10 @@ pub struct ImportFinding {
|
||||
pub message: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub operation_key: Option<String>,
|
||||
/// RFC 6901 source pointer of the finding. Optional so preview payloads
|
||||
/// persisted before this field was introduced still deserialize.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -514,6 +518,17 @@ pub struct ImportPreview {
|
||||
pub groups: Vec<ImportGroupPreview>,
|
||||
#[serde(default)]
|
||||
pub findings: Vec<ImportFinding>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub conflicts: Vec<ImportNameConflict>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ImportNameConflict {
|
||||
pub operation_key: String,
|
||||
pub conflict_type: String,
|
||||
pub proposed_name: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -528,6 +543,13 @@ pub struct ImportOperationCandidate {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
/// Workspace-aware readiness is attached by the API after immutable replay.
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
pub status: String,
|
||||
/// RFC 6901 pointer of the source operation. Optional so preview payloads
|
||||
/// persisted before this field was introduced still deserialize.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
@@ -583,6 +605,10 @@ pub struct RestImportOperation {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
/// Authoritative RFC 6901 pointer of the operation when it was produced by
|
||||
/// the normalizer. Parser state only; never persisted.
|
||||
#[serde(skip)]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::rest::{
|
||||
openapi3, swagger2,
|
||||
};
|
||||
|
||||
use super::decode_budget;
|
||||
use super::normalize_coverage;
|
||||
use super::normalize_limits;
|
||||
|
||||
@@ -61,9 +62,9 @@ pub fn external_reference_uris(
|
||||
pub fn preview_document_legacy_v1(document: &str) -> Result<ImportPreview, ImportParseError> {
|
||||
let root = decode_legacy_v1(document)?;
|
||||
let mut parsed = match root.get("openapi") {
|
||||
Some(_) => super::openapi3_legacy::parse_document_legacy_v1(&root)?,
|
||||
Some(_) => openapi3::parse_document_legacy_v1(&root)?,
|
||||
None if root.get("swagger").and_then(Value::as_str) == Some("2.0") => {
|
||||
super::swagger2_legacy::parse_document_legacy_v1(&root)?
|
||||
swagger2::parse_document_legacy_v1(&root)?
|
||||
}
|
||||
None => return Err(ImportParseError::UnsupportedDocument),
|
||||
};
|
||||
@@ -80,7 +81,7 @@ pub fn preview_document_legacy_v1(document: &str) -> Result<ImportPreview, Impor
|
||||
operation.response_schema = Some(resolve_local_ref(&root, &schema, 0));
|
||||
}
|
||||
}
|
||||
Ok(super::normalize_preview::preview_from_document(parsed))
|
||||
Ok(preview_from_document(parsed))
|
||||
}
|
||||
|
||||
fn decode_legacy_v1(document: &str) -> Result<Value, ImportParseError> {
|
||||
@@ -90,6 +91,7 @@ fn decode_legacy_v1(document: &str) -> Result<Value, ImportParseError> {
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
decode_budget::preflight_primary(document, &config)?;
|
||||
let root = decode(document)?;
|
||||
validate_value_limits(&root, &config)?;
|
||||
Ok(root)
|
||||
@@ -103,6 +105,39 @@ pub fn normalize_verified_document(
|
||||
normalize_verified_bundle(document, digest, &[], config)
|
||||
}
|
||||
|
||||
/// Rejects source documents containing credential-like literals before a
|
||||
/// caller persists their original bytes. Accepted source bytes remain verbatim.
|
||||
pub fn validate_document_source_safe(
|
||||
document: &str,
|
||||
config: &NormalizationConfig,
|
||||
) -> Result<(), ImportParseError> {
|
||||
config
|
||||
.validate_versions()
|
||||
.map_err(|_| ImportParseError::UnsupportedDocument)?;
|
||||
if document.len() > config.max_bytes
|
||||
|| normalize_limits::alias_count(document) > config.max_aliases
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
decode_budget::preflight_primary(document, config)?;
|
||||
let mut root =
|
||||
super::strict_decode::decode(document).map_err(|_| ImportParseError::InvalidDocument)?;
|
||||
validate_value_limits(&root, config)?;
|
||||
let mut findings = Vec::new();
|
||||
let mut locations = Vec::new();
|
||||
super::metadata_findings::redact_secret_like_literals(
|
||||
&mut root,
|
||||
"",
|
||||
&mut findings,
|
||||
&mut locations,
|
||||
);
|
||||
if findings.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ImportParseError::InvalidDocument)
|
||||
}
|
||||
}
|
||||
|
||||
/// Normalizes a verified primary document together with immutable external
|
||||
/// snapshots. This function is pure: callers must perform all URL policy,
|
||||
/// fetching, artifact persistence and digest verification beforehand.
|
||||
@@ -120,12 +155,24 @@ pub fn normalize_verified_bundle(
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
if snapshots.len() > config.max_reference_documents {
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
for snapshot in snapshots {
|
||||
if snapshot.document.len() > config.max_external_document_bytes
|
||||
|| normalize_limits::alias_count(&snapshot.document) > config.max_aliases
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
}
|
||||
decode_budget::preflight_bundle(document, snapshots, config)?;
|
||||
let source_syntax = if serde_json::from_str::<Value>(document).is_ok() {
|
||||
SourceSyntax::Json
|
||||
} else {
|
||||
SourceSyntax::Yaml
|
||||
};
|
||||
let root = decode(document)?;
|
||||
let root =
|
||||
super::strict_decode::decode(document).map_err(|_| ImportParseError::InvalidDocument)?;
|
||||
validate_value_limits(&root, config)?;
|
||||
for snapshot in snapshots {
|
||||
if snapshot.document.len() > config.max_external_document_bytes {
|
||||
@@ -136,7 +183,14 @@ pub fn normalize_verified_bundle(
|
||||
let mut root = resolution.root;
|
||||
validate_value_limits(&root, config)?;
|
||||
|
||||
let redacted_literals = super::security_literals::inspect_and_redact(&mut root);
|
||||
let mut literal_findings = Vec::new();
|
||||
let mut literal_locations = Vec::new();
|
||||
super::metadata_findings::redact_secret_like_literals(
|
||||
&mut root,
|
||||
"",
|
||||
&mut literal_findings,
|
||||
&mut literal_locations,
|
||||
);
|
||||
|
||||
let mut parsed = match root.get("openapi").and_then(Value::as_str) {
|
||||
Some(version) if supported_oas_version(version) => openapi3::parse_document(&root)?,
|
||||
@@ -146,15 +200,8 @@ pub fn normalize_verified_bundle(
|
||||
}
|
||||
None => return Err(ImportParseError::UnsupportedDocument),
|
||||
};
|
||||
for literal in redacted_literals {
|
||||
parsed.findings.push(super::recommendations::document_finding(
|
||||
"secret_literal_redacted",
|
||||
"Документ содержит literal credential; значение удалено из normalized representation.",
|
||||
));
|
||||
parsed
|
||||
.internal_finding_locations
|
||||
.push(Some(literal.location));
|
||||
}
|
||||
parsed.findings.extend(literal_findings);
|
||||
parsed.internal_finding_locations.extend(literal_locations);
|
||||
|
||||
if parsed.operations.is_empty()
|
||||
&& !parsed
|
||||
@@ -176,7 +223,11 @@ pub fn normalize_verified_bundle(
|
||||
}
|
||||
|
||||
pub fn preview_from_ir(ir: &NormalizedIr) -> ImportPreview {
|
||||
super::normalize_preview::preview_from_ir(ir)
|
||||
super::normalize_projection::preview_from_ir(ir)
|
||||
}
|
||||
|
||||
fn preview_from_document(document: RestImportDocument) -> ImportPreview {
|
||||
super::normalize_projection::preview_from_document(document)
|
||||
}
|
||||
|
||||
pub(super) fn decode(document: &str) -> Result<Value, ImportParseError> {
|
||||
@@ -205,7 +256,6 @@ fn canonicalize(
|
||||
reference_graph: crate::rest::model::ResolvedReferenceGraph,
|
||||
resolution_findings: Vec<NormalizedFinding>,
|
||||
) -> Result<NormalizedIr, ImportParseError> {
|
||||
let security_schemes = document.security_schemes.clone();
|
||||
let source = ImportSourcePreview {
|
||||
format: document.format,
|
||||
version: document.version,
|
||||
@@ -505,8 +555,6 @@ fn canonicalize(
|
||||
key: operation.key,
|
||||
method: operation.method,
|
||||
path: operation.path,
|
||||
security_requirements: operation.security_requirements,
|
||||
security_schemes: security_schemes.clone(),
|
||||
operation_id: operation.operation_id,
|
||||
summary: operation.summary,
|
||||
description: operation.description,
|
||||
@@ -517,6 +565,8 @@ fn canonicalize(
|
||||
request_body_variants,
|
||||
response_variants,
|
||||
servers: operation.servers,
|
||||
security_requirements: operation.security_requirements,
|
||||
security_schemes: document.security_schemes.clone(),
|
||||
findings: operation_findings,
|
||||
})
|
||||
})
|
||||
@@ -708,11 +758,11 @@ fn canonicalize(
|
||||
}
|
||||
|
||||
pub fn validate_normalized_ir(ir: &NormalizedIr) -> Result<(), ImportParseError> {
|
||||
let current =
|
||||
ir.normalizer_version == NORMALIZER_VERSION && ir.projection_version == PROJECTION_VERSION;
|
||||
let historical_v4 = ir.normalizer_version == super::model::HISTORICAL_NORMALIZER_VERSION
|
||||
&& ir.projection_version == super::model::HISTORICAL_PROJECTION_VERSION;
|
||||
if !current && !historical_v4 {
|
||||
if !((ir.normalizer_version == NORMALIZER_VERSION
|
||||
&& ir.projection_version == PROJECTION_VERSION)
|
||||
|| (ir.normalizer_version == crate::rest::model::HISTORICAL_NORMALIZER_VERSION
|
||||
&& ir.projection_version == crate::rest::model::HISTORICAL_PROJECTION_VERSION))
|
||||
{
|
||||
return Err(ImportParseError::InvalidDocument);
|
||||
}
|
||||
validate_reference_graph(ir)?;
|
||||
|
||||
@@ -4,9 +4,9 @@ use serde_json::Value;
|
||||
|
||||
use crate::rest::model::{
|
||||
CanonicalSourceNode, CanonicalSourceValue, CoverageDisposition, CoverageEntry,
|
||||
ImportSourcePreview, NORMALIZER_VERSION, NormalizedIr, NormalizedOperation, NormalizedPath,
|
||||
NormalizedReference, NormalizedSchema, NormalizedSchemaKind, PROJECTION_VERSION,
|
||||
SourceLocation,
|
||||
HISTORICAL_NORMALIZER_VERSION, HISTORICAL_PROJECTION_VERSION, ImportSourcePreview,
|
||||
NORMALIZER_VERSION, NormalizedIr, NormalizedOperation, NormalizedPath, NormalizedReference,
|
||||
NormalizedSchema, NormalizedSchemaKind, PROJECTION_VERSION, SourceLocation,
|
||||
};
|
||||
|
||||
use super::ImportParseError;
|
||||
@@ -16,11 +16,11 @@ pub(super) use super::normalize_schema::{
|
||||
};
|
||||
|
||||
pub(super) fn validate_coverage(ir: &NormalizedIr) -> Result<(), ImportParseError> {
|
||||
let current =
|
||||
ir.normalizer_version == NORMALIZER_VERSION && ir.projection_version == PROJECTION_VERSION;
|
||||
let historical_v4 = ir.normalizer_version == super::model::HISTORICAL_NORMALIZER_VERSION
|
||||
&& ir.projection_version == super::model::HISTORICAL_PROJECTION_VERSION;
|
||||
if !current && !historical_v4 {
|
||||
if !((ir.normalizer_version == NORMALIZER_VERSION
|
||||
&& ir.projection_version == PROJECTION_VERSION)
|
||||
|| (ir.normalizer_version == HISTORICAL_NORMALIZER_VERSION
|
||||
&& ir.projection_version == HISTORICAL_PROJECTION_VERSION))
|
||||
{
|
||||
return Err(ImportParseError::InvalidDocument);
|
||||
}
|
||||
let mut source_nodes = BTreeMap::new();
|
||||
@@ -98,15 +98,17 @@ pub(super) fn validate_coverage(ir: &NormalizedIr) -> Result<(), ImportParseErro
|
||||
.flat_map(|operation| &operation.findings),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
if findings.iter().any(|finding| {
|
||||
is_security_finding_code(&finding.code)
|
||||
&& !super::normalize_finding_validation::matches_source(finding, ir, &source_nodes)
|
||||
}) {
|
||||
return Err(ImportParseError::InvalidDocument);
|
||||
}
|
||||
for finding in &findings {
|
||||
if super::normalize_finding_validation::matches_source(finding, ir, &source_nodes)
|
||||
&& finding.construct_id == format!("{version}:{}", finding.location.pointer)
|
||||
let source_match =
|
||||
super::normalize_finding_validation::matches_source(finding, ir, &source_nodes);
|
||||
if matches!(
|
||||
finding.code.as_str(),
|
||||
"path_parameter_not_declared" | "unsupported_compound_default"
|
||||
) && !source_match
|
||||
{
|
||||
return Err(ImportParseError::InvalidDocument);
|
||||
}
|
||||
if source_match && finding.construct_id == format!("{version}:{}", finding.location.pointer)
|
||||
{
|
||||
insert_real_expected(
|
||||
&mut expected,
|
||||
@@ -155,20 +157,6 @@ pub(super) fn validate_coverage(ir: &NormalizedIr) -> Result<(), ImportParseErro
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_security_finding_code(code: &str) -> bool {
|
||||
matches!(
|
||||
code,
|
||||
"invalid_security_requirements"
|
||||
| "invalid_security_requirement"
|
||||
| "unresolved_security_scheme"
|
||||
| "unsupported_security_and_requirement"
|
||||
| "unsupported_security_scheme"
|
||||
| "unsupported_security_requirements"
|
||||
| "invalid_security_scopes"
|
||||
| "unexpected_security_scopes"
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
struct ExpectedCoverage {
|
||||
location: SourceLocation,
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
|
||||
|
||||
use crate::rest::model::{
|
||||
CanonicalSourceNode, CanonicalSourceValue, ImportFindingSeverity, NormalizedFinding,
|
||||
NormalizedIr, NormalizedOperation, NormalizedSecuritySchemeKind, SecurityRequirementsSource,
|
||||
NormalizedIr,
|
||||
};
|
||||
|
||||
pub(super) fn matches_source(
|
||||
@@ -48,164 +48,184 @@ pub(super) fn matches_source(
|
||||
finding.operation_key.as_deref() == Some(operation.key.as_str())
|
||||
&& matches!(&node.value, CanonicalSourceValue::Object(fields) if matches!(fields.get("name").map(|node| &node.value), Some(CanonicalSourceValue::String(name)) if !operation.path.contains(&format!("{{{name}}}"))))
|
||||
}),
|
||||
"path_parameter_not_declared" if is_error => {
|
||||
path_parameter_missing_in_source(finding, ir, node, nodes)
|
||||
}
|
||||
"unsupported_compound_default" if is_error => {
|
||||
pointer.ends_with("/default")
|
||||
&& matches!(node.value, CanonicalSourceValue::Object(_) | CanonicalSourceValue::Array(_))
|
||||
}
|
||||
"unsupported_schema_keyword" if is_error => schema_keyword(pointer, node),
|
||||
"unsupported_schema_enum" if is_error => {
|
||||
pointer.ends_with("/enum")
|
||||
&& matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().any(|item| !matches!(item.value, CanonicalSourceValue::String(_))))
|
||||
}
|
||||
"secret_like_example" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
pointer.contains("/example") && matches!(&node.value, CanonicalSourceValue::String(value) if secret_like(pointer, value))
|
||||
matches!(&node.value, CanonicalSourceValue::String(value)
|
||||
if secret_like(pointer, value)
|
||||
|| super::metadata_findings::url_has_secret(value)
|
||||
|| (pointer.ends_with("/url") && !value.contains('@'))
|
||||
|| value == super::metadata_findings::REDACTED_LITERAL
|
||||
|| sanitized_secret_url(value))
|
||||
}
|
||||
"secret_literal_redacted" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
matches!(&node.value, CanonicalSourceValue::String(value) if value == "[REDACTED]")
|
||||
}
|
||||
"invalid_security_requirements"
|
||||
| "invalid_security_requirement"
|
||||
| "unresolved_security_scheme"
|
||||
| "unsupported_security_and_requirement"
|
||||
| "unsupported_security_scheme"
|
||||
| "unsupported_security_requirements"
|
||||
| "invalid_security_scopes"
|
||||
| "unexpected_security_scopes" => security_finding(finding, ir, nodes),
|
||||
"invalid_server" if is_error => invalid_server(pointer, node),
|
||||
"unsupported_security_requirement" if is_error => {
|
||||
matches!(&node.value, CanonicalSourceValue::Object(fields) if !fields.is_empty())
|
||||
|| invalid_security_requirement(pointer, node)
|
||||
}
|
||||
"invalid_security_requirements" if is_error => {
|
||||
!matches!(&node.value, CanonicalSourceValue::Array(_))
|
||||
|| matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().any(|item| !matches!(item.value, CanonicalSourceValue::Object(_))))
|
||||
}
|
||||
"invalid_security_requirement" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
!matches!(&node.value, CanonicalSourceValue::Object(_))
|
||||
}
|
||||
"unsupported_security_requirements" if is_error => ir
|
||||
.operations
|
||||
.iter()
|
||||
.find(|operation| finding.operation_key.as_deref() == Some(operation.key.as_str()))
|
||||
.is_some_and(|operation| {
|
||||
!operation.security_requirements.alternatives.is_empty()
|
||||
&& operation
|
||||
.security_requirements
|
||||
.alternatives
|
||||
.iter()
|
||||
.all(|alternative| !alternative.supported)
|
||||
}),
|
||||
"unsupported_security_and_requirement"
|
||||
if finding.severity == ImportFindingSeverity::Warning =>
|
||||
{
|
||||
matches!(&node.value, CanonicalSourceValue::Object(fields) if fields.len() > 1)
|
||||
}
|
||||
"unsupported_security_scheme" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
ir.security_schemes.get(&scheme_name).is_some_and(|scheme| {
|
||||
matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::Unsupported { .. })
|
||||
|| matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::ApiKey { location: crate::rest::model::SecurityParameterLocation::Cookie, .. })
|
||||
}) && matches!(&node.value, CanonicalSourceValue::Array(_))
|
||||
}
|
||||
"unsupported_security_scheme_definition"
|
||||
if finding.severity == ImportFindingSeverity::Warning =>
|
||||
{
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
ir.security_schemes.get(&scheme_name).is_some_and(|scheme| {
|
||||
matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::Unsupported { .. })
|
||||
}) && matches!(&node.value, CanonicalSourceValue::Object(_))
|
||||
}
|
||||
"unresolved_security_scheme" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
!ir.security_schemes.contains_key(&scheme_name)
|
||||
}
|
||||
"invalid_security_scopes" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
!matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().all(|item| matches!(item.value, CanonicalSourceValue::String(_))))
|
||||
}
|
||||
"unexpected_security_scopes" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
let supports_scopes = ir.security_schemes.get(&scheme_name).is_some_and(|scheme| {
|
||||
matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::Unsupported { scheme_type: Some(kind) } if matches!(kind.as_str(), "oauth2" | "openIdConnect"))
|
||||
});
|
||||
!supports_scopes
|
||||
&& matches!(&node.value, CanonicalSourceValue::Array(items) if !items.is_empty())
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn security_finding(
|
||||
fn path_placeholders(path: &str) -> Vec<String> {
|
||||
let mut placeholders = Vec::new();
|
||||
let mut remaining = path;
|
||||
while let Some(open) = remaining.find('{') {
|
||||
let after_open = &remaining[open + 1..];
|
||||
let Some(close) = after_open.find('}') else {
|
||||
break;
|
||||
};
|
||||
if close > 0 {
|
||||
placeholders.push(after_open[..close].to_owned());
|
||||
}
|
||||
remaining = &after_open[close + 1..];
|
||||
}
|
||||
placeholders
|
||||
}
|
||||
|
||||
fn path_parameter_missing_in_source(
|
||||
finding: &NormalizedFinding,
|
||||
ir: &NormalizedIr,
|
||||
operation_node: &CanonicalSourceNode,
|
||||
nodes: &BTreeMap<String, &CanonicalSourceNode>,
|
||||
) -> bool {
|
||||
let Some(operation) = ir
|
||||
.operations
|
||||
.iter()
|
||||
.find(|operation| finding.operation_key.as_deref() == Some(operation.key.as_str()))
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let Some(requirements_pointer) = requirements_pointer(operation) else {
|
||||
return false;
|
||||
};
|
||||
let pointer = finding.location.pointer.as_str();
|
||||
let node = nodes.get(pointer).copied();
|
||||
|
||||
match finding.code.as_str() {
|
||||
"invalid_security_requirements" => {
|
||||
finding.severity == ImportFindingSeverity::Error
|
||||
&& pointer == requirements_pointer
|
||||
&& node.is_some_and(|node| !matches!(&node.value, CanonicalSourceValue::Array(_)))
|
||||
}
|
||||
"invalid_security_requirement" => {
|
||||
finding.severity == ImportFindingSeverity::Warning
|
||||
&& alternative_at(operation, pointer).is_some_and(|_| {
|
||||
node.is_some_and(|node| !matches!(&node.value, CanonicalSourceValue::Object(_)))
|
||||
})
|
||||
}
|
||||
"unresolved_security_scheme" => {
|
||||
finding.severity == ImportFindingSeverity::Warning
|
||||
&& scheme_at(operation, pointer)
|
||||
.is_some_and(|name| node.is_some() && !ir.security_schemes.contains_key(name))
|
||||
}
|
||||
"unsupported_security_and_requirement" => {
|
||||
finding.severity == ImportFindingSeverity::Warning
|
||||
&& alternative_at(operation, pointer)
|
||||
.is_some_and(|alternative| alternative.schemes.len() > 1)
|
||||
&& node.is_some_and(|node| matches!(&node.value, CanonicalSourceValue::Object(_)))
|
||||
}
|
||||
"unsupported_security_scheme" => {
|
||||
finding.severity == ImportFindingSeverity::Warning
|
||||
&& scheme_at(operation, pointer).is_some_and(|name| {
|
||||
let Some(scheme) = ir.security_schemes.get(name) else {
|
||||
return false;
|
||||
};
|
||||
node.is_some()
|
||||
&& matches!(
|
||||
&scheme.kind,
|
||||
NormalizedSecuritySchemeKind::Unsupported { .. }
|
||||
| NormalizedSecuritySchemeKind::ApiKey {
|
||||
location: crate::rest::model::SecurityParameterLocation::Cookie,
|
||||
..
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
"unsupported_security_requirements" => {
|
||||
finding.severity == ImportFindingSeverity::Error
|
||||
&& pointer == requirements_pointer
|
||||
&& !operation.security_requirements.alternatives.is_empty()
|
||||
&& operation
|
||||
.security_requirements
|
||||
.alternatives
|
||||
.iter()
|
||||
.all(|alternative| !alternative.supported)
|
||||
&& node.is_some_and(|node| matches!(&node.value, CanonicalSourceValue::Array(_)))
|
||||
}
|
||||
"invalid_security_scopes" | "unexpected_security_scopes" => {
|
||||
if finding.severity != ImportFindingSeverity::Warning {
|
||||
return false;
|
||||
}
|
||||
let Some(name) = scheme_at(operation, pointer) else {
|
||||
let segments = pointer.split('/').collect::<Vec<_>>();
|
||||
if segments.len() != 4 || segments[1] != "paths" {
|
||||
return false;
|
||||
}
|
||||
let path = segments[2].replace("~1", "/").replace("~0", "~");
|
||||
let method = segments[3];
|
||||
let expected_key = format!("{} {path}", method.to_uppercase());
|
||||
let Some(operation) = ir.operations.iter().find(|operation| {
|
||||
operation.key == expected_key
|
||||
&& operation.path == path
|
||||
&& operation.location.pointer == pointer
|
||||
}) else {
|
||||
return false;
|
||||
};
|
||||
let Some(path_item) = nodes.get(&format!("/paths/{}", segments[2])).copied() else {
|
||||
return false;
|
||||
};
|
||||
let has_declared_parameter = |owner: &CanonicalSourceNode, name: &str| {
|
||||
let CanonicalSourceValue::Object(fields) = &owner.value else {
|
||||
return false;
|
||||
};
|
||||
let Some(CanonicalSourceNode {
|
||||
value: CanonicalSourceValue::Array(parameters),
|
||||
..
|
||||
}) = fields.get("parameters")
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
parameters.iter().any(|parameter| {
|
||||
let CanonicalSourceValue::Object(fields) = ¶meter.value else {
|
||||
return false;
|
||||
};
|
||||
let Some(node) = node else {
|
||||
if fields.contains_key("$ref") {
|
||||
return false;
|
||||
};
|
||||
let valid_scopes = matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().all(|item| matches!(item.value, CanonicalSourceValue::String(_))));
|
||||
if finding.code == "invalid_security_scopes" {
|
||||
!valid_scopes
|
||||
} else {
|
||||
let nonempty = matches!(&node.value, CanonicalSourceValue::Array(items) if !items.is_empty() && items.iter().all(|item| matches!(item.value, CanonicalSourceValue::String(_))));
|
||||
let oauth_scoped = ir.security_schemes.get(name).is_some_and(|scheme| {
|
||||
matches!(
|
||||
&scheme.kind,
|
||||
NormalizedSecuritySchemeKind::Unsupported {
|
||||
scheme_type: Some(scheme_type)
|
||||
} if matches!(scheme_type.as_str(), "oauth2" | "openIdConnect")
|
||||
)
|
||||
});
|
||||
nonempty && !oauth_scoped
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn requirements_pointer(operation: &NormalizedOperation) -> Option<String> {
|
||||
match operation.security_requirements.source {
|
||||
SecurityRequirementsSource::Document => Some("/security".to_owned()),
|
||||
SecurityRequirementsSource::Operation => {
|
||||
Some(format!("{}/security", operation.location.pointer))
|
||||
}
|
||||
SecurityRequirementsSource::None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn alternative_at<'a>(
|
||||
operation: &'a NormalizedOperation,
|
||||
pointer: &str,
|
||||
) -> Option<&'a crate::rest::model::SecurityRequirementAlternative> {
|
||||
operation
|
||||
.security_requirements
|
||||
.alternatives
|
||||
.iter()
|
||||
.find(|alternative| {
|
||||
alternative
|
||||
.source_location
|
||||
.as_ref()
|
||||
.is_some_and(|location| location.pointer == pointer)
|
||||
matches!(fields.get("name").map(|node| &node.value), Some(CanonicalSourceValue::String(value)) if value == name)
|
||||
&& matches!(fields.get("in").map(|node| &node.value), Some(CanonicalSourceValue::String(value)) if value == "path")
|
||||
})
|
||||
};
|
||||
path_placeholders(&operation.path).into_iter().any(|name| {
|
||||
!has_declared_parameter(path_item, &name)
|
||||
&& !has_declared_parameter(operation_node, &name)
|
||||
&& !operation.parameters.iter().any(|parameter| {
|
||||
parameter.name == name
|
||||
&& parameter.location == crate::rest::model::RestParameterLocation::Path
|
||||
})
|
||||
}) && finding.operation_key.as_deref() == Some(expected_key.as_str())
|
||||
}
|
||||
|
||||
fn scheme_at<'a>(operation: &'a NormalizedOperation, pointer: &str) -> Option<&'a str> {
|
||||
let (alternative_pointer, scheme) = pointer.rsplit_once('/')?;
|
||||
let alternative = alternative_at(operation, alternative_pointer)?;
|
||||
let name = scheme.replace("~1", "/").replace("~0", "~");
|
||||
alternative
|
||||
.schemes
|
||||
.iter()
|
||||
.find(|candidate| **candidate == name)
|
||||
.map(String::as_str)
|
||||
fn sanitized_secret_url(value: &str) -> bool {
|
||||
value.contains("=[REDACTED]")
|
||||
|| ((value.contains("://") || value.starts_with("//")) && !value.contains('@'))
|
||||
}
|
||||
|
||||
fn parameter_style(
|
||||
@@ -348,6 +368,31 @@ fn secret_like(pointer: &str, value: &str) -> bool {
|
||||
|| value.starts_with("sk-")
|
||||
}
|
||||
|
||||
/// Accepts malformed `security` shapes at their scoped source location only:
|
||||
/// the document `security` member, an operation `security` member, or a
|
||||
/// non-object item of the corresponding security array. An object is valid
|
||||
/// only as an array item, including the empty `{}` public alternative.
|
||||
fn invalid_security_requirement(pointer: &str, node: &CanonicalSourceNode) -> bool {
|
||||
const METHODS: &[&str] = &[
|
||||
"get", "post", "put", "patch", "delete", "head", "options", "trace", "connect",
|
||||
];
|
||||
let is_index = |part: &str| !part.is_empty() && part.bytes().all(|b| b.is_ascii_digit());
|
||||
let segments: Vec<&str> = pointer.split('/').collect();
|
||||
match segments.as_slice() {
|
||||
["", "security"] => true,
|
||||
["", "security", index] => {
|
||||
is_index(index) && !matches!(&node.value, CanonicalSourceValue::Object(_))
|
||||
}
|
||||
["", "paths", _, method, "security"] => METHODS.contains(method),
|
||||
["", "paths", _, method, "security", index] => {
|
||||
METHODS.contains(method)
|
||||
&& is_index(index)
|
||||
&& !matches!(&node.value, CanonicalSourceValue::Object(_))
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn invalid_server(pointer: &str, node: &CanonicalSourceNode) -> bool {
|
||||
if pointer == "/host" {
|
||||
return !matches!(&node.value, CanonicalSourceValue::String(host) if !host.is_empty() && !host.contains('@') && !host.chars().any(char::is_whitespace));
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use crate::rest::model::{
|
||||
ImportFinding, ImportGroupPreview, ImportPreview, ImportSourcePreview, NormalizedIr,
|
||||
NormalizedSecurityScheme, RestImportDocument,
|
||||
};
|
||||
|
||||
pub(super) fn preview_from_ir(ir: &NormalizedIr) -> ImportPreview {
|
||||
let operations = ir
|
||||
.operations
|
||||
.iter()
|
||||
.map(super::normalize_projection::operation_from_normalized)
|
||||
.collect::<Vec<_>>();
|
||||
let findings = ir
|
||||
.findings
|
||||
.iter()
|
||||
.map(|finding| ImportFinding {
|
||||
code: finding.code.clone(),
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
})
|
||||
.collect();
|
||||
preview_from_operations(
|
||||
&ir.source,
|
||||
&ir.security_schemes,
|
||||
operations.iter(),
|
||||
findings,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn preview_from_document(document: RestImportDocument) -> ImportPreview {
|
||||
let source = ImportSourcePreview {
|
||||
format: document.format,
|
||||
version: document.version,
|
||||
title: document.title,
|
||||
servers: document.servers,
|
||||
};
|
||||
preview_from_operations(
|
||||
&source,
|
||||
&document.security_schemes,
|
||||
document.operations.iter(),
|
||||
document.findings,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
fn preview_from_operations<'a>(
|
||||
source: &ImportSourcePreview,
|
||||
security_schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
operations: impl Iterator<Item = &'a crate::rest::model::RestImportOperation>,
|
||||
mut findings: Vec<ImportFinding>,
|
||||
legacy: bool,
|
||||
) -> ImportPreview {
|
||||
let mut groups: BTreeMap<String, ImportGroupPreview> = BTreeMap::new();
|
||||
let mut used_names = BTreeSet::new();
|
||||
|
||||
for operation in operations {
|
||||
let candidate = if legacy {
|
||||
super::legacy_payload::candidate_from_operation(
|
||||
operation,
|
||||
&source.servers,
|
||||
&mut used_names,
|
||||
)
|
||||
} else {
|
||||
super::payload::candidate_from_operation(
|
||||
operation,
|
||||
security_schemes,
|
||||
&source.servers,
|
||||
&mut used_names,
|
||||
)
|
||||
};
|
||||
let group_title = operation
|
||||
.tags
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "Без группы".to_owned());
|
||||
let group_key = crate::rest::naming::snake_name(&group_title);
|
||||
groups
|
||||
.entry(group_key.clone())
|
||||
.or_insert_with(|| ImportGroupPreview {
|
||||
key: group_key,
|
||||
title: group_title,
|
||||
operations: Vec::new(),
|
||||
})
|
||||
.operations
|
||||
.push(candidate);
|
||||
}
|
||||
|
||||
super::normalize::sort_findings(&mut findings);
|
||||
ImportPreview {
|
||||
source: source.clone(),
|
||||
groups: groups.into_values().collect(),
|
||||
findings,
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,115 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::rest::model::{
|
||||
ImportFinding, NormalizedLiteral, NormalizedOperation, NormalizedScalarKind, NormalizedSchema,
|
||||
NormalizedSchemaKind, RestImportOperation, RestImportParameter, RestRequestBodyVariant,
|
||||
RestResponseVariant,
|
||||
ImportFinding, ImportGroupPreview, ImportOperationCandidate, ImportPreview,
|
||||
ImportSourcePreview, NormalizedLiteral, NormalizedOperation, NormalizedScalarKind,
|
||||
NormalizedSchema, NormalizedSchemaKind, NormalizedSecurityScheme, RestImportDocument,
|
||||
RestImportOperation, RestImportParameter, RestRequestBodyVariant, RestResponseVariant,
|
||||
};
|
||||
|
||||
pub(super) fn preview_from_ir(ir: &crate::rest::model::NormalizedIr) -> ImportPreview {
|
||||
let operations = ir
|
||||
.operations
|
||||
.iter()
|
||||
.map(operation_from_normalized)
|
||||
.collect::<Vec<_>>();
|
||||
let findings = ir
|
||||
.findings
|
||||
.iter()
|
||||
.map(|finding| ImportFinding {
|
||||
code: finding.code.clone(),
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
source_location: Some(finding.location.clone()),
|
||||
})
|
||||
.collect();
|
||||
preview_from_operations(
|
||||
&ir.source,
|
||||
operations.iter(),
|
||||
findings,
|
||||
&ir.security_schemes,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn preview_from_document(document: RestImportDocument) -> ImportPreview {
|
||||
let security_schemes = document.security_schemes.clone();
|
||||
let source = ImportSourcePreview {
|
||||
format: document.format,
|
||||
version: document.version,
|
||||
title: document.title,
|
||||
servers: document.servers,
|
||||
};
|
||||
preview_from_operations(
|
||||
&source,
|
||||
document.operations.iter(),
|
||||
document.findings,
|
||||
&security_schemes,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
fn preview_from_operations<'a>(
|
||||
source: &ImportSourcePreview,
|
||||
operations: impl Iterator<Item = &'a RestImportOperation>,
|
||||
mut findings: Vec<ImportFinding>,
|
||||
security_schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
legacy: bool,
|
||||
) -> ImportPreview {
|
||||
let mut groups: BTreeMap<String, ImportGroupPreview> = BTreeMap::new();
|
||||
let mut used_names = BTreeSet::new();
|
||||
|
||||
for operation in operations {
|
||||
let candidate = if legacy {
|
||||
super::legacy_payload::candidate_from_operation(
|
||||
operation,
|
||||
&source.servers,
|
||||
&mut used_names,
|
||||
)
|
||||
} else {
|
||||
crate::rest::payload::candidate_from_operation(
|
||||
operation,
|
||||
security_schemes,
|
||||
&source.servers,
|
||||
&mut used_names,
|
||||
)
|
||||
};
|
||||
let group_title = operation
|
||||
.tags
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "Без группы".to_owned());
|
||||
let group_key = crate::rest::naming::snake_name(&group_title);
|
||||
groups
|
||||
.entry(group_key.clone())
|
||||
.or_insert_with(|| ImportGroupPreview {
|
||||
key: group_key,
|
||||
title: group_title,
|
||||
operations: Vec::<ImportOperationCandidate>::new(),
|
||||
})
|
||||
.operations
|
||||
.push(candidate);
|
||||
}
|
||||
|
||||
super::normalize_security::attach_operation_findings(&mut groups, &findings);
|
||||
super::normalize::sort_findings(&mut findings);
|
||||
ImportPreview {
|
||||
source: source.clone(),
|
||||
groups: groups.into_values().collect(),
|
||||
findings,
|
||||
conflicts: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn operation_from_normalized(operation: &NormalizedOperation) -> RestImportOperation {
|
||||
RestImportOperation {
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
source_location: Some(operation.location.clone()),
|
||||
security_requirements: operation.security_requirements.clone(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
summary: operation.summary.clone(),
|
||||
@@ -68,6 +165,7 @@ pub(super) fn operation_from_normalized(operation: &NormalizedOperation) -> Rest
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
source_location: Some(finding.location.clone()),
|
||||
})
|
||||
.collect(),
|
||||
internal_finding_locations: Vec::new(),
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//! Attaches document-level findings to their affected operation candidates.
|
||||
|
||||
use super::model::{ImportFinding, ImportFindingSeverity, ImportGroupPreview};
|
||||
|
||||
pub(super) fn attach_operation_findings(
|
||||
groups: &mut std::collections::BTreeMap<String, ImportGroupPreview>,
|
||||
findings: &[ImportFinding],
|
||||
) {
|
||||
for group in groups.values_mut() {
|
||||
for candidate in &mut group.operations {
|
||||
let additions = findings
|
||||
.iter()
|
||||
.filter(|finding| {
|
||||
finding.severity == ImportFindingSeverity::Error
|
||||
&& finding.operation_key.as_deref() == Some(candidate.key.as_str())
|
||||
&& !candidate.findings.iter().any(|existing| {
|
||||
existing.code == finding.code
|
||||
&& existing.severity == finding.severity
|
||||
&& existing.message == finding.message
|
||||
})
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
candidate.findings.extend(additions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use crank_core::HttpMethod;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::parser_findings::append_unused_security_scheme_findings as append_unused;
|
||||
use crate::rest::{
|
||||
model::{
|
||||
ImportFinding, RestImportDocument, RestImportOperation, RestImportParameter,
|
||||
@@ -15,6 +16,7 @@ pub fn parse_document(root: &Value) -> Result<RestImportDocument, ImportParseErr
|
||||
}
|
||||
|
||||
fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseError> {
|
||||
let security_schemes = super::security::schemes(root, false);
|
||||
let version = root
|
||||
.get("openapi")
|
||||
.and_then(Value::as_str)
|
||||
@@ -25,21 +27,16 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
.unwrap_or("Imported API")
|
||||
.to_owned();
|
||||
let mut findings = Vec::new();
|
||||
let mut internal_finding_locations = Vec::new();
|
||||
let mut locations = Vec::new();
|
||||
let servers = parse_servers(root.get("servers"), "/servers");
|
||||
let security_schemes = super::security::schemes(root, false);
|
||||
append_findings_with_locations(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
servers.findings,
|
||||
);
|
||||
super::parser_findings::append_located(&mut findings, &mut locations, servers.findings);
|
||||
let servers = servers.servers;
|
||||
if servers.is_empty() {
|
||||
findings.push(document_finding(
|
||||
"missing_servers",
|
||||
"В документе не указаны servers, base URL нужно будет выбрать вручную.",
|
||||
));
|
||||
internal_finding_locations.push(Some(crate::rest::model::SourceLocation {
|
||||
locations.push(Some(crate::rest::model::SourceLocation {
|
||||
pointer: String::new(),
|
||||
}));
|
||||
} else if servers.len() > 1 {
|
||||
@@ -47,7 +44,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
"multiple_servers",
|
||||
"В документе несколько servers, при импорте нужно выбрать нужный base URL.",
|
||||
));
|
||||
internal_finding_locations.push(Some(crate::rest::model::SourceLocation {
|
||||
locations.push(Some(crate::rest::model::SourceLocation {
|
||||
pointer: "/servers".to_owned(),
|
||||
}));
|
||||
}
|
||||
@@ -61,7 +58,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
for (path, path_item) in paths {
|
||||
if !path_item.is_object() {
|
||||
findings.push(super::http_methods::invalid_path_item());
|
||||
internal_finding_locations.push(Some(crate::rest::model::SourceLocation {
|
||||
locations.push(Some(crate::rest::model::SourceLocation {
|
||||
pointer: format!("/paths/{}", path.replace('~', "~0").replace('/', "~1")),
|
||||
}));
|
||||
continue;
|
||||
@@ -72,7 +69,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
"unsupported_http_method",
|
||||
format!("Метод {method_name} для пути {path} пока не поддерживается."),
|
||||
));
|
||||
internal_finding_locations.push(Some(crate::rest::model::SourceLocation {
|
||||
locations.push(Some(crate::rest::model::SourceLocation {
|
||||
pointer: format!(
|
||||
"/paths/{}/{}",
|
||||
path.replace('~', "~0").replace('/', "~1"),
|
||||
@@ -86,17 +83,17 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
path_item.get("parameters"),
|
||||
&format!("{path_pointer}/parameters"),
|
||||
);
|
||||
append_findings_with_locations(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
&mut locations,
|
||||
path_parameters.findings,
|
||||
);
|
||||
let path_parameters = path_parameters.parameters;
|
||||
let path_servers =
|
||||
parse_servers(path_item.get("servers"), &format!("{path_pointer}/servers"));
|
||||
append_findings_with_locations(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
&mut locations,
|
||||
path_servers.findings,
|
||||
);
|
||||
let path_servers = path_servers.servers;
|
||||
@@ -109,7 +106,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
"invalid_operation",
|
||||
"Операция имеет неверную структуру и не была интерпретирована.",
|
||||
));
|
||||
internal_finding_locations.push(Some(crate::rest::model::SourceLocation {
|
||||
locations.push(Some(crate::rest::model::SourceLocation {
|
||||
pointer: format!(
|
||||
"/paths/{}/{}",
|
||||
path.replace('~', "~0").replace('/', "~1"),
|
||||
@@ -128,9 +125,9 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
operation_value.get("parameters"),
|
||||
&format!("{path_pointer}/{method_name}/parameters"),
|
||||
);
|
||||
append_findings_with_locations(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
&mut locations,
|
||||
parsed_parameters.findings,
|
||||
);
|
||||
operation_parameters.extend(parsed_parameters.parameters);
|
||||
@@ -139,9 +136,9 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
operation_value.get("servers"),
|
||||
&format!("{operation_pointer}/servers"),
|
||||
);
|
||||
append_findings_with_locations(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
&mut locations,
|
||||
operation_servers.findings,
|
||||
);
|
||||
let operation_servers = operation_servers.servers;
|
||||
@@ -149,27 +146,24 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
operation_value.get("tags"),
|
||||
&format!("{operation_pointer}/tags"),
|
||||
);
|
||||
append_findings_with_locations(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
tags.findings,
|
||||
);
|
||||
super::parser_findings::append_located(&mut findings, &mut locations, tags.findings);
|
||||
|
||||
let mut located_operation_findings =
|
||||
super::openapi3_findings::operation(operation_value, &operation_pointer);
|
||||
let security_requirements = super::security::collect_operation_requirements(
|
||||
root,
|
||||
operation_value,
|
||||
&operation_pointer,
|
||||
&security_schemes,
|
||||
&mut located_operation_findings,
|
||||
);
|
||||
let (security_requirements, security_findings) =
|
||||
super::security::collect_operation_requirements(
|
||||
root,
|
||||
operation_value,
|
||||
&operation_pointer,
|
||||
&security_schemes,
|
||||
);
|
||||
located_operation_findings.extend(security_findings);
|
||||
located_operation_findings.extend(super::openapi3_findings::path_parameters(
|
||||
path,
|
||||
&operation_parameters,
|
||||
&operation_pointer,
|
||||
));
|
||||
let (operation_findings, internal_finding_locations) =
|
||||
located_operation_findings.into_iter().unzip();
|
||||
let (operation_findings, locations) = located_operation_findings.into_iter().unzip();
|
||||
let response_schema = (method != HttpMethod::Head)
|
||||
.then(|| response_schema(operation_value, &operation_pointer))
|
||||
.flatten();
|
||||
@@ -177,6 +171,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements,
|
||||
operation_id: operation_value
|
||||
.get("operationId")
|
||||
@@ -209,11 +204,11 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
operation_servers
|
||||
},
|
||||
findings: operation_findings,
|
||||
internal_finding_locations,
|
||||
internal_finding_locations: locations,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
append_unused(root, &security_schemes, &mut findings, &mut locations);
|
||||
Ok(RestImportDocument {
|
||||
format: "openapi".to_owned(),
|
||||
version,
|
||||
@@ -222,7 +217,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
security_schemes,
|
||||
operations,
|
||||
findings,
|
||||
internal_finding_locations,
|
||||
internal_finding_locations: locations,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -233,6 +228,231 @@ fn deduplicate_parameters(parameters: &mut Vec<RestImportParameter>) {
|
||||
parameters.reverse();
|
||||
}
|
||||
|
||||
pub fn parse_document_legacy_v1(root: &Value) -> Result<RestImportDocument, ImportParseError> {
|
||||
let version = root
|
||||
.get("openapi")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned);
|
||||
let title = root
|
||||
.pointer("/info/title")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("Imported API")
|
||||
.to_owned();
|
||||
let servers = legacy_servers(root.get("servers"));
|
||||
let mut findings = Vec::new();
|
||||
if servers.is_empty() {
|
||||
findings.push(document_finding(
|
||||
"missing_servers",
|
||||
"В документе не указаны servers, base URL нужно будет выбрать вручную.",
|
||||
));
|
||||
} else if servers.len() > 1 {
|
||||
findings.push(document_finding(
|
||||
"multiple_servers",
|
||||
"В документе несколько servers, при импорте нужно выбрать нужный base URL.",
|
||||
));
|
||||
}
|
||||
|
||||
let mut operations = Vec::new();
|
||||
let paths = root
|
||||
.get("paths")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or(ImportParseError::UnsupportedDocument)?;
|
||||
for (path, path_item) in paths {
|
||||
let path_pointer = format!("/paths/{}", path.replace('~', "~0").replace('/', "~1"));
|
||||
let path_parameters = legacy_parameters(
|
||||
root,
|
||||
path_item.get("parameters"),
|
||||
&format!("{path_pointer}/parameters"),
|
||||
);
|
||||
for method_name in ["get", "post", "put", "patch", "delete"] {
|
||||
let Some(operation) = path_item.get(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let Some(method) = super::http_methods::from_lower(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let operation_pointer = format!("{path_pointer}/{method_name}");
|
||||
let mut parameters = path_parameters.clone();
|
||||
parameters.extend(legacy_parameters(
|
||||
root,
|
||||
operation.get("parameters"),
|
||||
&format!("{operation_pointer}/parameters"),
|
||||
));
|
||||
operations.push(RestImportOperation {
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements: Default::default(),
|
||||
operation_id: operation
|
||||
.get("operationId")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
summary: operation
|
||||
.get("summary")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
description: operation
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
tags: legacy_tags(operation.get("tags")),
|
||||
parameters,
|
||||
request_body_schema: legacy_request_body_schema(root, operation),
|
||||
request_body_schema_location: None,
|
||||
request_body_variants: Vec::new(),
|
||||
response_schema: legacy_response_schema(root, operation),
|
||||
response_schema_location: None,
|
||||
response_variants: Vec::new(),
|
||||
servers: legacy_servers(operation.get("servers")),
|
||||
findings: legacy_operation_findings(operation),
|
||||
internal_finding_locations: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(RestImportDocument {
|
||||
format: "openapi".to_owned(),
|
||||
version,
|
||||
title,
|
||||
servers,
|
||||
security_schemes: Default::default(),
|
||||
operations,
|
||||
findings,
|
||||
internal_finding_locations: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn legacy_servers(value: Option<&Value>) -> Vec<String> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(|item| item.get("url").and_then(Value::as_str))
|
||||
.map(|url| url.trim_end_matches('/').to_owned())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_tags(value: Option<&Value>) -> Vec<String> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(Value::as_str)
|
||||
.map(ToOwned::to_owned)
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_parameters(
|
||||
root: &Value,
|
||||
value: Option<&Value>,
|
||||
base_pointer: &str,
|
||||
) -> Vec<RestImportParameter> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, item)| {
|
||||
let item = crate::rest::normalize::resolve_local_ref(root, item, 0);
|
||||
let location = match item.get("in").and_then(Value::as_str)? {
|
||||
"path" => RestParameterLocation::Path,
|
||||
"query" => RestParameterLocation::Query,
|
||||
"header" => RestParameterLocation::Header,
|
||||
_ => return None,
|
||||
};
|
||||
Some(RestImportParameter {
|
||||
name: item.get("name").and_then(Value::as_str)?.to_owned(),
|
||||
location,
|
||||
required: item
|
||||
.get("required")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
|| location == RestParameterLocation::Path,
|
||||
description: item
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
schema: item.get("schema").map(|schema| {
|
||||
crate::rest::normalize::resolve_local_ref(root, schema, 0)
|
||||
}),
|
||||
source_location: crate::rest::model::SourceLocation {
|
||||
pointer: format!("{base_pointer}/{index}"),
|
||||
},
|
||||
schema_source_location: None,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_request_body_schema(root: &Value, operation: &Value) -> Option<Value> {
|
||||
let body = crate::rest::normalize::resolve_local_ref(root, operation.get("requestBody")?, 0);
|
||||
let content = body.get("content")?.as_object()?;
|
||||
for content_type in ["application/json", "application/*+json"] {
|
||||
if let Some(schema) = content
|
||||
.get(content_type)
|
||||
.and_then(|media| media.get("schema"))
|
||||
{
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
content
|
||||
.iter()
|
||||
.find(|(content_type, _)| content_type.contains("json"))
|
||||
.and_then(|(_, media)| media.get("schema"))
|
||||
.map(|schema| crate::rest::normalize::resolve_local_ref(root, schema, 0))
|
||||
}
|
||||
|
||||
fn legacy_response_schema(root: &Value, operation: &Value) -> Option<Value> {
|
||||
let responses = operation.get("responses")?.as_object()?;
|
||||
for code in ["200", "201", "202", "default"] {
|
||||
let Some(response) = responses.get(code) else {
|
||||
continue;
|
||||
};
|
||||
let response = crate::rest::normalize::resolve_local_ref(root, response, 0);
|
||||
let Some(content) = response.get("content").and_then(Value::as_object) else {
|
||||
continue;
|
||||
};
|
||||
for content_type in ["application/json", "application/*+json"] {
|
||||
if let Some(schema) = content
|
||||
.get(content_type)
|
||||
.and_then(|media| media.get("schema"))
|
||||
{
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
if let Some(schema) = content
|
||||
.iter()
|
||||
.find(|(content_type, _)| content_type.contains("json"))
|
||||
.and_then(|(_, media)| media.get("schema"))
|
||||
{
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn legacy_operation_findings(operation: &Value) -> Vec<ImportFinding> {
|
||||
if operation.get("requestBody").is_some()
|
||||
&& legacy_request_body_schema(&Value::Null, operation).is_none()
|
||||
{
|
||||
vec![document_finding(
|
||||
"unsupported_request_body",
|
||||
"У метода есть requestBody, но JSON schema не найдена.",
|
||||
)]
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
struct ParsedParameters {
|
||||
parameters: Vec<RestImportParameter>,
|
||||
findings: Vec<(ImportFinding, crate::rest::model::SourceLocation)>,
|
||||
@@ -488,17 +708,6 @@ fn parameter_blocker(
|
||||
)
|
||||
}
|
||||
|
||||
fn append_findings_with_locations(
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<crate::rest::model::SourceLocation>>,
|
||||
parameter_findings: Vec<(ImportFinding, crate::rest::model::SourceLocation)>,
|
||||
) {
|
||||
for (finding, location) in parameter_findings {
|
||||
findings.push(finding);
|
||||
locations.push(Some(location));
|
||||
}
|
||||
}
|
||||
|
||||
fn request_body_schema(
|
||||
operation: &Value,
|
||||
operation_pointer: &str,
|
||||
|
||||
@@ -299,6 +299,17 @@ pub(super) fn schema_findings(
|
||||
pointer: &str,
|
||||
findings: &mut Vec<(ImportFinding, SourceLocation)>,
|
||||
) {
|
||||
if schema
|
||||
.get("default")
|
||||
.is_some_and(|value| value.is_object() || value.is_array())
|
||||
{
|
||||
push(
|
||||
findings,
|
||||
"unsupported_compound_default",
|
||||
"Object и array schema defaults не поддерживаются executable import contract.",
|
||||
&format!("{pointer}/default"),
|
||||
);
|
||||
}
|
||||
if let Some(types) = schema.get("type").and_then(Value::as_array) {
|
||||
let concrete = types
|
||||
.iter()
|
||||
@@ -389,8 +400,9 @@ pub(super) fn schema_findings(
|
||||
pub(super) fn path_parameters(
|
||||
path: &str,
|
||||
parameters: &[RestImportParameter],
|
||||
operation_pointer: &str,
|
||||
) -> Vec<(ImportFinding, SourceLocation)> {
|
||||
parameters
|
||||
let mut findings = parameters
|
||||
.iter()
|
||||
.filter(|parameter| parameter.location == RestParameterLocation::Path)
|
||||
.filter_map(|parameter| {
|
||||
@@ -415,7 +427,39 @@ pub(super) fn path_parameters(
|
||||
parameter.source_location.clone(),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
.collect::<Vec<_>>();
|
||||
for name in path_placeholders(path) {
|
||||
if !parameters.iter().any(|parameter| {
|
||||
parameter.location == RestParameterLocation::Path && parameter.name == name
|
||||
}) {
|
||||
findings.push((
|
||||
document_blocker(
|
||||
"path_parameter_not_declared",
|
||||
format!("Path placeholder {name} не объявлен как path parameter."),
|
||||
),
|
||||
SourceLocation {
|
||||
pointer: operation_pointer.to_owned(),
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
findings
|
||||
}
|
||||
|
||||
fn path_placeholders(path: &str) -> Vec<String> {
|
||||
let mut placeholders = Vec::new();
|
||||
let mut remaining = path;
|
||||
while let Some(open) = remaining.find('{') {
|
||||
let after_open = &remaining[open + 1..];
|
||||
let Some(close) = after_open.find('}') else {
|
||||
break;
|
||||
};
|
||||
if close > 0 {
|
||||
placeholders.push(after_open[..close].to_owned());
|
||||
}
|
||||
remaining = &after_open[close + 1..];
|
||||
}
|
||||
placeholders
|
||||
}
|
||||
|
||||
pub(super) fn unsupported_methods(path_item: &Value) -> Vec<&str> {
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::rest::{
|
||||
model::{
|
||||
ImportFinding, RestImportDocument, RestImportOperation, RestImportParameter,
|
||||
RestParameterLocation,
|
||||
},
|
||||
normalize::ImportParseError,
|
||||
recommendations::document_finding,
|
||||
};
|
||||
|
||||
pub(super) fn parse_document_legacy_v1(
|
||||
root: &Value,
|
||||
) -> Result<RestImportDocument, ImportParseError> {
|
||||
let version = root
|
||||
.get("openapi")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned);
|
||||
let title = root
|
||||
.pointer("/info/title")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("Imported API")
|
||||
.to_owned();
|
||||
let servers = legacy_servers(root.get("servers"));
|
||||
let mut findings = Vec::new();
|
||||
if servers.is_empty() {
|
||||
findings.push(document_finding(
|
||||
"missing_servers",
|
||||
"В документе не указаны servers, base URL нужно будет выбрать вручную.",
|
||||
));
|
||||
} else if servers.len() > 1 {
|
||||
findings.push(document_finding(
|
||||
"multiple_servers",
|
||||
"В документе несколько servers, при импорте нужно выбрать нужный base URL.",
|
||||
));
|
||||
}
|
||||
|
||||
let mut operations = Vec::new();
|
||||
let paths = root
|
||||
.get("paths")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or(ImportParseError::UnsupportedDocument)?;
|
||||
for (path, path_item) in paths {
|
||||
let path_pointer = format!("/paths/{}", path.replace('~', "~0").replace('/', "~1"));
|
||||
let path_parameters = legacy_parameters(
|
||||
root,
|
||||
path_item.get("parameters"),
|
||||
&format!("{path_pointer}/parameters"),
|
||||
);
|
||||
for method_name in ["get", "post", "put", "patch", "delete"] {
|
||||
let Some(operation) = path_item.get(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let Some(method) = super::http_methods::from_lower(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let operation_pointer = format!("{path_pointer}/{method_name}");
|
||||
let mut parameters = path_parameters.clone();
|
||||
parameters.extend(legacy_parameters(
|
||||
root,
|
||||
operation.get("parameters"),
|
||||
&format!("{operation_pointer}/parameters"),
|
||||
));
|
||||
operations.push(RestImportOperation {
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
security_requirements: Default::default(),
|
||||
operation_id: operation
|
||||
.get("operationId")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
summary: operation
|
||||
.get("summary")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
description: operation
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
tags: legacy_tags(operation.get("tags")),
|
||||
parameters,
|
||||
request_body_schema: legacy_request_body_schema(root, operation),
|
||||
request_body_schema_location: None,
|
||||
request_body_variants: Vec::new(),
|
||||
response_schema: legacy_response_schema(root, operation),
|
||||
response_schema_location: None,
|
||||
response_variants: Vec::new(),
|
||||
servers: legacy_servers(operation.get("servers")),
|
||||
findings: legacy_operation_findings(operation),
|
||||
internal_finding_locations: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(RestImportDocument {
|
||||
format: "openapi".to_owned(),
|
||||
version,
|
||||
title,
|
||||
servers,
|
||||
security_schemes: Default::default(),
|
||||
operations,
|
||||
findings,
|
||||
internal_finding_locations: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn legacy_servers(value: Option<&Value>) -> Vec<String> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(|item| item.get("url").and_then(Value::as_str))
|
||||
.map(|url| url.trim_end_matches('/').to_owned())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_tags(value: Option<&Value>) -> Vec<String> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(Value::as_str)
|
||||
.map(ToOwned::to_owned)
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_parameters(
|
||||
root: &Value,
|
||||
value: Option<&Value>,
|
||||
base_pointer: &str,
|
||||
) -> Vec<RestImportParameter> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, item)| {
|
||||
let item = crate::rest::normalize::resolve_local_ref(root, item, 0);
|
||||
let location = match item.get("in").and_then(Value::as_str)? {
|
||||
"path" => RestParameterLocation::Path,
|
||||
"query" => RestParameterLocation::Query,
|
||||
"header" => RestParameterLocation::Header,
|
||||
_ => return None,
|
||||
};
|
||||
Some(RestImportParameter {
|
||||
name: item.get("name").and_then(Value::as_str)?.to_owned(),
|
||||
location,
|
||||
required: item
|
||||
.get("required")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
|| location == RestParameterLocation::Path,
|
||||
description: item
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
schema: item.get("schema").map(|schema| {
|
||||
crate::rest::normalize::resolve_local_ref(root, schema, 0)
|
||||
}),
|
||||
source_location: crate::rest::model::SourceLocation {
|
||||
pointer: format!("{base_pointer}/{index}"),
|
||||
},
|
||||
schema_source_location: None,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_request_body_schema(root: &Value, operation: &Value) -> Option<Value> {
|
||||
let body = crate::rest::normalize::resolve_local_ref(root, operation.get("requestBody")?, 0);
|
||||
let content = body.get("content")?.as_object()?;
|
||||
for content_type in ["application/json", "application/*+json"] {
|
||||
if let Some(schema) = content
|
||||
.get(content_type)
|
||||
.and_then(|media| media.get("schema"))
|
||||
{
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
content
|
||||
.iter()
|
||||
.find(|(content_type, _)| content_type.contains("json"))
|
||||
.and_then(|(_, media)| media.get("schema"))
|
||||
.map(|schema| crate::rest::normalize::resolve_local_ref(root, schema, 0))
|
||||
}
|
||||
|
||||
fn legacy_response_schema(root: &Value, operation: &Value) -> Option<Value> {
|
||||
let responses = operation.get("responses")?.as_object()?;
|
||||
for code in ["200", "201", "202", "default"] {
|
||||
let Some(response) = responses.get(code) else {
|
||||
continue;
|
||||
};
|
||||
let response = crate::rest::normalize::resolve_local_ref(root, response, 0);
|
||||
let Some(content) = response.get("content").and_then(Value::as_object) else {
|
||||
continue;
|
||||
};
|
||||
for content_type in ["application/json", "application/*+json"] {
|
||||
if let Some(schema) = content
|
||||
.get(content_type)
|
||||
.and_then(|media| media.get("schema"))
|
||||
{
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
if let Some(schema) = content
|
||||
.iter()
|
||||
.find(|(content_type, _)| content_type.contains("json"))
|
||||
.and_then(|(_, media)| media.get("schema"))
|
||||
{
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn legacy_operation_findings(operation: &Value) -> Vec<ImportFinding> {
|
||||
if operation.get("requestBody").is_some()
|
||||
&& legacy_request_body_schema(&Value::Null, operation).is_none()
|
||||
{
|
||||
vec![document_finding(
|
||||
"unsupported_request_body",
|
||||
"У метода есть requestBody, но JSON schema не найдена.",
|
||||
)]
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
use crate::rest::model::NormalizedSecurityScheme;
|
||||
use crate::rest::model::{ImportFinding, SourceLocation};
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub(super) fn append_located(
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<SourceLocation>>,
|
||||
entries: Vec<(ImportFinding, SourceLocation)>,
|
||||
) {
|
||||
for (finding, location) in entries {
|
||||
findings.push(finding);
|
||||
locations.push(Some(location));
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn append_unused_security_scheme_findings(
|
||||
root: &Value,
|
||||
schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<SourceLocation>>,
|
||||
) {
|
||||
append_located(
|
||||
findings,
|
||||
locations,
|
||||
super::security::unused_unsupported_scheme_findings(root, schemes),
|
||||
);
|
||||
}
|
||||
@@ -10,8 +10,7 @@ use serde_json::json;
|
||||
use crate::rest::{
|
||||
mapping::{BodyFieldMapping, ParameterFieldMapping, input_mapping, output_mapping},
|
||||
model::{
|
||||
ImportOperationCandidate, NormalizedSecurityScheme, RestImportCandidate,
|
||||
RestImportOperation, RestParameterLocation,
|
||||
ImportOperationCandidate, RestImportCandidate, RestImportOperation, RestParameterLocation,
|
||||
},
|
||||
naming::{fallback_operation_seed, title_from_name, unique_name},
|
||||
recommendations::{candidate_recommendations, operation_recommendations},
|
||||
@@ -22,7 +21,7 @@ use crate::rest::{
|
||||
|
||||
pub fn candidate_from_operation(
|
||||
operation: &RestImportOperation,
|
||||
security_schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
security_schemes: &BTreeMap<String, crate::rest::model::NormalizedSecurityScheme>,
|
||||
document_servers: &[String],
|
||||
used_names: &mut BTreeSet<String>,
|
||||
) -> ImportOperationCandidate {
|
||||
@@ -156,6 +155,8 @@ pub fn candidate_from_operation(
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
status: String::new(),
|
||||
source_location: operation.source_location.clone(),
|
||||
security_requirements: operation.security_requirements.clone(),
|
||||
security_schemes: security_schemes.clone(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
|
||||
@@ -8,6 +8,7 @@ pub fn document_finding(code: &str, message: impl Into<String>) -> ImportFinding
|
||||
severity: ImportFindingSeverity::Warning,
|
||||
message: message.into(),
|
||||
operation_key: None,
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +18,7 @@ pub fn document_blocker(code: &str, message: impl Into<String>) -> ImportFinding
|
||||
severity: ImportFindingSeverity::Error,
|
||||
message: message.into(),
|
||||
operation_key: None,
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +32,7 @@ pub fn operation_finding(
|
||||
severity: ImportFindingSeverity::Warning,
|
||||
message: message.into(),
|
||||
operation_key: Some(operation_key.to_owned()),
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +46,7 @@ pub fn operation_info(
|
||||
severity: ImportFindingSeverity::Info,
|
||||
message: message.into(),
|
||||
operation_key: Some(operation_key.to_owned()),
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +129,7 @@ pub fn operation_recommendations(operation: &RestImportOperation) -> Vec<ImportF
|
||||
),
|
||||
));
|
||||
}
|
||||
findings
|
||||
with_operation_location(findings, operation)
|
||||
}
|
||||
|
||||
pub fn candidate_recommendations(
|
||||
@@ -179,6 +183,18 @@ pub fn candidate_recommendations(
|
||||
));
|
||||
}
|
||||
|
||||
with_operation_location(findings, operation)
|
||||
}
|
||||
|
||||
fn with_operation_location(
|
||||
mut findings: Vec<ImportFinding>,
|
||||
operation: &RestImportOperation,
|
||||
) -> Vec<ImportFinding> {
|
||||
for finding in &mut findings {
|
||||
if finding.source_location.is_none() {
|
||||
finding.source_location = operation.source_location.clone();
|
||||
}
|
||||
}
|
||||
findings
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ use crate::rest::model::{
|
||||
SourceLocation,
|
||||
};
|
||||
|
||||
use super::{ImportParseError, normalize_coverage::escape_pointer};
|
||||
use super::reference_budget::{CopyBudget, count_branch_bytes, count_copy_bytes, merge_object};
|
||||
use super::{ImportParseError, decode_budget, normalize_coverage::escape_pointer};
|
||||
|
||||
pub(super) struct ResolutionResult {
|
||||
pub root: Value,
|
||||
@@ -61,6 +62,11 @@ fn reference_uris_with_max_bytes(
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
decode_budget::preflight_single(
|
||||
document,
|
||||
decode_budget::ShapeLimits::from_config(config),
|
||||
max_bytes,
|
||||
)?;
|
||||
let root = decode_snapshot(document)?;
|
||||
super::normalize::validate_value_limits(&root, config)?;
|
||||
let mut uris = BTreeSet::new();
|
||||
@@ -95,6 +101,7 @@ struct Resolver<'a> {
|
||||
findings: Vec<NormalizedFinding>,
|
||||
references: usize,
|
||||
expanded_nodes: usize,
|
||||
copy_budget: CopyBudget,
|
||||
}
|
||||
|
||||
pub(super) fn resolve(
|
||||
@@ -139,6 +146,10 @@ pub(super) fn resolve(
|
||||
root,
|
||||
});
|
||||
}
|
||||
let copy_limit = decode_budget::allowance(
|
||||
config.max_bytes.max(config.max_external_document_bytes),
|
||||
config.max_scalar_bytes,
|
||||
)?;
|
||||
let mut resolver = Resolver {
|
||||
config,
|
||||
documents,
|
||||
@@ -150,7 +161,10 @@ pub(super) fn resolve(
|
||||
findings: Vec::new(),
|
||||
references: 0,
|
||||
expanded_nodes: 0,
|
||||
copy_budget: CopyBudget::new(copy_limit),
|
||||
};
|
||||
let primary_copy_bytes = count_copy_bytes(&resolver.documents[0].root);
|
||||
resolver.copy_budget.charge(primary_copy_bytes)?;
|
||||
let root = resolver.documents[0].root.clone();
|
||||
let root = resolver.expand_value(
|
||||
0,
|
||||
@@ -320,7 +334,7 @@ impl Resolver<'_> {
|
||||
return Ok(Value::Object(source_object));
|
||||
}
|
||||
let Some((target_document, target_pointer)) = target.ok().flatten() else {
|
||||
let external = reference.starts_with("http://") || reference.starts_with("https://");
|
||||
let external = is_external_http_scheme(reference);
|
||||
let code = if external {
|
||||
if self.config.external_references_enabled {
|
||||
"external_reference_unavailable"
|
||||
@@ -360,6 +374,18 @@ impl Resolver<'_> {
|
||||
// producing an opaque object for the finite preview projection.
|
||||
return Ok(Value::Object(Map::new()));
|
||||
}
|
||||
let Some(target_bytes) = self.documents[target_document]
|
||||
.root
|
||||
.pointer(&target_pointer)
|
||||
.map(count_copy_bytes)
|
||||
else {
|
||||
self.push_finding(
|
||||
"reference_target_missing",
|
||||
&format!("{}/$ref", location.projection),
|
||||
);
|
||||
return Ok(Value::Object(source_object));
|
||||
};
|
||||
self.copy_budget.charge(target_bytes)?;
|
||||
let Some(target_value) = self.documents[target_document]
|
||||
.root
|
||||
.pointer(&target_pointer)
|
||||
@@ -471,6 +497,8 @@ impl Resolver<'_> {
|
||||
return Ok(Value::Object(object));
|
||||
}
|
||||
};
|
||||
let branch_bytes = count_branch_bytes(&branches);
|
||||
self.copy_budget.charge(branch_bytes)?;
|
||||
let original = branches.clone();
|
||||
for branch in branches {
|
||||
let Some(fields) = branch.as_object() else {
|
||||
@@ -478,7 +506,7 @@ impl Resolver<'_> {
|
||||
self.push_finding("all_of_conflict", &format!("{pointer}/allOf"));
|
||||
return Ok(Value::Object(object));
|
||||
};
|
||||
if !merge_object(&mut object, fields) {
|
||||
if !merge_object(&mut object, fields, &mut self.copy_budget)? {
|
||||
object.insert("allOf".to_owned(), Value::Array(original));
|
||||
self.push_finding("all_of_conflict", &format!("{pointer}/allOf"));
|
||||
return Ok(Value::Object(object));
|
||||
@@ -517,122 +545,6 @@ impl Resolver<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_object(target: &mut Map<String, Value>, source: &Map<String, Value>) -> bool {
|
||||
for (key, value) in source {
|
||||
match key.as_str() {
|
||||
"properties" => {
|
||||
let Some(source_properties) = value.as_object() else {
|
||||
return false;
|
||||
};
|
||||
let properties = target
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Value::Object(Map::new()));
|
||||
let Some(target_properties) = properties.as_object_mut() else {
|
||||
return false;
|
||||
};
|
||||
for (name, schema) in source_properties {
|
||||
if let Some(existing) = target_properties.get(name) {
|
||||
let (Some(existing), Some(schema)) =
|
||||
(existing.as_object(), schema.as_object())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let mut merged = existing.clone();
|
||||
if !merge_object(&mut merged, schema) {
|
||||
return false;
|
||||
}
|
||||
target_properties.insert(name.clone(), Value::Object(merged));
|
||||
} else {
|
||||
target_properties.insert(name.clone(), schema.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
"required" => {
|
||||
let Some(source_required) = value.as_array() else {
|
||||
return false;
|
||||
};
|
||||
let required = target
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Value::Array(Vec::new()));
|
||||
let Some(target_required) = required.as_array_mut() else {
|
||||
return false;
|
||||
};
|
||||
target_required.extend(source_required.iter().cloned());
|
||||
target_required.sort_by(|left, right| left.as_str().cmp(&right.as_str()));
|
||||
target_required.dedup();
|
||||
}
|
||||
"minimum" | "maximum" => {
|
||||
let Some(source_value) = value.as_f64() else {
|
||||
return false;
|
||||
};
|
||||
if target.contains_key(key) && target.get(key).and_then(Value::as_f64).is_none() {
|
||||
return false;
|
||||
}
|
||||
let merged = match (key.as_str(), target.get(key).and_then(Value::as_f64)) {
|
||||
("minimum", Some(current)) => current.max(source_value),
|
||||
("maximum", Some(current)) => current.min(source_value),
|
||||
_ => source_value,
|
||||
};
|
||||
let Some(number) = serde_json::Number::from_f64(merged) else {
|
||||
return false;
|
||||
};
|
||||
target.insert(key.clone(), Value::Number(number));
|
||||
if constraint_contradiction(target, "minimum", "maximum") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
"minLength" | "maxLength" => {
|
||||
let Some(source_value) = value.as_u64() else {
|
||||
return false;
|
||||
};
|
||||
if target.contains_key(key) && target.get(key).and_then(Value::as_u64).is_none() {
|
||||
return false;
|
||||
}
|
||||
let merged = match (key.as_str(), target.get(key).and_then(Value::as_u64)) {
|
||||
("minLength", Some(current)) => current.max(source_value),
|
||||
("maxLength", Some(current)) => current.min(source_value),
|
||||
_ => source_value,
|
||||
};
|
||||
target.insert(key.clone(), Value::Number(merged.into()));
|
||||
if integer_constraint_contradiction(target, "minLength", "maxLength") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if target.get(key).is_some_and(|existing| existing != value) {
|
||||
return false;
|
||||
}
|
||||
target.insert(key.clone(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn constraint_contradiction(target: &Map<String, Value>, minimum: &str, maximum: &str) -> bool {
|
||||
match (
|
||||
target.get(minimum).and_then(Value::as_f64),
|
||||
target.get(maximum).and_then(Value::as_f64),
|
||||
) {
|
||||
(Some(minimum), Some(maximum)) => minimum > maximum,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_constraint_contradiction(
|
||||
target: &Map<String, Value>,
|
||||
minimum: &str,
|
||||
maximum: &str,
|
||||
) -> bool {
|
||||
match (
|
||||
target.get(minimum).and_then(Value::as_u64),
|
||||
target.get(maximum).and_then(Value::as_u64),
|
||||
) {
|
||||
(Some(minimum), Some(maximum)) => minimum > maximum,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn edge_key(edge: &ResolvedReferenceEdge) -> (&str, &str, &str, &str, bool) {
|
||||
(
|
||||
edge.source.snapshot_digest.as_str(),
|
||||
@@ -644,12 +556,7 @@ fn edge_key(edge: &ResolvedReferenceEdge) -> (&str, &str, &str, &str, bool) {
|
||||
}
|
||||
|
||||
fn decode_snapshot(document: &str) -> Result<Value, ImportParseError> {
|
||||
if let Ok(value) = serde_json::from_str(document) {
|
||||
return Ok(value);
|
||||
}
|
||||
let yaml: serde_yaml::Value =
|
||||
serde_yaml::from_str(document).map_err(|_| ImportParseError::InvalidDocument)?;
|
||||
serde_json::to_value(yaml).map_err(|_| ImportParseError::InvalidDocument)
|
||||
super::strict_decode::decode(document).map_err(|_| ImportParseError::InvalidDocument)
|
||||
}
|
||||
|
||||
fn is_oas31(root: &Value) -> bool {
|
||||
@@ -774,14 +681,37 @@ fn canonical_authority(authority: &str, scheme: &str) -> String {
|
||||
"https" => Some("443"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(default_port) = default_port
|
||||
let authority = if let Some(default_port) = default_port
|
||||
&& let Some((host, port)) = authority.rsplit_once(':')
|
||||
&& port == default_port
|
||||
&& (!host.contains(':') || host.ends_with(']'))
|
||||
{
|
||||
return host.to_owned();
|
||||
host.to_owned()
|
||||
} else {
|
||||
authority
|
||||
};
|
||||
punycode_authority(authority, scheme)
|
||||
}
|
||||
|
||||
/// Applies the same IDNA/punycode host identity that the external-snapshot
|
||||
/// materializer gets from `url::Url`, so a Unicode `$ref` and the stored
|
||||
/// punycode `canonical_uri` resolve to the same snapshot. ASCII-only
|
||||
/// authorities (including IPv6 literals) and authorities with userinfo keep the
|
||||
/// previous ASCII-lowercase rendering, preserving RFC 3986 behavior.
|
||||
fn punycode_authority(authority: String, scheme: &str) -> String {
|
||||
if authority.is_ascii() || !matches!(scheme, "http" | "https") || authority.contains('@') {
|
||||
return authority;
|
||||
}
|
||||
let Ok(parsed) = url::Url::parse(&format!("{scheme}://{authority}")) else {
|
||||
return authority;
|
||||
};
|
||||
let Some(host) = parsed.host_str() else {
|
||||
return authority;
|
||||
};
|
||||
match parsed.port() {
|
||||
Some(port) => format!("{host}:{port}"),
|
||||
None => host.to_owned(),
|
||||
}
|
||||
authority
|
||||
}
|
||||
|
||||
fn has_uri_scheme(value: &str) -> bool {
|
||||
@@ -790,6 +720,14 @@ fn has_uri_scheme(value: &str) -> bool {
|
||||
.is_some_and(|(candidate, _)| is_uri_scheme(candidate))
|
||||
}
|
||||
|
||||
/// URI schemes are case-insensitive (RFC 3986 §3.1), so the failed-target
|
||||
/// classification must not depend on the literal case of `http`/`https`.
|
||||
fn is_external_http_scheme(reference: &str) -> bool {
|
||||
reference.split_once(':').is_some_and(|(scheme, _)| {
|
||||
scheme.eq_ignore_ascii_case("http") || scheme.eq_ignore_ascii_case("https")
|
||||
})
|
||||
}
|
||||
|
||||
fn is_uri_scheme(candidate: &str) -> bool {
|
||||
let Some(first) = candidate.as_bytes().first() else {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
//! Aggregate copy budget for string/key payloads allocated while resolving
|
||||
//! `$ref`s and merging `allOf` branches (Gitea #88).
|
||||
//!
|
||||
//! The budget is shared by the whole `resolve` call and never reset, so many
|
||||
//! individually small copies cannot multiply without bound. Checked arithmetic
|
||||
//! maps overflow to `ImportParseError::LimitExceeded`. `merge_object` charges
|
||||
//! every borrowed schema/required/value/key before it is cloned, so budget
|
||||
//! exhaustion is reported as `LimitExceeded` and never replaced by an
|
||||
//! `all_of_conflict` finding.
|
||||
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use super::normalize::ImportParseError;
|
||||
|
||||
pub(super) struct CopyBudget {
|
||||
limit: u64,
|
||||
used: u64,
|
||||
}
|
||||
|
||||
impl CopyBudget {
|
||||
pub(super) fn new(limit: u64) -> Self {
|
||||
Self { limit, used: 0 }
|
||||
}
|
||||
|
||||
pub(super) fn charge(&mut self, bytes: u64) -> Result<(), ImportParseError> {
|
||||
self.used = self
|
||||
.used
|
||||
.checked_add(bytes)
|
||||
.ok_or(ImportParseError::LimitExceeded)?;
|
||||
if self.used > self.limit {
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Sums the UTF-8 bytes of every string and object key in a borrowed value,
|
||||
/// mirroring the payload a later `clone` allocates.
|
||||
pub(super) fn count_copy_bytes(value: &Value) -> u64 {
|
||||
match value {
|
||||
Value::String(text) => text.len() as u64,
|
||||
Value::Array(items) => items.iter().fold(0u64, |total, item| {
|
||||
total.saturating_add(count_copy_bytes(item))
|
||||
}),
|
||||
Value::Object(object) => count_object_copy_bytes(object),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn count_object_copy_bytes(object: &Map<String, Value>) -> u64 {
|
||||
object.iter().fold(0u64, |total, (key, item)| {
|
||||
total
|
||||
.saturating_add(key.len() as u64)
|
||||
.saturating_add(count_copy_bytes(item))
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn count_branch_bytes(branches: &[Value]) -> u64 {
|
||||
branches.iter().fold(0u64, |total, branch| {
|
||||
total.saturating_add(count_copy_bytes(branch))
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn merge_object(
|
||||
target: &mut Map<String, Value>,
|
||||
source: &Map<String, Value>,
|
||||
budget: &mut CopyBudget,
|
||||
) -> Result<bool, ImportParseError> {
|
||||
for (key, value) in source {
|
||||
match key.as_str() {
|
||||
"properties" => {
|
||||
let Some(source_properties) = value.as_object() else {
|
||||
return Ok(false);
|
||||
};
|
||||
budget.charge(key.len() as u64)?;
|
||||
let properties = target
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Value::Object(Map::new()));
|
||||
let Some(target_properties) = properties.as_object_mut() else {
|
||||
return Ok(false);
|
||||
};
|
||||
for (name, schema) in source_properties {
|
||||
budget.charge(name.len() as u64)?;
|
||||
if let Some(existing) = target_properties.get(name) {
|
||||
let (Some(existing), Some(schema)) =
|
||||
(existing.as_object(), schema.as_object())
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
budget.charge(count_object_copy_bytes(existing))?;
|
||||
let mut merged = existing.clone();
|
||||
if !merge_object(&mut merged, schema, budget)? {
|
||||
return Ok(false);
|
||||
}
|
||||
target_properties.insert(name.clone(), Value::Object(merged));
|
||||
} else {
|
||||
budget.charge(count_copy_bytes(schema))?;
|
||||
target_properties.insert(name.clone(), schema.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
"required" => {
|
||||
let Some(source_required) = value.as_array() else {
|
||||
return Ok(false);
|
||||
};
|
||||
budget.charge(key.len() as u64)?;
|
||||
let required = target
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Value::Array(Vec::new()));
|
||||
let Some(target_required) = required.as_array_mut() else {
|
||||
return Ok(false);
|
||||
};
|
||||
budget.charge(count_branch_bytes(source_required))?;
|
||||
target_required.extend(source_required.iter().cloned());
|
||||
target_required.sort_by(|left, right| left.as_str().cmp(&right.as_str()));
|
||||
target_required.dedup();
|
||||
}
|
||||
"minimum" | "maximum" => {
|
||||
let Some(source_value) = value.as_f64() else {
|
||||
return Ok(false);
|
||||
};
|
||||
if target.contains_key(key) && target.get(key).and_then(Value::as_f64).is_none() {
|
||||
return Ok(false);
|
||||
}
|
||||
let merged = match (key.as_str(), target.get(key).and_then(Value::as_f64)) {
|
||||
("minimum", Some(current)) => current.max(source_value),
|
||||
("maximum", Some(current)) => current.min(source_value),
|
||||
_ => source_value,
|
||||
};
|
||||
let Some(number) = serde_json::Number::from_f64(merged) else {
|
||||
return Ok(false);
|
||||
};
|
||||
budget.charge(key.len() as u64)?;
|
||||
target.insert(key.clone(), Value::Number(number));
|
||||
if constraint_contradiction(target, "minimum", "maximum") {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
"minLength" | "maxLength" => {
|
||||
let Some(source_value) = value.as_u64() else {
|
||||
return Ok(false);
|
||||
};
|
||||
if target.contains_key(key) && target.get(key).and_then(Value::as_u64).is_none() {
|
||||
return Ok(false);
|
||||
}
|
||||
let merged = match (key.as_str(), target.get(key).and_then(Value::as_u64)) {
|
||||
("minLength", Some(current)) => current.max(source_value),
|
||||
("maxLength", Some(current)) => current.min(source_value),
|
||||
_ => source_value,
|
||||
};
|
||||
budget.charge(key.len() as u64)?;
|
||||
target.insert(key.clone(), Value::Number(merged.into()));
|
||||
if integer_constraint_contradiction(target, "minLength", "maxLength") {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
_ => match target.get(key) {
|
||||
Some(existing) if existing != value => return Ok(false),
|
||||
// Equal value already present: skip the redundant copy.
|
||||
Some(_) => {}
|
||||
None => {
|
||||
budget.charge(key.len() as u64)?;
|
||||
budget.charge(count_copy_bytes(value))?;
|
||||
target.insert(key.clone(), value.clone());
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn constraint_contradiction(target: &Map<String, Value>, minimum: &str, maximum: &str) -> bool {
|
||||
match (
|
||||
target.get(minimum).and_then(Value::as_f64),
|
||||
target.get(maximum).and_then(Value::as_f64),
|
||||
) {
|
||||
(Some(minimum), Some(maximum)) => minimum > maximum,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_constraint_contradiction(
|
||||
target: &Map<String, Value>,
|
||||
minimum: &str,
|
||||
maximum: &str,
|
||||
) -> bool {
|
||||
match (
|
||||
target.get(minimum).and_then(Value::as_u64),
|
||||
target.get(maximum).and_then(Value::as_u64),
|
||||
) {
|
||||
(Some(minimum), Some(maximum)) => minimum > maximum,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
fn object(value: Value) -> Map<String, Value> {
|
||||
value.as_object().cloned().expect("object")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_object_charges_existing_property_object_copy() {
|
||||
// The target already has the property, so merging clones the whole
|
||||
// existing property object. With a small remaining quota this must be
|
||||
// rejected by the budget, not silently allocated.
|
||||
let mut target = object(json!({
|
||||
"properties": { "id": { "type": "string", "description": "x".repeat(64) } }
|
||||
}));
|
||||
let source = object(json!({
|
||||
"properties": { "id": { "type": "number" } }
|
||||
}));
|
||||
let mut budget = CopyBudget::new(16);
|
||||
assert_eq!(
|
||||
merge_object(&mut target, &source, &mut budget),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_object_charges_required_extension_copy() {
|
||||
let mut target = object(json!({ "required": ["x"] }));
|
||||
let source = object(json!({
|
||||
"required": ["aaaaaaaa", "bbbbbbbb", "cccccccc", "dddddddd"]
|
||||
}));
|
||||
let mut budget = CopyBudget::new(16);
|
||||
assert_eq!(
|
||||
merge_object(&mut target, &source, &mut budget),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,28 @@
|
||||
//! Typed security scheme extraction and effective requirement
|
||||
//! classification for OpenAPI 3.x and Swagger 2.0 documents.
|
||||
//!
|
||||
//! The module is pure: it never reads Auth Profiles or Secrets and never
|
||||
//! captures credential values. Requirements are classified alternative by
|
||||
//! alternative (OR semantics preserved): a supported single-scheme
|
||||
//! alternative stays resolvable via a compatible Auth Profile; malformed
|
||||
//! requirements, unresolvable schemes and AND combinations mark the
|
||||
//! affected alternative as unsupported; an operation is blocked only when
|
||||
//! none of its alternatives is selectable.
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use super::model::{
|
||||
NormalizedSecurityRequirements, NormalizedSecurityScheme, NormalizedSecuritySchemeKind,
|
||||
SecurityParameterLocation, SecurityRequirementAlternative, SecurityRequirementsSource,
|
||||
SourceLocation,
|
||||
ImportFinding, NormalizedSecurityRequirements, NormalizedSecurityScheme,
|
||||
NormalizedSecuritySchemeKind, SecurityParameterLocation, SecurityRequirementAlternative,
|
||||
SecurityRequirementsSource, SourceLocation,
|
||||
};
|
||||
use super::recommendations::{document_blocker, document_finding};
|
||||
|
||||
/// Extracts typed schema metadata from `components.securitySchemes`
|
||||
/// (OpenAPI) or `securityDefinitions` (Swagger 2.0). Only scheme names,
|
||||
/// kinds, locations and safe format hints are preserved; credential values
|
||||
/// are never captured.
|
||||
pub(super) fn schemes(root: &Value, swagger: bool) -> BTreeMap<String, NormalizedSecurityScheme> {
|
||||
let (container, prefix) = if swagger {
|
||||
(root.get("securityDefinitions"), "/securityDefinitions")
|
||||
@@ -84,6 +98,56 @@ pub(super) fn schemes(root: &Value, swagger: bool) -> BTreeMap<String, Normalize
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Reports unsupported scheme definitions that are never used by a security
|
||||
/// requirement. They still need manual configuration, but cannot affect an
|
||||
/// operation that does not select them.
|
||||
pub(super) fn unused_unsupported_scheme_findings(
|
||||
root: &Value,
|
||||
schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
) -> Vec<(ImportFinding, SourceLocation)> {
|
||||
let mut used = std::collections::BTreeSet::new();
|
||||
collect_requirement_names(root.get("security"), &mut used);
|
||||
if let Some(paths) = root.get("paths").and_then(Value::as_object) {
|
||||
for path_item in paths.values().filter_map(Value::as_object) {
|
||||
for operation in path_item.values().filter_map(Value::as_object) {
|
||||
collect_requirement_names(operation.get("security"), &mut used);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
schemes
|
||||
.iter()
|
||||
.filter_map(|(name, scheme)| {
|
||||
if used.contains(name)
|
||||
|| !matches!(
|
||||
&scheme.kind,
|
||||
NormalizedSecuritySchemeKind::Unsupported { .. }
|
||||
)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some((
|
||||
document_finding(
|
||||
"unsupported_security_scheme_definition",
|
||||
format!(
|
||||
"Объявленная схема {name} пока не поддерживается и не используется операциями; настройте authentication вручную, если она потребуется."
|
||||
),
|
||||
),
|
||||
scheme.source_location.clone(),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn collect_requirement_names(value: Option<&Value>, used: &mut std::collections::BTreeSet<String>) {
|
||||
let Some(alternatives) = value.and_then(Value::as_array) else {
|
||||
return;
|
||||
};
|
||||
for alternative in alternatives.iter().filter_map(Value::as_object) {
|
||||
used.extend(alternative.keys().cloned());
|
||||
}
|
||||
}
|
||||
|
||||
fn api_key(definition: &Value, allow_cookie: bool) -> NormalizedSecuritySchemeKind {
|
||||
let location = match definition.get("in").and_then(Value::as_str) {
|
||||
Some("header") => Some(SecurityParameterLocation::Header),
|
||||
@@ -92,15 +156,17 @@ fn api_key(definition: &Value, allow_cookie: bool) -> NormalizedSecuritySchemeKi
|
||||
_ => None,
|
||||
};
|
||||
match (location, definition.get("name").and_then(Value::as_str)) {
|
||||
(Some(location), Some(parameter_name)) => NormalizedSecuritySchemeKind::ApiKey {
|
||||
location,
|
||||
parameter_name: parameter_name.to_owned(),
|
||||
format_hint: definition
|
||||
.get("x-format-hint")
|
||||
.and_then(Value::as_str)
|
||||
.filter(|value| safe_format_hint(value) && !looks_secret_hint(value))
|
||||
.map(ToOwned::to_owned),
|
||||
},
|
||||
(Some(location), Some(parameter_name)) if !parameter_name.is_empty() => {
|
||||
NormalizedSecuritySchemeKind::ApiKey {
|
||||
location,
|
||||
parameter_name: parameter_name.to_owned(),
|
||||
format_hint: definition
|
||||
.get("x-format-hint")
|
||||
.and_then(Value::as_str)
|
||||
.filter(|value| safe_format_hint(value) && !looks_secret_hint(value))
|
||||
.map(ToOwned::to_owned),
|
||||
}
|
||||
}
|
||||
_ => NormalizedSecuritySchemeKind::Unsupported {
|
||||
scheme_type: Some("apiKey".to_owned()),
|
||||
},
|
||||
@@ -124,6 +190,11 @@ fn looks_secret_hint(value: &str) -> bool {
|
||||
|| value.starts_with("bearer ")
|
||||
}
|
||||
|
||||
/// Computes the effective requirement for one operation: the operation
|
||||
/// `security` member wins over the document root; a missing member means no
|
||||
/// requirement. Every array item is one OR alternative and is classified
|
||||
/// independently, so a single unsupported alternative never collapses
|
||||
/// supported siblings into a false AND.
|
||||
pub(super) fn effective_requirements(
|
||||
root: &Value,
|
||||
operation: &Value,
|
||||
@@ -146,19 +217,16 @@ pub(super) fn effective_requirements(
|
||||
"/security".to_owned(),
|
||||
)
|
||||
} else {
|
||||
(None, SecurityRequirementsSource::None, String::new())
|
||||
};
|
||||
let mut findings = Vec::new();
|
||||
let Some(value) = value else {
|
||||
return (
|
||||
NormalizedSecurityRequirements {
|
||||
source,
|
||||
source: SecurityRequirementsSource::None,
|
||||
alternatives: Vec::new(),
|
||||
},
|
||||
findings,
|
||||
Vec::new(),
|
||||
);
|
||||
};
|
||||
let Some(alternatives) = value.as_array() else {
|
||||
let mut findings = Vec::new();
|
||||
let Some(alternatives) = value.and_then(Value::as_array) else {
|
||||
findings.push((
|
||||
document_blocker(
|
||||
"invalid_security_requirements",
|
||||
@@ -176,24 +244,27 @@ pub(super) fn effective_requirements(
|
||||
};
|
||||
let mut projected = Vec::new();
|
||||
let mut supported_alternatives = 0usize;
|
||||
let mut has_malformed_alternative = false;
|
||||
for (alternative_index, alternative) in alternatives.iter().enumerate() {
|
||||
let alternative_pointer = format!("{pointer}/{alternative_index}");
|
||||
let Some(requirement) = alternative.as_object() else {
|
||||
let source_location = SourceLocation {
|
||||
pointer: alternative_pointer,
|
||||
};
|
||||
has_malformed_alternative = true;
|
||||
findings.push((
|
||||
document_finding(
|
||||
"invalid_security_requirement",
|
||||
"Security alternative имеет неверную структуру и недоступна для выбора.",
|
||||
),
|
||||
source_location.clone(),
|
||||
SourceLocation {
|
||||
pointer: alternative_pointer.clone(),
|
||||
},
|
||||
));
|
||||
projected.push(SecurityRequirementAlternative {
|
||||
schemes: Vec::new(),
|
||||
supported: false,
|
||||
findings: vec!["invalid_security_requirement".to_owned()],
|
||||
source_location: Some(source_location),
|
||||
source_location: Some(SourceLocation {
|
||||
pointer: alternative_pointer,
|
||||
}),
|
||||
});
|
||||
continue;
|
||||
};
|
||||
@@ -212,7 +283,10 @@ pub(super) fn effective_requirements(
|
||||
"Security scopes должны быть массивом строк; эта альтернатива недоступна для выбора.",
|
||||
),
|
||||
SourceLocation {
|
||||
pointer: format!("{alternative_pointer}/{}", super::normalize_coverage::escape_pointer(name)),
|
||||
pointer: format!(
|
||||
"{alternative_pointer}/{}",
|
||||
super::normalize_coverage::escape_pointer(name)
|
||||
),
|
||||
},
|
||||
));
|
||||
} else if scopes.is_some_and(|scopes| !scopes.is_empty())
|
||||
@@ -225,7 +299,10 @@ pub(super) fn effective_requirements(
|
||||
format!("Схема {name} не поддерживает OAuth scopes; непустой список блокирует эту alternative."),
|
||||
),
|
||||
SourceLocation {
|
||||
pointer: format!("{alternative_pointer}/{}", super::normalize_coverage::escape_pointer(name)),
|
||||
pointer: format!(
|
||||
"{alternative_pointer}/{}",
|
||||
super::normalize_coverage::escape_pointer(name)
|
||||
),
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -259,7 +336,7 @@ pub(super) fn effective_requirements(
|
||||
},
|
||||
));
|
||||
}
|
||||
if let Some((_unsupported, message)) = names.iter().find_map(|name| {
|
||||
if let Some((unsupported, message)) = names.iter().find_map(|name| {
|
||||
schemes.get(name).and_then(|scheme| match &scheme.kind {
|
||||
NormalizedSecuritySchemeKind::Unsupported { .. } => Some((
|
||||
name,
|
||||
@@ -277,12 +354,12 @@ pub(super) fn effective_requirements(
|
||||
}) {
|
||||
alternative_findings.push("unsupported_security_scheme".to_owned());
|
||||
findings.push((
|
||||
document_finding(
|
||||
"unsupported_security_scheme",
|
||||
message,
|
||||
),
|
||||
document_finding("unsupported_security_scheme", message),
|
||||
SourceLocation {
|
||||
pointer: format!("{alternative_pointer}/{}", super::normalize_coverage::escape_pointer(_unsupported)),
|
||||
pointer: format!(
|
||||
"{alternative_pointer}/{}",
|
||||
super::normalize_coverage::escape_pointer(unsupported)
|
||||
),
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -299,11 +376,19 @@ pub(super) fn effective_requirements(
|
||||
}),
|
||||
});
|
||||
}
|
||||
if !projected.is_empty() && supported_alternatives == 0 {
|
||||
if has_malformed_alternative || (!projected.is_empty() && supported_alternatives == 0) {
|
||||
findings.push((
|
||||
document_blocker(
|
||||
"unsupported_security_requirements",
|
||||
"Ни одну authentication alternative нельзя безопасно выбрать; импорт операции заблокирован.",
|
||||
if has_malformed_alternative {
|
||||
"invalid_security_requirements"
|
||||
} else {
|
||||
"unsupported_security_requirements"
|
||||
},
|
||||
if has_malformed_alternative {
|
||||
"Security requirements содержат malformed alternative и блокируют импорт операции."
|
||||
} else {
|
||||
"Ни одну authentication alternative нельзя безопасно выбрать; импорт операции заблокирован."
|
||||
},
|
||||
),
|
||||
SourceLocation { pointer },
|
||||
));
|
||||
@@ -317,17 +402,19 @@ pub(super) fn effective_requirements(
|
||||
)
|
||||
}
|
||||
|
||||
/// Convenience wrapper keeping the parser call site short. The operation
|
||||
/// value must be the method object (`paths.{path}.{method}`); pointers use
|
||||
/// the same JSON-pointer escaping as the rest of the importer.
|
||||
pub(super) fn collect_operation_requirements(
|
||||
root: &Value,
|
||||
operation: &Value,
|
||||
pointer: &str,
|
||||
operation_pointer: &str,
|
||||
schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
findings: &mut Vec<(super::model::ImportFinding, SourceLocation)>,
|
||||
) -> NormalizedSecurityRequirements {
|
||||
let (requirements, security_findings) =
|
||||
effective_requirements(root, operation, pointer, schemes);
|
||||
findings.extend(security_findings);
|
||||
requirements
|
||||
) -> (
|
||||
NormalizedSecurityRequirements,
|
||||
Vec<(super::model::ImportFinding, SourceLocation)>,
|
||||
) {
|
||||
effective_requirements(root, operation, operation_pointer, schemes)
|
||||
}
|
||||
|
||||
fn supports_named_scopes(scheme: &NormalizedSecurityScheme) -> bool {
|
||||
@@ -338,3 +425,38 @@ fn supports_named_scopes(scheme: &NormalizedSecurityScheme) -> bool {
|
||||
} if matches!(scheme_type.as_str(), "oauth2" | "openIdConnect")
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn empty_api_key_parameter_name_is_unsupported() {
|
||||
for swagger in [false, true] {
|
||||
let definition = json!({ "type": "apiKey", "in": "header", "name": "" });
|
||||
let root = if swagger {
|
||||
json!({ "securityDefinitions": { "Key": definition } })
|
||||
} else {
|
||||
json!({ "components": { "securitySchemes": { "Key": definition } } })
|
||||
};
|
||||
let schemes = schemes(&root, swagger);
|
||||
assert!(matches!(
|
||||
schemes["Key"].kind,
|
||||
NormalizedSecuritySchemeKind::Unsupported { .. }
|
||||
));
|
||||
let (requirements, findings) = effective_requirements(
|
||||
&root,
|
||||
&json!({ "security": [{ "Key": [] }] }),
|
||||
"/paths/~1secure/get",
|
||||
&schemes,
|
||||
);
|
||||
assert!(!requirements.alternatives[0].supported);
|
||||
assert!(
|
||||
findings
|
||||
.iter()
|
||||
.any(|(finding, _)| { finding.code == "unsupported_security_requirements" })
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use super::model::SourceLocation;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct SecretLiteralFinding {
|
||||
pub location: SourceLocation,
|
||||
}
|
||||
|
||||
/// Scans UTF-8 JSON or YAML and returns source locations without literal values.
|
||||
pub fn scan_secret_literals(
|
||||
bytes: &[u8],
|
||||
) -> Result<Vec<SecretLiteralFinding>, super::normalize::ImportParseError> {
|
||||
let document = std::str::from_utf8(bytes)
|
||||
.map_err(|_| super::normalize::ImportParseError::InvalidDocument)?;
|
||||
let mut root = super::normalize::decode(document)?;
|
||||
Ok(inspect_and_redact(&mut root))
|
||||
}
|
||||
|
||||
pub(super) fn inspect_and_redact(root: &mut Value) -> Vec<SecretLiteralFinding> {
|
||||
let mut findings = Vec::new();
|
||||
walk(root, "", false, false, &mut findings, true, false);
|
||||
findings
|
||||
}
|
||||
|
||||
fn walk(
|
||||
value: &mut Value,
|
||||
pointer: &str,
|
||||
sensitive_context: bool,
|
||||
example_context: bool,
|
||||
findings: &mut Vec<SecretLiteralFinding>,
|
||||
redact: bool,
|
||||
cookie_context: bool,
|
||||
) {
|
||||
if example_context
|
||||
&& value
|
||||
.as_object()
|
||||
.is_some_and(|fields| fields.keys().any(|key| is_jwt(key)))
|
||||
{
|
||||
findings.push(SecretLiteralFinding {
|
||||
location: SourceLocation {
|
||||
pointer: pointer.to_owned(),
|
||||
},
|
||||
});
|
||||
if redact {
|
||||
*value = Value::String("[REDACTED]".to_owned());
|
||||
}
|
||||
return;
|
||||
}
|
||||
match value {
|
||||
Value::Object(fields) => {
|
||||
let header_parameter = fields
|
||||
.get("in")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|location| location.eq_ignore_ascii_case("header"));
|
||||
let parameter_name = fields.get("name").and_then(Value::as_str).unwrap_or("");
|
||||
let named_sensitive_parameter =
|
||||
sensitive_key(parameter_name) && fields.get("in").and_then(Value::as_str).is_some();
|
||||
let named_cookie_header = is_cookie_header(parameter_name);
|
||||
for (key, child) in fields {
|
||||
let child_pointer = format!(
|
||||
"{pointer}/{}",
|
||||
super::normalize_coverage::escape_pointer(key)
|
||||
);
|
||||
let property_definition = (pointer.contains("/properties/")
|
||||
|| pointer.ends_with("/properties"))
|
||||
&& !key.to_ascii_lowercase().starts_with("x-");
|
||||
let sensitive = sensitive_context
|
||||
|| (sensitive_key(key)
|
||||
&& !property_definition
|
||||
&& !is_oauth_flow_name(pointer, key));
|
||||
let example = example_context
|
||||
|| matches!(
|
||||
key.to_ascii_lowercase().as_str(),
|
||||
"example" | "examples" | "default"
|
||||
);
|
||||
let header_example = header_parameter
|
||||
&& matches!(
|
||||
key.to_ascii_lowercase().as_str(),
|
||||
"example" | "examples" | "default"
|
||||
);
|
||||
let named_header = is_cookie_header(key);
|
||||
let credential_example = matches!(
|
||||
key.to_ascii_lowercase().as_str(),
|
||||
"example" | "examples" | "default"
|
||||
) && (named_sensitive_parameter
|
||||
|| (cookie_context && !property_definition)
|
||||
|| (named_cookie_header && !property_definition));
|
||||
walk(
|
||||
child,
|
||||
&child_pointer,
|
||||
sensitive || header_example || credential_example,
|
||||
example,
|
||||
findings,
|
||||
redact,
|
||||
cookie_context || named_cookie_header || named_header,
|
||||
);
|
||||
}
|
||||
}
|
||||
Value::Array(items) => {
|
||||
for (index, child) in items.iter_mut().enumerate() {
|
||||
walk(
|
||||
child,
|
||||
&format!("{pointer}/{index}"),
|
||||
sensitive_context,
|
||||
example_context,
|
||||
findings,
|
||||
redact,
|
||||
cookie_context,
|
||||
);
|
||||
}
|
||||
}
|
||||
Value::String(string) => {
|
||||
let userinfo = url_userinfo_range(string);
|
||||
let query_secret = sensitive_query_value(string);
|
||||
let likely_example_secret = (example_context
|
||||
&& (looks_secret_like(pointer, string) || is_jwt(string)))
|
||||
|| looks_secret_value(string)
|
||||
|| ((pointer.ends_with("/bearerFormat") || pointer.ends_with("/x-format-hint"))
|
||||
&& looks_secret_like(pointer, string));
|
||||
if sensitive_context || likely_example_secret || userinfo.is_some() || query_secret {
|
||||
findings.push(SecretLiteralFinding {
|
||||
location: SourceLocation {
|
||||
pointer: pointer.to_owned(),
|
||||
},
|
||||
});
|
||||
if redact {
|
||||
if query_secret {
|
||||
*string = "[REDACTED]".to_owned();
|
||||
} else if let Some((start, end)) = userinfo {
|
||||
string.replace_range(start..end, "[REDACTED]");
|
||||
} else {
|
||||
*string = "[REDACTED]".to_owned();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Value::Number(_) | Value::Bool(_) if sensitive_context => {
|
||||
findings.push(SecretLiteralFinding {
|
||||
location: SourceLocation {
|
||||
pointer: pointer.to_owned(),
|
||||
},
|
||||
});
|
||||
if redact {
|
||||
*value = Value::String("[REDACTED]".to_owned());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn sensitive_key(key: &str) -> bool {
|
||||
let mut normalized = String::new();
|
||||
let mut previous_lower = false;
|
||||
for ch in key.chars() {
|
||||
if ch.is_ascii_uppercase() && previous_lower {
|
||||
normalized.push('_');
|
||||
}
|
||||
if ch == '-' || ch == ' ' {
|
||||
normalized.push('_');
|
||||
} else {
|
||||
normalized.push(ch.to_ascii_lowercase());
|
||||
}
|
||||
previous_lower = ch.is_ascii_lowercase() || ch.is_ascii_digit();
|
||||
}
|
||||
let key = normalized;
|
||||
if matches!(key.as_str(), "authorization_url" | "token_url") {
|
||||
return false;
|
||||
}
|
||||
[
|
||||
"token",
|
||||
"secret",
|
||||
"secret_hash",
|
||||
"secrethash",
|
||||
"password",
|
||||
"password_hash",
|
||||
"passwordhash",
|
||||
"passwd",
|
||||
"api_key",
|
||||
"apikey",
|
||||
"authorization",
|
||||
"credential",
|
||||
"credentials",
|
||||
"access_key",
|
||||
"private_key",
|
||||
"privatekey",
|
||||
"ciphertext",
|
||||
]
|
||||
.iter()
|
||||
.any(|marker| {
|
||||
key == *marker
|
||||
|| key.ends_with(&format!("_{marker}"))
|
||||
|| key.starts_with(&format!("{marker}_"))
|
||||
})
|
||||
}
|
||||
|
||||
fn is_oauth_flow_name(parent_pointer: &str, key: &str) -> bool {
|
||||
if !parent_pointer.ends_with("/flows") {
|
||||
return false;
|
||||
}
|
||||
let compact_key: String = key
|
||||
.chars()
|
||||
.filter(|character| character.is_ascii_alphanumeric())
|
||||
.map(|character| character.to_ascii_lowercase())
|
||||
.collect();
|
||||
matches!(
|
||||
compact_key.as_str(),
|
||||
"implicit" | "password" | "clientcredentials" | "authorizationcode"
|
||||
)
|
||||
}
|
||||
|
||||
fn is_cookie_header(value: &str) -> bool {
|
||||
value.eq_ignore_ascii_case("cookie") || value.eq_ignore_ascii_case("set-cookie")
|
||||
}
|
||||
|
||||
fn is_jwt(value: &str) -> bool {
|
||||
let mut parts = value.split('.');
|
||||
let Some(header) = parts.next() else {
|
||||
return false;
|
||||
};
|
||||
let Some(payload) = parts.next() else {
|
||||
return false;
|
||||
};
|
||||
let Some(signature) = parts.next() else {
|
||||
return false;
|
||||
};
|
||||
parts.next().is_none()
|
||||
&& header.starts_with("eyJ")
|
||||
&& payload.starts_with("eyJ")
|
||||
&& header.len() >= 8
|
||||
&& payload.len() >= 16
|
||||
&& signature.len() >= 12
|
||||
&& [header, payload, signature].iter().all(|part| {
|
||||
!part.is_empty()
|
||||
&& part
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'-')
|
||||
})
|
||||
}
|
||||
|
||||
fn sensitive_query_value(value: &str) -> bool {
|
||||
let Some(query_start) = value.find('?') else {
|
||||
return false;
|
||||
};
|
||||
value[query_start + 1..]
|
||||
.split('#')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.split(['&', ';'])
|
||||
.any(|pair| {
|
||||
let (key, value) = pair.split_once('=').unwrap_or((pair, ""));
|
||||
!value.is_empty() && sensitive_key(key)
|
||||
})
|
||||
}
|
||||
|
||||
fn looks_secret_like(pointer: &str, value: &str) -> bool {
|
||||
let pointer = pointer.to_ascii_lowercase();
|
||||
let value = value.to_ascii_lowercase();
|
||||
[
|
||||
"token",
|
||||
"secret",
|
||||
"password",
|
||||
"api_key",
|
||||
"apikey",
|
||||
"authorization",
|
||||
]
|
||||
.iter()
|
||||
.any(|marker| pointer.contains(marker) || value.contains(marker))
|
||||
|| value.starts_with("bearer ")
|
||||
|| value.starts_with("sk-")
|
||||
}
|
||||
|
||||
fn looks_secret_value(value: &str) -> bool {
|
||||
let value = value.to_ascii_lowercase();
|
||||
value.starts_with("bearer ") || value.starts_with("sk-")
|
||||
}
|
||||
|
||||
fn url_userinfo_range(value: &str) -> Option<(usize, usize)> {
|
||||
let scheme_end = value.find("://")? + 3;
|
||||
let authority_end = value[scheme_end..]
|
||||
.find('/')
|
||||
.map(|index| scheme_end + index)
|
||||
.unwrap_or(value.len());
|
||||
let authority = &value[scheme_end..authority_end];
|
||||
let at = authority.find('@')?;
|
||||
(at > 0).then_some((scheme_end, scheme_end + at))
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
use crate::rest::model::{ExternalDocumentSnapshot, SourceDigest};
|
||||
|
||||
use super::model::NormalizationConfig;
|
||||
use super::{
|
||||
decode_budget, metadata_findings,
|
||||
normalize::{ImportParseError, decode, validate_value_limits},
|
||||
normalize_limits, reference,
|
||||
};
|
||||
|
||||
/// Rejects a source bundle containing credential-like literals before any
|
||||
/// primary or dependency bytes are persisted. Credential names are collected
|
||||
/// across all raw documents so split `$ref` targets receive the same checks.
|
||||
pub fn validate_document_bundle_source_safe(
|
||||
documents: &[&str],
|
||||
config: &NormalizationConfig,
|
||||
) -> Result<(), ImportParseError> {
|
||||
config
|
||||
.validate_versions()
|
||||
.map_err(|_| ImportParseError::UnsupportedDocument)?;
|
||||
if config
|
||||
.max_reference_documents
|
||||
.checked_add(1)
|
||||
.is_some_and(|cap| documents.len() > cap)
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
for document in documents {
|
||||
if document.len() > config.max_bytes
|
||||
|| normalize_limits::alias_count(document) > config.max_aliases
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
}
|
||||
decode_budget::preflight_raw_bundle(documents, config)?;
|
||||
let mut roots = Vec::with_capacity(documents.len());
|
||||
for document in documents {
|
||||
let root = decode(document)?;
|
||||
validate_value_limits(&root, config)?;
|
||||
roots.push(root);
|
||||
}
|
||||
let declared_names = metadata_findings::credential_names(roots.iter());
|
||||
for mut root in roots {
|
||||
let mut findings = Vec::new();
|
||||
let mut locations = Vec::new();
|
||||
metadata_findings::redact_secret_like_literals_with_names(
|
||||
&mut root,
|
||||
"",
|
||||
&declared_names,
|
||||
&mut findings,
|
||||
&mut locations,
|
||||
);
|
||||
if !findings.is_empty() {
|
||||
return Err(ImportParseError::InvalidDocument);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validates the resolved source tree with the same security-aware traversal
|
||||
/// used by normalization, before a caller persists any bytes in the bundle.
|
||||
pub fn validate_resolved_bundle_source_safe(
|
||||
document: &str,
|
||||
digest: SourceDigest,
|
||||
snapshots: &[ExternalDocumentSnapshot],
|
||||
config: &NormalizationConfig,
|
||||
) -> Result<(), ImportParseError> {
|
||||
config
|
||||
.validate_versions()
|
||||
.map_err(|_| ImportParseError::UnsupportedDocument)?;
|
||||
if document.len() > config.max_bytes
|
||||
|| normalize_limits::alias_count(document) > config.max_aliases
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
if snapshots.len() > config.max_reference_documents {
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
for snapshot in snapshots {
|
||||
if snapshot.document.len() > config.max_external_document_bytes
|
||||
|| normalize_limits::alias_count(&snapshot.document) > config.max_aliases
|
||||
{
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
}
|
||||
decode_budget::preflight_bundle(document, snapshots, config)?;
|
||||
let root = decode(document)?;
|
||||
validate_value_limits(&root, config)?;
|
||||
for snapshot in snapshots {
|
||||
if snapshot.document.len() > config.max_external_document_bytes {
|
||||
return Err(ImportParseError::LimitExceeded);
|
||||
}
|
||||
}
|
||||
let resolution = reference::resolve(root, digest, snapshots, config)?;
|
||||
let mut root = resolution.root;
|
||||
validate_value_limits(&root, config)?;
|
||||
let mut findings = Vec::new();
|
||||
let mut locations = Vec::new();
|
||||
metadata_findings::redact_secret_like_literals(&mut root, "", &mut findings, &mut locations);
|
||||
if !findings.is_empty() {
|
||||
return Err(ImportParseError::InvalidDocument);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
use serde::de::{self, MapAccess, SeqAccess, Visitor};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
/// Decodes JSON or YAML into a JSON value while rejecting duplicate mapping
|
||||
/// keys at every depth. This is used for new primary documents and immutable
|
||||
/// external snapshots; the isolated legacy v1 decoder keeps its old behavior.
|
||||
pub(super) fn decode(document: &str) -> Result<Value, ()> {
|
||||
let value = serde_json::from_str::<StrictValue>(document)
|
||||
.or_else(|_| serde_yaml::from_str::<StrictValue>(document))
|
||||
.map_err(|_| ())?;
|
||||
Ok(value.0)
|
||||
}
|
||||
|
||||
struct StrictValue(Value);
|
||||
|
||||
impl<'de> Deserialize<'de> for StrictValue {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_any(StrictValueVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct StrictValueVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for StrictValueVisitor {
|
||||
type Value = StrictValue;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
formatter.write_str("a JSON-compatible value without duplicate object keys")
|
||||
}
|
||||
|
||||
fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::Bool(value)))
|
||||
}
|
||||
|
||||
fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::Number(value.into())))
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::Number(value.into())))
|
||||
}
|
||||
|
||||
fn visit_f64<E>(self, value: f64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
serde_json::Number::from_f64(value)
|
||||
.map(Value::Number)
|
||||
.map(StrictValue)
|
||||
.ok_or_else(|| E::custom("value contains a non-finite number"))
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::String(value.to_owned())))
|
||||
}
|
||||
|
||||
fn visit_string<E>(self, value: String) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::String(value)))
|
||||
}
|
||||
|
||||
fn visit_none<E>(self) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::Null))
|
||||
}
|
||||
|
||||
fn visit_unit<E>(self) -> Result<Self::Value, E> {
|
||||
Ok(StrictValue(Value::Null))
|
||||
}
|
||||
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
StrictValue::deserialize(deserializer)
|
||||
}
|
||||
|
||||
fn visit_seq<A>(self, mut sequence: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
{
|
||||
let mut values = Vec::new();
|
||||
while let Some(value) = sequence.next_element::<StrictValue>()? {
|
||||
values.push(value.0);
|
||||
}
|
||||
Ok(StrictValue(Value::Array(values)))
|
||||
}
|
||||
|
||||
fn visit_map<A>(self, mut mapping: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: MapAccess<'de>,
|
||||
{
|
||||
let mut values = Map::new();
|
||||
while let Some(key) = mapping.next_key::<String>()? {
|
||||
if values.contains_key(&key) {
|
||||
return Err(de::Error::custom("duplicate object key"));
|
||||
}
|
||||
let value = mapping.next_value::<StrictValue>()?;
|
||||
values.insert(key, value.0);
|
||||
}
|
||||
Ok(StrictValue(Value::Object(values)))
|
||||
}
|
||||
}
|
||||
@@ -15,16 +15,16 @@ pub fn parse_document(root: &Value) -> Result<RestImportDocument, ImportParseErr
|
||||
}
|
||||
|
||||
fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseError> {
|
||||
let security_schemes = super::security::schemes(root, true);
|
||||
let title = root
|
||||
.pointer("/info/title")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("Imported API")
|
||||
.to_owned();
|
||||
let servers = swagger_servers(root);
|
||||
let security_schemes = super::security::schemes(root, true);
|
||||
let mut findings = Vec::new();
|
||||
let mut internal_finding_locations = Vec::new();
|
||||
append_parameter_findings(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
super::swagger2_findings::servers(root),
|
||||
@@ -74,7 +74,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
path_item.get("parameters"),
|
||||
&format!("{path_pointer}/parameters"),
|
||||
);
|
||||
append_parameter_findings(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
path_parameters.findings,
|
||||
@@ -114,7 +114,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
operation_value.get("tags"),
|
||||
&format!("{path_pointer}/{method_name}/tags"),
|
||||
);
|
||||
append_parameter_findings(
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
tags.findings,
|
||||
@@ -147,17 +147,19 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
let operation_pointer = format!("{path_pointer}/{method_name}");
|
||||
let mut located_operation_findings =
|
||||
super::swagger2_findings::operation(root, operation_value, &operation_pointer);
|
||||
let security_requirements = super::security::collect_operation_requirements(
|
||||
root,
|
||||
operation_value,
|
||||
&operation_pointer,
|
||||
&security_schemes,
|
||||
&mut located_operation_findings,
|
||||
);
|
||||
let (security_requirements, security_findings) =
|
||||
super::security::collect_operation_requirements(
|
||||
root,
|
||||
operation_value,
|
||||
&operation_pointer,
|
||||
&security_schemes,
|
||||
);
|
||||
located_operation_findings.extend(security_findings);
|
||||
located_operation_findings.extend(parsed_parameter_findings);
|
||||
located_operation_findings.extend(super::swagger2_findings::path_parameters(
|
||||
path,
|
||||
&operation_parameters,
|
||||
&operation_pointer,
|
||||
));
|
||||
let (operation_findings, internal_finding_locations) =
|
||||
located_operation_findings.into_iter().unzip();
|
||||
@@ -168,6 +170,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements,
|
||||
operation_id: operation_value
|
||||
.get("operationId")
|
||||
@@ -203,6 +206,12 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
}
|
||||
}
|
||||
|
||||
super::parser_findings::append_located(
|
||||
&mut findings,
|
||||
&mut internal_finding_locations,
|
||||
super::security::unused_unsupported_scheme_findings(root, &security_schemes),
|
||||
);
|
||||
|
||||
Ok(RestImportDocument {
|
||||
format: "swagger".to_owned(),
|
||||
version: Some("2.0".to_owned()),
|
||||
@@ -222,7 +231,204 @@ fn deduplicate_parameters(parameters: &mut Vec<RestImportParameter>) {
|
||||
parameters.reverse();
|
||||
}
|
||||
|
||||
pub(super) fn swagger_servers(root: &Value) -> Vec<String> {
|
||||
pub fn parse_document_legacy_v1(root: &Value) -> Result<RestImportDocument, ImportParseError> {
|
||||
let title = root
|
||||
.pointer("/info/title")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("Imported API")
|
||||
.to_owned();
|
||||
let servers = swagger_servers(root);
|
||||
let mut findings = Vec::new();
|
||||
if servers.is_empty() {
|
||||
findings.push(document_finding(
|
||||
"missing_servers",
|
||||
"В Swagger 2.0 документе не указаны host/schemes, base URL нужно будет выбрать вручную.",
|
||||
));
|
||||
}
|
||||
let mut operations = Vec::new();
|
||||
let paths = root
|
||||
.get("paths")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or(ImportParseError::UnsupportedDocument)?;
|
||||
for (path, path_item) in paths {
|
||||
let path_pointer = format!("/paths/{}", path.replace('~', "~0").replace('/', "~1"));
|
||||
let path_parameters = legacy_parameters(
|
||||
root,
|
||||
path_item.get("parameters"),
|
||||
&format!("{path_pointer}/parameters"),
|
||||
);
|
||||
for method_name in ["get", "post", "put", "patch", "delete"] {
|
||||
let Some(operation) = path_item.get(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let Some(method) = super::http_methods::from_lower(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let operation_pointer = format!("{path_pointer}/{method_name}");
|
||||
let mut parameters = path_parameters.clone();
|
||||
parameters.extend(legacy_parameters(
|
||||
root,
|
||||
operation.get("parameters"),
|
||||
&format!("{operation_pointer}/parameters"),
|
||||
));
|
||||
let request_body_schema = parameters
|
||||
.iter()
|
||||
.find(|parameter| parameter.name == "body")
|
||||
.and_then(|parameter| parameter.schema.clone());
|
||||
let parameters = parameters
|
||||
.into_iter()
|
||||
.filter(|parameter| parameter.name != "body")
|
||||
.collect();
|
||||
operations.push(RestImportOperation {
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements: Default::default(),
|
||||
operation_id: operation
|
||||
.get("operationId")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
summary: operation
|
||||
.get("summary")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
description: operation
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
tags: legacy_tags(operation.get("tags")),
|
||||
parameters,
|
||||
request_body_schema,
|
||||
request_body_schema_location: None,
|
||||
request_body_variants: Vec::new(),
|
||||
response_schema: legacy_response_schema(root, operation),
|
||||
response_schema_location: None,
|
||||
response_variants: Vec::new(),
|
||||
servers: Vec::new(),
|
||||
findings: super::swagger2_findings::legacy_operation(path, operation),
|
||||
internal_finding_locations: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(RestImportDocument {
|
||||
format: "swagger".to_owned(),
|
||||
version: Some("2.0".to_owned()),
|
||||
title,
|
||||
servers,
|
||||
security_schemes: Default::default(),
|
||||
operations,
|
||||
findings,
|
||||
internal_finding_locations: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn legacy_tags(value: Option<&Value>) -> Vec<String> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(Value::as_str)
|
||||
.map(ToOwned::to_owned)
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_parameters(
|
||||
root: &Value,
|
||||
value: Option<&Value>,
|
||||
base_pointer: &str,
|
||||
) -> Vec<RestImportParameter> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, item)| {
|
||||
let item = crate::rest::normalize::resolve_local_ref(root, item, 0);
|
||||
let raw_location = item.get("in").and_then(Value::as_str)?;
|
||||
let pointer = format!("{base_pointer}/{index}");
|
||||
if raw_location == "body" {
|
||||
return Some(RestImportParameter {
|
||||
name: "body".to_owned(),
|
||||
location: RestParameterLocation::Query,
|
||||
required: item
|
||||
.get("required")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false),
|
||||
description: item
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
schema: item.get("schema").map(|schema| {
|
||||
crate::rest::normalize::resolve_local_ref(root, schema, 0)
|
||||
}),
|
||||
source_location: crate::rest::model::SourceLocation { pointer },
|
||||
schema_source_location: None,
|
||||
});
|
||||
}
|
||||
let location = match raw_location {
|
||||
"path" => RestParameterLocation::Path,
|
||||
"query" => RestParameterLocation::Query,
|
||||
"header" => RestParameterLocation::Header,
|
||||
_ => return None,
|
||||
};
|
||||
Some(RestImportParameter {
|
||||
name: item.get("name").and_then(Value::as_str)?.to_owned(),
|
||||
location,
|
||||
required: item
|
||||
.get("required")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
|| location == RestParameterLocation::Path,
|
||||
description: item
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
schema: legacy_parameter_schema(root, &item),
|
||||
source_location: crate::rest::model::SourceLocation { pointer },
|
||||
schema_source_location: None,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_parameter_schema(root: &Value, parameter: &Value) -> Option<Value> {
|
||||
if let Some(schema) = parameter.get("schema") {
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
let mut schema = serde_json::Map::new();
|
||||
for key in ["type", "format", "items", "enum", "default", "description"] {
|
||||
if let Some(value) = parameter.get(key) {
|
||||
schema.insert(
|
||||
key.to_owned(),
|
||||
crate::rest::normalize::resolve_local_ref(root, value, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
(!schema.is_empty()).then_some(Value::Object(schema))
|
||||
}
|
||||
|
||||
fn legacy_response_schema(root: &Value, operation: &Value) -> Option<Value> {
|
||||
let responses = operation.get("responses")?.as_object()?;
|
||||
for code in ["200", "201", "202", "default"] {
|
||||
let Some(response) = responses.get(code) else {
|
||||
continue;
|
||||
};
|
||||
let response = crate::rest::normalize::resolve_local_ref(root, response, 0);
|
||||
if let Some(schema) = response.get("schema") {
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn swagger_servers(root: &Value) -> Vec<String> {
|
||||
let Some(host) = root.get("host").and_then(Value::as_str) else {
|
||||
return Vec::new();
|
||||
};
|
||||
@@ -467,17 +673,6 @@ fn parameter_blocker(
|
||||
)
|
||||
}
|
||||
|
||||
fn append_parameter_findings(
|
||||
findings: &mut Vec<ImportFinding>,
|
||||
locations: &mut Vec<Option<crate::rest::model::SourceLocation>>,
|
||||
parameter_findings: Vec<(ImportFinding, crate::rest::model::SourceLocation)>,
|
||||
) {
|
||||
for (finding, location) in parameter_findings {
|
||||
findings.push(finding);
|
||||
locations.push(Some(location));
|
||||
}
|
||||
}
|
||||
|
||||
fn swagger_parameter_schema(_root: &Value, parameter: &Value) -> Option<Value> {
|
||||
if let Some(schema) = parameter.get("schema") {
|
||||
return Some(schema.clone());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::rest::{
|
||||
model::{ImportFinding, RestImportParameter, RestParameterLocation, SourceLocation},
|
||||
model::{ImportFinding, RestImportParameter, SourceLocation},
|
||||
recommendations::{document_blocker, operation_finding},
|
||||
};
|
||||
|
||||
@@ -175,33 +175,9 @@ pub(super) fn legacy_operation(path: &str, operation: &Value) -> Vec<ImportFindi
|
||||
pub(super) fn path_parameters(
|
||||
path: &str,
|
||||
parameters: &[RestImportParameter],
|
||||
operation_pointer: &str,
|
||||
) -> Vec<(ImportFinding, SourceLocation)> {
|
||||
parameters
|
||||
.iter()
|
||||
.filter(|parameter| parameter.location == RestParameterLocation::Path)
|
||||
.filter_map(|parameter| {
|
||||
let finding = if !parameter.required {
|
||||
Some((
|
||||
"path_parameter_not_required",
|
||||
format!("Path parameter {} должен быть required.", parameter.name),
|
||||
))
|
||||
} else if !path.contains(&format!("{{{}}}", parameter.name)) {
|
||||
Some((
|
||||
"path_parameter_placeholder_missing",
|
||||
format!(
|
||||
"Path parameter {} не имеет placeholder в пути.",
|
||||
parameter.name
|
||||
),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}?;
|
||||
Some((
|
||||
document_blocker(finding.0, finding.1),
|
||||
parameter.source_location.clone(),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
super::openapi3_findings::path_parameters(path, parameters, operation_pointer)
|
||||
}
|
||||
|
||||
pub(super) fn unsupported_methods(path_item: &Value) -> Vec<&str> {
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use super::swagger2::swagger_servers;
|
||||
use crate::rest::{
|
||||
model::{RestImportDocument, RestImportOperation, RestImportParameter, RestParameterLocation},
|
||||
normalize::ImportParseError,
|
||||
recommendations::document_finding,
|
||||
};
|
||||
|
||||
pub(super) fn parse_document_legacy_v1(
|
||||
root: &Value,
|
||||
) -> Result<RestImportDocument, ImportParseError> {
|
||||
let title = root
|
||||
.pointer("/info/title")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("Imported API")
|
||||
.to_owned();
|
||||
let servers = swagger_servers(root);
|
||||
let mut findings = Vec::new();
|
||||
if servers.is_empty() {
|
||||
findings.push(document_finding(
|
||||
"missing_servers",
|
||||
"В Swagger 2.0 документе не указаны host/schemes, base URL нужно будет выбрать вручную.",
|
||||
));
|
||||
}
|
||||
let mut operations = Vec::new();
|
||||
let paths = root
|
||||
.get("paths")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or(ImportParseError::UnsupportedDocument)?;
|
||||
for (path, path_item) in paths {
|
||||
let path_pointer = format!("/paths/{}", path.replace('~', "~0").replace('/', "~1"));
|
||||
let path_parameters = legacy_parameters(
|
||||
root,
|
||||
path_item.get("parameters"),
|
||||
&format!("{path_pointer}/parameters"),
|
||||
);
|
||||
for method_name in ["get", "post", "put", "patch", "delete"] {
|
||||
let Some(operation) = path_item.get(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let Some(method) = super::http_methods::from_lower(method_name) else {
|
||||
continue;
|
||||
};
|
||||
let operation_pointer = format!("{path_pointer}/{method_name}");
|
||||
let mut parameters = path_parameters.clone();
|
||||
parameters.extend(legacy_parameters(
|
||||
root,
|
||||
operation.get("parameters"),
|
||||
&format!("{operation_pointer}/parameters"),
|
||||
));
|
||||
let request_body_schema = parameters
|
||||
.iter()
|
||||
.find(|parameter| parameter.name == "body")
|
||||
.and_then(|parameter| parameter.schema.clone());
|
||||
let parameters = parameters
|
||||
.into_iter()
|
||||
.filter(|parameter| parameter.name != "body")
|
||||
.collect();
|
||||
operations.push(RestImportOperation {
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
security_requirements: Default::default(),
|
||||
operation_id: operation
|
||||
.get("operationId")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
summary: operation
|
||||
.get("summary")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
description: operation
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
tags: legacy_tags(operation.get("tags")),
|
||||
parameters,
|
||||
request_body_schema,
|
||||
request_body_schema_location: None,
|
||||
request_body_variants: Vec::new(),
|
||||
response_schema: legacy_response_schema(root, operation),
|
||||
response_schema_location: None,
|
||||
response_variants: Vec::new(),
|
||||
servers: Vec::new(),
|
||||
findings: super::swagger2_findings::legacy_operation(path, operation),
|
||||
internal_finding_locations: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(RestImportDocument {
|
||||
format: "swagger".to_owned(),
|
||||
version: Some("2.0".to_owned()),
|
||||
title,
|
||||
servers,
|
||||
security_schemes: Default::default(),
|
||||
operations,
|
||||
findings,
|
||||
internal_finding_locations: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn legacy_tags(value: Option<&Value>) -> Vec<String> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(Value::as_str)
|
||||
.map(ToOwned::to_owned)
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_parameters(
|
||||
root: &Value,
|
||||
value: Option<&Value>,
|
||||
base_pointer: &str,
|
||||
) -> Vec<RestImportParameter> {
|
||||
value
|
||||
.and_then(Value::as_array)
|
||||
.map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, item)| {
|
||||
let item = crate::rest::normalize::resolve_local_ref(root, item, 0);
|
||||
let raw_location = item.get("in").and_then(Value::as_str)?;
|
||||
let pointer = format!("{base_pointer}/{index}");
|
||||
if raw_location == "body" {
|
||||
return Some(RestImportParameter {
|
||||
name: "body".to_owned(),
|
||||
location: RestParameterLocation::Query,
|
||||
required: item
|
||||
.get("required")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false),
|
||||
description: item
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
schema: item.get("schema").map(|schema| {
|
||||
crate::rest::normalize::resolve_local_ref(root, schema, 0)
|
||||
}),
|
||||
source_location: crate::rest::model::SourceLocation { pointer },
|
||||
schema_source_location: None,
|
||||
});
|
||||
}
|
||||
let location = match raw_location {
|
||||
"path" => RestParameterLocation::Path,
|
||||
"query" => RestParameterLocation::Query,
|
||||
"header" => RestParameterLocation::Header,
|
||||
_ => return None,
|
||||
};
|
||||
Some(RestImportParameter {
|
||||
name: item.get("name").and_then(Value::as_str)?.to_owned(),
|
||||
location,
|
||||
required: item
|
||||
.get("required")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
|| location == RestParameterLocation::Path,
|
||||
description: item
|
||||
.get("description")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned),
|
||||
schema: legacy_parameter_schema(root, &item),
|
||||
source_location: crate::rest::model::SourceLocation { pointer },
|
||||
schema_source_location: None,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn legacy_parameter_schema(root: &Value, parameter: &Value) -> Option<Value> {
|
||||
if let Some(schema) = parameter.get("schema") {
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
let mut schema = serde_json::Map::new();
|
||||
for key in ["type", "format", "items", "enum", "default", "description"] {
|
||||
if let Some(value) = parameter.get(key) {
|
||||
schema.insert(
|
||||
key.to_owned(),
|
||||
crate::rest::normalize::resolve_local_ref(root, value, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
(!schema.is_empty()).then_some(Value::Object(schema))
|
||||
}
|
||||
|
||||
fn legacy_response_schema(root: &Value, operation: &Value) -> Option<Value> {
|
||||
let responses = operation.get("responses")?.as_object()?;
|
||||
for code in ["200", "201", "202", "default"] {
|
||||
let Some(response) = responses.get(code) else {
|
||||
continue;
|
||||
};
|
||||
let response = crate::rest::normalize::resolve_local_ref(root, response, 0);
|
||||
if let Some(schema) = response.get("schema") {
|
||||
return Some(crate::rest::normalize::resolve_local_ref(root, schema, 0));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -0,0 +1,962 @@
|
||||
//! Offline regression gates for the versioned OpenAPI support matrix and corpus.
|
||||
use crank_import::rest::model::CoverageDisposition;
|
||||
use crank_import::rest::model::{CanonicalSourceNode, CanonicalSourceValue};
|
||||
use crank_import::rest::{
|
||||
ImportParseError, NormalizationConfig, SourceDigest, normalize_verified_document,
|
||||
preview_from_ir, validate_normalized_ir,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
#[path = "corpus/matrix.rs"]
|
||||
mod matrix;
|
||||
|
||||
fn tests_root() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests")
|
||||
}
|
||||
fn hex(bytes: impl AsRef<[u8]>) -> String {
|
||||
Sha256::digest(bytes)
|
||||
.iter()
|
||||
.map(|b| format!("{b:02x}"))
|
||||
.collect()
|
||||
}
|
||||
fn canonical_json(value: &Value) -> Vec<u8> {
|
||||
serde_json::to_vec(value).expect("JSON values serialize")
|
||||
}
|
||||
fn escape_pointer(value: &str) -> String {
|
||||
value.replace('~', "~0").replace('/', "~1")
|
||||
}
|
||||
fn source_ledger(
|
||||
value: &Value,
|
||||
pointer: &str,
|
||||
ledger: &mut std::collections::BTreeMap<String, Value>,
|
||||
) {
|
||||
assert!(ledger.insert(pointer.to_owned(), value.clone()).is_none());
|
||||
match value {
|
||||
Value::Array(items) => {
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
source_ledger(item, &format!("{pointer}/{index}"), ledger);
|
||||
}
|
||||
}
|
||||
Value::Object(fields) => {
|
||||
for (key, item) in fields {
|
||||
source_ledger(item, &format!("{pointer}/{}", escape_pointer(key)), ledger);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn canonical_source_ledger(
|
||||
node: &CanonicalSourceNode,
|
||||
ledger: &mut std::collections::BTreeMap<String, Value>,
|
||||
) -> Value {
|
||||
let value = match &node.value {
|
||||
CanonicalSourceValue::Null => Value::Null,
|
||||
CanonicalSourceValue::Boolean(value) => json!(value),
|
||||
CanonicalSourceValue::Number(value) => {
|
||||
serde_json::from_str(value).expect("canonical number")
|
||||
}
|
||||
CanonicalSourceValue::String(value) => json!(value),
|
||||
CanonicalSourceValue::Array(items) => Value::Array(
|
||||
items
|
||||
.iter()
|
||||
.map(|item| canonical_source_ledger(item, ledger))
|
||||
.collect(),
|
||||
),
|
||||
CanonicalSourceValue::Object(items) => {
|
||||
let mut fields = serde_json::Map::new();
|
||||
for (key, item) in items {
|
||||
fields.insert(key.clone(), canonical_source_ledger(item, ledger));
|
||||
}
|
||||
Value::Object(fields)
|
||||
}
|
||||
};
|
||||
assert!(
|
||||
ledger
|
||||
.insert(node.location.pointer.clone(), value.clone())
|
||||
.is_none()
|
||||
);
|
||||
value
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Manifest {
|
||||
corpus_version: String,
|
||||
matrix_version: String,
|
||||
compatibility_impact: String,
|
||||
documents: Vec<Document>,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Document {
|
||||
id: String,
|
||||
file: String,
|
||||
sha256: String,
|
||||
canonical_digest: Option<String>,
|
||||
origin: String,
|
||||
license: String,
|
||||
specification_version: String,
|
||||
classification: String,
|
||||
expected_preview: Value,
|
||||
}
|
||||
fn manifest() -> Manifest {
|
||||
serde_json::from_slice(
|
||||
&fs::read(tests_root().join("corpus/manifest.json")).expect("manifest exists"),
|
||||
)
|
||||
.expect("manifest JSON is valid")
|
||||
}
|
||||
fn normalize(source: &str) -> Result<crank_import::rest::NormalizedIr, ImportParseError> {
|
||||
let source_digest = SourceDigest::parse(hex(source.as_bytes())).expect("sha256 is valid");
|
||||
normalize_verified_document(source, source_digest, &NormalizationConfig::default())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ac_2_manifest_covers_fifty_provenanced_specs_with_exact_expectations() {
|
||||
let manifest = manifest();
|
||||
assert_eq!(manifest.corpus_version, "1.0.4");
|
||||
assert_eq!(manifest.matrix_version, "1.0.3");
|
||||
assert!(!manifest.compatibility_impact.trim().is_empty());
|
||||
assert!(manifest.documents.len() >= 50);
|
||||
let root = tests_root().join("corpus");
|
||||
let mut versions = std::collections::BTreeSet::new();
|
||||
let mut representative_count = 0;
|
||||
for document in &manifest.documents {
|
||||
assert!(!document.id.is_empty());
|
||||
assert!(
|
||||
document.origin.starts_with("synthetic:"),
|
||||
"{} lacks provenance",
|
||||
document.id
|
||||
);
|
||||
assert!(
|
||||
document.license.contains("CC0"),
|
||||
"{} lacks license",
|
||||
document.id
|
||||
);
|
||||
assert_eq!(document.sha256.len(), 64);
|
||||
versions.insert(document.specification_version.as_str());
|
||||
let source = fs::read(root.join(&document.file))
|
||||
.unwrap_or_else(|e| panic!("{}: {e}", document.file));
|
||||
assert_eq!(
|
||||
hex(&source),
|
||||
document.sha256,
|
||||
"checksum mismatch for {}",
|
||||
document.file
|
||||
);
|
||||
if let Ok(value) = serde_json::from_slice::<Value>(&source) {
|
||||
let digest = hex(canonical_json(&value));
|
||||
assert_eq!(
|
||||
document.canonical_digest.as_deref(),
|
||||
Some(digest.as_str()),
|
||||
"canonical digest mismatch for {}",
|
||||
document.file
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
document.canonical_digest.is_none(),
|
||||
"malformed JSON has no canonical digest"
|
||||
);
|
||||
}
|
||||
if document.classification == "representative" {
|
||||
representative_count += 1;
|
||||
let text = std::str::from_utf8(&source).expect("fixtures are UTF-8");
|
||||
let ir =
|
||||
normalize(text).unwrap_or_else(|e| panic!("{} failed parser: {e}", document.file));
|
||||
validate_normalized_ir(&ir).expect("normalized IR has explicit source coverage");
|
||||
let preview = preview_from_ir(&ir);
|
||||
let repeated_preview =
|
||||
preview_from_ir(&normalize(text).expect("repeat normalization succeeds"));
|
||||
assert_eq!(
|
||||
serde_json::to_value(&preview).unwrap(),
|
||||
serde_json::to_value(&repeated_preview).unwrap(),
|
||||
"deterministic preview diff for {}:\nexpected={}\nactual={}",
|
||||
document.file,
|
||||
serde_json::to_string_pretty(&preview).unwrap(),
|
||||
serde_json::to_string_pretty(&repeated_preview).unwrap(),
|
||||
);
|
||||
let candidates = preview
|
||||
.groups
|
||||
.iter()
|
||||
.flat_map(|g| &g.operations)
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
candidates.len(),
|
||||
document.expected_preview["operation_count"]
|
||||
.as_u64()
|
||||
.unwrap() as usize,
|
||||
"operation count in {}",
|
||||
document.file
|
||||
);
|
||||
assert_eq!(
|
||||
candidates.len(),
|
||||
1,
|
||||
"corpus fixtures are single-operation exact oracles"
|
||||
);
|
||||
let expected = &document.expected_preview["operations"][0];
|
||||
let mut actual_candidate = serde_json::to_value(candidates[0]).unwrap();
|
||||
// Corpus snapshots freeze the pre-location semantic candidate.
|
||||
// Source provenance is covered by dedicated preview assertions.
|
||||
actual_candidate
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("source_location");
|
||||
for finding in actual_candidate["findings"].as_array_mut().unwrap() {
|
||||
finding.as_object_mut().unwrap().remove("source_location");
|
||||
}
|
||||
assert_eq!(
|
||||
actual_candidate,
|
||||
expected["candidate"],
|
||||
"frozen candidate diff for {}:\nexpected={}\nactual={}",
|
||||
document.file,
|
||||
serde_json::to_string_pretty(&expected["candidate"]).unwrap(),
|
||||
serde_json::to_string_pretty(&actual_candidate).unwrap(),
|
||||
);
|
||||
let blocking_codes = candidates[0]
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| {
|
||||
finding.severity == crank_import::rest::ImportFindingSeverity::Error
|
||||
})
|
||||
.map(|finding| finding.code.clone())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(json!(blocking_codes), expected["blocker_codes"]);
|
||||
assert_eq!(
|
||||
blocking_codes.is_empty(),
|
||||
expected["actionable"].as_bool().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
hex(canonical_json(&actual_candidate)),
|
||||
expected["candidate_digest"],
|
||||
"candidate canonical digest in {}",
|
||||
document.file
|
||||
);
|
||||
let mut actual_preview = serde_json::to_value(&preview).unwrap();
|
||||
for group in actual_preview["groups"].as_array_mut().unwrap() {
|
||||
for candidate in group["operations"].as_array_mut().unwrap() {
|
||||
candidate.as_object_mut().unwrap().remove("source_location");
|
||||
for finding in candidate["findings"].as_array_mut().unwrap() {
|
||||
finding.as_object_mut().unwrap().remove("source_location");
|
||||
}
|
||||
}
|
||||
}
|
||||
for finding in actual_preview["findings"].as_array_mut().unwrap() {
|
||||
finding.as_object_mut().unwrap().remove("source_location");
|
||||
}
|
||||
assert_eq!(
|
||||
hex(canonical_json(&actual_preview)),
|
||||
document.expected_preview["canonical_preview_digest"],
|
||||
"preview canonical digest in {}",
|
||||
document.file
|
||||
);
|
||||
assert_eq!(
|
||||
actual_preview,
|
||||
document.expected_preview["canonical_preview"],
|
||||
"frozen readable preview diff for {}:\nexpected={}\nactual={}",
|
||||
document.file,
|
||||
serde_json::to_string_pretty(&document.expected_preview["canonical_preview"])
|
||||
.unwrap(),
|
||||
serde_json::to_string_pretty(&actual_preview).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(candidates[0].method).unwrap().as_str(),
|
||||
expected["method"].as_str()
|
||||
);
|
||||
assert_eq!(candidates[0].path, expected["path"].as_str().unwrap());
|
||||
assert_eq!(
|
||||
candidates[0].operation_id.as_deref(),
|
||||
expected["operation_id"].as_str()
|
||||
);
|
||||
assert!(
|
||||
preview.findings.is_empty(),
|
||||
"unexpected preview findings in {}: {:?}",
|
||||
document.file,
|
||||
preview.findings
|
||||
);
|
||||
let mut actual_findings = candidates[0]
|
||||
.findings
|
||||
.iter()
|
||||
.map(|f| f.code.as_str())
|
||||
.collect::<Vec<_>>();
|
||||
let mut expected_findings = document.expected_preview["finding_codes"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|v| v.as_str().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
actual_findings.sort_unstable();
|
||||
expected_findings.sort_unstable();
|
||||
assert_eq!(
|
||||
actual_findings, expected_findings,
|
||||
"finding codes in {}",
|
||||
document.file
|
||||
);
|
||||
} else {
|
||||
assert_eq!(document.classification, "hostile");
|
||||
let text = std::str::from_utf8(&source).unwrap();
|
||||
let parsed = normalize(text);
|
||||
assert_eq!(
|
||||
parsed,
|
||||
normalize(text),
|
||||
"hostile parser result changed on deterministic rerun for {}",
|
||||
document.file
|
||||
);
|
||||
if [
|
||||
"hostile-empty.json",
|
||||
"hostile-malformed.json",
|
||||
"hostile-oversized.json",
|
||||
"hostile-deep.json",
|
||||
"hostile-aliases.yaml",
|
||||
]
|
||||
.contains(&document.file.as_str())
|
||||
{
|
||||
if [
|
||||
"hostile-oversized.json",
|
||||
"hostile-deep.json",
|
||||
"hostile-aliases.yaml",
|
||||
]
|
||||
.contains(&document.file.as_str())
|
||||
{
|
||||
assert!(
|
||||
matches!(parsed, Err(ImportParseError::LimitExceeded)),
|
||||
"{} must fail within configured bounds: {parsed:?}",
|
||||
document.file
|
||||
);
|
||||
} else {
|
||||
assert!(parsed.is_err(), "{} must be rejected", document.file);
|
||||
}
|
||||
} else if document.file == "hostile-trace.json" {
|
||||
let ir = parsed.expect("TRACE is reported instead of silently discarded");
|
||||
assert!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.any(|f| f.code == "unsupported_http_method")
|
||||
);
|
||||
assert!(ir.coverage.iter().any(|c| c.construct_id.contains("trace")
|
||||
&& c.disposition == CoverageDisposition::Finding));
|
||||
} else if document.file == "hostile-xml.json" {
|
||||
let ir = parsed.expect("XML is represented by an explicit finding");
|
||||
let preview = preview_from_ir(&ir);
|
||||
let codes = preview
|
||||
.groups
|
||||
.iter()
|
||||
.flat_map(|g| &g.operations)
|
||||
.flat_map(|o| &o.findings)
|
||||
.map(|f| f.code.as_str())
|
||||
.collect::<Vec<_>>();
|
||||
assert!(
|
||||
codes
|
||||
.iter()
|
||||
.any(|code| code.contains("xml") || code.contains("media")),
|
||||
"XML findings: {codes:?}"
|
||||
);
|
||||
} else if document.file == "hostile-secret.json" {
|
||||
let ir = parsed.expect("secret-like examples remain inspectable");
|
||||
let evidence = serde_json::to_string(&preview_from_ir(&ir)).unwrap();
|
||||
assert!(
|
||||
!evidence.contains("sk_test_corpus_secret_canary"),
|
||||
"secret canary leaked into preview evidence"
|
||||
);
|
||||
} else {
|
||||
let ir = parsed.unwrap_or_else(|error| {
|
||||
panic!(
|
||||
"{} must have an explicit finding or bounded rejection: {error}",
|
||||
document.file
|
||||
)
|
||||
});
|
||||
validate_normalized_ir(&ir).expect("hostile construct coverage remains explicit");
|
||||
assert!(
|
||||
!ir.coverage.is_empty(),
|
||||
"{} has no construct ledger",
|
||||
document.file
|
||||
);
|
||||
let preview = preview_from_ir(&ir);
|
||||
match document.file.as_str() {
|
||||
"hostile-cycle.json" => {
|
||||
assert_eq!(
|
||||
ir.operations.len(),
|
||||
1,
|
||||
"recursive schema must not drop the source operation"
|
||||
);
|
||||
assert!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.chain(ir.operations.iter().flat_map(|op| &op.findings))
|
||||
.all(|finding| {
|
||||
finding.severity
|
||||
!= crank_import::rest::ImportFindingSeverity::Error
|
||||
}),
|
||||
"bounded cycle policy must not yield an unexplained blocker: {:?} {:?}",
|
||||
ir.findings,
|
||||
ir.operations.iter().map(|op| &op.findings)
|
||||
);
|
||||
assert!(
|
||||
ir.unresolved_references.is_empty(),
|
||||
"resolved recursion must not be reported as unresolvable: {:?}",
|
||||
ir.unresolved_references
|
||||
);
|
||||
let cycle_edge = |recursive: bool| {
|
||||
ir.reference_graph.edges.iter().any(|edge| {
|
||||
edge.recursive == recursive
|
||||
&& edge.source.location.pointer
|
||||
== "/components/schemas/Node/properties/next/$ref"
|
||||
&& edge.target.location.pointer == "/components/schemas/Node"
|
||||
})
|
||||
};
|
||||
assert!(
|
||||
cycle_edge(false) && cycle_edge(true),
|
||||
"Node.next must resolve through both bounded and recursive edges: {:?}",
|
||||
ir.reference_graph.edges
|
||||
);
|
||||
let response = ir.operations[0]
|
||||
.response_variants
|
||||
.iter()
|
||||
.find(|variant| variant.status_code == 200)
|
||||
.expect("200 response is retained");
|
||||
assert!(
|
||||
matches!(
|
||||
&response.schema,
|
||||
Some(schema) if matches!(
|
||||
&schema.kind,
|
||||
crank_import::rest::NormalizedSchemaKind::Object {
|
||||
properties, ..
|
||||
} if properties.contains_key("next")
|
||||
)
|
||||
),
|
||||
"recursive node schema must be projected: {:?}",
|
||||
response.schema
|
||||
);
|
||||
assert!(
|
||||
ir.coverage.iter().any(|entry| {
|
||||
entry.location.pointer
|
||||
== "/components/schemas/Node/properties/next/properties/next"
|
||||
&& entry.disposition == CoverageDisposition::Mapped
|
||||
}),
|
||||
"bounded recursion must remain Mapped in the resolved source ledger: {:?}",
|
||||
ir.coverage
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["mapped_recursive_pointer"].as_str(),
|
||||
Some("/components/schemas/Node/properties/next/properties/next")
|
||||
);
|
||||
assert_eq!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.map(|f| (f.code.clone(), f.severity.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(
|
||||
"missing_servers".to_owned(),
|
||||
crank_import::rest::ImportFindingSeverity::Warning
|
||||
)],
|
||||
"cycle fixture must expose only the exact bounded warning set: {:?}",
|
||||
ir.findings
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["operation_count"].as_u64(),
|
||||
Some(1)
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["recursive_edge"]["source"].as_str(),
|
||||
Some("/components/schemas/Node/properties/next/$ref")
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["recursive_edge"]["target"].as_str(),
|
||||
Some("/components/schemas/Node")
|
||||
);
|
||||
assert_eq!(document.expected_preview["blocker_findings"], json!([]));
|
||||
assert_eq!(
|
||||
document.expected_preview["unresolved_references"],
|
||||
json!([])
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["warning_findings"],
|
||||
json!([{"code":"missing_servers","severity":"Warning","operation_key":null}])
|
||||
);
|
||||
}
|
||||
"hostile-external-ref.json" => assert!(
|
||||
ir.findings.iter()
|
||||
.chain(ir.operations.iter().flat_map(|op| &op.findings))
|
||||
.any(|finding| finding.code == "external_reference_disabled"
|
||||
&& finding.location.pointer == "/paths/~1hostile/get/responses/200/content/application~1json/schema/$ref"),
|
||||
"external ref must be denied at its source: {:?}",
|
||||
ir.findings
|
||||
),
|
||||
"hostile-duplicate-ids.json" => assert_eq!(
|
||||
ir.operations.len(),
|
||||
2,
|
||||
"duplicate IDs must not drop a source operation"
|
||||
),
|
||||
"hostile-composition-conflict.json" => {
|
||||
assert_eq!(
|
||||
ir.operations.len(),
|
||||
1,
|
||||
"conflicting allOf must keep the source operation explicit"
|
||||
);
|
||||
let conflict = ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.find(|finding| finding.code == "all_of_conflict")
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"allOf conflict must be named: {:?}",
|
||||
ir.operations[0].findings
|
||||
)
|
||||
});
|
||||
assert_eq!(
|
||||
conflict.severity,
|
||||
crank_import::rest::ImportFindingSeverity::Error,
|
||||
"allOf conflict must block the candidate: {:?}",
|
||||
conflict
|
||||
);
|
||||
assert_eq!(
|
||||
conflict.operation_key.as_deref(),
|
||||
Some("GET /hostile"),
|
||||
"conflict must belong to the affected candidate: {:?}",
|
||||
conflict
|
||||
);
|
||||
assert_eq!(
|
||||
conflict.location.pointer,
|
||||
"/paths/~1hostile/get/responses/200/content/application~1json/schema/allOf",
|
||||
"conflict must point at the conflicting allOf: {:?}",
|
||||
conflict
|
||||
);
|
||||
assert!(
|
||||
ir.coverage
|
||||
.iter()
|
||||
.any(|entry| {
|
||||
entry.location
|
||||
.pointer
|
||||
== "/paths/~1hostile/get/responses/200/content/application~1json/schema/allOf"
|
||||
})
|
||||
&& ir
|
||||
.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == "all_of_conflict"
|
||||
&& finding.location.pointer
|
||||
== "/paths/~1hostile/get/responses/200/content/application~1json/schema/allOf"),
|
||||
"conflicting allOf must stay in the source ledger bound to the explicit finding: {:?}",
|
||||
ir.coverage
|
||||
);
|
||||
let response = ir.operations[0]
|
||||
.response_variants
|
||||
.iter()
|
||||
.find(|variant| variant.status_code == 200)
|
||||
.expect("200 response is retained");
|
||||
assert!(
|
||||
matches!(
|
||||
&response.schema,
|
||||
Some(schema) if matches!(
|
||||
&schema.kind,
|
||||
crank_import::rest::NormalizedSchemaKind::Composition {
|
||||
operator, variants
|
||||
} if operator == "allOf" && variants.len() == 2
|
||||
)
|
||||
),
|
||||
"conflict branches must be preserved verbatim: {:?}",
|
||||
response.schema
|
||||
);
|
||||
assert_eq!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.map(|f| (f.code.clone(), f.severity.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(
|
||||
"missing_servers".to_owned(),
|
||||
crank_import::rest::ImportFindingSeverity::Warning
|
||||
)],
|
||||
"composition conflict fixture must keep the exact warning set: {:?}",
|
||||
ir.findings
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["operation_count"].as_u64(),
|
||||
Some(1)
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["blocker_findings"],
|
||||
json!([{"code":"all_of_conflict","severity":"Error",
|
||||
"operation_key":"GET /hostile",
|
||||
"location":"/paths/~1hostile/get/responses/200/content/application~1json/schema/allOf"}])
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["composition"],
|
||||
json!({"operator":"allOf","branch_count":2})
|
||||
);
|
||||
assert_eq!(
|
||||
document.expected_preview["warning_findings"],
|
||||
json!([{"code":"missing_servers","severity":"Warning","operation_key":null}])
|
||||
);
|
||||
}
|
||||
"hostile-security-scope.json" => {
|
||||
assert_eq!(
|
||||
ir.operations.len(),
|
||||
2,
|
||||
"security-scope fixture must keep both candidates explicit: {:?}",
|
||||
ir.operations.iter().map(|op| &op.key).collect::<Vec<_>>()
|
||||
);
|
||||
let requirements = ir.findings.iter().filter(|finding| {
|
||||
finding.code == "unsupported_security_requirements"
|
||||
}).collect::<Vec<_>>();
|
||||
assert!(requirements.is_empty(), "supported inherited basic requirement must remain selectable: {:?}", ir.findings);
|
||||
let secured_operation = ir.operations.iter().find(|operation| operation.key == "GET /secure").unwrap();
|
||||
assert!(secured_operation.security_requirements.alternatives[0].supported);
|
||||
assert_eq!(secured_operation.security_requirements.alternatives[0].source_location.as_ref().unwrap().pointer, "/security/0");
|
||||
let mut by_key = std::collections::BTreeMap::new();
|
||||
for group in &preview.groups {
|
||||
for candidate in &group.operations {
|
||||
by_key.insert(candidate.key.clone(), candidate);
|
||||
}
|
||||
}
|
||||
let public = by_key.get("GET /public").expect("public candidate present");
|
||||
assert!(
|
||||
public.findings.iter().all(|finding| finding.severity
|
||||
!= crank_import::rest::ImportFindingSeverity::Error),
|
||||
"public operation with security: [] must stay actionable: {:?}",
|
||||
public.findings
|
||||
);
|
||||
assert!(by_key.get("GET /secure").expect("secured candidate present").findings.iter().all(|finding| {
|
||||
finding.severity != crank_import::rest::ImportFindingSeverity::Error
|
||||
}), "supported security must remain selectable before API binding: {:?}", by_key.get("GET /secure").unwrap().findings);
|
||||
assert!(
|
||||
preview
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.operation_key.is_some()),
|
||||
"no document-global blocker may be produced: {:?}",
|
||||
preview.findings
|
||||
);
|
||||
assert!(
|
||||
ir.coverage
|
||||
.iter()
|
||||
.any(|entry| entry.location.pointer == "/security/0"
|
||||
&& entry.disposition == CoverageDisposition::Mapped),
|
||||
"inherited requirement must stay mapped in the source ledger: {:?}",
|
||||
ir.coverage
|
||||
);
|
||||
let mut actual_operation_keys = preview
|
||||
.groups
|
||||
.iter()
|
||||
.flat_map(|group| &group.operations)
|
||||
.map(|op| op.key.clone())
|
||||
.collect::<Vec<_>>();
|
||||
actual_operation_keys.sort();
|
||||
assert_eq!(
|
||||
json!(actual_operation_keys),
|
||||
document.expected_preview["operation_keys"],
|
||||
"security-scope operation oracle for {}",
|
||||
document.file
|
||||
);
|
||||
let actual_blockers = requirements
|
||||
.iter()
|
||||
.map(|finding| {
|
||||
json!({"code": finding.code.clone(), "severity": "Error",
|
||||
"operation_key": finding.operation_key.clone(),
|
||||
"location": finding.location.pointer.clone()})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
actual_blockers,
|
||||
document.expected_preview["blocker_findings"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.clone(),
|
||||
"security-scope blocker oracle for {}: actual {actual_blockers:?}",
|
||||
document.file
|
||||
);
|
||||
let actual_warnings = ir
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| {
|
||||
finding.severity
|
||||
== crank_import::rest::ImportFindingSeverity::Warning
|
||||
})
|
||||
.map(|finding| {
|
||||
json!({"code": finding.code.clone(), "severity": "Warning",
|
||||
"operation_key": finding.operation_key.clone()})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
actual_warnings,
|
||||
document.expected_preview["warning_findings"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.clone(),
|
||||
"security-scope warning oracle for {}: actual {actual_warnings:?}",
|
||||
document.file
|
||||
);
|
||||
}
|
||||
_ => unreachable!("hostile fixture must have a dedicated expectation"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Exact file set: manifest rows are unique and every corpus data file is
|
||||
// accounted exactly once, so duplicates or orphan fixtures cannot inflate
|
||||
// or hide coverage.
|
||||
let mut ids = std::collections::BTreeSet::new();
|
||||
let mut files = std::collections::BTreeSet::new();
|
||||
for document in &manifest.documents {
|
||||
assert!(
|
||||
ids.insert(document.id.clone()),
|
||||
"duplicate manifest document id {}",
|
||||
document.id
|
||||
);
|
||||
assert!(
|
||||
files.insert(document.file.clone()),
|
||||
"duplicate manifest file {}",
|
||||
document.file
|
||||
);
|
||||
}
|
||||
let expected_files = files
|
||||
.into_iter()
|
||||
.chain(std::iter::once("manifest.json".to_owned()))
|
||||
.chain(std::iter::once("matrix.rs".to_owned()))
|
||||
.collect::<std::collections::BTreeSet<_>>();
|
||||
let actual_files = fs::read_dir(&root)
|
||||
.expect("corpus directory exists")
|
||||
.map(|entry| entry.unwrap().file_name().to_string_lossy().into_owned())
|
||||
.collect::<std::collections::BTreeSet<_>>();
|
||||
assert_eq!(
|
||||
actual_files, expected_files,
|
||||
"corpus directory must equal the manifest file set exactly"
|
||||
);
|
||||
assert_eq!(representative_count, 50);
|
||||
assert!(
|
||||
versions
|
||||
.iter()
|
||||
.any(|version| version.starts_with("OpenAPI 3.0"))
|
||||
&& versions
|
||||
.iter()
|
||||
.any(|version| version.starts_with("OpenAPI 3.1"))
|
||||
&& versions.contains("Swagger 2.0")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ac_3_evidence_reports_actionable_denominator_exclusions_and_zero_silent_loss() {
|
||||
let manifest = manifest();
|
||||
let mut denominator = 0_u64;
|
||||
let mut actionable_count = 0_u64;
|
||||
let mut operation_count = 0_u64;
|
||||
let mut source_construct_count = 0_u64;
|
||||
let mut covered_source_construct_count = 0_u64;
|
||||
let mut semantic_coverage_count = 0_u64;
|
||||
let mut silent_loss = Vec::new();
|
||||
let mut exclusions = Vec::new();
|
||||
let mut finding_count = 0_u64;
|
||||
for document in &manifest.documents {
|
||||
if document.classification != "representative" {
|
||||
continue;
|
||||
}
|
||||
let source_bytes = fs::read(tests_root().join("corpus").join(&document.file)).unwrap();
|
||||
let source: Value =
|
||||
serde_json::from_slice(&source_bytes).expect("representative corpus source is JSON");
|
||||
let mut raw_ledger = std::collections::BTreeMap::new();
|
||||
source_ledger(&source, "", &mut raw_ledger);
|
||||
let source_text = std::str::from_utf8(&source_bytes).unwrap();
|
||||
let ir = normalize(source_text).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
let mut normalized_ledger = std::collections::BTreeMap::new();
|
||||
let _ = canonical_source_ledger(&ir.source_tree, &mut normalized_ledger);
|
||||
assert_eq!(
|
||||
normalized_ledger, raw_ledger,
|
||||
"normalizer source-tree ledger differs from raw document for {}",
|
||||
document.file
|
||||
);
|
||||
source_construct_count += raw_ledger.len() as u64;
|
||||
let coverage_by_id = ir
|
||||
.coverage
|
||||
.iter()
|
||||
.map(|entry| (entry.construct_id.as_str(), entry))
|
||||
.collect::<std::collections::BTreeMap<_, _>>();
|
||||
for pointer in raw_ledger.keys() {
|
||||
let source_id = format!("source:{pointer}");
|
||||
match coverage_by_id.get(source_id.as_str()) {
|
||||
Some(entry)
|
||||
if entry.location.pointer == *pointer
|
||||
&& entry.disposition == CoverageDisposition::Mapped =>
|
||||
{
|
||||
covered_source_construct_count += 1;
|
||||
}
|
||||
_ => silent_loss.push(json!({"document":document.id,"source_pointer":pointer,"coverage_id":source_id})),
|
||||
}
|
||||
}
|
||||
let findings = ir
|
||||
.findings
|
||||
.iter()
|
||||
.chain(
|
||||
ir.operations
|
||||
.iter()
|
||||
.flat_map(|operation| &operation.findings),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
for entry in ir
|
||||
.coverage
|
||||
.iter()
|
||||
.filter(|entry| !entry.construct_id.starts_with("source:"))
|
||||
{
|
||||
semantic_coverage_count += 1;
|
||||
assert!(
|
||||
raw_ledger.contains_key(&entry.location.pointer),
|
||||
"coverage {} points outside raw source tree for {}",
|
||||
entry.construct_id,
|
||||
document.file
|
||||
);
|
||||
match entry.disposition {
|
||||
CoverageDisposition::Mapped => {}
|
||||
CoverageDisposition::Finding => assert!(
|
||||
findings
|
||||
.iter()
|
||||
.any(|finding| finding.construct_id == entry.construct_id
|
||||
&& finding.location == entry.location),
|
||||
"finding coverage {} has no matching finding in {}",
|
||||
entry.construct_id,
|
||||
document.file
|
||||
),
|
||||
}
|
||||
}
|
||||
for operation in &ir.operations {
|
||||
denominator += 1;
|
||||
operation_count += 1;
|
||||
if operation
|
||||
.findings
|
||||
.iter()
|
||||
.all(|f| f.severity != crank_import::rest::ImportFindingSeverity::Error)
|
||||
{
|
||||
actionable_count += 1;
|
||||
} else {
|
||||
exclusions.push(json!({"document":document.id,"operation":operation.key,"reason":"blocking_finding","findings":operation.findings.iter().map(|f| &f.code).collect::<Vec<_>>()}));
|
||||
}
|
||||
}
|
||||
finding_count += ir.findings.len() as u64;
|
||||
}
|
||||
assert!(denominator > 0);
|
||||
assert!(
|
||||
actionable_count * 100 >= denominator * 95,
|
||||
"actionable {actionable_count}/{denominator}; exclusions={exclusions:?}"
|
||||
);
|
||||
let silent_loss_count = silent_loss.len() as u64;
|
||||
assert_eq!(
|
||||
source_construct_count, covered_source_construct_count,
|
||||
"independently enumerated raw source constructs lack coverage: {silent_loss:?}"
|
||||
);
|
||||
let mut reversed_counts = (0_u64, 0_u64, 0_u64);
|
||||
for document in manifest
|
||||
.documents
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|document| document.classification == "representative")
|
||||
{
|
||||
let source = fs::read_to_string(tests_root().join("corpus").join(&document.file)).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
reversed_counts.0 += ir.operations.len() as u64;
|
||||
reversed_counts.1 += ir
|
||||
.operations
|
||||
.iter()
|
||||
.filter(|operation| {
|
||||
operation.findings.iter().all(|finding| {
|
||||
finding.severity != crank_import::rest::ImportFindingSeverity::Error
|
||||
})
|
||||
})
|
||||
.count() as u64;
|
||||
reversed_counts.2 += ir.findings.len() as u64;
|
||||
}
|
||||
assert_eq!(
|
||||
reversed_counts,
|
||||
(operation_count, actionable_count, finding_count),
|
||||
"aggregate evidence must not depend on manifest order"
|
||||
);
|
||||
let manifest_bytes = fs::read(tests_root().join("corpus/manifest.json")).unwrap();
|
||||
let manifest_digest = hex(&manifest_bytes);
|
||||
let matrix_bytes = fs::read(tests_root().join("support-matrix.yaml")).unwrap();
|
||||
let matrix_digest = hex(&matrix_bytes);
|
||||
let matrix_value: serde_yaml::Value = serde_yaml::from_slice(&matrix_bytes).unwrap();
|
||||
let matrix_row_count = matrix_value["constructs"].as_sequence().unwrap().len();
|
||||
let evidence_identity = hex(format!(
|
||||
"{}\n{}\n{}\n{}",
|
||||
manifest.corpus_version, manifest.matrix_version, manifest_digest, matrix_digest
|
||||
));
|
||||
let mut evidence = json!({
|
||||
"evidence_version":"1.0.0", "corpus_version":manifest.corpus_version, "matrix_version":manifest.matrix_version,
|
||||
"evidence_identity":evidence_identity,
|
||||
"content_digest_algorithm":"sha256",
|
||||
"content_digest_definition":"SHA-256 of compact key-sorted JSON before the content_digest field is added.",
|
||||
"manifest_digest":manifest_digest,
|
||||
"matrix_digest":matrix_digest,
|
||||
"denominator":denominator, "actionable_count":actionable_count, "exclusions":exclusions,
|
||||
"raw_counts":{"documents":manifest.documents.len(),"representative_operations":operation_count,"findings":finding_count,"source_constructs":source_construct_count,"covered_source_constructs":covered_source_construct_count,"semantic_coverage_entries":semantic_coverage_count},
|
||||
"matrix_contract":{"construct_rows":matrix_row_count,"semantic_probes":"AC-1 runs a generated normalizer probe for every matrix row, including every 2xx status in all three formats."},
|
||||
"uncovered_source_constructs":silent_loss,
|
||||
"silent_loss_count":silent_loss_count,
|
||||
"method":"real normalize_verified_document + preview_from_ir; every NormalizedIr passed validate_normalized_ir"
|
||||
});
|
||||
let content_digest = hex(canonical_json(&evidence));
|
||||
evidence["content_digest"] = json!(content_digest);
|
||||
let artifact = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!(
|
||||
"target/openapi-corpus/evidence-{evidence_identity}.json"
|
||||
));
|
||||
let target_dir = artifact.parent().unwrap();
|
||||
fs::create_dir_all(target_dir).unwrap();
|
||||
let bytes = serde_json::to_vec_pretty(&evidence).unwrap();
|
||||
// Each process needs its own temp file: concurrent corpus runs must not
|
||||
// truncate each other's pending evidence before atomic publication.
|
||||
let mut nonce = 0u32;
|
||||
let (publish, mut file) = loop {
|
||||
let path = target_dir.join(format!(
|
||||
"evidence.json.tmp-{}-{}-{nonce}",
|
||||
&evidence_identity[..16],
|
||||
std::process::id()
|
||||
));
|
||||
match fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&path)
|
||||
{
|
||||
Ok(file) => break (path, file),
|
||||
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists && nonce < 1024 => {
|
||||
nonce += 1;
|
||||
}
|
||||
Err(error) => panic!(
|
||||
"cannot create evidence temp file {}: {error}",
|
||||
path.display()
|
||||
),
|
||||
}
|
||||
};
|
||||
{
|
||||
use std::io::Write;
|
||||
file.write_all(&bytes).unwrap();
|
||||
file.sync_all().unwrap();
|
||||
}
|
||||
// hard_link fails atomically when the final identity already exists.
|
||||
// Rename would silently overwrite after an exists-check race, while
|
||||
// create_new on the final path would expose partial bytes after a crash.
|
||||
let published = match fs::hard_link(&publish, &artifact) {
|
||||
Ok(()) => true,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => false,
|
||||
Err(error) => panic!(
|
||||
"cannot publish immutable evidence artifact {}: {error}",
|
||||
artifact.display()
|
||||
),
|
||||
};
|
||||
fs::remove_file(&publish).ok();
|
||||
if !published {
|
||||
let existing = fs::read(&artifact).unwrap();
|
||||
assert_eq!(
|
||||
existing,
|
||||
bytes,
|
||||
"immutable evidence identity {evidence_identity} already has conflicting contents at {}",
|
||||
artifact.display()
|
||||
);
|
||||
}
|
||||
if let Ok(directory) = fs::File::open(target_dir) {
|
||||
let _ = directory.sync_all();
|
||||
}
|
||||
let reread: Value = serde_json::from_slice(&fs::read(artifact).unwrap()).unwrap();
|
||||
assert_eq!(reread, evidence);
|
||||
assert_eq!(reread["silent_loss_count"], 0);
|
||||
assert_eq!(source_construct_count, covered_source_construct_count);
|
||||
assert_eq!(reread["denominator"], denominator);
|
||||
assert_eq!(reread["actionable_count"], actionable_count);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
openapi: 3.1.0
|
||||
info: {title: Aliases, version: 1}
|
||||
paths: {}
|
||||
x-anchor: &anchor {type: string}
|
||||
x-aliases: [*anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor, *anchor]
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Hostile generated",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/hostile": {
|
||||
"get": {
|
||||
"operationId": "hostileOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Hostile generated",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/hostile": {
|
||||
"get": {
|
||||
"operationId": "hostileOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Node"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"Node": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"next": {
|
||||
"$ref": "#/components/schemas/Node"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"openapi":"3.1.0","info":{"title":"Hostile generated","version":"1"},"paths":{"/hostile":{"get":{"operationId":"hostileOperation","responses":{"200":{"description":"ok","content":{"application/json":{"schema":{"type":"object"}}}}}}}},"components":{"schemas":{"Deep":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"array","items":{"type":"string"}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Hostile generated",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/hostile": {
|
||||
"get": {
|
||||
"operationId": "hostileOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "https://external.example.test/schema.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/other": {
|
||||
"post": {
|
||||
"operationId": "hostileOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Hostile generated",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/hostile": {
|
||||
"get": {
|
||||
"operationId": "hostileOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "https://external.example.test/schema.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"openapi":
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {"title": "Hostile generated", "version": "1"},
|
||||
"paths": {"/hostile": {"get": {"operationId": "hostileOperation", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"type": "string"}}}}}}}},
|
||||
"x-padding-0": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaLine truncated
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Secret hostile",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/secret": {
|
||||
"get": {
|
||||
"operationId": "secretOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-example": "sk_test_corpus_secret_canary"
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"openapi": "3.0.3",
|
||||
"info": {
|
||||
"title": "Hostile security scope",
|
||||
"version": "1"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://corpus.example.test"
|
||||
}
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"corpusProbe": []
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"securitySchemes": {
|
||||
"corpusProbe": {
|
||||
"type": "http",
|
||||
"scheme": "basic"
|
||||
}
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"/public": {
|
||||
"get": {
|
||||
"operationId": "publicProbe",
|
||||
"security": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/secure": {
|
||||
"get": {
|
||||
"operationId": "secureProbe",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "TRACE hostile",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/trace": {
|
||||
"trace": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "unsupported"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "XML hostile",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/xml": {
|
||||
"get": {
|
||||
"operationId": "xmlOperation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/xml": {
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,924 @@
|
||||
//! Executable normalizer probes for every normative support-matrix row.
|
||||
use super::*;
|
||||
use crank_import::rest::{NormalizedSchemaKind, normalize_verified_bundle};
|
||||
|
||||
fn assert_actionable(ir: &crank_import::rest::NormalizedIr, context: &str) {
|
||||
let preview = preview_from_ir(ir);
|
||||
assert!(
|
||||
!preview.findings.iter().any(|finding| {
|
||||
finding.severity == crank_import::rest::ImportFindingSeverity::Error
|
||||
}),
|
||||
"{context} has a document blocker: {:?}",
|
||||
preview.findings
|
||||
);
|
||||
assert!(
|
||||
preview
|
||||
.groups
|
||||
.iter()
|
||||
.flat_map(|group| &group.operations)
|
||||
.all(|candidate| {
|
||||
!candidate.findings.iter().any(|finding| {
|
||||
finding.severity == crank_import::rest::ImportFindingSeverity::Error
|
||||
})
|
||||
}),
|
||||
"{context} unexpectedly blocked: {:?}",
|
||||
preview.groups
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ac_1_support_matrix_rows_have_exact_construct_contracts() {
|
||||
let matrix_text = fs::read_to_string(tests_root().join("support-matrix.yaml"))
|
||||
.expect("support matrix exists");
|
||||
let matrix: serde_yaml::Value = serde_yaml::from_str(&matrix_text).expect("valid YAML");
|
||||
assert_eq!(matrix["matrix_version"].as_str(), Some("1.0.3"));
|
||||
assert!(
|
||||
matrix["compatibility_impact"]
|
||||
.as_str()
|
||||
.is_some_and(|s| !s.trim().is_empty())
|
||||
);
|
||||
let rows = matrix["constructs"].as_sequence().expect("construct rows");
|
||||
assert!(rows.len() >= 375);
|
||||
let mut construct_keys = std::collections::BTreeSet::new();
|
||||
for row in rows {
|
||||
assert!(
|
||||
row["specification_version"].as_str().is_some_and(|s| [
|
||||
"OpenAPI 3.0",
|
||||
"OpenAPI 3.1",
|
||||
"Swagger 2.0"
|
||||
]
|
||||
.contains(&s))
|
||||
);
|
||||
assert!(row["construct_id"].as_str().is_some_and(|s| !s.is_empty()));
|
||||
assert!(matches!(
|
||||
row["status"].as_str(),
|
||||
Some("supported" | "unsupported")
|
||||
));
|
||||
assert!(
|
||||
row["preserved_semantics"]
|
||||
.as_str()
|
||||
.is_some_and(|s| !s.trim().is_empty())
|
||||
);
|
||||
assert!(
|
||||
row["expected_finding"]
|
||||
.as_str()
|
||||
.is_some_and(|s| !s.trim().is_empty())
|
||||
);
|
||||
let key = format!(
|
||||
"{}:{}",
|
||||
row["specification_version"].as_str().unwrap(),
|
||||
row["construct_id"].as_str().unwrap()
|
||||
);
|
||||
assert!(
|
||||
construct_keys.insert(key.clone()),
|
||||
"duplicate normative construct row: {key}"
|
||||
);
|
||||
if row["status"] == "supported" {
|
||||
assert_eq!(
|
||||
row["expected_finding"], "none",
|
||||
"supported construct has a finding: {key}"
|
||||
);
|
||||
} else {
|
||||
assert_ne!(
|
||||
row["expected_finding"], "none",
|
||||
"unsupported construct has no finding: {key}"
|
||||
);
|
||||
}
|
||||
}
|
||||
for version in ["OpenAPI 3.0", "OpenAPI 3.1", "Swagger 2.0"] {
|
||||
// Exhaustive accounting: every normative row of this format must be
|
||||
// matched by an executed probe before the loop completes.
|
||||
let mut unprobed = rows
|
||||
.iter()
|
||||
.filter(|row| row["specification_version"] == version)
|
||||
.map(|row| {
|
||||
(
|
||||
version.to_owned(),
|
||||
row["construct_id"].as_str().unwrap().to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<std::collections::BTreeSet<_>>();
|
||||
let mut probed = |construct: &str| {
|
||||
let taken = unprobed.remove(&(version.to_owned(), construct.to_owned()));
|
||||
assert!(taken, "{version} double-probes or misses {construct}");
|
||||
};
|
||||
let ids = rows
|
||||
.iter()
|
||||
.filter(|r| r["specification_version"] == version)
|
||||
.filter_map(|r| r["construct_id"].as_str())
|
||||
.collect::<Vec<_>>();
|
||||
for id in [
|
||||
"http.method.get",
|
||||
"http.method.post",
|
||||
"http.method.put",
|
||||
"http.method.patch",
|
||||
"http.method.delete",
|
||||
"http.method.head",
|
||||
"http.method.options",
|
||||
"parameter.location.path",
|
||||
"parameter.location.query",
|
||||
"parameter.location.header",
|
||||
"parameter.location.cookie",
|
||||
"request_body.application/json",
|
||||
"request_body.application/x-www-form-urlencoded",
|
||||
"request_body.multipart/form-data",
|
||||
"reference.local",
|
||||
"reference.external_allowlisted",
|
||||
"composition.allOf",
|
||||
"composition.oneOf",
|
||||
"composition.anyOf",
|
||||
"security.bearer",
|
||||
"security.basic",
|
||||
"security.api_key",
|
||||
"media_type.application_xml.request",
|
||||
"media_type.application_xml.response",
|
||||
"http.method.trace",
|
||||
"http.method.connect",
|
||||
"parameter.path.declaration",
|
||||
"schema.default.compound",
|
||||
] {
|
||||
assert!(ids.contains(&id), "{version} matrix misses {id}");
|
||||
}
|
||||
for security_kind in ["bearer", "basic", "api_key"] {
|
||||
let construct = format!("security.{security_kind}");
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({
|
||||
"swagger":"2.0", "info":{"title":"Security probe","version":"1"},
|
||||
"securityDefinitions":{"probe": if security_kind == "bearer" {
|
||||
json!({"type":"oauth2","flow":"implicit","authorizationUrl":"https://auth.example.test","scopes":{}})
|
||||
} else if security_kind == "api_key" {
|
||||
json!({"type":"apiKey","name":"X-Key","in":"header"})
|
||||
} else {
|
||||
json!({"type":"basic"})
|
||||
}},
|
||||
"paths":{"/probe":{"get":{"security":[{"probe":[]}],"operationId":"securityProbe","responses":{"200":{"description":"ok"}}}}}
|
||||
})
|
||||
} else {
|
||||
let scheme = match security_kind {
|
||||
"bearer" => json!({"type":"http","scheme":"bearer"}),
|
||||
"basic" => json!({"type":"http","scheme":"basic"}),
|
||||
"api_key" => json!({"type":"apiKey","name":"X-Key","in":"header"}),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
json!({
|
||||
"openapi": if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Security probe","version":"1"},
|
||||
"servers":[{"url":"https://matrix.example.test"}],
|
||||
"components":{"securitySchemes":{"probe":scheme}},
|
||||
"paths":{"/probe":{"get":{"security":[{"probe":[]}],"operationId":"securityProbe","responses":{"200":{"description":"ok"}}}}}
|
||||
})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
let expected_finding = row["expected_finding"].as_str().unwrap();
|
||||
let preview = preview_from_ir(&ir);
|
||||
let candidate = &preview.groups[0].operations[0];
|
||||
let requirement = &ir.operations[0].security_requirements.alternatives[0];
|
||||
if expected_finding == "none" {
|
||||
assert!(
|
||||
requirement.supported,
|
||||
"{version} {construct} is not selectable"
|
||||
);
|
||||
assert!(
|
||||
candidate.findings.iter().all(|finding| {
|
||||
finding.severity != crank_import::rest::ImportFindingSeverity::Error
|
||||
}),
|
||||
"{version} {construct} unexpectedly blocked: {:?}",
|
||||
candidate.findings
|
||||
);
|
||||
assert!(ir.security_schemes.contains_key("probe"));
|
||||
assert!(
|
||||
ir.coverage.iter().any(|entry| {
|
||||
entry.location.pointer == "/paths/~1probe/get/security/0"
|
||||
&& entry.disposition == CoverageDisposition::Mapped
|
||||
}),
|
||||
"{version} {construct} requirement has no mapped source coverage"
|
||||
);
|
||||
} else {
|
||||
let finding = ir
|
||||
.findings
|
||||
.iter()
|
||||
.chain(
|
||||
ir.operations
|
||||
.iter()
|
||||
.flat_map(|operation| operation.findings.iter()),
|
||||
)
|
||||
.find(|finding| {
|
||||
finding.code == expected_finding
|
||||
&& finding.severity == crank_import::rest::ImportFindingSeverity::Error
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
panic!("{version} {construct} missing blocker: {:?}", ir.findings)
|
||||
});
|
||||
assert_eq!(finding.operation_key.as_deref(), Some("GET /probe"));
|
||||
assert_eq!(finding.location.pointer, "/paths/~1probe/get/security");
|
||||
assert!(
|
||||
candidate
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == expected_finding
|
||||
&& finding.severity
|
||||
== crank_import::rest::ImportFindingSeverity::Error)
|
||||
);
|
||||
assert!(ir.coverage.iter().any(|entry| entry.location.pointer
|
||||
== "/paths/~1probe/get/security"
|
||||
&& entry.disposition == CoverageDisposition::Finding));
|
||||
}
|
||||
probed(&construct);
|
||||
}
|
||||
{
|
||||
let construct = "security.override_empty";
|
||||
let override_probe = |path: &str| {
|
||||
if version == "Swagger 2.0" {
|
||||
json!({
|
||||
"swagger":"2.0", "info":{"title":"Security override probe","version":"1"},
|
||||
"securityDefinitions":{"probe":{"type":"basic"}},
|
||||
"security":[{"probe":[]}],
|
||||
"paths":{path:{"get":{"security":[],"operationId":"securityOverride","responses":{"200":{"description":"ok"}}}}}
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"openapi": if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Security override probe","version":"1"},
|
||||
"servers":[{"url":"https://matrix.example.test"}],
|
||||
"components":{"securitySchemes":{"probe":{"type":"http","scheme":"basic"}}},
|
||||
"security":[{"probe":[]}],
|
||||
"paths":{path:{"get":{"security":[],"operationId":"securityOverride","responses":{"200":{"description":"ok"}}}}}
|
||||
})
|
||||
}
|
||||
};
|
||||
let source = serde_json::to_string(&override_probe("/override")).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
assert!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.all(|finding| finding.code != "unsupported_security_requirement"),
|
||||
"explicit empty security override must disable inheritance: {:?}",
|
||||
ir.findings
|
||||
);
|
||||
let preview = preview_from_ir(&ir);
|
||||
let candidate = &preview.groups[0].operations[0];
|
||||
assert!(
|
||||
candidate
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.severity
|
||||
!= crank_import::rest::ImportFindingSeverity::Error),
|
||||
"overridden operation must remain actionable: {:?}",
|
||||
candidate.findings
|
||||
);
|
||||
probed(construct);
|
||||
}
|
||||
{
|
||||
let construct = "security.mixed_operations";
|
||||
let mixed_probe = if version == "Swagger 2.0" {
|
||||
json!({
|
||||
"swagger":"2.0", "info":{"title":"Mixed security probe","version":"1"},
|
||||
"securityDefinitions":{"probe":{"type":"basic"}},
|
||||
"security":[{"probe":[]}],
|
||||
"paths":{
|
||||
"/public":{"get":{"security":[],"operationId":"publicProbe","responses":{"200":{"description":"ok"}}}},
|
||||
"/secured":{"get":{"operationId":"securedProbe","responses":{"200":{"description":"ok"}}}}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"openapi": if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Mixed security probe","version":"1"},
|
||||
"servers":[{"url":"https://matrix.example.test"}],
|
||||
"components":{"securitySchemes":{"probe":{"type":"http","scheme":"basic"}}},
|
||||
"security":[{"probe":[]}],
|
||||
"paths":{
|
||||
"/public":{"get":{"security":[],"operationId":"publicProbe","responses":{"200":{"description":"ok"}}}},
|
||||
"/secured":{"get":{"operationId":"securedProbe","responses":{"200":{"description":"ok"}}}}
|
||||
}
|
||||
})
|
||||
};
|
||||
let source = serde_json::to_string(&mixed_probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
let expected_finding = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap()["expected_finding"]
|
||||
.as_str()
|
||||
.unwrap();
|
||||
assert_eq!(expected_finding, "none");
|
||||
let secured_operation = ir
|
||||
.operations
|
||||
.iter()
|
||||
.find(|operation| operation.key == "GET /secured")
|
||||
.unwrap();
|
||||
assert!(secured_operation.security_requirements.alternatives[0].supported);
|
||||
assert_eq!(
|
||||
secured_operation.security_requirements.alternatives[0]
|
||||
.source_location
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.pointer,
|
||||
"/security/0"
|
||||
);
|
||||
let preview = preview_from_ir(&ir);
|
||||
let mut by_key = std::collections::BTreeMap::new();
|
||||
for group in &preview.groups {
|
||||
for candidate in &group.operations {
|
||||
by_key.insert(candidate.key.clone(), candidate);
|
||||
}
|
||||
}
|
||||
let public = by_key.get("GET /public").expect("public candidate present");
|
||||
assert!(
|
||||
public
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.severity
|
||||
!= crank_import::rest::ImportFindingSeverity::Error),
|
||||
"public operation must stay actionable: {:?}",
|
||||
public.findings
|
||||
);
|
||||
let secured = by_key
|
||||
.get("GET /secured")
|
||||
.expect("secured candidate present");
|
||||
assert!(
|
||||
secured
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.severity
|
||||
!= crank_import::rest::ImportFindingSeverity::Error),
|
||||
"supported secured operation must remain selectable before API binding: {:?}",
|
||||
secured.findings
|
||||
);
|
||||
assert!(
|
||||
ir.coverage
|
||||
.iter()
|
||||
.any(|entry| entry.location.pointer == "/security/0"
|
||||
&& entry.disposition == CoverageDisposition::Mapped),
|
||||
"mixed probe has no mapped security coverage"
|
||||
);
|
||||
probed(construct);
|
||||
}
|
||||
for method in [
|
||||
"get", "post", "put", "patch", "delete", "head", "options", "trace", "connect",
|
||||
] {
|
||||
let construct = format!("http.method.{method}");
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let mut path_item = serde_json::Map::new();
|
||||
path_item.insert(
|
||||
method.to_owned(),
|
||||
json!({
|
||||
"operationId":"methodProbe", "responses":{"200":{"description":"ok"}}
|
||||
}),
|
||||
);
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({"swagger":"2.0","info":{"title":"Method probe","version":"1"},"paths":{"/probe":path_item,"/normal":{"get":{"operationId":"normalProbe","responses":{"200":{"description":"ok"}}}}}})
|
||||
} else {
|
||||
json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Method probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":path_item,"/normal":{"get":{"operationId":"normalProbe","responses":{"200":{"description":"ok"}}}}}})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
if row["status"] == "supported" {
|
||||
assert!(
|
||||
ir.operations
|
||||
.iter()
|
||||
.any(
|
||||
|operation| serde_json::to_value(operation.method).unwrap().as_str()
|
||||
== Some(&method.to_ascii_uppercase())
|
||||
),
|
||||
"{version} {construct} was not preserved"
|
||||
);
|
||||
assert_eq!(row["expected_finding"], "none");
|
||||
assert_actionable(&ir, &format!("{version} {construct}"));
|
||||
} else {
|
||||
let expected_finding = row["expected_finding"].as_str().unwrap();
|
||||
assert!(
|
||||
ir.operations
|
||||
.iter()
|
||||
.any(|operation| operation.path == "/normal"),
|
||||
"{version} {construct} must not discard a supported neighbour"
|
||||
);
|
||||
assert!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == expected_finding
|
||||
&& finding.severity
|
||||
== crank_import::rest::ImportFindingSeverity::Error),
|
||||
"{version} {construct} missing exact finding {expected_finding}: {:?}",
|
||||
ir.findings
|
||||
);
|
||||
assert!(
|
||||
ir.coverage
|
||||
.iter()
|
||||
.any(|entry| entry.construct_id.ends_with(&format!("/{method}"))
|
||||
&& entry.disposition == CoverageDisposition::Finding),
|
||||
"{version} {construct} has no finding coverage"
|
||||
);
|
||||
}
|
||||
probed(&construct);
|
||||
}
|
||||
for location in ["path", "query", "header", "cookie"] {
|
||||
let construct = format!("parameter.location.{location}");
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let parameter = if version == "Swagger 2.0" {
|
||||
json!({"name":"probe","in":location,"required":location == "path","type":"string"})
|
||||
} else {
|
||||
json!({"name":"probe","in":location,"required":location == "path","schema":{"type":"string"}})
|
||||
};
|
||||
let path = if location == "path" {
|
||||
"/probe/{probe}"
|
||||
} else {
|
||||
"/probe"
|
||||
};
|
||||
let operation = json!({"operationId":"parameterProbe","parameters":[parameter],"responses":{"200":{"description":"ok"}}});
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({"swagger":"2.0","info":{"title":"Parameter probe","version":"1"},"paths":{path:{"get":operation}}})
|
||||
} else {
|
||||
json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Parameter probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{path:{"get":operation}}})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
if row["status"] == "supported" {
|
||||
let parameter = ir.operations[0]
|
||||
.parameters
|
||||
.iter()
|
||||
.find(|parameter| parameter.name == "probe")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
serde_json::to_value(parameter.location).unwrap(),
|
||||
location,
|
||||
"{version} {construct} location was changed"
|
||||
);
|
||||
assert!(
|
||||
parameter.schema.is_some(),
|
||||
"{version} {construct} schema was lost"
|
||||
);
|
||||
assert_eq!(parameter.required, location == "path");
|
||||
let preview = preview_from_ir(&ir);
|
||||
let candidate = &preview.groups[0].operations[0];
|
||||
let expected_root = match location {
|
||||
"path" => "$.request.path.",
|
||||
"query" => "$.request.query.",
|
||||
"header" => "$.request.headers.",
|
||||
"cookie" => "$.request.cookies.",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
assert!(
|
||||
candidate
|
||||
.draft
|
||||
.input_mapping
|
||||
.rules
|
||||
.iter()
|
||||
.any(|rule| rule.source == "$.mcp.probe"
|
||||
&& rule.target.starts_with(expected_root)),
|
||||
"{version} {construct} input mapping missing {expected_root}: {:?}",
|
||||
candidate.draft.input_mapping
|
||||
);
|
||||
assert_actionable(&ir, &format!("{version} {construct}"));
|
||||
} else {
|
||||
let expected_finding = row["expected_finding"].as_str().unwrap();
|
||||
assert!(
|
||||
ir.operations[0].findings.iter().any(|finding| finding.code
|
||||
== expected_finding
|
||||
&& finding.severity == crank_import::rest::ImportFindingSeverity::Error
|
||||
&& finding.location.pointer == "/paths/~1probe/get/parameters/0"),
|
||||
"{version} {construct} missing exact finding {expected_finding}"
|
||||
);
|
||||
}
|
||||
probed(&construct);
|
||||
}
|
||||
for media_type in [
|
||||
"application/json",
|
||||
"application/x-www-form-urlencoded",
|
||||
"multipart/form-data",
|
||||
] {
|
||||
let construct = format!("request_body.{media_type}");
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let operation = if version == "Swagger 2.0" {
|
||||
let mut operation =
|
||||
json!({"operationId":"bodyProbe","responses":{"200":{"description":"ok"}}});
|
||||
operation["consumes"] = json!([media_type]);
|
||||
if media_type == "application/json" {
|
||||
operation["parameters"] = json!([{"name":"body","in":"body","required":true,"schema":{"type":"object","properties":{"value":{"type":"string"}}}}]);
|
||||
} else {
|
||||
operation["parameters"] =
|
||||
json!([{"name":"value","in":"formData","required":true,"type":"string"}]);
|
||||
}
|
||||
operation
|
||||
} else {
|
||||
json!({"operationId":"bodyProbe","requestBody":{"required":true,"content":{
|
||||
(media_type):{"schema":{"type":"object","properties":{"value":{"type":"string"}}}}
|
||||
}},"responses":{"200":{"description":"ok"}}})
|
||||
};
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({"swagger":"2.0","info":{"title":"Body probe","version":"1"},"paths":{"/probe":{"post":operation}}})
|
||||
} else {
|
||||
json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Body probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"post":operation}}})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
if row["status"] == "supported" {
|
||||
let variant = ir.operations[0]
|
||||
.request_body_variants
|
||||
.iter()
|
||||
.find(|variant| variant.content_type == media_type)
|
||||
.expect("request body variant retained");
|
||||
assert!(
|
||||
variant.schema.is_some(),
|
||||
"{version} {construct} schema was lost: {:?}",
|
||||
variant
|
||||
);
|
||||
assert!(
|
||||
variant.required,
|
||||
"{version} {construct} required request body contract was lost: {variant:?}"
|
||||
);
|
||||
let preview = preview_from_ir(&ir);
|
||||
let contract = preview.groups[0].operations[0]
|
||||
.draft
|
||||
.target
|
||||
.request_contract
|
||||
.as_ref()
|
||||
.expect("draft request contract");
|
||||
assert!(contract.body_required);
|
||||
assert!(
|
||||
contract
|
||||
.variants
|
||||
.iter()
|
||||
.any(|variant| variant.media_type == media_type)
|
||||
);
|
||||
assert_actionable(&ir, &format!("{version} {construct}"));
|
||||
} else {
|
||||
let expected_finding = row["expected_finding"].as_str().unwrap();
|
||||
assert!(
|
||||
ir.operations[0].findings.iter().any(|finding| finding.code
|
||||
== expected_finding
|
||||
&& finding.severity == crank_import::rest::ImportFindingSeverity::Error)
|
||||
);
|
||||
}
|
||||
probed(&construct);
|
||||
}
|
||||
for (construct, is_request) in [
|
||||
("media_type.application_xml.request", true),
|
||||
("media_type.application_xml.response", false),
|
||||
] {
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let operation = if version == "Swagger 2.0" {
|
||||
let mut operation = json!({"operationId":"xmlProbe","responses":{"200":{"description":"ok","schema":{"type":"string"}}}});
|
||||
if is_request {
|
||||
operation["consumes"] = json!(["application/xml"]);
|
||||
operation["parameters"] = json!([{"name":"body","in":"body","required":true,"schema":{"type":"string"}}]);
|
||||
} else {
|
||||
operation["produces"] = json!(["application/xml"]);
|
||||
}
|
||||
operation
|
||||
} else if is_request {
|
||||
json!({"operationId":"xmlProbe","requestBody":{"content":{"application/xml":{"schema":{"type":"string"}}}},"responses":{"200":{"description":"ok"}}})
|
||||
} else {
|
||||
json!({"operationId":"xmlProbe","responses":{"200":{"description":"ok","content":{"application/xml":{"schema":{"type":"string"}}}}}})
|
||||
};
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({"swagger":"2.0","info":{"title":"XML probe","version":"1"},"paths":{"/probe":{"post":operation}}})
|
||||
} else {
|
||||
json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"XML probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"post":operation}}})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
let expected_finding = row["expected_finding"].as_str().unwrap();
|
||||
assert_eq!(row["status"], "unsupported");
|
||||
let expected_pointer = if version == "Swagger 2.0" {
|
||||
if is_request {
|
||||
"/paths/~1probe/post/consumes/0"
|
||||
} else {
|
||||
"/paths/~1probe/post/produces/0"
|
||||
}
|
||||
} else if is_request {
|
||||
"/paths/~1probe/post/requestBody/content/application~1xml"
|
||||
} else {
|
||||
"/paths/~1probe/post/responses/200/content/application~1xml"
|
||||
};
|
||||
assert!(
|
||||
ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == expected_finding
|
||||
&& finding.severity == crank_import::rest::ImportFindingSeverity::Error
|
||||
&& finding.location.pointer == expected_pointer),
|
||||
"{version} {construct} missing exact blocker {expected_finding}: {:?}",
|
||||
ir.operations[0].findings
|
||||
);
|
||||
probed(construct);
|
||||
}
|
||||
for composition in ["allOf", "oneOf", "anyOf"] {
|
||||
let construct = format!("composition.{composition}");
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let schema = json!({(composition):[{"type":"object","properties":{"id":{"type":"string"}}},{"type":"object","properties":{"name":{"type":"string"}}}]});
|
||||
let response = if version == "Swagger 2.0" {
|
||||
json!({"description":"ok","schema":schema})
|
||||
} else {
|
||||
json!({"description":"ok","content":{"application/json":{"schema":schema}}})
|
||||
};
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({"swagger":"2.0","info":{"title":"Composition probe","version":"1"},"paths":{"/probe":{"get":{"operationId":"compositionProbe","responses":{"200":response}}}}})
|
||||
} else {
|
||||
json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Composition probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"get":{"operationId":"compositionProbe","responses":{"200":response}}}}})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source).unwrap();
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
assert_eq!(row["status"], "supported");
|
||||
assert!(ir.operations[0].response_variants[0].schema.as_ref().is_some_and(|schema|
|
||||
if composition == "allOf" {
|
||||
matches!(&schema.kind, NormalizedSchemaKind::Object { properties, .. }
|
||||
if properties.contains_key("id") && properties.contains_key("name"))
|
||||
} else {
|
||||
matches!(&schema.kind, NormalizedSchemaKind::Composition { operator, variants }
|
||||
if operator == composition && variants.len() == 2
|
||||
&& matches!(&variants[0].kind, NormalizedSchemaKind::Object { properties, .. }
|
||||
if properties.contains_key("id"))
|
||||
&& matches!(&variants[1].kind, NormalizedSchemaKind::Object { properties, .. }
|
||||
if properties.contains_key("name")))
|
||||
}),
|
||||
"{version} {construct} composition was not retained: {:?}", ir.operations[0].response_variants);
|
||||
assert_eq!(row["expected_finding"], "none");
|
||||
assert_actionable(&ir, &format!("{version} {construct}"));
|
||||
probed(&construct);
|
||||
}
|
||||
for external in [false, true] {
|
||||
let construct = if external {
|
||||
"reference.external_allowlisted"
|
||||
} else {
|
||||
"reference.local"
|
||||
};
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let reference = if external {
|
||||
"https://schemas.example.test/root.yaml#/Item"
|
||||
} else if version == "Swagger 2.0" {
|
||||
"#/definitions/Item"
|
||||
} else {
|
||||
"#/components/schemas/Item"
|
||||
};
|
||||
let schema = json!({"$ref":reference});
|
||||
let response = if version == "Swagger 2.0" {
|
||||
json!({"description":"ok","schema":schema})
|
||||
} else {
|
||||
json!({"description":"ok","content":{"application/json":{"schema":schema}}})
|
||||
};
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
let mut root = json!({"swagger":"2.0","info":{"title":"Reference probe","version":"1"},"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
|
||||
if !external {
|
||||
root["definitions"] =
|
||||
json!({"Item":{"type":"object","properties":{"id":{"type":"string"}}}});
|
||||
}
|
||||
root
|
||||
} else {
|
||||
let mut root = json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Reference probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
|
||||
if !external {
|
||||
root["components"] = json!({"schemas":{"Item":{"type":"object","properties":{"id":{"type":"string"}}}}});
|
||||
}
|
||||
root
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = if external {
|
||||
let external_source =
|
||||
"Item: { type: object, properties: { id: { type: string } } }";
|
||||
let snapshot = crank_import::rest::ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
|
||||
digest: SourceDigest::parse(hex(external_source.as_bytes())).unwrap(),
|
||||
document: external_source.to_owned(),
|
||||
};
|
||||
let digest = SourceDigest::parse(hex(source.as_bytes())).unwrap();
|
||||
normalize_verified_bundle(
|
||||
&source,
|
||||
digest,
|
||||
&[snapshot],
|
||||
&NormalizationConfig::default(),
|
||||
)
|
||||
.unwrap()
|
||||
} else {
|
||||
normalize(&source).unwrap()
|
||||
};
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
assert_eq!(row["status"], "supported");
|
||||
assert!(
|
||||
!ir.reference_graph.edges.is_empty(),
|
||||
"{version} {construct} did not resolve through a source-backed edge"
|
||||
);
|
||||
assert!(
|
||||
ir.unresolved_references.is_empty(),
|
||||
"{version} {construct} remains unresolved"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
ir.operations[0].response_variants[0].schema.as_ref().map(|schema| &schema.kind),
|
||||
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
|
||||
),
|
||||
"{version} {construct} resolved schema was not projected into the operation"
|
||||
);
|
||||
assert_actionable(&ir, &format!("{version} {construct}"));
|
||||
assert_eq!(row["expected_finding"], "none");
|
||||
probed(construct);
|
||||
}
|
||||
for code in 200..300 {
|
||||
let construct = format!("response.{code}");
|
||||
let response_row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap_or_else(|| panic!("{version} matrix misses {construct}"));
|
||||
assert!(
|
||||
ids.contains(&construct.as_str()),
|
||||
"{version} matrix misses {construct}"
|
||||
);
|
||||
assert_eq!(response_row["status"], "supported");
|
||||
assert_eq!(response_row["expected_finding"], "none");
|
||||
let has_body = !matches!(code, 204 | 205);
|
||||
let source = if version == "Swagger 2.0" {
|
||||
json!({
|
||||
"swagger":"2.0", "info":{"title":"Matrix probe","version":"1"},
|
||||
"paths":{"/probe":{"get":{"operationId":"matrixProbe","responses":{
|
||||
code.to_string(): if has_body {json!({"description":"success","schema":{"type":"object","properties":{"id":{"type":"string"}}}})} else {json!({"description":"success"})}
|
||||
}}}}
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"openapi": if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Matrix probe","version":"1"},
|
||||
"servers":[{"url":"https://matrix.example.test"}],
|
||||
"paths":{"/probe":{"get":{"operationId":"matrixProbe","responses":{
|
||||
code.to_string(): if has_body {json!({"description":"success","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"}}}}}})} else {json!({"description":"success"})}
|
||||
}}}}
|
||||
})
|
||||
};
|
||||
let source = serde_json::to_string(&source).unwrap();
|
||||
let ir = normalize(&source)
|
||||
.unwrap_or_else(|error| panic!("{version} {construct} probe rejected: {error}"));
|
||||
validate_normalized_ir(&ir).unwrap_or_else(|error| {
|
||||
panic!("{version} {construct} probe has invalid ledger: {error}")
|
||||
});
|
||||
let response = ir.operations[0]
|
||||
.response_variants
|
||||
.iter()
|
||||
.find(|variant| variant.status_code == code)
|
||||
.unwrap_or_else(|| panic!("{version} {construct} was not preserved"));
|
||||
assert_eq!(
|
||||
response.schema.is_some(),
|
||||
has_body,
|
||||
"{version} {construct} body contract differs from 204/205 bodyless response semantics"
|
||||
);
|
||||
assert!(
|
||||
!ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.severity
|
||||
== crank_import::rest::ImportFindingSeverity::Error),
|
||||
"{version} {construct} unexpectedly blocked: {:?}",
|
||||
ir.operations[0].findings
|
||||
);
|
||||
probed(&construct);
|
||||
}
|
||||
for construct in ["parameter.path.declaration", "schema.default.compound"] {
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(row["status"], "unsupported");
|
||||
let operation = if construct == "parameter.path.declaration" {
|
||||
json!({
|
||||
"operationId":"pathDeclarationProbe",
|
||||
"responses":{"200":{"description":"ok"}}
|
||||
})
|
||||
} else {
|
||||
let schema = json!({
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"compound":{"type":"object","default":{"nested":"value"}},
|
||||
"list":{"type":"array","items":{"type":"string"},"default":["a","b"]},
|
||||
"scalar":{"type":"string","default":"kept"}
|
||||
}
|
||||
});
|
||||
if version == "Swagger 2.0" {
|
||||
json!({
|
||||
"operationId":"compoundDefaultProbe",
|
||||
"responses":{"200":{"description":"ok","schema":schema}}
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"operationId":"compoundDefaultProbe",
|
||||
"responses":{"200":{"description":"ok","content":{"application/json":{"schema":schema}}}}
|
||||
})
|
||||
}
|
||||
};
|
||||
let path = if construct == "parameter.path.declaration" {
|
||||
"/probe/{item_id}"
|
||||
} else {
|
||||
"/probe"
|
||||
};
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
json!({
|
||||
"swagger":"2.0", "info":{"title":"Matrix probe","version":"1"},
|
||||
"paths":{path:{"get":operation}}
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Matrix probe","version":"1"},
|
||||
"servers":[{"url":"https://matrix.example.test"}],
|
||||
"paths":{path:{"get":operation}}
|
||||
})
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = normalize(&source)
|
||||
.unwrap_or_else(|error| panic!("{version} {construct} probe rejected: {error}"));
|
||||
validate_normalized_ir(&ir).unwrap_or_else(|error| {
|
||||
panic!("{version} {construct} probe has invalid ledger: {error}")
|
||||
});
|
||||
let expected_finding = row["expected_finding"].as_str().unwrap();
|
||||
assert!(
|
||||
ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == expected_finding
|
||||
&& finding.severity == crank_import::rest::ImportFindingSeverity::Error),
|
||||
"{version} {construct} lacks {expected_finding}: {:?}",
|
||||
ir.operations[0].findings
|
||||
);
|
||||
if construct == "schema.default.compound" {
|
||||
assert_eq!(
|
||||
ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| finding.code == expected_finding)
|
||||
.count(),
|
||||
2,
|
||||
"{version} must block the object and array defaults"
|
||||
);
|
||||
let schema = ir.operations[0].response_variants[0]
|
||||
.schema
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
assert!(matches!(
|
||||
&schema.kind,
|
||||
NormalizedSchemaKind::Object { properties, .. }
|
||||
if matches!(&properties["scalar"].kind,
|
||||
NormalizedSchemaKind::Scalar { default_value: Some(value), .. }
|
||||
if value == &crank_import::rest::model::NormalizedLiteral::String("kept".to_owned()))
|
||||
));
|
||||
}
|
||||
probed(construct);
|
||||
}
|
||||
assert!(
|
||||
unprobed.is_empty(),
|
||||
"normative {version} rows lack an executed probe: {unprobed:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 00",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/0": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation00",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p00",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 00",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 01",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/{p01}": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation01",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p01",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 01",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 02",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/2": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation02",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p02",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 02",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 03",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/3": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation03",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p03",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 03",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 04",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/4": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation04",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p04",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 04",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 05",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/{p05}": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation05",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p05",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 05",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 06",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/6": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation06",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p06",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 06",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 07",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/7": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation07",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p07",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 07",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 08",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/8": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation08",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p08",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 08",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 09",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/{p09}": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation09",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p09",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 09",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 10",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/10": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation10",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p10",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 10",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 11",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/11": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation11",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p11",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 11",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 12",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/12": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation12",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p12",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 12",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 13",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/{p13}": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation13",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p13",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 13",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 14",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/14": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation14",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p14",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 14",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 15",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/15": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation15",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p15",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 15",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 16",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/16": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation16",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p16",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 16",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 17",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/{p17}": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation17",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p17",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 17",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 18",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/18": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation18",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p18",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 18",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 19",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/19": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation19",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p19",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 19",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 20",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/20": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation20",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p20",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 20",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 21",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/{p21}": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation21",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p21",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 21",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 22",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/22": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation22",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p22",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 22",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 23",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/23": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation23",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p23",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 23",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 24",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/24": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation24",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p24",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 24",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 25",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/{p25}": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation25",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p25",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 25",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 26",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/26": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation26",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p26",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 26",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 27",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/27": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation27",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p27",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 27",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 28",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/28": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation28",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p28",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 28",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 29",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/{p29}": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation29",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p29",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 29",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 30",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/30": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation30",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p30",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 30",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 31",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/31": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation31",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p31",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 31",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 32",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/32": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation32",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p32",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 32",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 33",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/{p33}": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation33",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p33",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 33",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 34",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/34": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation34",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p34",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 34",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 35",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/35": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation35",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p35",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 35",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 36",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/36": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation36",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p36",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 36",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 37",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/{p37}": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation37",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p37",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 37",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 38",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/38": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation38",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p38",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 38",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 39",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/39": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation39",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p39",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 39",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 40",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/40": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation40",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p40",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 40",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 41",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/{p41}": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation41",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p41",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 41",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 42",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/42": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation42",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p42",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 42",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 43",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/43": {
|
||||
"post": {
|
||||
"operationId": "corpusOperation43",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "cookie",
|
||||
"name": "p43",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 43",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 44",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/44": {
|
||||
"put": {
|
||||
"operationId": "corpusOperation44",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p44",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 44",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 45",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/{p45}": {
|
||||
"patch": {
|
||||
"operationId": "corpusOperation45",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p45",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 45",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 46",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/46": {
|
||||
"delete": {
|
||||
"operationId": "corpusOperation46",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p46",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 46",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "api.example.test",
|
||||
"info": {
|
||||
"title": "Synthetic corpus 47",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/items/47": {
|
||||
"head": {
|
||||
"operationId": "corpusOperation47",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "p47",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "synthetic success",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 47",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 48",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.0.3",
|
||||
"paths": {
|
||||
"/items/48": {
|
||||
"options": {
|
||||
"operationId": "corpusOperation48",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "p48",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 48",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"title": "Synthetic corpus 49",
|
||||
"version": "1.0"
|
||||
},
|
||||
"openapi": "3.1.0",
|
||||
"paths": {
|
||||
"/items/{p49}": {
|
||||
"get": {
|
||||
"operationId": "corpusOperation49",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "p49",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "synthetic success"
|
||||
}
|
||||
},
|
||||
"summary": "Synthetic operation 49",
|
||||
"tags": [
|
||||
"corpus"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.example.test/v1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
//! Regression coverage for the bounded YAML/JSON materialization guard
|
||||
//! (Gitea #87).
|
||||
//!
|
||||
//! Alias expansions are charged against an aggregate expanded string/key
|
||||
//! budget *before* `serde_yaml` materializes an owned `Value`. The public
|
||||
//! entry points must return the controlled `ImportParseError::LimitExceeded`
|
||||
//! instead of materializing an oversized tree. Small, ordinary alias usage,
|
||||
//! duplicate keys, non-finite numbers and legacy behaviour are unchanged.
|
||||
//!
|
||||
//! The fixtures here are deliberately modest (a 16 KiB scalar with eight
|
||||
//! doubling levels expands to a few MiB, well under the risky 256 MiB
|
||||
//! reproduction) so the suite is safe to run in-process. Exact boundary
|
||||
//! arithmetic is covered by unit tests inside `decode_budget`.
|
||||
|
||||
use crank_import::rest::{
|
||||
ExternalDocumentSnapshot, ImportParseError, NormalizationConfig, SourceDigest,
|
||||
external_reference_uris, normalize_verified_bundle, normalize_verified_document,
|
||||
preview_document_legacy_v1, reference_uris, validate_document_bundle_source_safe,
|
||||
validate_document_source_safe, validate_resolved_bundle_source_safe,
|
||||
};
|
||||
|
||||
fn digest(byte: char) -> SourceDigest {
|
||||
SourceDigest::parse(byte.to_string().repeat(64)).expect("64-char digest is valid")
|
||||
}
|
||||
|
||||
/// Minimal valid OpenAPI 3.1 document with one GET operation. `extra` is
|
||||
/// inserted at the root, ahead of `servers`, for extension fields.
|
||||
fn valid_openapi(extra: &str) -> String {
|
||||
format!(
|
||||
"openapi: 3.1.0\n\
|
||||
info: {{ title: Alias budget, version: '1' }}\n\
|
||||
{extra}\
|
||||
servers: [{{ url: https://api.example.test }}]\n\
|
||||
paths:\n\
|
||||
\x20 /items:\n\
|
||||
\x20 get:\n\
|
||||
\x20 operationId: listItems\n\
|
||||
\x20 responses:\n\
|
||||
\x20 '200': {{ description: ok }}\n"
|
||||
)
|
||||
}
|
||||
|
||||
/// Root extension whose value doubles the previous alias `levels` times,
|
||||
/// starting from a 16 KiB scalar. Every per-item default limit is respected;
|
||||
/// only the aggregate materialized size grows.
|
||||
fn doubling_alias_document(levels: usize) -> String {
|
||||
let scalar = "a".repeat(16 * 1024);
|
||||
let mut extra = format!("x-expansion-0: &expansion0 \"{scalar}\"\n");
|
||||
for level in 1..levels {
|
||||
let previous = level - 1;
|
||||
extra.push_str(&format!(
|
||||
"x-expansion-{level}: &expansion{level} [*expansion{previous}, *expansion{previous}]\n"
|
||||
));
|
||||
}
|
||||
let previous = levels - 1;
|
||||
extra.push_str(&format!(
|
||||
"x-expansion: &expansion{levels} [*expansion{previous}, *expansion{previous}]\n"
|
||||
));
|
||||
valid_openapi(&extra)
|
||||
}
|
||||
|
||||
/// A compact alias chain for configurable boundary tests. The top-level value
|
||||
/// repeats the scalar `2^levels` times through aliases.
|
||||
fn alias_chain(scalar_len: usize, levels: usize) -> String {
|
||||
let scalar = "b".repeat(scalar_len);
|
||||
let mut document = format!("k0: &a0 \"{scalar}\"\n");
|
||||
for level in 1..=levels {
|
||||
let previous = level - 1;
|
||||
document.push_str(&format!(
|
||||
"k{level}: &a{level} [*a{previous}, *a{previous}]\n"
|
||||
));
|
||||
}
|
||||
document
|
||||
}
|
||||
|
||||
/// Ordinary, small alias usage that must remain accepted.
|
||||
fn small_alias_document() -> String {
|
||||
valid_openapi(
|
||||
"x-anchor: &anchor { type: string }\n\
|
||||
x-aliases: [*anchor, *anchor, *anchor]\n",
|
||||
)
|
||||
}
|
||||
|
||||
const LEVELS: usize = 8;
|
||||
|
||||
#[test]
|
||||
fn primary_source_safety_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let document = doubling_alias_document(LEVELS);
|
||||
assert_eq!(
|
||||
validate_document_source_safe(&document, &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundle_source_safety_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let document = doubling_alias_document(LEVELS);
|
||||
assert_eq!(
|
||||
validate_document_bundle_source_safe(&[document.as_str()], &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolved_source_safety_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let document = doubling_alias_document(LEVELS);
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(
|
||||
&document,
|
||||
digest('a'),
|
||||
&[],
|
||||
&NormalizationConfig::default()
|
||||
),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalization_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let document = doubling_alias_document(LEVELS);
|
||||
assert!(matches!(
|
||||
normalize_verified_document(&document, digest('a'), &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn primary_reference_uri_scan_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let document = doubling_alias_document(LEVELS);
|
||||
assert_eq!(
|
||||
reference_uris(&document, &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_reference_uri_scan_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let document = doubling_alias_document(LEVELS);
|
||||
assert_eq!(
|
||||
external_reference_uris(&document, &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supplied_external_snapshot_rejects_doubling_aliases_over_aggregate_budget() {
|
||||
let primary = valid_openapi("");
|
||||
let snapshot = ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
|
||||
digest: digest('b'),
|
||||
document: doubling_alias_document(LEVELS),
|
||||
};
|
||||
assert!(matches!(
|
||||
normalize_verified_bundle(
|
||||
&primary,
|
||||
digest('a'),
|
||||
&[snapshot],
|
||||
&NormalizationConfig::default()
|
||||
),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolved_source_safety_rejects_doubling_aliases_in_supplied_snapshot() {
|
||||
let primary = valid_openapi("");
|
||||
let snapshot = ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
|
||||
digest: digest('b'),
|
||||
document: doubling_alias_document(LEVELS),
|
||||
};
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(
|
||||
&primary,
|
||||
digest('a'),
|
||||
&[snapshot],
|
||||
&NormalizationConfig::default()
|
||||
),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn small_aliases_remain_accepted_across_public_entry_points() {
|
||||
let document = small_alias_document();
|
||||
let config = NormalizationConfig::default();
|
||||
|
||||
assert_eq!(validate_document_source_safe(&document, &config), Ok(()));
|
||||
assert_eq!(
|
||||
validate_document_bundle_source_safe(&[document.as_str()], &config),
|
||||
Ok(())
|
||||
);
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(&document, digest('a'), &[], &config),
|
||||
Ok(())
|
||||
);
|
||||
assert!(normalize_verified_document(&document, digest('a'), &config).is_ok());
|
||||
assert_eq!(reference_uris(&document, &config), Ok(Vec::new()));
|
||||
assert_eq!(external_reference_uris(&document, &config), Ok(Vec::new()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_keys_are_still_rejected_as_invalid_document() {
|
||||
let document = valid_openapi("x-dup: 1\nx-dup: 2\n");
|
||||
assert_eq!(
|
||||
validate_document_source_safe(&document, &NormalizationConfig::default()),
|
||||
Err(ImportParseError::InvalidDocument)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_yaml_scalars_are_still_rejected_as_invalid_document() {
|
||||
let document = valid_openapi("x-nonfinite: .inf\n");
|
||||
assert_eq!(
|
||||
validate_document_source_safe(&document, &NormalizationConfig::default()),
|
||||
Err(ImportParseError::InvalidDocument)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_expansion_below_boundary_is_accepted_and_above_is_rejected() {
|
||||
// allowance = 16 * max(max_bytes, max_scalar_bytes) = 16 * 4096 = 65536.
|
||||
let config = NormalizationConfig {
|
||||
max_bytes: 4096,
|
||||
max_scalar_bytes: 64,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let below = alias_chain(60, 9); // ~61_400 expanded string bytes
|
||||
let above = alias_chain(60, 10); // ~122_800 expanded string bytes
|
||||
assert!(
|
||||
below.len() <= config.max_bytes,
|
||||
"fixture must fit raw limit"
|
||||
);
|
||||
assert!(
|
||||
above.len() <= config.max_bytes,
|
||||
"fixture must fit raw limit"
|
||||
);
|
||||
|
||||
assert_eq!(reference_uris(&below, &config), Ok(Vec::new()));
|
||||
assert_eq!(
|
||||
reference_uris(&above, &config),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordinary_alias_output_matches_expanded_equivalent() {
|
||||
let aliased = valid_openapi("x-shared: &shared { type: string }\nx-copy: *shared\n");
|
||||
let expanded = valid_openapi("x-shared: { type: string }\nx-copy: { type: string }\n");
|
||||
let config = NormalizationConfig::default();
|
||||
let aliased = normalize_verified_document(&aliased, digest('a'), &config)
|
||||
.expect("aliased fixture parses");
|
||||
let expanded = normalize_verified_document(&expanded, digest('a'), &config)
|
||||
.expect("expanded fixture parses");
|
||||
assert_eq!(aliased, expanded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_duplicate_keys_keep_historical_invalid_document() {
|
||||
// The legacy `serde_yaml::Value` mapping rejects duplicate keys, the same
|
||||
// as the strict decoder; the preflight must not change that.
|
||||
let document = "openapi: 3.0.3\n\
|
||||
info: { title: Legacy, version: '1' }\n\
|
||||
info: { title: Second, version: '1' }\n\
|
||||
paths:\n\
|
||||
\x20 /x:\n\
|
||||
\x20 get:\n\
|
||||
\x20 responses:\n\
|
||||
\x20 '200': { description: ok }\n";
|
||||
assert_eq!(
|
||||
preview_document_legacy_v1(document),
|
||||
Err(ImportParseError::InvalidDocument)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_tagged_extension_keeps_historical_mapping_conversion() {
|
||||
let document = "openapi: 3.0.3\n\
|
||||
info: { title: Legacy tag, version: '1' }\n\
|
||||
x-tagged: !Thing value\n\
|
||||
paths:\n\
|
||||
\x20 /x:\n\
|
||||
\x20 get:\n\
|
||||
\x20 responses:\n\
|
||||
\x20 '200': { description: ok }\n";
|
||||
assert!(preview_document_legacy_v1(document).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_non_finite_numbers_keep_historical_null_conversion() {
|
||||
// The legacy path converts through `serde_yaml::Value` and then JSON, so a
|
||||
// non-finite number becomes `null` and stays accepted; the strict decoder
|
||||
// rejects it (covered above). The permissive preflight must preserve this.
|
||||
let document = "openapi: 3.0.3\n\
|
||||
info: { title: Legacy non-finite, version: '1' }\n\
|
||||
x-nonfinite: .inf\n\
|
||||
paths:\n\
|
||||
\x20 /x:\n\
|
||||
\x20 get:\n\
|
||||
\x20 responses:\n\
|
||||
\x20 '200': { description: ok }\n";
|
||||
assert!(preview_document_legacy_v1(document).is_ok());
|
||||
}
|
||||
|
||||
fn snapshot(document: &str) -> ExternalDocumentSnapshot {
|
||||
ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
|
||||
digest: digest('b'),
|
||||
document: document.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_bundle_document_count_is_capped_before_preflight() {
|
||||
// Without the early count guard the empty documents would fail later as
|
||||
// InvalidDocument; the explicit cap must win with LimitExceeded.
|
||||
let config = NormalizationConfig {
|
||||
max_reference_documents: 1,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let documents = ["", "", ""];
|
||||
assert_eq!(
|
||||
validate_document_bundle_source_safe(&documents, &config),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolved_bundle_snapshot_count_is_capped_before_preflight() {
|
||||
let config = NormalizationConfig {
|
||||
max_reference_documents: 0,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let primary = valid_openapi("");
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(&primary, digest('a'), &[snapshot("{}")], &config),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundle_snapshot_raw_bytes_and_aliases_are_guarded_before_preflight() {
|
||||
let primary = valid_openapi("");
|
||||
let bytes_config = NormalizationConfig {
|
||||
max_external_document_bytes: 4,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
assert!(matches!(
|
||||
normalize_verified_bundle(
|
||||
&primary,
|
||||
digest('a'),
|
||||
&[snapshot("{\"a\":1}")],
|
||||
&bytes_config
|
||||
),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
));
|
||||
|
||||
let alias_config = NormalizationConfig {
|
||||
max_aliases: 8,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let aliased = "a: &x 1\nb: [*x, *x, *x, *x, *x, *x, *x, *x, *x]\n";
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(
|
||||
&primary,
|
||||
digest('a'),
|
||||
&[snapshot(aliased)],
|
||||
&alias_config
|
||||
),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use crank_core::HttpMethod;
|
||||
use crank_import::rest::model::NormalizedScalarKind;
|
||||
use crank_import::rest::model::{NormalizedFinding, NormalizedLiteral, NormalizedScalarKind};
|
||||
use crank_import::rest::{
|
||||
ImportFindingSeverity, NormalizationConfig, NormalizedSchemaKind, SourceDigest,
|
||||
normalize_verified_document, validate_normalized_ir,
|
||||
@@ -14,6 +14,217 @@ fn normalize(document: &str) -> crank_import::rest::NormalizedIr {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undeclared_path_placeholders_are_exact_blockers_in_all_supported_formats() {
|
||||
let openapi31 = r#"
|
||||
openapi: 3.1.0
|
||||
info: {title: Missing path declaration, version: '1'}
|
||||
servers: [{url: https://example.test}]
|
||||
paths:
|
||||
/items/{item_id}:
|
||||
get:
|
||||
operationId: getItem
|
||||
responses: {'200': {description: ok}}
|
||||
"#;
|
||||
let openapi30 = openapi31.replace("3.1.0", "3.0.3");
|
||||
let swagger2 = r#"
|
||||
swagger: '2.0'
|
||||
info: {title: Missing path declaration, version: '1'}
|
||||
host: example.test
|
||||
schemes: [https]
|
||||
paths:
|
||||
/items/{item_id}:
|
||||
get:
|
||||
operationId: getItem
|
||||
responses: {'200': {description: ok}}
|
||||
"#;
|
||||
let documents = [
|
||||
("OpenAPI 3.1", openapi31),
|
||||
("OpenAPI 3.0", openapi30.as_str()),
|
||||
("Swagger 2.0", swagger2),
|
||||
];
|
||||
|
||||
for (version, document) in documents {
|
||||
let ir = normalize(document);
|
||||
validate_normalized_ir(&ir).expect("the source-attested path blocker must validate");
|
||||
let operation = &ir.operations[0];
|
||||
assert!(
|
||||
operation.findings.iter().any(|finding| {
|
||||
finding.code == "path_parameter_not_declared"
|
||||
&& finding.severity == ImportFindingSeverity::Error
|
||||
&& finding.operation_key.as_deref() == Some("GET /items/{item_id}")
|
||||
&& finding.location.pointer == "/paths/~1items~1{item_id}/get"
|
||||
}),
|
||||
"{version} must report an undeclared path placeholder at the existing operation node: {:?}",
|
||||
operation.findings
|
||||
);
|
||||
}
|
||||
|
||||
let declared = r#"
|
||||
openapi: 3.1.0
|
||||
info: {title: Declared path parameter, version: '1'}
|
||||
servers: [{url: https://example.test}]
|
||||
paths:
|
||||
/items/{item_id}:
|
||||
get:
|
||||
operationId: getItem
|
||||
parameters:
|
||||
- {name: item_id, in: path, required: true, schema: {type: string}}
|
||||
responses: {'200': {description: ok}}
|
||||
"#;
|
||||
let mut ir = normalize(declared);
|
||||
let operation = &mut ir.operations[0];
|
||||
operation.findings.push(NormalizedFinding {
|
||||
code: "path_parameter_not_declared".to_owned(),
|
||||
severity: ImportFindingSeverity::Error,
|
||||
message: "fabricated blocker".to_owned(),
|
||||
construct_id: operation.stable_id.clone(),
|
||||
location: operation.location.clone(),
|
||||
operation_key: Some(operation.key.clone()),
|
||||
});
|
||||
assert!(
|
||||
validate_normalized_ir(&ir).is_err(),
|
||||
"a path blocker must not validate when the canonical source declares the placeholder"
|
||||
);
|
||||
|
||||
let referenced = r#"
|
||||
openapi: 3.1.0
|
||||
info: {title: Referenced path parameter, version: '1'}
|
||||
servers: [{url: https://example.test}]
|
||||
paths:
|
||||
/items/{item_id}:
|
||||
get:
|
||||
operationId: getItem
|
||||
parameters: [{$ref: '#/components/parameters/ItemId'}]
|
||||
responses: {'200': {description: ok}}
|
||||
components:
|
||||
parameters:
|
||||
ItemId: {name: item_id, in: path, required: true, schema: {type: string}}
|
||||
"#;
|
||||
let mut ir = normalize(referenced);
|
||||
validate_normalized_ir(&ir).expect("a resolved referenced path parameter must validate");
|
||||
let operation = &mut ir.operations[0];
|
||||
assert!(operation.parameters.iter().any(|parameter| {
|
||||
parameter.name == "item_id"
|
||||
&& parameter.location == crank_import::rest::model::RestParameterLocation::Path
|
||||
}));
|
||||
operation.findings.push(NormalizedFinding {
|
||||
code: "path_parameter_not_declared".to_owned(),
|
||||
severity: ImportFindingSeverity::Error,
|
||||
message: "fabricated blocker".to_owned(),
|
||||
construct_id: operation.stable_id.clone(),
|
||||
location: operation.location.clone(),
|
||||
operation_key: Some(operation.key.clone()),
|
||||
});
|
||||
assert!(
|
||||
validate_normalized_ir(&ir).is_err(),
|
||||
"a blocker must not validate when a referenced parameter is effective"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_schema_defaults_are_blocked_without_changing_scalar_defaults() {
|
||||
let openapi31 = r#"
|
||||
openapi: 3.1.0
|
||||
info: {title: Compound defaults, version: '1'}
|
||||
servers: [{url: https://example.test}]
|
||||
paths:
|
||||
/defaults:
|
||||
get:
|
||||
operationId: getDefaults
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
compound: {type: object, default: {nested: value}}
|
||||
list: {type: array, items: {type: string}, default: [a, b]}
|
||||
scalar: {type: string, default: original}
|
||||
"#;
|
||||
let openapi30 = openapi31.replace("3.1.0", "3.0.3");
|
||||
let swagger2 = r#"
|
||||
swagger: '2.0'
|
||||
info: {title: Compound defaults, version: '1'}
|
||||
host: example.test
|
||||
schemes: [https]
|
||||
paths:
|
||||
/defaults:
|
||||
get:
|
||||
operationId: getDefaults
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
compound: {type: object, default: {nested: value}}
|
||||
list: {type: array, items: {type: string}, default: [a, b]}
|
||||
scalar: {type: string, default: original}
|
||||
"#;
|
||||
let documents = [
|
||||
("OpenAPI 3.1", openapi31),
|
||||
("OpenAPI 3.0", openapi30.as_str()),
|
||||
("Swagger 2.0", swagger2),
|
||||
];
|
||||
|
||||
for (version, document) in documents {
|
||||
let ir = normalize(document);
|
||||
validate_normalized_ir(&ir).expect("source-attested compound blockers must validate");
|
||||
let operation = &ir.operations[0];
|
||||
let mut blockers = operation
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| finding.code == "unsupported_compound_default")
|
||||
.collect::<Vec<_>>();
|
||||
blockers.sort_by(|left, right| left.location.pointer.cmp(&right.location.pointer));
|
||||
assert_eq!(
|
||||
blockers.len(),
|
||||
2,
|
||||
"{version} should block only object/array defaults: {:?}",
|
||||
operation.findings
|
||||
);
|
||||
assert!(blockers.iter().all(|finding| {
|
||||
finding.severity == ImportFindingSeverity::Error
|
||||
&& finding.location.pointer.ends_with("/default")
|
||||
&& finding.operation_key.as_deref() == Some("GET /defaults")
|
||||
}));
|
||||
let Some(NormalizedSchemaKind::Object { properties, .. }) = operation
|
||||
.response_variants
|
||||
.first()
|
||||
.and_then(|variant| variant.schema.as_ref())
|
||||
.map(|schema| &schema.kind)
|
||||
else {
|
||||
panic!("{version} response schema should remain an object");
|
||||
};
|
||||
assert!(matches!(
|
||||
&properties["scalar"].kind,
|
||||
NormalizedSchemaKind::Scalar { default_value: Some(value), .. }
|
||||
if value == &NormalizedLiteral::String("original".to_owned())
|
||||
));
|
||||
|
||||
let mut tampered = ir.clone();
|
||||
let operation = &mut tampered.operations[0];
|
||||
let scalar_default = operation
|
||||
.findings
|
||||
.iter_mut()
|
||||
.find(|finding| finding.code == "unsupported_compound_default")
|
||||
.unwrap();
|
||||
let scalar_pointer = if version == "Swagger 2.0" {
|
||||
"/paths/~1defaults/get/responses/200/schema/properties/scalar/default"
|
||||
} else {
|
||||
"/paths/~1defaults/get/responses/200/content/application~1json/schema/properties/scalar/default"
|
||||
};
|
||||
scalar_default.location.pointer = scalar_pointer.to_owned();
|
||||
assert!(
|
||||
validate_normalized_ir(&tampered).is_err(),
|
||||
"{version} must reject a compound-default finding moved onto a scalar source value"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn variants_keep_exact_schema_coverage_and_reject_tampered_provenance() {
|
||||
let document = r#"
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
use crank_import::rest::{NormalizationConfig, SourceDigest, normalize_verified_document};
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[test]
|
||||
fn path_item_parameters_are_inherited_and_operation_parameters_override_by_name_and_location() {
|
||||
for version in ["3.0.3", "3.1.0", "2.0"] {
|
||||
let parameter = |name: &str, location: &str, kind: &str| {
|
||||
if version == "2.0" {
|
||||
json!({"name":name,"in":location,"required":location == "path","type":kind})
|
||||
} else {
|
||||
json!({"name":name,"in":location,"required":location == "path","schema":{"type":kind}})
|
||||
}
|
||||
};
|
||||
let mut document = if version == "2.0" {
|
||||
json!({"swagger":"2.0","info":{"title":"Path parameters","version":"1"}})
|
||||
} else {
|
||||
json!({"openapi":version,"info":{"title":"Path parameters","version":"1"},"servers":[{"url":"https://example.test"}]})
|
||||
};
|
||||
document["paths"] = json!({
|
||||
"/items/{id}": {
|
||||
"parameters": [parameter("id", "path", "string"), parameter("filter", "query", "string")],
|
||||
"get": {"operationId":"readItem","responses":{"200":{"description":"ok"}}},
|
||||
"post": {"operationId":"updateItem","parameters":[parameter("filter", "query", "integer")],
|
||||
"responses":{"200":{"description":"ok"}}}
|
||||
}
|
||||
});
|
||||
let source = serde_json::to_string(&document).unwrap();
|
||||
let digest =
|
||||
SourceDigest::parse(format!("{:x}", Sha256::digest(source.as_bytes()))).unwrap();
|
||||
let ir =
|
||||
normalize_verified_document(&source, digest, &NormalizationConfig::default()).unwrap();
|
||||
for (key, expected_kind) in [
|
||||
("GET /items/{id}", "string"),
|
||||
("POST /items/{id}", "integer"),
|
||||
] {
|
||||
let operation = ir
|
||||
.operations
|
||||
.iter()
|
||||
.find(|operation| operation.key == key)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
operation.parameters.len(),
|
||||
2,
|
||||
"{version} {key}: {:?}",
|
||||
operation.parameters
|
||||
);
|
||||
let id = operation
|
||||
.parameters
|
||||
.iter()
|
||||
.find(|parameter| parameter.name == "id")
|
||||
.unwrap();
|
||||
assert_eq!(id.location, crank_import::rest::RestParameterLocation::Path);
|
||||
let filter = operation
|
||||
.parameters
|
||||
.iter()
|
||||
.find(|parameter| parameter.name == "filter")
|
||||
.unwrap();
|
||||
let schema = serde_json::to_value(filter.schema.as_ref().unwrap()).unwrap();
|
||||
assert_eq!(
|
||||
schema["kind"]["scalar_type"],
|
||||
Value::String(expected_kind.to_owned()),
|
||||
"{version} {key}: {schema}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,19 @@ definitions:
|
||||
assert_eq!(operation.draft.input_mapping.rules.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn historical_preview_without_locations_still_deserializes() {
|
||||
let old = serde_json::to_value(preview_document_legacy_v1(OPENAPI3).unwrap()).unwrap();
|
||||
let replay: crank_import::rest::ImportPreview = serde_json::from_value(old).unwrap();
|
||||
assert!(replay.groups[0].operations[0].source_location.is_none());
|
||||
assert!(
|
||||
replay.groups[0].operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.source_location.is_none())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn previews_swagger2_and_resolves_local_definitions() {
|
||||
let preview = preview_document(SWAGGER2).unwrap();
|
||||
@@ -511,6 +524,26 @@ paths:
|
||||
assert!(codes.contains(&"missing_summary"));
|
||||
assert!(codes.contains(&"missing_description"));
|
||||
assert!(codes.contains(&"missing_response_schema"));
|
||||
assert_eq!(
|
||||
operation
|
||||
.source_location
|
||||
.as_ref()
|
||||
.map(|location| location.pointer.as_str()),
|
||||
Some("/paths/~1items/get")
|
||||
);
|
||||
assert!(operation.findings.iter().any(|finding| {
|
||||
finding.code == "missing_operation_id"
|
||||
&& finding
|
||||
.source_location
|
||||
.as_ref()
|
||||
.is_some_and(|location| location.pointer == "/paths/~1items/get/operationId")
|
||||
}));
|
||||
assert!(
|
||||
operation
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.source_location.is_some())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -656,6 +689,13 @@ paths:
|
||||
.filter(|finding| finding.code == "unsupported_http_method")
|
||||
.count();
|
||||
assert_eq!(unsupported, 2);
|
||||
assert!(preview.findings.iter().any(|finding| {
|
||||
finding.code == "unsupported_http_method"
|
||||
&& finding
|
||||
.source_location
|
||||
.as_ref()
|
||||
.is_some_and(|location| location.pointer == "/paths/~1health/trace")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
//! Regressions for the `$ref` expansion aggregate string/key byte budget
|
||||
//! (Gitea #88).
|
||||
//!
|
||||
//! `reference::resolve` clones the referenced target subtree per `$ref`
|
||||
//! occurrence. Many individually small (but not tiny) targets therefore
|
||||
//! multiply into a large materialized tree while staying under
|
||||
//! `max_references`, `max_expanded_nodes`, `max_nodes`, `max_collection_items`
|
||||
//! and `max_scalar_bytes`; a bounded probe reproduced a child address-space
|
||||
//! abort for such an input. The aggregate copy budget must reject these with
|
||||
//! `ImportParseError::LimitExceeded` before the copies allocate, for both local
|
||||
//! and supplied external references, while small ordinary usage keeps working.
|
||||
//!
|
||||
//! The fixture is deliberately modest (16 KiB payload, 400 references → ≈6.4
|
||||
//! MiB expanded, far below the risky 256 MiB reproduction and below 20 MiB).
|
||||
|
||||
use crank_import::rest::{
|
||||
ExternalDocumentSnapshot, ImportParseError, NormalizationConfig, SourceDigest,
|
||||
normalize_verified_document, validate_resolved_bundle_source_safe,
|
||||
};
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
const DESCRIPTION_BYTES: usize = 16 * 1024;
|
||||
const EXPANDING_REFS: usize = 400;
|
||||
const EXTERNAL_URI: &str = "https://schemas.example.test/root.yaml";
|
||||
|
||||
// The fixture must stay comfortably below the unsafe reproduction size.
|
||||
const _: () = assert!(DESCRIPTION_BYTES * EXPANDING_REFS < 20 * 1024 * 1024);
|
||||
|
||||
fn digest(byte: char) -> SourceDigest {
|
||||
SourceDigest::parse(byte.to_string().repeat(64)).expect("64-char digest is valid")
|
||||
}
|
||||
|
||||
fn big_schema() -> Value {
|
||||
json!({
|
||||
"type": "object",
|
||||
"description": "x".repeat(DESCRIPTION_BYTES),
|
||||
"properties": { "id": { "type": "string" } }
|
||||
})
|
||||
}
|
||||
|
||||
fn big_schema_with_large_property_key() -> Value {
|
||||
let mut properties = Map::new();
|
||||
properties.insert("k".repeat(DESCRIPTION_BYTES), json!({ "type": "string" }));
|
||||
json!({ "type": "object", "properties": Value::Object(properties) })
|
||||
}
|
||||
|
||||
fn document_with_refs(ref_uri: &str, ref_count: usize) -> String {
|
||||
let all_of: Vec<Value> = (0..ref_count).map(|_| json!({ "$ref": ref_uri })).collect();
|
||||
let document = json!({
|
||||
"openapi": "3.1.0",
|
||||
"info": { "title": "Ref budget", "version": "1" },
|
||||
"servers": [{ "url": "https://api.example.test" }],
|
||||
"paths": {
|
||||
"/items": {
|
||||
"get": {
|
||||
"operationId": "listItems",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": { "allOf": all_of }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
serde_json::to_string(&document).expect("document serializes")
|
||||
}
|
||||
|
||||
fn local_ref_document(ref_count: usize) -> String {
|
||||
local_ref_document_with(big_schema(), ref_count)
|
||||
}
|
||||
|
||||
fn local_ref_document_with(schema: Value, ref_count: usize) -> String {
|
||||
let mut document: Value =
|
||||
serde_json::from_str(&document_with_refs("#/components/schemas/Big", ref_count))
|
||||
.expect("valid JSON");
|
||||
document["components"] = json!({ "schemas": { "Big": schema } });
|
||||
serde_json::to_string(&document).expect("document serializes")
|
||||
}
|
||||
|
||||
fn external_ref_document(ref_count: usize) -> String {
|
||||
let uri = format!("{EXTERNAL_URI}#/Big");
|
||||
document_with_refs(&uri, ref_count)
|
||||
}
|
||||
|
||||
fn external_snapshot() -> ExternalDocumentSnapshot {
|
||||
let document =
|
||||
serde_json::to_string(&json!({ "Big": big_schema() })).expect("snapshot serializes");
|
||||
ExternalDocumentSnapshot {
|
||||
canonical_uri: EXTERNAL_URI.to_owned(),
|
||||
digest: digest('b'),
|
||||
document,
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_fits_raw_limit(document: &str) {
|
||||
assert!(
|
||||
document.len() < NormalizationConfig::default().max_bytes,
|
||||
"fixture must stay under the raw byte limit, got {} bytes",
|
||||
document.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_ref_expansion_over_aggregate_budget_is_rejected() {
|
||||
let document = local_ref_document(EXPANDING_REFS);
|
||||
assert_fits_raw_limit(&document);
|
||||
assert!(matches!(
|
||||
normalize_verified_document(&document, digest('a'), &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_ref_expansion_counts_large_object_keys() {
|
||||
let document = local_ref_document_with(big_schema_with_large_property_key(), EXPANDING_REFS);
|
||||
assert_fits_raw_limit(&document);
|
||||
assert!(matches!(
|
||||
normalize_verified_document(&document, digest('a'), &NormalizationConfig::default()),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supplied_external_ref_expansion_over_aggregate_budget_is_rejected() {
|
||||
let primary = external_ref_document(EXPANDING_REFS);
|
||||
assert_fits_raw_limit(&primary);
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(
|
||||
&primary,
|
||||
digest('a'),
|
||||
&[external_snapshot()],
|
||||
&NormalizationConfig::default()
|
||||
),
|
||||
Err(ImportParseError::LimitExceeded)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_local_ref_stays_within_budget() {
|
||||
let document = local_ref_document(1);
|
||||
let ir = normalize_verified_document(&document, digest('a'), &NormalizationConfig::default())
|
||||
.expect("a single reference must stay within the expanded budget");
|
||||
assert_eq!(ir.operations.len(), 1);
|
||||
assert_eq!(ir.reference_graph.edges.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_local_refs_stay_within_budget() {
|
||||
let document = local_ref_document(4);
|
||||
assert!(
|
||||
normalize_verified_document(&document, digest('a'), &NormalizationConfig::default())
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_supplied_external_ref_stays_within_budget() {
|
||||
let primary = external_ref_document(1);
|
||||
assert_eq!(
|
||||
validate_resolved_bundle_source_safe(
|
||||
&primary,
|
||||
digest('a'),
|
||||
&[external_snapshot()],
|
||||
&NormalizationConfig::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use crank_import::rest::{
|
||||
ExternalDocumentSnapshot, ImportFindingSeverity, NormalizationConfig, NormalizedSchemaKind,
|
||||
SourceDigest, external_reference_uris, normalize_verified_bundle, normalize_verified_document,
|
||||
preview_from_ir, reference_uris,
|
||||
ExternalDocumentSnapshot, ImportFindingSeverity, ImportParseError, NormalizationConfig,
|
||||
NormalizedSchemaKind, SourceDigest, external_reference_uris, normalize_verified_bundle,
|
||||
normalize_verified_document, preview_from_ir, reference_uris,
|
||||
};
|
||||
|
||||
fn digest(byte: char) -> SourceDigest {
|
||||
@@ -189,6 +189,162 @@ paths:
|
||||
assert!(first.unresolved_references.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_duplicate_keys_in_external_snapshot_json_and_yaml_fallback() {
|
||||
let document = r#"
|
||||
openapi: 3.1.0
|
||||
info: { title: Duplicate snapshot keys }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: listItems
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content: { application/json: { schema: { $ref: 'https://schemas.example.test/root.yaml#/Item' } } }
|
||||
"#;
|
||||
let snapshots = [
|
||||
r#"{"Item":{"type":"string","type":"integer"}}"#,
|
||||
"Item: { type: string }\nItem: { type: integer }",
|
||||
// JSON flow syntax is also accepted by the YAML fallback, so a strict
|
||||
// JSON duplicate failure must not become a last-key-wins YAML parse.
|
||||
r#"{"Item":{"type":"string","type":"integer"},"title":"snapshot"}"#,
|
||||
];
|
||||
|
||||
for snapshot in snapshots {
|
||||
let result = normalize_verified_bundle(
|
||||
document,
|
||||
digest('a'),
|
||||
&[ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
|
||||
digest: digest('b'),
|
||||
document: snapshot.to_owned(),
|
||||
}],
|
||||
&NormalizationConfig::default(),
|
||||
);
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"duplicate snapshot keys must fail closed: {snapshot}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_duplicate_keys_in_new_primary_json_documents() {
|
||||
let document = r#"{"openapi":"3.1.0","info":{"title":"duplicates","version":"1"},"servers":[{"url":"https://api.example.test"}],"paths":{"/items":{"get":{"operationId":"firstName","operationId":"lastName","responses":{"200":{"description":"ok"}}}}}}"#;
|
||||
assert!(matches!(
|
||||
normalize_verified_document(document, digest('a'), &NormalizationConfig::default()),
|
||||
Err(ImportParseError::InvalidDocument)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_primary_decoder_preserves_yaml_flow_syntax() {
|
||||
let document = "openapi: 3.1.0\ninfo: { title: Flow, version: '1' }\nservers: [{ url: https://api.example.test }]\npaths: { /items: { get: { operationId: listItems, responses: { '200': { description: ok } } } } }\n";
|
||||
assert!(
|
||||
normalize_verified_document(document, digest('a'), &NormalizationConfig::default()).is_ok()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uppercase_external_scheme_is_classified_as_external_reference() {
|
||||
let document = r#"
|
||||
openapi: 3.1.0
|
||||
info: { title: Uppercase external }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: listItems
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content: { application/json: { schema: { $ref: 'HTTPS://missing.example/schema.json' } } }
|
||||
"#;
|
||||
let ir = normalize(document);
|
||||
assert!(
|
||||
ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == "external_reference_disabled"),
|
||||
"uppercase HTTPS ref must be classified as an external reference, got: {:?}",
|
||||
ir.operations[0].findings
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabled_uppercase_https_ref_with_fragment_is_unavailable() {
|
||||
let document = r#"
|
||||
openapi: 3.1.0
|
||||
info: { title: Uppercase external enabled }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: listItems
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content: { application/json: { schema: { $ref: 'HTTPS://missing.example/schema.json#/Item' } } }
|
||||
"#;
|
||||
let config = NormalizationConfig {
|
||||
external_references_enabled: true,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let ir = normalize_verified_document(document, digest('a'), &config).unwrap();
|
||||
assert!(
|
||||
ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == "external_reference_unavailable"),
|
||||
"enabled uppercase HTTPS ref with fragment must be classified unavailable, got: {:?}",
|
||||
ir.operations[0].findings
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_idn_reference_matches_punycode_canonical_snapshot() {
|
||||
let document = r#"
|
||||
openapi: 3.1.0
|
||||
info: { title: IDN identity }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: listItems
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content: { application/json: { schema: { $ref: 'https://пример.example/schema.json#/Item' } } }
|
||||
"#;
|
||||
let snapshots = vec![ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://xn--e1afmkfd.example/schema.json".to_owned(),
|
||||
digest: digest('b'),
|
||||
document: "Item: { type: object, properties: { id: { type: string } } }".to_owned(),
|
||||
}];
|
||||
let config = NormalizationConfig {
|
||||
external_references_enabled: true,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let ir = normalize_verified_bundle(document, digest('a'), &snapshots, &config).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
ir.operations[0].response_schema.as_ref().map(|schema| &schema.kind),
|
||||
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
|
||||
),
|
||||
"Unicode IDN ref must match the punycode canonical snapshot"
|
||||
);
|
||||
assert!(
|
||||
ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| !finding.code.starts_with("external_reference")),
|
||||
"resolved IDN snapshot must not produce external findings: {:?}",
|
||||
ir.operations[0].findings
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursion_is_a_stable_graph_edge_without_unbounded_expansion() {
|
||||
let document = r#"
|
||||
|
||||
Loaded 100 of 244 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user