libninja icon indicating copy to clipboard operation
libninja copied to clipboard

Check all rust keywords, deal with recursive structs

Open pscott31 opened this issue 2 years ago • 2 comments

I was using this to generate an API for Square; and they had a api method called 'break' which upset the generator; so I've added in a crate that purports to have an exhaustive list.

Secondly, they have calls where youve got something like

struct Item{
   name: String
   related_item: Option<Item>
}

Which was causing the example generator to try and make an infinitely nested example. I had a go at refactoring to_rust_example_value to be iterative instead of recursive but gave up and instead pass around a set identifiers that we've already used in the tree to that point and put a None there instead of Some<Item>.

Might be nice to allow a couple one or two levels perhaps, we could change the HashSet into a HashMap with a depth - but thought I'd keep it simple.

pscott31 avatar Nov 24 '23 14:11 pscott31

Can you add a regression test to this, or at least a minimal real-world OpenAPI spec that'd have such recursion. I'm not sure how you'd encounter this in an OpenAPI spec in the real world.

struct Item{
   name: String
   related_item: Option<Item>
}

is an illegal struct for the same reason (it'd have to be a Option<Box<Item>> or a Vec<Item>`).

The check_keyword is a great find, happy to merge that separately or when above question is addressed.

EDIT: Nevermind, saw that you brought this up via Issue #12

kurtbuilds avatar Dec 14 '23 12:12 kurtbuilds

Would you be able to trim down the vwphere spec to the offending endpoint or struct to facilitate adding a regression test? I think it's from ClusterComputeResourcePlaceVmRequest, but I'm not sure.

kurtbuilds avatar Dec 14 '23 13:12 kurtbuilds