Skip to content

Commit

Permalink
Publish v0.1.23 with emension
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Jun 27, 2024
1 parent 153565e commit a9fd47f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 74 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.1.23-dev.20240626-6",
"version": "0.1.23",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/internal/MigrateConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IMigrateDocument } from "../IMigrateDocument";
import { OpenApi } from "../OpenApi";
import { StringUtil } from "../utils/StringUtil";
import { MigrateOperationConverter } from "./MigrateOperationConverter";
import { MigrateRouteNamespacer } from "./MigrateRouteNamespacer";
import { MigrateRouteAccessor } from "./MigrateRouteAccessor";

export namespace MigrateConverter {
export const convert = (document: OpenApi.IDocument): IMigrateDocument => {
Expand Down Expand Up @@ -40,7 +40,7 @@ export namespace MigrateConverter {
const operations: IMigrateRoute[] = entire.filter(
(o): o is IMigrateRoute => !!o,
);
MigrateRouteNamespacer.overwrite(operations);
MigrateRouteAccessor.overwrite(operations);
return {
routes: operations,
errors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Escaper } from "../utils/Escaper";
import { MapUtil } from "../utils/MapUtil";
import { StringUtil } from "../utils/StringUtil";

export namespace MigrateRouteNamespacer {
export namespace MigrateRouteAccessor {
export const overwrite = (routes: IMigrateRoute[]): void => {
const dict: Map<string, IElement> = collect((op) =>
op.emendedPath
Expand All @@ -14,10 +14,12 @@ export namespace MigrateRouteNamespacer {
)(routes);
for (const props of dict.values())
props.entries.forEach((entry, i) => {
entry.alias = StringUtil.escapeDuplicate([
...props.children,
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
])(entry.alias);
entry.alias = StringUtil.escapeDuplicate(
[
...props.children,
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
].map(StringUtil.normalize),
)(StringUtil.normalize(entry.alias));
entry.route.accessor = [...props.namespace, entry.alias];

const parameters: { name: string; key: string }[] = [
Expand Down
66 changes: 0 additions & 66 deletions src/utils/StringUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ export namespace StringUtil {
.map(NamingConvention.pascal)
.join("");

export const camel = (path: string) =>
splitWithNormalization(path)
.map((str, i) =>
i === 0 ? NamingConvention.camel(str) : NamingConvention.pascal(str),
)
.join("");

export const splitWithNormalization = (path: string) =>
path
.split("/")
Expand All @@ -37,67 +30,8 @@ export namespace StringUtil {
export const normalize = (str: string) =>
str.split(".").join("_").split("-").join("_");

export const commonPrefix = (strs: string[]): string => {
if (strs.length === 0) return "";

let prefix = strs[0];
for (let i = 1; i < strs.length; i++) {
while (strs[i].indexOf(prefix) !== 0) {
prefix = prefix.substring(0, prefix.length - 1);
if (prefix === "") return "";
}
}
return prefix
.split("/")
.filter((str) => str[0] !== "{" || str[str.length - 1] === "}")
.join("/");
};

export const escapeDuplicate =
(keep: string[]) =>
(change: string): string =>
keep.includes(change) ? escapeDuplicate(keep)(`_${change}`) : change;

export const escapeNonVariableSymbols = (str: string): string => {
for (const [before, after] of VARIABLE_REPLACERS)
str = str.split(before).join(after);
for (let i: number = 0; i <= 9; ++i)
if (str[0] === i.toString()) {
str = "_" + str;
break;
}
str = str.trim();
if (str === "") return "_empty_";
return str;
};
}

const VARIABLE_REPLACERS: [string, string][] = [
["`", "_backquote_"],
["!", "_exclamation_"],
["#", "_hash_"],
["$", "_dollar_"],
["%", "_percent_"],
["^", "_caret_"],
["&", "_and_"],
["*", "_star_"],
["(", "_lparen_"],
[")", "_rparen_"],
["-", "_minus_"],
["+", "_plus_"],
["|", "_or_"],
["{", "_blt_"],
["}", "_bgt_"],
["<", "_lt_"],
[">", "_gt_"],
["[", "_alt_"],
["]", "_agt_"],
[",", "_comma_"],
["'", "_singlequote_"],
['"', "_doublequote_"],
[" ", "_space_"],
["?", "_question_"],
[":", "_colon_"],
[";", "_semicolon_"],
["...", "_rest_"],
];

0 comments on commit a9fd47f

Please sign in to comment.