fork of hey-api/openapi-ts because I need some additional things
1import { compileInputPath } from '../path';
2
3describe('compileInputPath', () => {
4 it('with raw OpenAPI specification', () => {
5 const path = compileInputPath({
6 path: {
7 info: {
8 version: '1.0.0',
9 },
10 openapi: '3.1.0',
11 },
12 });
13 expect(path).toEqual({
14 path: {
15 info: {
16 version: '1.0.0',
17 },
18 openapi: '3.1.0',
19 },
20 });
21 });
22
23 it('with arbitrary string', () => {
24 const path = compileInputPath({
25 path: 'path/to/openapi.json',
26 });
27 expect(path).toEqual({
28 path: 'path/to/openapi.json',
29 });
30 });
31
32 it('with platform string', () => {
33 const path = compileInputPath({
34 path: 'https://get.heyapi.dev/foo/bar?branch=main&commit_sha=sha&tags=a,b,c&version=1.0.0',
35 registry: 'hey-api',
36 });
37 expect(path).toEqual({
38 branch: 'main',
39 commit_sha: 'sha',
40 organization: 'foo',
41 path: 'https://get.heyapi.dev/foo/bar?branch=main&commit_sha=sha&tags=a,b,c&version=1.0.0',
42 project: 'bar',
43 registry: 'hey-api',
44 tags: ['a', 'b', 'c'],
45 version: '1.0.0',
46 });
47 });
48
49 it('with platform arguments', () => {
50 const path = compileInputPath({
51 branch: 'main',
52 commit_sha: 'sha',
53 organization: 'foo',
54 path: '',
55 project: 'bar',
56 tags: ['a', 'b', 'c'],
57 version: '1.0.0',
58 });
59 expect(path).toEqual({
60 branch: 'main',
61 commit_sha: 'sha',
62 organization: 'foo',
63 path: 'https://get.heyapi.dev/foo/bar?branch=main&commit_sha=sha&tags=a,b,c&version=1.0.0',
64 project: 'bar',
65 tags: ['a', 'b', 'c'],
66 version: '1.0.0',
67 });
68 });
69
70 it('loads API key from HEY_API_TOKEN', () => {
71 process.env.HEY_API_TOKEN = 'foo';
72 const path = compileInputPath({
73 path: 'https://get.heyapi.dev/foo/bar',
74 registry: 'hey-api',
75 });
76 delete process.env.HEY_API_TOKEN;
77 expect(path).toEqual({
78 api_key: 'foo',
79 organization: 'foo',
80 path: 'https://get.heyapi.dev/foo/bar?api_key=foo',
81 project: 'bar',
82 registry: 'hey-api',
83 });
84 });
85});