Skip to content

feat: added resolve feature#95

Open
jeroenvervaeke wants to merge 3 commits intoglademiller:masterfrom
jeroenvervaeke:master
Open

feat: added resolve feature#95
jeroenvervaeke wants to merge 3 commits intoglademiller:masterfrom
jeroenvervaeke:master

Conversation

@jeroenvervaeke
Copy link

Add resolve helpers for ReferenceOr

What's this?

Makes it easier to get the value of a reference. Whether you have an inline value or a $ref pointing to #/components/, just call .resolve(&openapi) and get back a &T.

Example

let resp = op.responses.responses.get(&StatusCode::Code(200)).unwrap();
let resolved_resp = resp.resolve(&openapi).unwrap();

let mt = resolved_resp.content.get("application/json").unwrap();
let schema = mt.schema.resolve(&openapi).unwrap();
// schema is the fully resolved Schema, whether it was inline or a $ref

Works with ReferenceOr<T>, ReferenceOr<Box<T>>, and Option<ReferenceOr<T>>.

Also added some iteration helpers like OpenAPI::operations() and PathItem::iter() while I was at it.

No breaking changes, everything's backward compatible.

@spikespaz
Copy link

I oppose this addition because I don't think it belongs in this library. Resolving references comprehensively is non-trivial, because they may be to arbitrary paths or other documents completely.

This belongs in downstream code, where the implementation only needs to satisfy the consumer's requirements specifically.

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

Successfully merging this pull request may close these issues.

2 participants

Comments