{"action":"created","issue":{"url":"https://api.github.com/repos/BigstickCarpet/swagger-parser/issues/8","labels_url":"https://api.github.com/repos/BigstickCarpet/swagger-parser/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/BigstickCarpet/swagger-parser/issues/8/comments","events_url":"https://api.github.com/repos/BigstickCarpet/swagger-parser/issues/8/events","html_url":"https://github.com/BigstickCarpet/swagger-parser/issues/8","id":82417412,"number":8,"title":"Fails to resolve file-based $refs with definitions","user":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-29T12:57:19Z","updated_at":"2015-05-29T13:49:00Z","closed_at":null,"body":"If you reference a definition in another file, the parser fails to load it because it doesn't strip before the `#`.\r\n\r\n```yaml\r\n# foo.yaml\r\ndefinitions:\r\n  Error:\r\n    properties:\r\n      error:\r\n        type: string\r\n    required: [\"error\"]\r\n```\r\n\r\n```yaml\r\n# main.yaml\r\n[...]\r\n  schema:\r\n    $ref: './foo.yaml#/definitions/Error'\r\n```\r\n\r\nFails with:\r\n```javascript\r\n// metadata\r\n{\r\n  baseDir: \"/home/swagger/\",\r\n  files: [\r\n    \"/home/swagger/main.yaml\",\r\n    \"/home/swagger/foo.yaml#/definitions/Error\"\r\n  ],\r\n  urls: [],\r\n  '$refs': {}\r\n}\r\n// error\r\nError: Error opening file \"/home/swagger/foo.yaml#/definitions/Error\"\r\n```\r\n\r\nAs an aside, I believe that when `$ref` references files, it is *not* compulsory to put a starting `.` (this threw me off for a while as I was trying `foo.yaml#/definitions/Error` instead of `./foo.yaml#/definitions/Error`. It was only when debugging `resolve.js` did I notice:\r\n\r\n```javascript\r\n:14 // Matches anything that starts with \"http://\" or contains a period (\".\")\r\n```"},"comment":{"url":"https://api.github.com/repos/BigstickCarpet/swagger-parser/issues/comments/106807370","html_url":"https://github.com/BigstickCarpet/swagger-parser/issues/8#issuecomment-106807370","issue_url":"https://api.github.com/repos/BigstickCarpet/swagger-parser/issues/8","id":106807370,"user":{"login":"BigstickCarpet","id":3453903,"avatar_url":"https://avatars.githubusercontent.com/u/3453903?v=3","gravatar_id":"","url":"https://api.github.com/users/BigstickCarpet","html_url":"https://github.com/BigstickCarpet","followers_url":"https://api.github.com/users/BigstickCarpet/followers","following_url":"https://api.github.com/users/BigstickCarpet/following{/other_user}","gists_url":"https://api.github.com/users/BigstickCarpet/gists{/gist_id}","starred_url":"https://api.github.com/users/BigstickCarpet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BigstickCarpet/subscriptions","organizations_url":"https://api.github.com/users/BigstickCarpet/orgs","repos_url":"https://api.github.com/users/BigstickCarpet/repos","events_url":"https://api.github.com/users/BigstickCarpet/events{/privacy}","received_events_url":"https://api.github.com/users/BigstickCarpet/received_events","type":"User","site_admin":false},"created_at":"2015-05-29T13:49:00Z","updated_at":"2015-05-29T13:49:00Z","body":"Hi, thanks for opening this issue.  Swagger Parser doesn't currently support deep-linking into files using hash fragments, but I can definitely add that.   Expect it soon.\r\n\r\nAlso, when referencing an external file, you _don't_ need to start the file name with a period (` . `).  The RegExp pattern in `resolve.js` matches any path that _contains_ a period anywhere in the path (such as a file extension).   So you can use `foo.yaml` rather than `./foo.yaml`."}}