Skip to content

Commit

Permalink
Merge pull request #10 from stoplightio/fix/srn-ext
Browse files Browse the repository at this point in the history
fix: srn extensions
  • Loading branch information
casserni authored Sep 6, 2019
2 parents b1e9f56 + 24ea17b commit ed5c8b0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
39 changes: 36 additions & 3 deletions src/__tests__/srn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { deserializeSrn, serializeSrn } from '../srn';

describe('deserializeSrn', () => {
it('should work deserialize org srns', () => {
it('should work deserialize org srn', () => {
expect(deserializeSrn('sl/org')).toEqual({
shortcode: 'sl',
orgSlug: 'org',
});
});

it('should work deserialize project srns', () => {
it('should work deserialize project srn', () => {
expect(deserializeSrn('sl/org/project')).toEqual({
shortcode: 'sl',
orgSlug: 'org',
projectSlug: 'project',
});
});

it('should work deserialize node srns', () => {
it('should work deserialize node srn', () => {
expect(deserializeSrn('sl/org/project/reference/todos/openapi.yml')).toEqual({
shortcode: 'sl',
orgSlug: 'org',
Expand All @@ -26,6 +26,39 @@ describe('deserializeSrn', () => {
ext: '.yml',
});
});

it('should work deserialize node srn two dots in file', () => {
expect(deserializeSrn('sl/org/project/reference/todos/openapi.v1.yml')).toEqual({
shortcode: 'sl',
orgSlug: 'org',
projectSlug: 'project',
uri: '/reference/todos/openapi.v1.yml',
file: 'openapi.v1.yml',
ext: '.yml',
});
});

it('should work deserialize node srn with extended uri parts', () => {
expect(deserializeSrn('sl/org/project/reference/todos/openapi.yml/components/schemas/pet')).toEqual({
shortcode: 'sl',
orgSlug: 'org',
projectSlug: 'project',
uri: '/reference/todos/openapi.yml/components/schemas/pet',
file: 'openapi.yml',
ext: '.yml',
});
});

it('should work deserialize node srn with dot in uri path', () => {
expect(deserializeSrn('sl/org/project/reference/stoplight/openapi.v1.yaml/paths/~1nodes.get/get')).toEqual({
shortcode: 'sl',
orgSlug: 'org',
projectSlug: 'project',
uri: '/reference/stoplight/openapi.v1.yaml/paths/~1nodes.get/get',
file: 'openapi.v1.yaml',
ext: '.yaml',
});
});
});

describe('serializeSrn', () => {
Expand Down
10 changes: 6 additions & 4 deletions src/srn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { basename } from './basename';
import { extname } from './extname';
import { parseBase } from './parseBase';

export interface IDeserializedSrn {
shortcode: string;
Expand All @@ -18,8 +17,11 @@ export function deserializeSrn(srn: string): IDeserializedSrn {
let file;
let ext;
if (uri) {
ext = extname(uri);
file = basename(uri);
file = uriParts.find(part => part.includes('.'));

if (file) {
ext = parseBase(file).ext;
}
}

return {
Expand Down

0 comments on commit ed5c8b0

Please sign in to comment.