Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better ergonomics for Operations #11

Open
JordiPolo opened this issue May 15, 2017 · 3 comments
Open

Better ergonomics for Operations #11

JordiPolo opened this issue May 15, 2017 · 3 comments

Comments

@JordiPolo
Copy link
Contributor

JordiPolo commented May 15, 2017

I've started working on code based on this library and working with Operations is difficult I want to do something like:

for operation in operations {
  ...
}

But each operation is a different field in the structure, I do not know if it's possible to iterate them in Rust

@softprops
Copy link
Owner

I'm not sure that the swagger spec itself is designed for that at the moment each path maps to a path item object when I started on this journey my assumptions where the same as yours and what the struct that represents this is called Operations. In testing deserializing more openapi examples in the wild I came across some examples using the shared parameters which broke that assumption. I think maybe it makes sense to provide an inherent impl for the Operations object which collects the HTTP methods into a vec to support this kind of iteration.

@yovoslav
Copy link

yovoslav commented May 7, 2022

I found myself in a similar situation today. I need to iterate over all operations (it's just easier with my current code). So far I have created an enum for all of the possible method verbs and I turn the Options into iterators and chain them, so something like:

let get = item.get.as_ref().map(|x| (Method::Get, x));
let post = // ....

get.into_iter().chain(post) // and so on

While this works, I think it would be more suitable/ergonomic for all operations to be a map (let's assume a BTreeMap) and the key should be something like the Method enum I mentioned. I believe this is possible with #[serde(flatten)].

I am willing to work on researching and/or implementing this, if it's deemed appropriate.

@yovoslav
Copy link

Since I needed this, I already implemented it in my fork https://github.com/IovoslavIovchev/openapi/blob/master/src/v3_0/schema.rs#L186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants