Skip to content

feat(typescript-fetch): add docs support #21719

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aheckmann
Copy link

Currently, the typescript-fetch client does not support generation of documentation. This PR adds documentation generation support and improves the generated package README.

fixes #18276
closes #18351 (abandoned)

To validate,

  1. Generate the samples
    • bin/generate-samples.sh bin/configs/typescript-fetch-*.yaml
  2. Open a generated typescript-fetch README.md (samples/client/petstore/typescript-fetch/builds/es6-target/README.md and click around to view the new readme, generated API documentation, model documentation and examples.
  3. Run the typescript-fetch integration tests:
    ./mvnw integration-test -f samples/client/petstore/typescript-fetch/tests/default/pom.xml

Committee mentions

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@@ -73,6 +73,8 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
protected boolean withoutRuntimeChecks = false;
protected boolean stringEnums = false;
protected String fileNaming = PASCAL_CASE;
protected String apiDocPath = "docs/";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these use File.separator as well?

Copy link
Author

Choose a reason for hiding this comment

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

I've removed the trailing slash here and added it in the web context (readme and docs files).

@@ -316,6 +331,16 @@ public void processOpts() {
setGenerateValidationAttributes(convertPropertyToBooleanAndWriteBack(VALIDATION_ATTRIBUTES));
}

@Override
public String apiDocFileFolder() {
return (outputFolder + File.separator + apiDocPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

...because we seem to be using those constantly here for a local path. If we want to use the constants both in a file path context and a web context we should remove the trailing slash and add it when we use them in a web context.

@aheckmann aheckmann force-pushed the typescript-fetch-docs branch from d9903a4 to ab65d6f Compare August 11, 2025 16:03
@aheckmann aheckmann requested a review from joscha August 11, 2025 16:05
- generate-samples.sh
- export_docs_generators.sh
@aheckmann aheckmann force-pushed the typescript-fetch-docs branch from ab65d6f to 0d17ea2 Compare August 12, 2025 00:59
embeddedTemplateDir = templateDir = "typescript-fetch";

this.apiTemplateFiles.put("apis.mustache", ".ts");
this.modelTemplateFiles.put("models.mustache", ".ts");
Copy link
Contributor

Choose a reason for hiding this comment

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

How will this interact with the withoutRuntimeChecks configuration property?

It looks like if this option is enabled models.mustache was not included in the modelTemplateFiles. See code here

Copy link
Author

Choose a reason for hiding this comment

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

Thank you - I'll push an update to exclude model docs when this option is enabled, matching the behavior of models.mustache, and also ensure this is handled in the api and readme docs.

Copy link
Author

Choose a reason for hiding this comment

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

What I ended up doing is generating model documentation whether or not withoutRuntimeChecks is enabled. It's helpful to see what input / output is expected, even if runtime checks are not enabled.

@aheckmann aheckmann requested a review from btpnlsl August 12, 2025 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG][TYPESCRIPT] TypeScript Won't Generate Docs Folder
3 participants