Skip to content

Commit

Permalink
fix: do not fail when bundling a description containing null in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Oct 31, 2024
1 parent 1c259fd commit cac939f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-humans-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": patch
"@redocly/cli": patch
---

Fixed API descriptions bundling. Previously, schemas containing nulls in examples were causing failures.
51 changes: 51 additions & 0 deletions packages/core/src/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,57 @@ describe('bundle', () => {
expect(problems).toHaveLength(0);
expect(res.parsed).toMatchSnapshot();
});

it('should not fail when bundling openapi with nulls', async () => {
const testDocument = parseYamlToDocument(
outdent`
openapi: 3.1.0
paths:
/:
get:
responses:
200:
content:
application/json:
schema:
type: object
properties:
examples:
Foo:
`,
''
);

const config = await makeConfig({ rules: {} });

const {
bundle: { parsed },
problems,
} = await bundleDocument({
document: testDocument,
config: config,
externalRefResolver: new BaseResolver(),
});

expect(problems).toHaveLength(0);
expect(parsed).toMatchInlineSnapshot(`
openapi: 3.1.0
paths:
/:
get:
responses:
'200':
content:
application/json:
schema:
type: object
properties: null
examples:
Foo: null
components: {}
`);
});
});

describe('bundleFromString', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SpecMajorVersion,
SpecVersion,
} from './oas-types';
import { isAbsoluteUrl, isRef, refBaseName } from './ref-utils';
import { isAbsoluteUrl, isExternalValue, isRef, refBaseName } from './ref-utils';
import { initRules } from './config/rules';
import { reportUnresolvedRef } from './rules/no-unresolved-refs';
import { dequal, isPlainObject, isTruthy } from './utils';
Expand Down Expand Up @@ -380,7 +380,7 @@ function makeBundleVisitor(
},
Example: {
leave(node: any, ctx: UserContext) {
if (node.externalValue && node.value === undefined) {
if (isExternalValue(node) && node.value === undefined) {
const resolved = ctx.resolve({ $ref: node.externalValue });

if (!resolved.location || resolved.node === undefined) {
Expand Down

0 comments on commit cac939f

Please sign in to comment.