Skip to content

Commit

Permalink
Merge pull request #37 from samchon/feature/mixed
Browse files Browse the repository at this point in the history
Fix samchon/nestia#983: mixed-in null type case.
  • Loading branch information
samchon authored Aug 11, 2024
2 parents 2aef676 + 87d2798 commit 9171a99
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/openapi",
"version": "0.4.3",
"version": "0.4.4",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"module": "./lib/index.mjs",
Expand Down
58 changes: 55 additions & 3 deletions src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,66 @@ export namespace OpenApi {
* Parameter of the operation.
*/
export interface IParameter<Schema extends IJsonSchema = IJsonSchema> {
/**
* Representative name of the parameter.
*
* In the most case, the `name` is equivalent to parameter variable name.
* Therefore, the `name` must be filled with the significant variable name
* of the parameter.
*
* By the way, only when the {@link in} property is `path`, the `name`
* can be omitted. In that case, the `name` is automatically deduced from
* the URL path's positional template argument analyzing.
*/
name?: string;

/**
* Location of the parameter.
*
* The `in` property is a string that determines the location of the parameter.
*
* - `path`: parameter is part of the path of the URL.
* - `query`: parameter is part of the query string.
* - `header`: parameter is part of the header.
* - `cookie`: parameter is part of the cookie.
*/
in: "path" | "query" | "header" | "cookie";

/**
* Type info of the parameter.
*/
schema: Schema;

/**
* Whether the parameter is required for execution or not.
*
* If the parameter is required, the value must be filled. Otherwise,
* it is possible to skip the parameter when executing the APi operation.
*
* For reference, the `required` property must be always `true` when the
* {@link in} property is `path`. Otherwise, the `required` property can
* be anything of them; `true`, `false` and `undefined`.
*/
required?: boolean;

/**
* Short title of the parameter.
*/
title?: string;

/**
* Verbose explanation of the parameter.
*/
description?: string;

/**
* Example value of the parameter.
*/
example?: any;

/**
* Collection of example values of the parameter with keys.
*/
examples?: Record<string, IExample>;
}

Expand All @@ -525,9 +578,8 @@ export namespace OpenApi {
/**
* List of content types supported in request/response body.
*/
export type IContent<Schema extends IJsonSchema = IJsonSchema> = Partial<
Record<ContentType, IMediaType<Schema>>
>;
export interface IContent<Schema extends IJsonSchema = IJsonSchema>
extends Partial<Record<ContentType, IMediaType<Schema>>> {}

/**
* Media type of a request/response body.
Expand Down
5 changes: 3 additions & 2 deletions src/OpenApiV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export namespace OpenApiV3 {
/* -----------------------------------------------------------
PATH ITEMS
----------------------------------------------------------- */
export type IPath = {
export interface IPath
extends Partial<Record<Method, IOperation | undefined>> {
parameters?: Array<
| IOperation.IParameter
| IJsonSchema.IReference<`#/components/headers/${string}`>
Expand All @@ -84,7 +85,7 @@ export namespace OpenApiV3 {
servers?: IServer[];
summary?: string;
description?: string;
} & Partial<Record<Method, IOperation | undefined>>;
}

export interface IOperation {
operationId?: string;
Expand Down
15 changes: 11 additions & 4 deletions src/OpenApiV3_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export namespace OpenApiV3_1 {
/* -----------------------------------------------------------
OPERATORS
----------------------------------------------------------- */
export type IPath = {
export interface IPath extends Partial<Record<Method, IOperation>> {
parameters?: Array<
| IOperation.IParameter
| IJsonSchema.IReference<`#/components/headers/${string}`>
Expand All @@ -90,7 +90,7 @@ export namespace OpenApiV3_1 {
servers?: IServer[];
summary?: string;
description?: string;
} & Partial<Record<Method, IOperation>>;
}

export interface IOperation {
operationId?: string;
Expand Down Expand Up @@ -197,9 +197,16 @@ export namespace OpenApiV3_1 {
Omit<IObject, "type">,
IOneOf,
IAnyOf,
IAllOf {
IAllOf,
IReference {
type: Array<
"boolean" | "integer" | "number" | "string" | "array" | "object"
| "boolean"
| "integer"
| "number"
| "string"
| "array"
| "object"
| "null"
>;
default?: any[] | null;
enum?: any[];
Expand Down
5 changes: 3 additions & 2 deletions src/SwaggerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ export namespace SwaggerV2 {
/* -----------------------------------------------------------
OPERATORS
----------------------------------------------------------- */
export type IPath = {
export interface IPath
extends Partial<Record<Method, IOperation | undefined>> {
parameters?: Array<
IOperation.IParameter | IJsonSchema.IReference<`#/parameters/${string}`>
>;
} & Partial<Record<Method, IOperation | undefined>>;
}

export interface IOperation {
operationId?: string;
Expand Down
18 changes: 16 additions & 2 deletions src/internal/OpenApiV3_1Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,25 +305,39 @@ export namespace OpenApiV3_1Converter {
...{
type: undefined,
oneOf: undefined,
anyOf: undefined,
allOf: undefined,
$ref: undefined,
},
});
if (schema.oneOf !== undefined)
visit({
...schema,
...{
type: undefined,
const: undefined,
anyOf: undefined,
allOf: undefined,
$ref: undefined,
},
});
if (schema.anyOf !== undefined)
visit({
...schema,
...{
type: undefined,
const: undefined,
oneOf: undefined,
allOf: undefined,
$ref: undefined,
},
});
if (schema.allOf !== undefined)
visit({
...schema,
...{
type: undefined,
oneOf: undefined,
anyOf: undefined,
$ref: undefined,
},
});
for (const type of schema.type)
Expand Down

0 comments on commit 9171a99

Please sign in to comment.