swaggie 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,5 +37,20 @@ function readLocalFile(filePath) {
37
37
  }
38
38
 
39
39
  function parseFileContents(contents, path) {
40
- return /.ya?ml$/i.test(path) ? (_jsyaml2.default.load(contents) ) : JSON.parse(contents);
40
+ // If the path ends with .yaml or .yml, parse as YAML
41
+ if (/.ya?ml$/i.test(path)) {
42
+ return _jsyaml2.default.load(contents) ;
43
+ }
44
+ // If the path ends with .json, parse as JSON
45
+ if (/.json$/i.test(path)) {
46
+ return JSON.parse(contents);
47
+ }
48
+
49
+ // It is possible that the URL does not have an extension, so we need to check the contents
50
+ const firstChar = contents.trimStart()[0];
51
+ if (firstChar === '{') {
52
+ return JSON.parse(contents);
53
+ }
54
+
55
+ return _jsyaml2.default.load(contents) ;
41
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Generate TypeScript REST client code from an OpenAPI spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",