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

Body type inheritance support #66

Open
dennisfoconnor opened this issue Jan 5, 2016 · 6 comments
Open

Body type inheritance support #66

dennisfoconnor opened this issue Jan 5, 2016 · 6 comments

Comments

@dennisfoconnor
Copy link

Currently when parsing a method request body or a response body, it appears that the body object does not inherit properties or examples or from the parent type.

Given the following example:

#%RAML 1.0
title: Pet shop
version: 1
baseUri: /shop

types:
  Pet:
    properties:
      name: string
      kind: string
      price: number
    example:
      name: "Snoopy"
      kind: "Mammal"
      price: 100
/pets:
  /{id}:
    get:
    reponses:
      200:
        body:
          application/json:
            type: Pet

When we run this RAML through through the parser and try to retrieve the body for the response. We get an error.

api.resources()[0].resources()[0].methods()[0].responses()[0].body()[0].properties();
TypeError: api.resources(...)[0].resources(...)[0].methods(...)[0].responses(...)[0].body(...)[0].properties is not a function

Ideally the parser should return the properties and example(s) from the parent type.

Is this feature currently on the roadmap?

@fkrauthan
Copy link

Same issue for traits. I use traits for queryParameters() but when I call queryParameters() I just get the ones returned that I define right away for that resource but not the one that are defined in traits.

@ddenisenko
Copy link
Contributor

@dennisfoconnor Type declaration AST node itself does not contain parent's properties. Because this node represents what actually is typed by user, the code.
What you can do to get parent properties is to get runtime type from the AST node like this:

var bodyType = api.resources()[0].resources()[0].methods()[0].responses()[0].body()[0];

var runtimeBodyType = bodyType.runtimeType();

You get the instance of ITypeDefinition, which can be asked for super types and properties of the super type like this:
runtimeBodyType.superTypes()[0].properties()

Or, if you do not want to bother with super type analysis, you can just ask for all type properties, including the ones defined in the super types:
runtimeBodyType.allProperties()

@ddenisenko
Copy link
Contributor

@fkrauthan You need to call expand() for your Api in order to apply traits and resource types.

@fkrauthan
Copy link

@ddenisenko Shouldn't expand also resolve custom types?

@DataGreed
Copy link

DataGreed commented Jan 11, 2019

2019, still the same problem.

I have a response body with custom types and I cannot render the properties of these types which makes the parser pretty useless.

@postatum
Copy link
Contributor

Note that raml-js-parser-2 has been deprecated, the new official parser is webapi-parser. Feel free to attempt to reproduce this issue with webapi-parser and report any issue you may have on that repository.

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

No branches or pull requests

5 participants