Skip to content

Commit ed5c8b0

Browse files
authored
Merge pull request #10 from stoplightio/fix/srn-ext
fix: srn extensions
2 parents b1e9f56 + 24ea17b commit ed5c8b0

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

src/__tests__/srn.spec.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { deserializeSrn, serializeSrn } from '../srn';
22

33
describe('deserializeSrn', () => {
4-
it('should work deserialize org srns', () => {
4+
it('should work deserialize org srn', () => {
55
expect(deserializeSrn('sl/org')).toEqual({
66
shortcode: 'sl',
77
orgSlug: 'org',
88
});
99
});
1010

11-
it('should work deserialize project srns', () => {
11+
it('should work deserialize project srn', () => {
1212
expect(deserializeSrn('sl/org/project')).toEqual({
1313
shortcode: 'sl',
1414
orgSlug: 'org',
1515
projectSlug: 'project',
1616
});
1717
});
1818

19-
it('should work deserialize node srns', () => {
19+
it('should work deserialize node srn', () => {
2020
expect(deserializeSrn('sl/org/project/reference/todos/openapi.yml')).toEqual({
2121
shortcode: 'sl',
2222
orgSlug: 'org',
@@ -26,6 +26,39 @@ describe('deserializeSrn', () => {
2626
ext: '.yml',
2727
});
2828
});
29+
30+
it('should work deserialize node srn two dots in file', () => {
31+
expect(deserializeSrn('sl/org/project/reference/todos/openapi.v1.yml')).toEqual({
32+
shortcode: 'sl',
33+
orgSlug: 'org',
34+
projectSlug: 'project',
35+
uri: '/reference/todos/openapi.v1.yml',
36+
file: 'openapi.v1.yml',
37+
ext: '.yml',
38+
});
39+
});
40+
41+
it('should work deserialize node srn with extended uri parts', () => {
42+
expect(deserializeSrn('sl/org/project/reference/todos/openapi.yml/components/schemas/pet')).toEqual({
43+
shortcode: 'sl',
44+
orgSlug: 'org',
45+
projectSlug: 'project',
46+
uri: '/reference/todos/openapi.yml/components/schemas/pet',
47+
file: 'openapi.yml',
48+
ext: '.yml',
49+
});
50+
});
51+
52+
it('should work deserialize node srn with dot in uri path', () => {
53+
expect(deserializeSrn('sl/org/project/reference/stoplight/openapi.v1.yaml/paths/~1nodes.get/get')).toEqual({
54+
shortcode: 'sl',
55+
orgSlug: 'org',
56+
projectSlug: 'project',
57+
uri: '/reference/stoplight/openapi.v1.yaml/paths/~1nodes.get/get',
58+
file: 'openapi.v1.yaml',
59+
ext: '.yaml',
60+
});
61+
});
2962
});
3063

3164
describe('serializeSrn', () => {

src/srn.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { basename } from './basename';
2-
import { extname } from './extname';
1+
import { parseBase } from './parseBase';
32

43
export interface IDeserializedSrn {
54
shortcode: string;
@@ -18,8 +17,11 @@ export function deserializeSrn(srn: string): IDeserializedSrn {
1817
let file;
1918
let ext;
2019
if (uri) {
21-
ext = extname(uri);
22-
file = basename(uri);
20+
file = uriParts.find(part => part.includes('.'));
21+
22+
if (file) {
23+
ext = parseBase(file).ext;
24+
}
2325
}
2426

2527
return {

0 commit comments

Comments
 (0)