michiel / jsonapi-rust

Rust library for serialization, deserialization and working with JSON-API data
MIT License
109 stars 30 forks source link

Should included arrays be de-duplicated for same id,type? #84

Open theowenyoung opened 2 years ago

theowenyoung commented 2 years ago

Hi, for now ,the following example will generate 4 chapters with id =1 :

    let book = vec![
        Book {
            id: "1".into(),
            title: "The Fellowship of the Ring".into(),
            first_chapter: Chapter {
                id: "1".into(),
                title: "A Long-expected Party".into(),
                ordering: 1,
            },
            chapters: vec![Chapter {
                id: "1".into(),
                title: "A Long-expected Party".into(),
                ordering: 1,
            }],
        },
        Book {
            id: "2".into(),
            title: "The Fellowship of the Ring".into(),
            first_chapter: Chapter {
                id: "1".into(),
                title: "A Long-expected Party".into(),
                ordering: 1,
            },
            chapters: vec![Chapter {
                id: "1".into(),
                title: "A Long-expected Party".into(),
                ordering: 1,
            }],
        },
    ];

    let doc = vec_to_jsonapi_document(book);
    dbg!(&doc);
    assert!(doc.is_valid());
 included: Some(
            [
                Resource {
                    _type: "chapters",
                    id: "1",
                    attributes: {
                        "ordering": Number(
                            1,
                        ),
                        "title": String(
                            "A Long-expected Party",
                        ),
                    },
                    relationships: None,
                    links: None,
                    meta: None,
                },
                Resource {
                    _type: "chapters",
                    id: "1",
                    attributes: {
                        "ordering": Number(
                            1,
                        ),
                        "title": String(
                            "A Long-expected Party",
                        ),
                    },
                    relationships: None,
                    links: None,
                    meta: None,
                },
                Resource {
                    _type: "chapters",
                    id: "1",
                    attributes: {
                        "ordering": Number(
                            1,
                        ),
                        "title": String(
                            "A Long-expected Party",
                        ),
                    },
                    relationships: None,
                    links: None,
                    meta: None,
                },
                Resource {
                    _type: "chapters",
                    id: "1",
                    attributes: {
                        "title": String(
                            "A Long-expected Party",
                        ),
                        "ordering": Number(
                            1,
                        ),
                    },
                    relationships: None,
                    links: None,
                    meta: None,
                },
            ],

Should these chapters be deduplicated?