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,64 @@
|
||||
use crank_import::rest::preview_document;
|
||||
use crank_schema::SchemaKind;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn preserves_format_default_nullable_and_string_enum_in_rest_projection() {
|
||||
let document = r#"
|
||||
openapi: 3.1.0
|
||||
info: { title: Schema metadata }
|
||||
paths:
|
||||
/metadata:
|
||||
get:
|
||||
operationId: metadata
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
identifier:
|
||||
type: string
|
||||
format: uuid
|
||||
default: 00000000-0000-0000-0000-000000000000
|
||||
nullable: true
|
||||
state:
|
||||
type: string
|
||||
enum: [draft, published]
|
||||
default: draft
|
||||
ratio:
|
||||
type: number
|
||||
format: double
|
||||
default: 1.5
|
||||
nullable: true
|
||||
"#;
|
||||
|
||||
let preview = preview_document(document).unwrap();
|
||||
let schema = &preview.groups[0].operations[0].draft.output_schema;
|
||||
|
||||
let identifier = schema.field("identifier").unwrap();
|
||||
assert_eq!(identifier.kind, SchemaKind::String);
|
||||
assert_eq!(identifier.format.as_deref(), Some("uuid"));
|
||||
assert_eq!(
|
||||
identifier.default_value,
|
||||
Some(json!("00000000-0000-0000-0000-000000000000"))
|
||||
);
|
||||
assert!(identifier.nullable);
|
||||
|
||||
let state = schema.field("state").unwrap();
|
||||
assert_eq!(state.kind, SchemaKind::Enum);
|
||||
assert_eq!(state.enum_values, vec!["draft", "published"]);
|
||||
assert_eq!(state.default_value, Some(json!("draft")));
|
||||
|
||||
let ratio = schema.field("ratio").unwrap();
|
||||
assert_eq!(ratio.kind, SchemaKind::Number);
|
||||
assert_eq!(ratio.format.as_deref(), Some("double"));
|
||||
assert_eq!(ratio.default_value, Some(json!(1.5)));
|
||||
assert!(ratio.nullable);
|
||||
|
||||
let serialized = serde_json::to_value(schema).unwrap();
|
||||
assert_eq!(serialized["fields"]["identifier"]["format"], "uuid");
|
||||
assert_eq!(serialized["fields"]["identifier"]["nullable"], true);
|
||||
}
|
||||
Reference in new issue
Block a user