Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Fix merging media type #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

monikma
Copy link

@monikma monikma commented Apr 7, 2015

We have noticed that there is a bug in current raml-java-parser:

In case the resource action has the schema specified right under the body, without specifying the media type (so the dedfault media type applies), and at the same type a resource type is applied to the whole resource, where media-type specific schemas are defined, the schemas are merged in such a way that the RAML becomes invalid, and it is not possible to be parsed. The parsing fails with an exception.

For example:

title: Example API
version: v1
mediaType: application/json

resourceTypes:
    - dummy:
        get:
            responses:
                200:
                    body:                    
                        application/json:
                            schema: |
                               {  "$schema": "http://json-schema.org/draft-03/schema",
                                   "type": "object",
                                   "description": "A dummy schema",
                                   "properties": {
                                     "id":  { "type": "string" }
                                   }
                                }

/mergedWithType:
    type: dummy
    get:
        responses:
            200:
              body:
                schema: |
                   {  "$schema": "http://json-schema.org/draft-03/schema",
                      "type": "object",
                      "description": "A merged schema",
                      "properties": {
                        "id":  { "type": "string" }
                      }
                   }

will be merged into:

/mergedWithType:
    type: dummy
    get:
        responses:
            200:
              body:
                application/json:
                    schema: |
                       {  "$schema": "http://json-schema.org/draft-03/schema",
                          "type": "object",
                          "description": "A merged schema",
                          "properties": {
                            "id":  { "type": "string" }
                          }
                       }
                    application/json:
                        schema: |
                          {  "$schema": "http://json-schema.org/draft-03/schema",
                              "type": "object",
                              "description": "A dummy schema",
                              "properties": {
                               "id":  { "type": "string" }
                           }
                         }

which is invalid.

Please check the src/test/resources/org/raml/media-type.yaml file below for this error case, I added a test for that, and a possible solution.

It should be however reviewed whether the order of schemas being applied is correct, ie which schema should have precedence over which, in case the schema specified on the resource is different from the schema defined in the resource type. Same applies to 'example' and 'formParameters'. You can see in the test which order is applied currently.

@machaval machaval added the v1 label Jul 14, 2016
@svacas svacas closed this Aug 17, 2016
@svacas svacas reopened this Aug 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants