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

"Fixed" type attribute should propagate to an empty object member #686

Closed
Ge11ert opened this issue Apr 29, 2019 · 3 comments
Closed

"Fixed" type attribute should propagate to an empty object member #686

Ge11ert opened this issue Apr 29, 2019 · 3 comments
Labels

Comments

@Ge11ert
Copy link

Ge11ert commented Apr 29, 2019

I'm running on v. 4.0.0-pre.4.

According to MSON Spec, fixed type attribute should propagate to nested members.

First example:

# My API

# Request [GET /first]

+ Response 200 (application/json)
    + Attributes
        + result (object, fixed)
            + obj_member (object)

produces the following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "result": {
      "type": "object",
      "properties": {
        "obj_member": {
          "type": "object"
        }
      },
      "required": [
        "obj_member"
      ],
      "additionalProperties": false
    }
  }
}

Second example (obj_member has explicit fixed attribute)

# My API

# Request [GET /first]

+ Response 200 (application/json)
    + Attributes
        + result (object, fixed)
            + obj_member (object, fixed)

produces this (obj_member has field "additionalProperties": false now) :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "result": {
      "type": "object",
      "properties": {
        "obj_member": {
          "type": "object",
          "additionalProperties": false
        }
      },
      "required": [
        "obj_member"
      ],
      "additionalProperties": false
    }
  }
}

Expected behaviour:
These 2 examples should generate the same json-schema.

P.S. If obj_member has any nested properties, fixed attribute propagation works correctly.

@kylef kylef added the bug label Apr 29, 2019
@kylef
Copy link
Member

kylef commented Apr 29, 2019

Thanks for the report @Ge11ert, we'll look into this.

(internal tracking: OACS-5809)

@kylef
Copy link
Member

kylef commented May 13, 2019

diff --git a/src/refract/ElementUtils.cc b/src/refract/ElementUtils.cc
index f40fca09..1373f720 100644
--- a/src/refract/ElementUtils.cc
+++ b/src/refract/ElementUtils.cc
@@ -38,7 +38,7 @@ bool refract::inheritsFixed(const IElement& e)

 bool refract::inheritsFixed(const ObjectElement& e)
 {
-    return definesValue(e);
+    return true;
 }

 bool refract::inheritsFixed(const ArrayElement& e)

The above patch would fix this particular case, but not sure what else it could break.

kylef added a commit that referenced this issue May 13, 2019
kylef added a commit that referenced this issue May 13, 2019
kylef added a commit that referenced this issue May 13, 2019
kylef added a commit that referenced this issue May 13, 2019
@tjanc tjanc closed this as completed in 62e9507 May 20, 2019
@kylef
Copy link
Member

kylef commented May 20, 2019

@Ge11ert We've released a fix in Drafter 4.0.0-pre.6.

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

2 participants