Skip to content

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

Closed

Conversation

karupanerura
Copy link
Contributor

Summary

If any fragment is included in a remote URL reference, it always fail to load file.

Test Plan

The latest test running is failed on CI:
refs. https://github.com/Himenon/openapi-typescript-code-generator/actions/runs/2532596212

And it failed on my environment too. So I hard to test it. 😢

@karupanerura
Copy link
Contributor Author

The testing issue is ticketed: #84

return !!(fs.existsSync(entryPoint) && fs.statSync(entryPoint).isFile());
}

public static loadJsonOrYaml(entryPoint: string): any {
const hasFragment: boolean = new RegExp(this.FRAGMENT).test(entryPoint);
const hasFragment = entryPoint.indexOf(this.FRAGMENT) !== -1;
Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I see. Thankyou!

@Himenon Himenon self-requested a review October 5, 2022 09:58
@Himenon
Copy link
Owner

Himenon commented Oct 5, 2022

Surely this is a necessary fix, please confirm as the test is failing in a windows environment.

@Himenon
Copy link
Owner

Himenon commented Oct 5, 2022

You can write use cases in your tests to verify your supposed behavior! You can update snapshots to maintain them in the future!

https://github.com/Himenon/openapi-typescript-code-generator/blob/main/test/api.test.domain/index.yml#L246-L247

If this is difficult, please include an example in the Description of your Pull Request. I will add it later!

Thanks your cooperation, @karupanerura .

@karupanerura
Copy link
Contributor Author

@Himenon Thank you for the guide!

I added the basic snapshot test for this case.
Please check it.

@Himenon Himenon added the Type: Enhancement New feature or request label Oct 6, 2022
@karupanerura
Copy link
Contributor Author

CI is maybe fixed by ca3da4b

name: MIT

servers:
- url: "http://dev.remote.ref.access.test/v1/"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: .test TLD is recommended to use in test cases. refs: https://www.rfc-editor.org/rfc/rfc2606#page-2

@@ -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" });
Copy link
Owner

Choose a reason for hiding this comment

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

import { posix as path } from "path";

Oh, sorry. Please change import path. Like this.

https://github.com/Himenon/openapi-typescript-code-generator/blob/main/scripts/tools/cherry-pick.ts#L2

Copy link
Owner

@Himenon Himenon Oct 6, 2022

Choose a reason for hiding this comment

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

"path" does not work properly in Windows environment, use posix path.

https://nodejs.org/api/path.html#pathposix

Copy link
Owner

Choose a reason for hiding this comment

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

This is another problem ...
#87

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"]
Copy link
Owner

Choose a reason for hiding this comment

The 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";

Copy link
Owner

Choose a reason for hiding this comment

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

This is another problem ...
#87

@Himenon
Copy link
Owner

Himenon commented Oct 6, 2022

I fixed in #87 and merge this pull request changed. Thanks your cooperation, @karupanerura !
I will let you know when we release it.

@Himenon Himenon closed this Oct 6, 2022
@Himenon
Copy link
Owner

Himenon commented Oct 6, 2022

It was released in npm at 0.19.0. Thank you!

https://github.com/Himenon/openapi-typescript-code-generator/releases/tag/%40himenon%2Fopenapi-typescript-code-generator%400.19.0

@karupanerura

@karupanerura karupanerura deleted the feature/fragement-in-remote-ref branch October 6, 2022 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants