-
Notifications
You must be signed in to change notification settings - Fork 16
feat: supports fragment in remote reference #83
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
Changes from all commits
19ff3a3
aeb1fe6
bb342ad
9a25292
ca3da4b
2ddf563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ jobs: | |
- name: Test & Build | ||
run: | | ||
pnpm build | ||
pnpm run test:code:gen | ||
pnpm test | ||
env: | ||
CI: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,22 +136,29 @@ export const generate = <T>(entryPoint: string, currentPoint: string, reference: | |
throw new NotFoundFileError(`Not found reference point from current point. \n Path: ${referencePoint}`); | ||
} | ||
|
||
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(path.sep); // ["components", "hoge", "fuga"] | ||
const targetPath: string = pathArray.join("/"); // components/hoge/fuga | ||
const fragmentIndex = referencePoint.indexOf("#/"); | ||
let targetPath: string; | ||
if (fragmentIndex !== -1) { | ||
targetPath = referencePoint.substring(fragmentIndex + 2); | ||
} else { | ||
const relativePathFromEntryPoint = path.relative(path.dirname(entryPoint), referencePoint); // components/hoge/fuga.yml | ||
const pathArray: string[] = relativePathFromEntryPoint.split(path.sep); // ["components", "hoge", "fuga"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this file also does not use the posix path, CI in the Windows environment is considered to have failed. - import * as path from "path";
+ import { posix as path } from "path"; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another problem ... |
||
if (pathArray[0] != "components") { | ||
throw new DevelopmentError(`targetPath is not start "components":\n${relativePathFromEntryPoint}`); | ||
} | ||
|
||
const ext = path.extname(relativePathFromEntryPoint); // .yml | ||
targetPath = pathArray.join("/").substring(0, relativePathFromEntryPoint.length - ext.length); // components/hoge/fuga | ||
} | ||
const pathArray: string[] = targetPath.split("/"); // ["components", "hoge", "fuga"] | ||
const schemaName = pathArray[pathArray.length - 1]; // fuga | ||
const componentName = pathArray[0] === "components" ? pathArray[1] : ""; | ||
const data = FileSystem.loadJsonOrYaml(referencePoint); | ||
|
||
const data = FileSystem.loadJsonOrYaml(referencePoint); | ||
if (Guard.isReference(data)) { | ||
return generate<T>(entryPoint, referencePoint, data); | ||
} | ||
|
||
if (!targetPath.startsWith("components")) { | ||
throw new DevelopmentError(`targetPath is not start "components":\n${targetPath}`); | ||
} | ||
|
||
return { | ||
type: "remote", | ||
referencePoint, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,9 @@ describe("Typedef with template", () => { | |
const text = Utils.replaceVersionInfo(generateCode); | ||
expect(text).toMatchSnapshot(); | ||
}); | ||
test("remote-ref-access", () => { | ||
const generateCode = fs.readFileSync(path.join(__dirname, "../code/typedef-with-template/remote-ref-access.ts"), { encoding: "utf-8" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import { posix as path } from "path"; Oh, sorry. Please change import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "path" does not work properly in Windows environment, use posix path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another problem ... |
||
const text = Utils.replaceVersionInfo(generateCode); | ||
expect(text).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
openapi: 3.1.0 | ||
info: | ||
version: 1.0.0 | ||
title: v0.remote.ref.access.test | ||
description: Library test schema | ||
license: | ||
name: MIT | ||
|
||
servers: | ||
- url: "http://dev.remote.ref.access.test/v0/" | ||
description: Development Environment | ||
- url: "https://ref,remote.access.test/v0/" | ||
description: Production Environment | ||
|
||
tags: | ||
- name: test | ||
|
||
components: | ||
schemas: | ||
Book: | ||
type: object | ||
required: | ||
- metadata | ||
properties: | ||
author: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
age: | ||
type: string | ||
publisher: | ||
type: object | ||
properties: | ||
name: | ||
type: String | ||
address: | ||
type: string | ||
metadata: | ||
type: object | ||
required: | ||
- description | ||
properties: | ||
description: | ||
type: string | ||
Author: | ||
$ref: "#/components/schemas/Book/properties/author" | ||
Publisher: | ||
$ref: "#/components/schemas/Book/properties/publisher" | ||
|
||
paths: | ||
/get/book/{id}: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
description: Book ID | ||
schema: | ||
type: string | ||
format: uuid | ||
get: | ||
operationId: getBook | ||
responses: | ||
200: | ||
description: Get Books | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Book" | ||
/get/book/{id}/description: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
description: Book ID | ||
schema: | ||
type: string | ||
format: uuid | ||
get: | ||
operationId: getDescription | ||
responses: | ||
200: | ||
description: Get Book Description | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Book/properties/metadata/properties/description" | ||
|
||
/get/author/{id}: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
description: Author Id | ||
schema: | ||
type: string | ||
format: uuid | ||
get: | ||
operationId: getAuthor | ||
responses: | ||
200: | ||
description: Get Author | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Book/properties/author" | ||
/get/publisher/{id}: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
description: Publisher ID | ||
schema: | ||
type: string | ||
format: uuid | ||
get: | ||
operationId: getPublisher | ||
responses: | ||
200: | ||
description: Get Publisher | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Publisher" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Thankyou!