Skip to content

Commit

Permalink
Merge pull request #26 from samchon/features/checker
Browse files Browse the repository at this point in the history
Add `IJsonSchema.IOneOf.discriminator`
  • Loading branch information
samchon authored Jul 5, 2024
2 parents 1524482 + 4e440b4 commit 5d27f91
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export namespace OpenApi {
* Path item.
*
* `OpenApi.IPath` represents a path item of emended OpenAPI v3.1,
* collecting multiple method operations in a signgle path.
* collecting multiple method operations in a single path.
*/
export interface IPath<
Schema extends IJsonSchema = IJsonSchema,
Expand Down Expand Up @@ -787,7 +787,7 @@ export namespace OpenApi {
}

/**
* Array type.
* Array type info.
*/
export interface IArray<Schema extends IJsonSchema = IJsonSchema>
extends __ISignificant<"array"> {
Expand Down Expand Up @@ -986,6 +986,32 @@ export namespace OpenApi {
* List of the union types.
*/
oneOf: Exclude<Schema, IJsonSchema.IOneOf>[];

/**
* Discriminator info of the union type.
*/
discriminator?: IOneOf.IDiscriminator;
}
export namespace IOneOf {
/**
* Discriminator info of the union type.
*/
export interface IDiscriminator {
/**
* Property name for the discriminator.
*/
propertyName: string;

/**
* Mapping of the discriminator value to the schema name.
*
* This property is valid only for {@link IReference} typed
* {@link IOneOf.oneof} elements. Therefore, `key` of `mapping` is
* the discriminator value, and `value` of `mapping` is the
* schema name like `#/components/schemas/SomeObject`.
*/
mapping?: Record<string, string>;
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/OpenApiV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ export namespace OpenApiV3 {
}
export interface IOneOf extends __IAttribute {
oneOf: IJsonSchema[];
discriminator?: IOneOf.IDiscriminator;
}
export namespace IOneOf {
export interface IDiscriminator {
propertyName: string;
mapping?: Record<string, string>;
}
}

export interface __ISignificant<Type extends string> extends __IAttribute {
Expand Down
7 changes: 7 additions & 0 deletions src/OpenApiV3_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ export namespace OpenApiV3_1 {
}
export interface IOneOf extends __IAttribute {
oneOf: IJsonSchema[];
discriminator?: IOneOf.IDiscriminator;
}
export namespace IOneOf {
export interface IDiscriminator {
propertyName: string;
mapping?: Record<string, string>;
}
}

export interface IArray extends __ISignificant<"array"> {
Expand Down
1 change: 1 addition & 0 deletions src/internal/SwaggerV2Downgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export namespace SwaggerV2Downgrader {
? { ...union[0] }
: { "x-oneOf": union.map((u) => ({ ...u, nullable: undefined })) }),
...attribute,
...(union.length > 1 ? { discriminator: undefined } : {}),
};
};

Expand Down

0 comments on commit 5d27f91

Please sign in to comment.