feat(import): preserve supported HTTP contracts
This commit is contained in:
1 parent
083974c27f
commit
f8ee7c9bfe
87 files changed
+7496
-534
No files matched your search
@@ -9,8 +9,8 @@ use serde_json::Value;
|
||||
/// The immutable contract used to normalize an OpenAPI source. These names
|
||||
/// deliberately travel with an import job: changing either contract must not
|
||||
/// silently reinterpret a pending preview.
|
||||
pub const NORMALIZER_VERSION: &str = "normalized-ir-v3";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v3";
|
||||
pub const NORMALIZER_VERSION: &str = "normalized-ir-v4";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v4";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
|
||||
pub struct SourceDigest(String);
|
||||
@@ -242,11 +242,35 @@ pub struct NormalizedOperation {
|
||||
pub request_body_schema: Option<NormalizedSchema>,
|
||||
pub response_schema: Option<NormalizedSchema>,
|
||||
#[serde(default)]
|
||||
pub request_body_variants: Vec<NormalizedRequestBodyVariant>,
|
||||
#[serde(default)]
|
||||
pub response_variants: Vec<NormalizedResponseVariant>,
|
||||
#[serde(default)]
|
||||
pub servers: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub findings: Vec<NormalizedFinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NormalizedRequestBodyVariant {
|
||||
pub content_type: String,
|
||||
pub required: bool,
|
||||
pub schema: Option<NormalizedSchema>,
|
||||
/// MIME types allowed for individual multipart fields, keyed by source
|
||||
/// property name. Empty when the source does not constrain a field.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub multipart_field_mime_types: BTreeMap<String, Vec<String>>,
|
||||
pub source_location: SourceLocation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NormalizedResponseVariant {
|
||||
pub status_code: u16,
|
||||
pub content_type: Option<String>,
|
||||
pub schema: Option<NormalizedSchema>,
|
||||
pub source_location: SourceLocation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NormalizedParameter {
|
||||
pub name: String,
|
||||
@@ -306,9 +330,13 @@ pub enum NormalizedSchemaKind {
|
||||
Object {
|
||||
properties: BTreeMap<String, NormalizedSchema>,
|
||||
required: Vec<String>,
|
||||
nullable: bool,
|
||||
default_value: Option<NormalizedLiteral>,
|
||||
},
|
||||
Array {
|
||||
items: Option<Box<NormalizedSchema>>,
|
||||
nullable: bool,
|
||||
default_value: Option<NormalizedLiteral>,
|
||||
},
|
||||
Reference {
|
||||
reference: UnresolvedReference,
|
||||
@@ -468,11 +496,21 @@ pub struct RestImportOperation {
|
||||
pub request_body_schema: Option<Value>,
|
||||
#[serde(skip)]
|
||||
pub request_body_schema_location: Option<SourceLocation>,
|
||||
/// Every executable request variant. `request_body_schema` remains for
|
||||
/// legacy replay only; modern projection must use this complete list.
|
||||
#[serde(default)]
|
||||
pub request_body_variants: Vec<RestRequestBodyVariant>,
|
||||
pub response_schema: Option<Value>,
|
||||
#[serde(skip)]
|
||||
pub response_schema_location: Option<SourceLocation>,
|
||||
/// All successful response branches, including explicit no-content
|
||||
/// outcomes. The old singular field is retained for legacy-v1 jobs.
|
||||
#[serde(default)]
|
||||
pub response_variants: Vec<RestResponseVariant>,
|
||||
pub servers: Vec<String>,
|
||||
pub findings: Vec<ImportFinding>,
|
||||
#[serde(skip)]
|
||||
pub internal_finding_locations: Vec<SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -488,6 +526,37 @@ pub struct RestImportParameter {
|
||||
pub schema_source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RestRequestBodyVariant {
|
||||
pub content_type: String,
|
||||
pub required: bool,
|
||||
pub schema: Option<Value>,
|
||||
/// MIME types from OpenAPI's multipart `encoding.*.contentType`.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub multipart_field_mime_types: BTreeMap<String, Vec<String>>,
|
||||
#[serde(skip, default = "empty_source_location")]
|
||||
pub source_location: SourceLocation,
|
||||
#[serde(skip, default)]
|
||||
pub schema_source_location: Option<SourceLocation>,
|
||||
/// Swagger 2 formData schemas are assembled from independent parameters.
|
||||
/// This keeps each generated property tied to its original parameter.
|
||||
#[serde(skip, default)]
|
||||
pub schema_property_source_locations: BTreeMap<String, SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RestResponseVariant {
|
||||
pub status_code: u16,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub schema: Option<Value>,
|
||||
#[serde(skip, default = "empty_source_location")]
|
||||
pub source_location: SourceLocation,
|
||||
#[serde(skip, default)]
|
||||
pub schema_source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
fn empty_source_location() -> SourceLocation {
|
||||
SourceLocation {
|
||||
pointer: String::new(),
|
||||
@@ -500,4 +569,5 @@ pub enum RestParameterLocation {
|
||||
Path,
|
||||
Query,
|
||||
Header,
|
||||
Cookie,
|
||||
}
|
||||
Reference in new issue
Block a user