fork of hey-api/openapi-ts because I need some additional things
1import path from 'node:path';
2
3import { $RefParser } from '..';
4import { getSpecsPath } from './utils';
5
6describe('pointer', () => {
7 it('inlines internal JSON Pointer refs under #/paths/ for OpenAPI bundling', async () => {
8 const refParser = new $RefParser();
9 const pathOrUrlOrSchema = path.join(
10 getSpecsPath(),
11 'json-schema-ref-parser',
12 'openapi-paths-ref.json',
13 );
14 const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any;
15
16 // The GET endpoint should have its schema defined inline
17 const getSchema = schema.paths['/foo'].get.responses['200'].content['application/json'].schema;
18 expect(getSchema.$ref).toBeUndefined();
19 expect(getSchema.type).toBe('object');
20 expect(getSchema.properties.bar.type).toBe('string');
21
22 // The POST endpoint should have its schema inlined (copied) instead of a $ref
23 const postSchema =
24 schema.paths['/foo'].post.responses['200'].content['application/json'].schema;
25 expect(postSchema.$ref).toBe(
26 '#/paths/~1foo/get/responses/200/content/application~1json/schema',
27 );
28 expect(postSchema.type).toBeUndefined();
29 expect(postSchema.properties?.bar?.type).toBeUndefined();
30
31 // Both schemas should be identical objects
32 expect(postSchema).not.toBe(getSchema);
33 });
34});