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

Expand does not work for traits that add response types #94

Closed
mpfau opened this issue Apr 6, 2016 · 3 comments
Closed

Expand does not work for traits that add response types #94

mpfau opened this issue Apr 6, 2016 · 3 comments
Assignees
Labels

Comments

@mpfau
Copy link

mpfau commented Apr 6, 2016

Response types that are added by an trait are not correctly expanded if their suffix is the same (+xml in this case). The following example should lead to two response types (application/tree_v1_0_0+xml and application/tree_v1_0_1+xml):

#%RAML 1.0
title: RAML spec
types:
  tree_v1_0_0:
  tree_v1_0_1:
traits:
  - responding-xml:
      responses:
        200?:
          description: OK
          body:
            application/<<type>>+xml:
              type: <<type>>
/test:
  get:
    is: [
      responding-xml: {
        type: tree_v1_0_0,
      },
      responding-xml: {
        type: tree_v1_0_1,
      },
    ]
    responses:
      200:

Unfortunately, one of the response-types is not added by the expand() method:

      "responses": {
        "200": {
          "description": "OK",
          "body": {
            "application/tree_v1_0_0+xml": {
              "type": "tree_v1_0_0"
            }
          }

The expected output would be:

      "responses": {
        "200": {
          "body": {
            "application/tree_v1_0_0+xml": {
              "type": "tree_v1_0_0"
            },
            "application/tree_v1_0_1+xml": {
              "type": "tree_v1_0_1"
            }
          },
          "description": "OK"
        }
      }

This has been tested against the current beta (v11). Everything is fine, if all used suffixes are distinct (e.g. +xml and +json). This bug makes using traits for responses effectively useless if multiple media types must be supported.

@ddenisenko
Copy link
Contributor

ddenisenko commented Apr 14, 2016

Well, expand does work for traits that add response types.

But you were happy to hit two different bugs at once :) Thanks for reporting this.

The first issue may be not a bug as-is, but something, which is not clearly stated by the spec, and this one should be discussed. Right now, you cant really apply the same trait twice to a same method.

The second issue is clearly a bug: when you have two traits, which apply a node, that looks -equally- in the unexpanded state, but differently in expanded state, the node is only applied once. In your case it is application/<<type>>+xml

Here is the modification of your RAML, which applies both types, just in case it helps until the second issue is fixed:

#%RAML 1.0
title: RAML spec
types:
  tree_v1_0_0:
  tree_v1_0_1:
traits:
  - responding-xml-1-0:
      responses:
        200?:
          description: OK
          body:
            application/<<type>>+xml:
              type: <<type>>
  - responding-xml-1-1:
      responses:
        200?:
          description: OK
          body:
            application/<<type2>>+xml:
              type: <<type2>>
/test:
  get:
    is: [
      responding-xml-1-0: {
        type: tree_v1_0_0,
      },
      responding-xml-1-1: {
        type2: tree_v1_0_1,
      },
    ]
    responses:
      200:

See that type2 instead of type parameter? That's because otherwise parser does not reapply application/<<type>>+xml second time.

@sichvoge
Copy link
Contributor

BTW, in RAML 1.0 RC2 the value of traits is not a sequence anymore.

@KonstantinSviridov
Copy link
Contributor

Fixed in the rc2 branch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants