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

Unable to render when named types are nested in array #117

Closed
pksunkara opened this issue Sep 14, 2015 · 17 comments
Closed

Unable to render when named types are nested in array #117

pksunkara opened this issue Sep 14, 2015 · 17 comments
Labels
Milestone

Comments

@pksunkara
Copy link
Contributor

Given the below blueprint,

# GET /
+ Response 200 (application/json)
    + Attributes (array[User])
​
# Data Structures
## User
+ username: pksunkara

The payload.body is not getting rendering because there is a problem with expanding MSON.

@obihann
Copy link

obihann commented Oct 7, 2015

@pksunkara I'll start looking into this now.

@obihann
Copy link

obihann commented Oct 8, 2015

@pksunkara do you have a sample JSON output of what this should look like? I have a rough idea but I want to be sure I'm on the right track.

@kylef
Copy link
Member

kylef commented Oct 8, 2015

I'd expect it would be rendered as:

{
  "username": "pksunkara"
}

@obihann
Copy link

obihann commented Oct 8, 2015

@kylef so from what I see the overall structure is fine, however their is no JSON body, and you provided what that should look like. I'll get started on this now.

@obihann
Copy link

obihann commented Oct 13, 2015

@pksunkara @kylef I'm still looking into this however I'm not making much progress. I'm feeling that this is related to the serialization of the MSON however wouldn't most of that be handled within snowcrash itself?

@obihann
Copy link

obihann commented Oct 14, 2015

I'm going to step aside from this for a little while incase somebody else wants to take a stab at it.

@pksunkara
Copy link
Contributor Author

When the above blueprint is parsed using the master branch, this is the output.

{
  "element": "category",
  "meta": {
    "classes": [
      "api"
    ],
    "title": ""
  },
  "content": [
    {
      "element": "category",
      "meta": {
        "classes": [
          "resourceGroup"
        ],
        "title": ""
      },
      "content": [
        {
          "element": "resource",
          "meta": {
            "title": ""
          },
          "attributes": {
            "href": "/"
          },
          "content": [
            {
              "element": "transition",
              "meta": {
                "title": ""
              },
              "content": [
                {
                  "element": "httpTransaction",
                  "content": [
                    {
                      "element": "httpRequest",
                      "attributes": {
                        "method": "GET"
                      },
                      "content": []
                    },
                    {
                      "element": "httpResponse",
                      "attributes": {
                        "statusCode": "200",
                        "headers": {
                          "element": "httpHeaders",
                          "content": [
                            {
                              "element": "member",
                              "content": {
                                "key": {
                                  "element": "string",
                                  "content": "Content-Type"
                                },
                                "value": {
                                  "element": "string",
                                  "content": "application/json"
                                }
                              }
                            }
                          ]
                        }
                      },
                      "content": [
                        {
                          "element": "dataStructure",
                          "content": [
                            {
                              "element": "array"
                            }
                          ]
                        },
                        {
                          "element": "asset",
                          "meta": {
                            "classes": "messageBody"
                          },
                          "attributes": {
                            "contentType": "application/json"
                          },
                          "content": "[]"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "element": "category",
      "meta": {
        "classes": [
          "dataStructures"
        ]
      },
      "content": [
        {
          "element": "dataStructure",
          "content": [
            {
              "element": "object",
              "meta": {
                "id": "User"
              },
              "content": [
                {
                  "element": "member",
                  "content": {
                    "key": {
                      "element": "string",
                      "content": "username"
                    },
                    "value": {
                      "element": "string",
                      "content": "pksunkara"
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]

As you can see, the dataStructure element inside the httpResponse is not correctly expanded which effects the serialising and rendering.

@obihann
Copy link

obihann commented Oct 15, 2015

@pksunkara Thanks for this. So do you think exists in refract/RenderJSONVisitor.cc when it is stepping through the elements or prior to that when the elements are serialized?

@pksunkara
Copy link
Contributor Author

Prior to that. I have even said that the issue is when converting the data structures to refract which happens in MSONToRefract

@obihann
Copy link

obihann commented Oct 15, 2015

@pksunkara thanks, I'll dive into that and see if I can come up with something.

@kylef
Copy link
Member

kylef commented Oct 16, 2015

I've had a look into this one. From what I understand is the issue is from converting the MSON data structure to a refract element (from within MSONToRefract). Inside RefractElementFromMSON it seems if there are no sections, no information will make it into the ElementData and subsequently the element.

ElementData<T> data;
std::for_each(ds.sections.begin(), ds.sections.end(), ExtractTypeSection<T>(data, ds));
TransformElementData<T>(element, data);

Perhaps the issue is in snowcrash and the section shouldn't be empty, but I don't know much about these details and if that's correct.

You can see the MSON attribute structure as follows:

screen shot 2015-10-15 at 21 30 54

Where you can see that the nested type for User exists but the sections is empty.

This results in an element as which doesn't have any information about the User type:

screen shot 2015-10-15 at 21 30 12

@pksunkara
Copy link
Contributor Author

Perhaps the issue is in snowcrash and the section shouldn't be empty, but I don't know much about these details and if that's correct.

That is incorrect. Sections should be empty in this case. It's just when we are doing MSONToRefract, we need to make sure that nestedTypes are also taken into consideration.

@obihann
Copy link

obihann commented Oct 19, 2015

@pksunkara I commented earlier today with a false assumption that we never hitting case mson::ArrayTypeName: (line 813) of MSONToRefract (line 789) in RefractDataStructure.cc however I since realized we do hit that.

I believe now that the issue is prior to this function though, and the reason is that when we loop through the data structures not only does the specific element have no value, it's base name is UndefinedTypeName. Below are some screenshots to hopefully help.

I'm going to look into some of the code prior to this and not 100% rule out snowcrash.

screen shot 2015-10-19 at 10 13 48 am
screen shot 2015-10-19 at 10 19 24 am

@obihann
Copy link

obihann commented Oct 19, 2015

After spending a lot of time today walking through the debugger I'm starting to see now the issue is not with snowcrash, and it is in drafter as @pksunkara originally stated. Ignore my previous comments.

@obihann
Copy link

obihann commented Oct 19, 2015

It seems that in RegisterNamedTypes (line 87) of RefractAPI.cc it is properly adding the type (in this case User), so it is later on that the bug exists. I'll keep debugging and post my notes as I go, I think I'm on to something though.

@obihann
Copy link

obihann commented Oct 19, 2015

One thing I'm seeing, and this could be a misunderstanding on my part, is in the snowcrash element, their are two content elements, one for the request and another for the data structures. The data structures looks fine however the request itself though it shows an element that should be the array of users, is empty. Their seems to be no connection at all between the request and the data structure. Perhaps that is the issue, and if so I'm not sure where to look next.

@obihann
Copy link

obihann commented Oct 20, 2015

@pksunkara is it correct to say that in RefractAPI.cc line 446 BlueprintToRefract is where the array elements are created and this is likely where we need to be checking against named types?

@kylef kylef modified the milestones: 1.1.0, 2.0.0 Oct 27, 2015
klokane pushed a commit that referenced this issue Nov 11, 2015
klokane pushed a commit that referenced this issue Nov 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants