Skip to content

Commit

Permalink
properly recognize struct type
Browse files Browse the repository at this point in the history
  • Loading branch information
wkarwacki committed Aug 20, 2024
1 parent abf9063 commit 6aa341a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src/lib/open_api/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,43 +290,39 @@ impl Schema {
null: self.nullable,
}),
"object" => {
if self.empty() {
Def::Struct(Struct {})
} else {
self.additional_properties
.clone()
.map(|additional_properties| {
Def::Map(Box::new(Map {
key: Desc::Def(Def::Str(Str {
null: self.nullable,
})),
val: additional_properties.desc(name.clone(), context),
null: self.nullable,
}))
})
.unwrap_or({
let vars: HashMap<_, _> = self
.properties
.iter()
.map(|(n, schema)| {
(
n.clone(),
Box::new(Var {
desc: schema.clone().desc(n.clone(), context),
opt: !self.required.contains(n),
}),
)
})
.collect();
Def::Obj(Obj {
ext: None,
mix: Vec::new(),
vars: vars,
adt: self.adt(name.clone(), context),
self.additional_properties
.clone()
.map(|additional_properties| {
Def::Map(Box::new(Map {
key: Desc::Def(Def::Str(Str {
null: self.nullable,
})),
val: additional_properties.desc(name.clone(), context),
null: self.nullable,
}))
})
.unwrap_or({
let vars: HashMap<_, _> = self
.properties
.iter()
.map(|(n, schema)| {
(
n.clone(),
Box::new(Var {
desc: schema.clone().desc(n.clone(), context),
opt: !self.required.contains(n),
}),
)
})
.collect();
Def::Obj(Obj {
ext: None,
mix: Vec::new(),
vars: vars,
adt: self.adt(name.clone(), context),
null: self.nullable,
})
}
})
}
"string" => {
if self.r#enum.is_empty() {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/test/types-open-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ components:
type: string
required:
- var
ObjEmpty:
type: object
Empty: {}
SeqMapStrToDec:
type: array
items:
Expand Down
4 changes: 4 additions & 0 deletions src/lib/test/types-trust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ defs:
vars:
var:
type: str
ObjEmpty:
type: obj
Empty:
type: struct
ObjWithSeq:
type: obj
vars:
Expand Down

0 comments on commit 6aa341a

Please sign in to comment.