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

file path for .yaml includes #791

Open
glodieu opened this issue Sep 11, 2017 · 5 comments
Open

file path for .yaml includes #791

glodieu opened this issue Sep 11, 2017 · 5 comments

Comments

@glodieu
Copy link

glodieu commented Sep 11, 2017

When I include a .json file for define a type, parser includes schemaPath attribute with its path.
But for .yaml files, parser doesn't keep file path.
Could you please do something similar like .json for .yaml files?
Thanks.

parser output

{
  "types": [
    {
      "Address": {
        "name": "Address",
        "typePropertyKind": "TYPE_EXPRESSION",
        "type": [
          "object"
        ],
        "description": "Address details,",
        "properties": {
          "streetName": {
            "name": "streetName",
            "typePropertyKind": "TYPE_EXPRESSION",
            "type": [
              "string"
            ]
          }
        }
      }
    },
    {
      "Address2": {
        "name": "Address2",
        "typePropertyKind": "JSON",
        "schemaPath": "Address.json",
        "type": [
          "{\n  \"type\": \"object\",\n  \"description\": \"Address details\",\n  \"properties\": {\n    \"streetName\": { \"type\": \"string\" }\n  },\n  \"required\": [ \"streetName\" ]\n}\n"
        ]
      }
    }
  ],
  "title": "My API With Types"
}

api.raml

#%RAML 1.0
title: My API With Types
types:
  Address: !include Address.yaml
  Address2: !include Address.json

Address.yaml

type: object
description: Address details,
properties:
  streetName:
    type: string

Address.json

{
  "type": "object",
  "description": "Address details",
  "properties": {
    "streetName": { "type": "string" }
  },
  "required": [ "streetName" ]
}
@KonstantinSviridov
Copy link
Contributor

Hi, @glodieu !

In the new JSON format we are going to introduce the sourceMap field which stores path of file where component has been defined. In your case it will be

{
  "specification": {
    "types": [
      {
        "name": "Address",
        "displayName": "Address",
        "type": [
          "object"
        ],
        "description": "Address details,",
        "properties": [
          {
            "name": "streetName",
            "displayName": "streetName",
            "type": [
              "string"
            ],
            "required": true,
            "mediaType": "application/raml+yaml",
            "typePropertyKind": "TYPE_EXPRESSION",
            "sourceMap": {
              "path": "Address.yaml"
            }
          }
        ],
        "mediaType": "application/raml+yaml",
        "typePropertyKind": "TYPE_EXPRESSION",
        "sourceMap": {
          "path": "Address.yaml"
        }
      },
      {
        "name": "Address2",
        "displayName": "Address2",
        "schemaPath": "Address.json",
        "sourceMap": {
          "path": "Address.json"
        },
        "type": [
          "{\r\n  \"type\": \"object\",\r\n  \"description\": \"Address details\",\r\n  \"properties\": {\r\n    \"streetName\": { \"type\": \"string\" }\r\n  },\r\n  \"required\": [ \"streetName\" ]\r\n}\r\n"
        ],
        "mediaType": "application/json",
        "typePropertyKind": "JSON"
      }
    ],
    "title": "My API With Types",
    "sourceMap": {
      "path": "api.raml"
    }
  },
  "ramlVersion": "RAML10",
  "type": "Api",
  "errors": []
}

Regards,
Konstantin

@glodieu
Copy link
Author

glodieu commented Sep 15, 2017

Hi @KonstantinSviridov
Great!, when it will be available?
Thanks

@sichvoge
Copy link
Contributor

Be careful! The new JSON output is fixing a lot of inconsistency issues and improvements that we applied with feedback from users of this parser. It's different from the current JSON and thats the reason we introduced a common load() method that returns the new JSON.

Using the new JSON would mean some work for us since we would need to replace the old.

@KonstantinSviridov
Copy link
Contributor

KonstantinSviridov commented Sep 19, 2017

Hi, @glodieu

when it will be available?

You'd better ask @sichvoge for details.

And yes, please, pay attention to structure changes in the output. E.g. types and properties are arrays, not maps. The good point here is that the new format has typings which describe it.

@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