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
@@ -0,0 +1,49 @@
|
||||
use crank_import::rest::preview_document_legacy_v1;
|
||||
use crank_schema::SchemaKind;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn legacy_v1_keeps_reserved_names_flattening_and_scalar_semantics() {
|
||||
let preview = preview_document_legacy_v1(
|
||||
r#"
|
||||
openapi: 3.0.3
|
||||
info: {title: Legacy contract}
|
||||
servers: [{url: 'https://example.test'}]
|
||||
paths:
|
||||
/items/{id}:
|
||||
head:
|
||||
responses: {'204': {description: Empty}}
|
||||
post:
|
||||
operationId: createItem
|
||||
parameters:
|
||||
- {in: path, name: id, schema: {type: string}}
|
||||
- {in: query, name: body, schema: {type: string, default: old, nullable: true}}
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
file: {type: string, format: binary}
|
||||
responses:
|
||||
'200': {description: OK, content: {application/json: {schema: {type: string}}}}
|
||||
'204': {description: Empty}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(preview.groups[0].operations.len(), 1);
|
||||
let draft = &preview.groups[0].operations[0].draft;
|
||||
assert!(draft.input_schema.fields["id"].required);
|
||||
assert_eq!(draft.input_schema.fields["file"].kind, SchemaKind::String);
|
||||
assert_eq!(draft.input_schema.fields["file"].format, None);
|
||||
assert!(!draft.input_schema.fields["body"].nullable);
|
||||
assert_eq!(draft.input_schema.fields["body"].default_value, None);
|
||||
assert!(draft.target.response_contract.is_empty());
|
||||
let mapped = draft
|
||||
.input_mapping
|
||||
.apply(&json!({"mcp": {"id": "1", "body": "query-value", "file": "legacy-string"}}))
|
||||
.unwrap();
|
||||
assert_eq!(mapped["request"]["query"]["body"], "query-value");
|
||||
assert_eq!(mapped["request"]["body"], json!({"file": "legacy-string"}));
|
||||
assert_eq!(draft.output_schema.kind, SchemaKind::String);
|
||||
}
|
||||
Reference in new issue
Block a user