GREsau / okapi

OpenAPI (AKA Swagger) document generation for Rust projects
MIT License
631 stars 112 forks source link

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

Open snpschaaf opened 2 years ago

snpschaaf commented 2 years ago

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.

Using rocket_okapi enables the feature 'preserve_order' by default.

Belongs to https://github.com/GREsau/okapi/issues/67

snpschaaf commented 2 years ago

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

snpschaaf commented 2 years ago

@SBechstedt

snpschaaf commented 2 years ago

@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: https://github.com/GREsau/schemars/pull/161

ralpha commented 2 years ago

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

snpschaaf commented 2 years ago

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.