Skip to content

Commit

Permalink
unignore tests, fix mapping of adt
Browse files Browse the repository at this point in the history
  • Loading branch information
wkarwacki committed Aug 21, 2024
1 parent c19bd4c commit 03db4b1
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lib/gen/python/client/templates/stubImpl.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if (and val.path (not (eq val.type "alias")))}}{{#with (resolve val)}}{{#if (eq this.type "obj")}}{{#if this.adt}}{{>dtoName val=(fmtClass (fmtName ../val.path))}}Base{{else}}{{>dtoName val=(fmtClass ../val.path)}}{{/if}}.get(){{else}}{{>stubImpl val=this indent=indent}}{{/if}}{{/with}}{{else if (or (eq val.type "obj") (or val.vars val.mix))}}{{key}}({{#each val.vars}}
{{#if (not val.type)}}{{key}}(){{else}}{{#if (and val.path (not (eq val.type "alias")))}}{{#with (resolve val)}}{{#if (eq this.type "obj")}}{{#if this.adt}}{{>dtoName val=(fmtClass (fmtName ../val.path))}}Base{{else}}{{>dtoName val=(fmtClass ../val.path)}}{{/if}}.get(){{else}}{{>stubImpl val=this indent=indent}}{{/if}}{{/with}}{{else if (or (eq val.type "obj") (or val.vars val.mix))}}{{key}}({{#each val.vars}}
{{../indent}} {{fmtName @key}}={{>stubImpl val=this key=(fmtClass @key) indent=(add ../indent " ") prefix=../key}}{{#if (or (not @last) ../val.mix)}},{{/if}}{{/each}}{{#each val.mix}}
{{../indent}} **{{#if ../adtVar}}{ k:v for k, v in {{/if}}{{>dtoName val=(fmtClass this.path)}}.get().dict(){{#if ../adtVar}}.items() if k != {{json (fmtName ../adtVar)}} }{{/if}}{{#unless @last}},{{/unless}}{{/each}}
{{indent}}){{else if (eq val.type "map")}}{ {{#if val.key}}{{#if (eq val.key.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Key"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Key") indent=indent}}{{/if}}: {{#if val.val}}{{#if (eq val.val.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Val"}}.get(){{else}}{{>stubImpl val=val.val indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Val") indent=indent}}{{/if}} }{{else if (eq val.type "seq")}}[{{#if (eq val.item.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{#if origin}}{{>dtoName val=(fmtClass origin.path)}}{{/if}}{{add key "Item"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=prefix}}{{/if}}]{{else}}{{stubImpl val indent=indent}}{{/if}}
{{indent}}){{else if (eq val.type "map")}}{ {{#if val.key}}{{#if (eq val.key.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Key"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Key") indent=indent}}{{/if}}: {{#if val.val}}{{#if (eq val.val.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Val"}}.get(){{else}}{{>stubImpl val=val.val indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Val") indent=indent}}{{/if}} }{{else if (eq val.type "seq")}}[{{#if (eq val.item.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{#if origin}}{{>dtoName val=(fmtClass origin.path)}}{{/if}}{{add key "Item"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=prefix}}{{/if}}]{{else}}{{stubImpl val}}{{/if}}{{/if}}
4 changes: 2 additions & 2 deletions src/lib/gen/python/server/templates/stubImpl.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if (and val.path (not (eq val.type "alias")))}}{{#with (resolve val)}}{{#if (eq this.type "obj")}}{{#if this.adt}}{{>dtoName val=(fmtClass (fmtName ../val.path))}}Base{{else}}{{>dtoName val=(fmtClass ../val.path)}}{{/if}}.get(){{else}}{{>stubImpl val=this indent=indent}}{{/if}}{{/with}}{{else if (or (eq val.type "obj") (or val.vars val.mix))}}{{key}}({{#each val.vars}}
{{#if (not val.type)}}{{key}}(){{else}}{{#if (and val.path (not (eq val.type "alias")))}}{{#with (resolve val)}}{{#if (eq this.type "obj")}}{{#if this.adt}}{{>dtoName val=(fmtClass (fmtName ../val.path))}}Base{{else}}{{>dtoName val=(fmtClass ../val.path)}}{{/if}}.get(){{else}}{{>stubImpl val=this indent=indent}}{{/if}}{{/with}}{{else if (or (eq val.type "obj") (or val.vars val.mix))}}{{key}}({{#each val.vars}}
{{../indent}} {{fmtName @key}}={{>stubImpl val=this key=(fmtClass @key) indent=(add ../indent " ") prefix=../key}}{{#if (or (not @last) ../val.mix)}},{{/if}}{{/each}}{{#each val.mix}}
{{../indent}} **{{#if ../adtVar}}{ k:v for k, v in {{/if}}{{>dtoName val=(fmtClass this.path)}}.get().dict(){{#if ../adtVar}}.items() if k != {{json (fmtName ../adtVar)}} }{{/if}}{{#unless @last}},{{/unless}}{{/each}}
{{indent}}){{else if (eq val.type "map")}}{ {{#if val.key}}{{#if (eq val.key.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Key"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Key") indent=indent}}{{/if}}: {{#if val.val}}{{#if (eq val.val.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Val"}}.get(){{else}}{{>stubImpl val=val.val indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Val") indent=indent}}{{/if}} }{{else if (eq val.type "seq")}}[{{#if (eq val.item.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{#if origin}}{{>dtoName val=(fmtClass origin.path)}}{{/if}}{{add key "Item"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=prefix}}{{/if}}]{{else}}{{stubImpl val indent=indent}}{{/if}}
{{indent}}){{else if (eq val.type "map")}}{ {{#if val.key}}{{#if (eq val.key.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Key"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Key") indent=indent}}{{/if}}: {{#if val.val}}{{#if (eq val.val.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{add key "Val"}}.get(){{else}}{{>stubImpl val=val.val indent=indent prefix=null}}{{/if}}{{else}}{{>stubImpl val="str" key=(add key "Val") indent=indent}}{{/if}} }{{else if (eq val.type "seq")}}[{{#if (eq val.item.type "obj")}}{{#if prefix}}{{prefix}}.{{/if}}{{#if origin}}{{>dtoName val=(fmtClass origin.path)}}{{/if}}{{add key "Item"}}.get(){{else}}{{>stubImpl val=val.item indent=indent prefix=prefix}}{{/if}}]{{else}}{{stubImpl val}}{{/if}}{{/if}}
13 changes: 12 additions & 1 deletion src/lib/open_api/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl Schema {
}))
})
.unwrap_or({
let vars: HashMap<_, _> = self
let mut vars: HashMap<_, _> = self
.properties
.iter()
.map(|(n, schema)| {
Expand All @@ -315,6 +315,17 @@ impl Schema {
)
})
.collect();
self.discriminator.iter().for_each(|discriminator| {
vars.insert(
discriminator.property_name.clone(),
Box::new(Var {
desc: Desc::Def(Def::Str(Str {
null: self.nullable,
})),
opt: false,
}),
);
});
Def::Obj(Obj {
ext: None,
mix: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/test/adt-from-open-api-open-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ components:
AnotherAdt:
type: object
discriminator:
propertyName: type
propertyName: anotherType
mapping:
typeToken0: '#/components/schemas/AnotherAdtTypeToken0'
typeToken1: '#/components/schemas/AnotherAdtTypeToken1'
Expand Down
8 changes: 7 additions & 1 deletion src/lib/test/adt-from-open-api-trust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defs:
Adt:
type: obj
vars:
type:
type: str
adt:
var: type
map:
Expand Down Expand Up @@ -40,8 +43,11 @@ defs:
- path: "defs.Adt"
AnotherAdt:
type: obj
vars:
anotherType:
type: str
adt:
var: type
var: anotherType
map:
typeToken0:
mix:
Expand Down
1 change: 0 additions & 1 deletion src/lib/test/adt-to-open-api-open-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ components:
type:
type: string
required:
- bool
- type
discriminator:
propertyName: type
Expand Down
1 change: 1 addition & 0 deletions src/lib/test/adt-to-open-api-trust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defs:
vars:
bool:
type: bool
opt: true
dec:
type: dec
opt: true
Expand Down
2 changes: 0 additions & 2 deletions src/lib/test/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ mod adt {
gen_test(Lang::Kotlin, Role::Server, "adt-to-open-api-trust.yml");
}

#[ignore]
#[test]
fn gen_python_client_test() {
gen_test(Lang::Python, Role::Client, "adt-from-open-api-trust.yml");
gen_test(Lang::Python, Role::Client, "adt-to-open-api-trust.yml");
}

#[ignore]
#[test]
fn gen_python_server_test() {
gen_test(Lang::Python, Role::Server, "adt-from-open-api-trust.yml");
Expand Down
2 changes: 0 additions & 2 deletions src/lib/test/type_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ mod type_params {
gen_test(Lang::Kotlin, Role::Server, "type-params-trust.yml");
}

#[ignore]
#[test]
fn gen_python_client_test() {
gen_test(Lang::Python, Role::Client, "type-params-trust.yml");
}

#[ignore]
#[test]
fn gen_python_server_test() {
gen_test(Lang::Python, Role::Server, "type-params-trust.yml");
Expand Down

0 comments on commit 03db4b1

Please sign in to comment.