Skip to content

Commit fbbf1c2

Browse files
committed
feat: update version to 0.3.7 and enhance changelog; refactor allOfToOneOf to always remove discriminator from base schemas
1 parent a908d00 commit fbbf1c2

File tree

5 files changed

+13
-28
lines changed

5 files changed

+13
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [0.3.7] - 2025-11-28
4+
### Changed
5+
- Fixed OAS with discriminator cleanup
6+
- Refined `allOfToOneOf` tests to assert the new discriminator ownership model.
7+
38
## [0.3.6] - 2025-11-28
49
### Added
510
- Introduced a minimal polymorphic OpenAPI 3.1 example (`examples/polymorphic-minimal.yaml`) showcasing `allOf` inheritance with a discriminator-based base schema.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@amartus/oas-utils",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"description": "Utilities for working with OpenAPI (OAS) documents.",
55
"type": "module",
66
"main": "dist/index.js",

src/lib/allOfToOneOf.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { refToName, buildInheritanceGraph } from "./oasUtils.js";
22

33

44
export interface AllOfToOneOfOptions {
5-
/** If true, remove discriminator from base schema and let oneOf wrapper handle it */
6-
removeDiscriminatorFromBase?: boolean;
75
/** If true, add const property with discriminator value to specialization schemas (default: true) */
86
addDiscriminatorConst?: boolean;
97
/** If true, skip oneOf transformation if only one specialization is found (default: false) */
@@ -139,12 +137,10 @@ export function allOfToOneOf(doc: any, opts: AllOfToOneOfOptions = {}): any {
139137
}
140138
}
141139

142-
// Step 6: Optionally remove discriminator from base schemas
143-
if (opts.removeDiscriminatorFromBase) {
144-
for (const baseName of baseSchemasWithDiscriminator.keys()) {
145-
if (schemas[baseName] && polymorphicWrappers.has(baseName)) {
146-
delete schemas[baseName].discriminator;
147-
}
140+
// Step 6: Always remove discriminator from base schemas that were converted
141+
for (const baseName of baseSchemasWithDiscriminator.keys()) {
142+
if (schemas[baseName] && polymorphicWrappers.has(baseName)) {
143+
delete schemas[baseName].discriminator;
148144
}
149145
}
150146

test/allOfToOneOf.test.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("allOfToOneOf", () => {
6464
);
6565
});
6666

67-
it("preserves base schema discriminator by default", () => {
67+
it("removes discriminator from base schema after conversion", () => {
6868
const doc: any = {
6969
components: {
7070
schemas: {
@@ -77,22 +77,6 @@ describe("allOfToOneOf", () => {
7777
};
7878

7979
allOfToOneOf(doc);
80-
expect(doc.components.schemas.Animal.discriminator).toBeDefined();
81-
});
82-
83-
it("removes discriminator from base when option is set", () => {
84-
const doc: any = {
85-
components: {
86-
schemas: {
87-
Animal: testSchemas.animalWithDiscriminator({
88-
Cat: "#/components/schemas/Cat",
89-
}),
90-
Cat: testSchemas.catSpecialized(),
91-
},
92-
},
93-
};
94-
95-
allOfToOneOf(doc, { removeDiscriminatorFromBase: true });
9680
expect(doc.components.schemas.Animal.discriminator).toBeUndefined();
9781
});
9882

0 commit comments

Comments
 (0)