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

okapi: fix deserialisation for openapi3 'extensions' fields #108

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

snpschaaf
Copy link

@snpschaaf snpschaaf commented Jul 12, 2022

The 'extensions' fields of various structs
within okapi/src/openapi3.rs was not
deserialized correctly.

#[serde(flatten)]

was empty.

The 'extensions' fields used a custom type 'Object'.
'Object' is an alias for IndexMap or BTreeMap depending
on feature 'preserve_order'. Deserialisation should work for both.

  • fix for IndexMap (preserve_order enabled)
  • fix for BTreeMap (preserve_order disabled)

Using rocket_okapi enables the feature 'preserve_order'
by default.

Belongs to #67

The 'extensions' fields of various structs
within okapi/src/openapi3.rs was not
deserialized correctly.

This commit fixes the behavior if the Object is
an indexmap. Using rocket_okapi enables the feature
'preserve_order' by default and hence an indexmap is used.

If the feature 'preserve_order' is disables, this commit should
not change the behavior.

Belongs to GREsau#67

Signed-off-by: Philippe Schaaf <philippe.schaaf@secunet.com>
@snpschaaf
Copy link
Author

IndexMap has a custom serde function: https://docs.rs/indexmap/latest/indexmap/serde_seq/index.html

@snpschaaf
Copy link
Author

@SBechstedt

@snpschaaf
Copy link
Author

@GREsau does it make sens to you to provide a serde_seq module via the schemars crate depending on the cfg feature? IMO this would be a cleaner way of achieving the desired de-/serialization in a feature-aware way and importing the indexmap crate would not be needed any longer.

My suggestion: GREsau/schemars#161

@ralpha
Copy link
Collaborator

ralpha commented Jul 12, 2022

So the problem is that the extensions field does not preserve the order correctly?

@snpschaaf
Copy link
Author

snpschaaf commented Jul 13, 2022

So the problem is that the extensions field does not preserve the order correctly?

The extension field was serialized correctly into a OAS JSON. During our golden unit test (#107) we noticed all deserialized extensions fields are empty (extension={}). You already mentioned this problem here.

Signed-off-by: Simon Bechstedt <simon.bechstedt@secunet.com>
Use patched version until PR GREsau/schemars#161 is merged.

Signed-off-by: Simon Bechstedt <simon.bechstedt@secunet.com>
Signed-off-by: Simon Bechstedt <simon.bechstedt@secunet.com>
@ralpha ralpha added the okapi This affects the okapi crate label Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
okapi This affects the okapi crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants