Skip to content

feat: support for windows + add ci task #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [12.x]
os: [windows-latest, ubuntu-latest]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add


steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"node-fetch": "2.6.1"
},
"dependencies": {
"@himenon/path-oriented-data-structure": "0.1.0",
"@himenon/path-oriented-data-structure": "0.1.3",
"@types/json-schema": "7.0.6",
"ajv": "7.0.3",
"dot-prop": "6.0.1",
Expand Down
6 changes: 3 additions & 3 deletions scripts/tools/copyPackageSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const copyPackageSet = async (): Promise<void> => {
const libDir = "lib";
const publishPackageJson = path.join(libDir, "package.json");
pkg.private = undefined;
pkg.main = path.relative(libDir, pkg.main);
pkg.module = path.relative(libDir, pkg.module);
pkg.types = path.relative(libDir, pkg.types);
pkg.main = path.posix.relative(libDir, pkg.main);
pkg.module = path.posix.relative(libDir, pkg.module);
pkg.types = path.posix.relative(libDir, pkg.types);
pkg.directories = undefined;
pkg.files = undefined;
fs.writeFileSync(publishPackageJson, JSON.stringify(pkg, null, 2), {
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/factory/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const escapeIdentiferText = (text: string): string => {
};

export const generateComment = (comment: string, deprecated?: boolean): Comment => {
const splitComments = deprecated ? ["@deprecated"].concat(comment.split(EOL)) : comment.split(EOL);
const splitComments = deprecated ? ["@deprecated"].concat(comment.split(/\r?\n/)) : comment.split(/\r?\n/);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trick

const comments = splitComments.filter((comment, index) => {
if (index === splitComments.length - 1 && comment === "") {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/v3/TypeNodeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export interface ReferencePathSet {
const generatePath = (entryPoint: string, currentPoint: string, referencePath: string): ReferencePathSet => {
const ext = Path.extname(currentPoint); // .yml
const from = Path.relative(Path.dirname(entryPoint), currentPoint).replace(ext, ""); // components/schemas/A/B
const base = Path.dirname(from);
const result = Path.relative(base, referencePath); // remoteの場合? localの場合 referencePath.split("/")
const base = Path.dirname(from).replace(Path.sep, "/");
const result = Path.posix.relative(base, referencePath); // remoteの場合? localの場合 referencePath.split("/")
const pathArray = result.split("/");
return {
pathArray,
Expand All @@ -29,7 +29,7 @@ const calculateReferencePath = (store: Store.Type, base: string, pathArray: stri
let names: string[] = [];
let unresolvedPaths: string[] = [];
pathArray.reduce((previous, lastPath, index) => {
const current = Path.join(previous, lastPath);
const current = Path.posix.join(previous, lastPath);
// ディレクトリが深い場合は相対パスが`..`を繰り返す可能性があり、
// その場合はすでに登録されたnamesを削除する
if (lastPath === ".." && names.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/Converter/v3/components/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const generateLocalReference = (reference: OpenApi.Reference): LocalRefer
return;
}
const name = reference.$ref.split(localReferencePattern)[1];
const localPath = path.join(localReferenceComponents[localReferencePattern], name);
const localPath = path.posix.join(localReferenceComponents[localReferencePattern], name);
if (!localPath.startsWith("components")) {
throw new DevelopmentError(`localPath is not start "components":\n${localPath}`);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ export const generate = <T>(entryPoint: string, currentPoint: string, reference:

const relativePathFromEntryPoint = path.relative(path.dirname(entryPoint), referencePoint); // components/hoge/fuga.yml
const ext = path.extname(relativePathFromEntryPoint); // .yml
const pathArray: string[] = relativePathFromEntryPoint.replace(ext, "").split("/"); // ["components", "hoge", "fuga"]
const pathArray: string[] = relativePathFromEntryPoint.replace(ext, "").split(path.sep); // ["components", "hoge", "fuga"]
const targetPath: string = pathArray.join("/"); // components/hoge/fuga
const schemaName = pathArray[pathArray.length - 1]; // fuga
const componentName = pathArray[0] === "components" ? pathArray[1] : "";
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/v3/components/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const generateReferenceNamespace = (
kind: "namespace",
name: nameWithStatusCode,
});
const headerNamespace = store.getStatement(path.join(responseReference.path, "Header"), "namespace");
const headerNamespace = store.getStatement(path.posix.join(responseReference.path, "Header"), "namespace");
if (headerNamespace) {
store.addStatement(`${basePath}/Header`, {
kind: "namespace",
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/v3/components/Responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const generateNamespace = (
reference.referencePoint,
store,
factory,
path.dirname(reference.path), // referencePoint basename === namespace name
path.posix.dirname(reference.path), // referencePoint basename === namespace name
reference.name,
reference.data,
context,
Expand Down Expand Up @@ -94,7 +94,7 @@ export const generateNamespaceWithStatusCode = (
reference.referencePoint,
store,
factory,
path.dirname(reference.path), // referencePoint basename === namespace name
path.posix.dirname(reference.path), // referencePoint basename === namespace name
reference.name,
reference.data,
context,
Expand Down Expand Up @@ -157,7 +157,7 @@ export const generateInterfacesWithStatusCode = (
reference.referencePoint,
store,
factory,
path.dirname(reference.path), // referencePoint basename === namespace name
path.posix.dirname(reference.path), // referencePoint basename === namespace name
reference.name,
reference.data,
context,
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/v3/store/Store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { relative } from "path";
import * as Path from "path";

import { Tree } from "@himenon/path-oriented-data-structure";
import Dot from "dot-prop";
Expand Down Expand Up @@ -87,11 +87,11 @@ export const create = (factory: Factory.Type, rootDocument: OpenApi.Document): T
if (!path.startsWith("components")) {
throw new UnSupportError(`componentsから始まっていません。path=${path}`);
}
const targetPath = relative("components", path);
const targetPath = Path.posix.relative("components", path);
operator.set(targetPath, Structure.createInstance(statement));
},
getStatement: <T extends Structure.DataStructure.Kind>(path: string, kind: T): Structure.DataStructure.GetChild<T> | undefined => {
const targetPath = relative("components", path);
const targetPath = Path.posix.relative("components", path);
return getChildByPaths(targetPath, kind);
},
getRootStatements,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EOL } from "os";

import ts from "typescript";

import { Factory } from "../../../../CodeGenerator";
Expand Down Expand Up @@ -40,68 +42,68 @@ describe("PathParameter Test", () => {
return getText(expression);
};
test("generateUrlTemplateExpression", () => {
expect(generate("/{a}", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}`;\n");
expect(generate("/{a}/", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}/`;\n");
expect(generate("/a/{b}", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}`;\n");
expect(generate("/a/{b}/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/`;\n");
expect(generate("/a/{b}/c", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c`;\n");
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c/`;\n");
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}`;\n");
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}/`;\n");
expect(generate("/{a}", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}`;" + EOL);
expect(generate("/{a}/", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}/`;" + EOL);
expect(generate("/a/{b}", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}`;" + EOL);
expect(generate("/a/{b}/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/`;" + EOL);
expect(generate("/a/{b}/c", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c`;" + EOL);
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c/`;" + EOL);
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}`;" + EOL);
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}/`;" + EOL);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update


expect(
generate("/{a}/{b}", [
{ in: "path", name: "a", required: true },
{ in: "path", name: "b", required: true },
]),
).toBe("`/${params.parameter.a}/${params.parameter.b}`;\n");
).toBe("`/${params.parameter.a}/${params.parameter.b}`;" + EOL);
expect(
generate("/{a}/{b}/", [
{ in: "path", name: "a", required: true },
{ in: "path", name: "b", required: true },
]),
).toBe("`/${params.parameter.a}/${params.parameter.b}/`;\n");
).toBe("`/${params.parameter.a}/${params.parameter.b}/`;" + EOL);
expect(
generate("/{a}/{b}/c", [
{ in: "path", name: "a", required: true },
{ in: "path", name: "b", required: true },
]),
).toBe("`/${params.parameter.a}/${params.parameter.b}/c`;\n");
).toBe("`/${params.parameter.a}/${params.parameter.b}/c`;" + EOL);
expect(
generate("/{a}/{b}/c/", [
{ in: "path", name: "a", required: true },
{ in: "path", name: "b", required: true },
]),
).toBe("`/${params.parameter.a}/${params.parameter.b}/c/`;\n");
).toBe("`/${params.parameter.a}/${params.parameter.b}/c/`;" + EOL);
expect(
generate("/{a}/b/{c}", [
{ in: "path", name: "a", required: true },
{ in: "path", name: "c", required: true },
]),
).toBe("`/${params.parameter.a}/b/${params.parameter.c}`;\n");
).toBe("`/${params.parameter.a}/b/${params.parameter.c}`;" + EOL);
expect(
generate("/{a}/b/{c}/", [
{ in: "path", name: "a", required: true },
{ in: "path", name: "c", required: true },
]),
).toBe("`/${params.parameter.a}/b/${params.parameter.c}/`;\n");
).toBe("`/${params.parameter.a}/b/${params.parameter.c}/`;" + EOL);
expect(
generate("/a/{b}/{c}", [
{ in: "path", name: "b", required: true },
{ in: "path", name: "c", required: true },
]),
).toBe("`/a/${params.parameter.b}/${params.parameter.c}`;\n");
).toBe("`/a/${params.parameter.b}/${params.parameter.c}`;" + EOL);
expect(
generate("/a/{b}/{c}/", [
{ in: "path", name: "b", required: true },
{ in: "path", name: "c", required: true },
]),
).toBe("`/a/${params.parameter.b}/${params.parameter.c}/`;\n");
).toBe("`/a/${params.parameter.b}/${params.parameter.c}/`;" + EOL);
expect(
generate("/a/{b}...{c}/", [
{ in: "path", name: "b", required: true },
{ in: "path", name: "c", required: true },
]),
).toBe("`/a/${params.parameter.b}...${params.parameter.c}/`;\n");
).toBe("`/a/${params.parameter.b}...${params.parameter.c}/`;" + EOL);
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,10 @@
unique-filename "^1.1.1"
which "^1.3.1"

"@himenon/[email protected].0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@himenon/path-oriented-data-structure/-/path-oriented-data-structure-0.1.0.tgz#b417a3cb46e3bbc409c4fc5216c42d924f2e7433"
integrity sha512-pU4wymQPvBbtPDyeVP8RekOUsQbUiztEae38BIPLFRSqOM68xCNcFzng71HhI2ZdD0kbt+zK1HgQKwB/nv8VkA==
"@himenon/[email protected].3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@himenon/path-oriented-data-structure/-/path-oriented-data-structure-0.1.3.tgz#a9298afd0097e2f5e466a2f86318c887e82570ed"
integrity sha512-1QaIv/cFdpg5GkpG6pQgrYgDouRO7dzz3djiSKLgd2+GjqMG0TsVvUaAxtIo7Y6Hqdk/pL7u7U+cYf80ww9tcw==

"@istanbuljs/load-nyc-config@^1.0.0":
version "1.0.0"
Expand Down