mirror of
https://github.com/LukeHagar/prettier-plugin-openapi.git
synced 2025-12-06 12:47:47 +00:00
Refactor OpenAPI plugin structure by consolidating parser and printer exports, enhancing type safety, and improving error handling in parsing functions. Update tests to reflect new structure and ensure consistent handling of OpenAPI file detection.
This commit is contained in:
@@ -32,13 +32,13 @@ describe('Prettier OpenAPI Plugin', () => {
|
||||
// @ts-expect-error We are mocking things here
|
||||
const parsed = parser?.parse(inputJson, { filepath: 'test.json' });
|
||||
expect(parsed).toBeDefined();
|
||||
expect(parsed?.type).toBe('openapi');
|
||||
expect(parsed?.isOpenAPI).toBeTrue();
|
||||
expect(parsed?.format).toBe('json');
|
||||
expect(parsed?.content).toBeDefined();
|
||||
|
||||
// Format the parsed content
|
||||
// @ts-expect-error We are mocking things here
|
||||
const result = printer?.print({ getValue: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
const result = printer?.print({ getNode: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result).toContain('"openapi"');
|
||||
@@ -80,13 +80,13 @@ openapi: 3.0.0`;
|
||||
// @ts-expect-error We are mocking things here
|
||||
const parsed = parser?.parse(inputYaml, { filepath: 'test.yaml' });
|
||||
expect(parsed).toBeDefined();
|
||||
expect(parsed?.type).toBe('openapi');
|
||||
expect(parsed?.isOpenAPI).toBeTrue();
|
||||
expect(parsed?.format).toBe('yaml');
|
||||
expect(parsed?.content).toBeDefined();
|
||||
|
||||
// Format the parsed content
|
||||
// @ts-expect-error We are mocking things here
|
||||
const result = printer?.print({ getValue: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
const result = printer?.print({ getNode: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result).toContain('openapi:');
|
||||
@@ -148,13 +148,13 @@ openapi: 3.0.0`;
|
||||
// @ts-expect-error We are mocking things here
|
||||
const parsed = parser?.parse(inputJson, { filepath: 'test.json' });
|
||||
expect(parsed).toBeDefined();
|
||||
expect(parsed?.type).toBe('openapi');
|
||||
expect(parsed?.isOpenAPI).toBeTrue();
|
||||
expect(parsed?.format).toBe('json');
|
||||
expect(parsed?.content).toBeDefined();
|
||||
|
||||
// Format the parsed content
|
||||
// @ts-expect-error We are mocking things here
|
||||
const result = printer?.print({ getValue: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
const result = printer?.print({ getNode: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result).toContain('"swagger"');
|
||||
@@ -201,13 +201,13 @@ describe('Key Ordering Tests', () => {
|
||||
// @ts-expect-error We are mocking things here
|
||||
const parsed = parser?.parse(inputJson, { filepath: 'test.json' });
|
||||
expect(parsed).toBeDefined();
|
||||
expect(parsed?.type).toBe('openapi');
|
||||
expect(parsed?.isOpenAPI).toBeTrue();
|
||||
expect(parsed?.format).toBe('json');
|
||||
expect(parsed?.content).toBeDefined();
|
||||
|
||||
// Format the parsed content
|
||||
// @ts-expect-error We are mocking things here
|
||||
const result = printer?.print({ getValue: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
const result = printer?.print({ getNode: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
|
||||
@@ -261,13 +261,13 @@ describe('Key Ordering Tests', () => {
|
||||
// @ts-expect-error We are mocking things here
|
||||
const parsed = parser?.parse(inputJson, { filepath: 'test.json' });
|
||||
expect(parsed).toBeDefined();
|
||||
expect(parsed?.type).toBe('openapi');
|
||||
expect(parsed?.isOpenAPI).toBeTrue();
|
||||
expect(parsed?.format).toBe('json');
|
||||
expect(parsed?.content).toBeDefined();
|
||||
|
||||
// Format the parsed content
|
||||
// @ts-expect-error We are mocking things here
|
||||
const result = printer?.print({ getValue: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
const result = printer?.print({ getNode: () => parsed }, { tabWidth: 2 }, () => '');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user