mirror of
https://github.com/LukeHagar/prettier-plugin-openapi.git
synced 2025-12-06 04:21:03 +00:00
Refactor OpenAPI parsing logic to improve error handling and type safety. Update integration tests to validate handling of malformed JSON and YAML inputs, ensuring consistent detection of non-OpenAPI content.
This commit is contained in:
@@ -457,7 +457,10 @@ describe('Integration Tests', () => {
|
||||
const malformedJson = '{"openapi": "3.0.0", "info": {';
|
||||
|
||||
// @ts-expect-error We are mocking things here
|
||||
expect(() => parser?.parse(malformedJson, { filepath: 'test.json' })).toThrow();
|
||||
const result = parser?.parse(malformedJson, { filepath: 'test.json' });
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result?.isOpenAPI).toBeFalse();
|
||||
});
|
||||
|
||||
it('should handle malformed YAML gracefully', () => {
|
||||
@@ -467,7 +470,10 @@ describe('Integration Tests', () => {
|
||||
const malformedYaml = 'openapi: 3.0.0\ninfo:\n title: Test\n version: 1.0.0\n invalid: [';
|
||||
|
||||
// @ts-expect-error We are mocking things here
|
||||
expect(() => parser?.parse(malformedYaml, { filepath: 'test.yaml' })).toThrow();
|
||||
const result = parser?.parse(malformedYaml, { filepath: 'test.yaml' });
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result?.isOpenAPI).toBeFalse();
|
||||
});
|
||||
|
||||
it('should handle non-OpenAPI content', () => {
|
||||
@@ -485,8 +491,6 @@ describe('Integration Tests', () => {
|
||||
const parsedData = parser?.parse(nonOpenAPI, { filepath: 'test.json' })
|
||||
expect(parsedData).toBeDefined();
|
||||
expect(parsedData?.isOpenAPI).toBeFalse();
|
||||
expect(parsedData?.content).toBeDefined();
|
||||
expect(parsedData?.content).toEqual(parsedJSON);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user