GREsau / GREsau/okapi

deserializing and serializing results in faulty json

Open
#67 2 comments 0 reactions 0 assignees View on GitHub
okapi
Dominant language
Rust
Stars
740
Forks
127
PR merge metrics
No merged PRs in 30d

Description

When deserializing from json the schemas from a param also get added to the extensions object of a param, resulting in faulty json being outputted when serializing again (schema attribute is added twice)

```rust
use okapi::openapi3::{Operation, RefOr, Parameter};

fn main() {

let json = "{\"responses\": {}, \"name\": \"someOp\", \"parameters\": [{\"in\": \"path\", \"schema\": {\"$ref\": \"#/defid\"}, \"name\": \"param1\"}]}";

let operation: Operation = serde_json::from_str(json).unwrap();

for param in &operation.parameters {
match param {
RefOr::Ref(_) => {
}
RefOr::Object(p) => {
println!("p.json: {}", serde_json::to_string(p).unwrap());
println!("p.value.json: {}", serde_json::to_string(&p.value).unwrap());
println!("p.extensions.json: {}", serde_json::to_string(&p.extensions).unwrap());
}
}
}

println!("json: {}", serde_json::to_string(&operation).unwrap());

}
```

results in
```
p.json: {"name":"param1","in":"path","schema":{"$ref":"#/defid"},"schema":{"$ref":"#/defid"}}
p.value.json: {"schema":{"$ref":"#/defid"}}
p.extensions.json: {"schema":{"$ref":"#/defid"}}
json: {"parameters":[{"name":"param1","in":"path","schema":{"$ref":"#/defid"},"schema":{"$ref":"#/defid"}}],"responses":{},"name":"someOp"}
```

The same happens when deserializing an operation with responses, deserializing and serializing this
```json
"responses": {
"200": {
"description": "info to be returned",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/getInfoResultSchema"
}
}
}
},
"default": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DefaultError"
}
}
}
}
}
```

results in this

```json
"responses": {
"default": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DefaultError"
}
}
}
},
"200": {
"description": "info to be returned",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/getInfoResultSchema"
}
}
}
},
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/getInfoResultSchema"
}
}
},
"description": "info to be returned"
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.