Skip to content

deserializing and serializing results in faulty json #67

Description

@andrieshiemstra

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)

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

   "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

"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"
          }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    okapiThis affects the okapi crate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions