raml-org / raml-spec

RAML Specification
http://raml.org
3.87k stars 858 forks source link

It is not defined if Default media type is inherit in imported libraries #592

Open eleonoraortega opened 7 years ago

eleonoraortega commented 7 years ago

ResourceType defined inside an imported library. The root raml file has a default media type (application/json). The resource type has a put method with a request body and this request body doesn't define the media type.

Root file:

#%RAML 1.0
title: Example API
version: v1
mediaType: application/json

uses:
  resourceTypes: resourceTypes.raml

/entity:
  get:

Library file looks like this:

#%RAML 1.0 Library
usage: Standard resourceTypes

resourceTypes:
  item:
    put:
      body:
          example: {"property":"value"}

This case is not documented on the RAML specification. It's not clear if the default media type is inherited in the imported libraries.

sichvoge commented 7 years ago

It should be if you, and only if you, declare entity to be of type resourceTypes.item.

#%RAML 1.0
title: Example API
version: v1
mediaType: application/json

uses:
  resourceTypes: resourceTypes.raml

/entity:
  type: resourceTypes.item
  get:

The version where the resource type from the library is applied, should look like the following:

#%RAML 1.0
title: Example API
version: v1
mediaType: application/json

/entity:
  put:
    body:
      example: {"property":"value"}
  get:

And the fully expanded version:

#%RAML 1.0
title: Example API
version: v1
mediaType: application/json

/entity:
  put:
    body:
      application/json: 
        example: {"property":"value"}
  get:

Does that answer your question?

Again, its not inherited into libraries, since the concept of expansion basically applies nodes only; not inherit.

svacas commented 7 years ago

The problem with this approach is that a library cannot be validated in isolation. It will be only valid when referenced from RAML files which have a default media type defined, which renders the library not much reusable.

sichvoge commented 7 years ago

That's a big problem in general. How can we make fragment's valid in isolation or actually should they only be able in the context of a root RAML file? There is no good answer atm.