Skip to content

Conversation

@mpppk
Copy link
Collaborator

@mpppk mpppk commented Sep 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive documentation files for the typed-api-spec library, covering API specifications, integration with various frameworks, and type-safe API interactions.
    • Added guides for using zero-fetch and validation libraries like Zod and Valibot.
  • Bug Fixes

    • Improved error handling logic in Express route handlers for better clarity and maintainability.
  • Chores

    • Updated project structure by excluding generated documentation and build artifacts from the IDE's project view.
    • Removed outdated tutorial files to streamline documentation.

@coderabbitai
Copy link

coderabbitai bot commented Sep 15, 2024

Walkthrough

This pull request introduces a variety of documentation files and updates within the typed-api-spec project. Key changes include the addition of new markdown files that provide comprehensive guides on API specifications, integration with server frameworks, and validation libraries. Additionally, the .idea/typed-api-spec.iml file is updated to exclude specific directories from the project structure, enhancing organization by reducing clutter in the IDE.

Changes

File(s) Change Summary
.idea/typed-api-spec.iml Added exclusions for docs/.docusaurus and docs/build directories to streamline the project structure.
docs/docs/01_overview.md Introduced an overview of typed-api-spec, detailing API specifications in TypeScript and showcasing type-safe API client features.
docs/docs/02_getting-started.md Added a guide for integrating @mpppk/typed-api-spec with npm projects, focusing on fetching data from the GitHub API in a type-safe manner.
docs/docs/03_api_specification.md Provided a guide on defining API specifications using TypeScript, including examples and integration with validation libraries like Zod.
docs/docs/04_client.md Introduced zero-fetch, a type-safe API client, detailing its features and usage examples.
docs/docs/05_server/_category_.json Defined a new category labeled "Server" for organizing server-related documentation.
docs/docs/05_server/express.md Added a guide for integrating Express with typed-api-spec, including request validation and error handling.
docs/docs/05_server/fastify.md Provided a guide for using Fastify with typed-api-spec, highlighting type-safe request handling.
docs/docs/06_validation/_category_.json Introduced a new category for "Validation" documentation.
docs/docs/06_validation/concept.md Offered an overview of defining API specifications with validation using typed-api-spec and Zod.
docs/docs/06_validation/valibot.md Documented Valibot, a schema library for TypeScript, detailing its integration with API specifications.
docs/docs/06_validation/write.md Provided guidance on creating custom integrations for unsupported validation libraries.
docs/docs/06_validation/zod.md Outlined the usage of Zod for defining API specifications and validation.
docs/docs/intro.md Deleted an introductory tutorial for Docusaurus.
docs/docs/tutorial-basics/_category_.json Removed metadata for the "Tutorial - Basics" category.
docs/docs/tutorial-basics/congratulations.md Deleted a concluding section for a Docusaurus tutorial.
docs/docs/tutorial-basics/create-a-blog-post.md Removed documentation for creating a blog post using Docusaurus.
docs/docs/tutorial-basics/create-a-document.md Deleted a tutorial on creating documents in Docusaurus.
docs/docs/tutorial-basics/create-a-page.md Removed instructions for creating standalone pages in Docusaurus.
docs/docs/tutorial-basics/deploy-your-site.md Deleted instructions for deploying a Docusaurus site.
docs/docs/tutorial-basics/markdown-features.mdx Removed a guide on Markdown features supported by Docusaurus.
docs/docs/tutorial-extras/_category_.json Deleted category metadata for "Tutorial - Extras."
docs/docs/tutorial-extras/manage-docs-versions.md Removed documentation for managing multiple versions of documentation in Docusaurus.
docs/docs/tutorial-extras/translate-your-site.md Deleted a guide on translating a Docusaurus site into French.
docs/docusaurus.config.ts Corrected a typographical error in comments related to the production URL.
examples/github/github.ts Introduced functionality to interact with the GitHub API, including type specifications and a typed fetch wrapper.
src/express/zod.ts Modified error handling logic in an Express route handler to improve clarity and maintainability.

Possibly related PRs

Poem

🐰 In the garden of code, changes bloom bright,
New docs and guides, a developer's delight.
With Zod and Fastify, our paths intertwine,
Type-safe and clear, our APIs shine!
So hop along, friends, let’s code and explore,
With each little change, we discover much more! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range and nitpick comments (5)
docs/docs/02_getting-started.md (1)

52-52: Consider adding missing articles.

To improve the readability of the documentation, consider adding the missing articles as suggested by the static analysis tool:

  • Line 52: "### Use the fetch function"
  • Line 69: "Notice that only a few (highlighted) lines have been changed from the original, but now the fetch is type-safe."

Also applies to: 69-69

Tools
LanguageTool

[uncategorized] ~52-~52: You might be missing the article “the” here.
Context: ... GITHUB_API_ORIGIN, Spec>; ### Use fetch function typescript {3} const GITHU...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

docs/docs/05_server/express.md (2)

38-38: Minor text improvement suggestion

Consider adding the article "the" before "validation library" for better readability:

-Note that the validate method is depended on validation library you use.
+Note that the validate method is depended on the validation library you use.
Tools
LanguageTool

[uncategorized] ~38-~38: Possible missing article found.
Context: ...depended on validation library you use. Following example uses zod. ```typescript impor...

(AI_HYDRA_LEO_MISSING_THE)


71-71: Minor text improvement suggestions

Consider adding the missing articles in this sentence for better readability:

-If error is thrown in async handler of wrapped app, it will be caught and passed to the error handler.
+If an error is thrown in an async handler of the wrapped app, it will be caught and passed to the error handler.
Tools
LanguageTool

[uncategorized] ~71-~71: Possible missing article found.
Context: ... to handle errors of async handlers. If error is thrown in async handler of wrapped a...

(AI_HYDRA_LEO_MISSING_AN)


[uncategorized] ~71-~71: Possible missing article found.
Context: ...f async handlers. If error is thrown in async handler of wrapped app, it will be caug...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~71-~71: Possible missing article found.
Context: ... If error is thrown in async handler of wrapped app, it will be caught and passed to th...

(AI_HYDRA_LEO_MISSING_A)

docs/docs/03_api_specification.md (1)

134-149: Consider adding a missing article.

The "API" section provides a clear introduction to the DefineApiEndpoints utility type and its purpose in enforcing type safety for API specifications. The code example effectively illustrates its usage. However, there is a small suggestion to improve the clarity of the explanation:

  • Line 139: Consider adding the article "a" before "wrong API specification" to improve readability.

Apply the following change to enhance the clarity of the explanation:

-If you write wrong API specification, DefineApiEndpoints will throw a type error.
+If you write a wrong API specification, DefineApiEndpoints will throw a type error.
Tools
LanguageTool

[uncategorized] ~139-~139: Possible missing article found.
Context: ...nes the API specification. If you write wrong API specification, DefineApiEndpoints w...

(AI_HYDRA_LEO_MISSING_THE)

docs/docs/04_client.md (1)

42-42: Address grammatical issues and missing articles.

The LanguageTool static analysis tool has identified a few grammatical issues and missing articles in the documentation. Please consider applying the following fixes:

  1. Line 42: Fix the noun/verb agreement error.
-If the response have multiple status codes, response type is union of each status code type.
+If the response has multiple status codes, the response type is a union of each status code type.
  1. Line 159: Add the missing article.
-FetchT is a type that adds type information to native fetch. First generic parameter is the origin of the API server, and the second generic parameter is the API specification.
+FetchT is a type that adds type information to native fetch. The first generic parameter is the origin of the API server, and the second generic parameter is the API specification.

Addressing these minor grammatical issues will further improve the clarity and readability of the documentation.

Also applies to: 159-159

Tools
LanguageTool

[grammar] ~42-~42: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: ...rNames: string[] } ``` If the response have multiple status codes, response type is...

(SINGULAR_NOUN_VERB_AGREEMENT)


[uncategorized] ~42-~42: Possible missing article found.
Context: ...he response have multiple status codes, response type is union of each status code type....

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~42-~42: Possible missing article found.
Context: ...multiple status codes, response type is union of each status code type. ```typescrip...

(AI_HYDRA_LEO_MISSING_THE)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 989ad7e and 7af0b64.

Files ignored due to path filters (3)
  • docs/docs/tutorial-extras/img/docsVersionDropdown.png is excluded by !**/*.png
  • docs/docs/tutorial-extras/img/localeDropdown.png is excluded by !**/*.png
  • docs/static/img/typed-api-spec.png is excluded by !**/*.png
Files selected for processing (27)
  • .idea/typed-api-spec.iml (1 hunks)
  • docs/docs/01_overview.md (1 hunks)
  • docs/docs/02_getting-started.md (1 hunks)
  • docs/docs/03_api_specification.md (1 hunks)
  • docs/docs/04_client.md (1 hunks)
  • docs/docs/05_server/category.json (1 hunks)
  • docs/docs/05_server/express.md (1 hunks)
  • docs/docs/05_server/fastify.md (1 hunks)
  • docs/docs/06_validation/category.json (1 hunks)
  • docs/docs/06_validation/concept.md (1 hunks)
  • docs/docs/06_validation/valibot.md (1 hunks)
  • docs/docs/06_validation/write.md (1 hunks)
  • docs/docs/06_validation/zod.md (1 hunks)
  • docs/docs/intro.md (0 hunks)
  • docs/docs/tutorial-basics/category.json (0 hunks)
  • docs/docs/tutorial-basics/congratulations.md (0 hunks)
  • docs/docs/tutorial-basics/create-a-blog-post.md (0 hunks)
  • docs/docs/tutorial-basics/create-a-document.md (0 hunks)
  • docs/docs/tutorial-basics/create-a-page.md (0 hunks)
  • docs/docs/tutorial-basics/deploy-your-site.md (0 hunks)
  • docs/docs/tutorial-basics/markdown-features.mdx (0 hunks)
  • docs/docs/tutorial-extras/category.json (0 hunks)
  • docs/docs/tutorial-extras/manage-docs-versions.md (0 hunks)
  • docs/docs/tutorial-extras/translate-your-site.md (0 hunks)
  • docs/docusaurus.config.ts (1 hunks)
  • examples/github/github.ts (1 hunks)
  • src/express/zod.ts (1 hunks)
Files not reviewed due to no reviewable changes (11)
  • docs/docs/intro.md
  • docs/docs/tutorial-basics/category.json
  • docs/docs/tutorial-basics/congratulations.md
  • docs/docs/tutorial-basics/create-a-blog-post.md
  • docs/docs/tutorial-basics/create-a-document.md
  • docs/docs/tutorial-basics/create-a-page.md
  • docs/docs/tutorial-basics/deploy-your-site.md
  • docs/docs/tutorial-basics/markdown-features.mdx
  • docs/docs/tutorial-extras/category.json
  • docs/docs/tutorial-extras/manage-docs-versions.md
  • docs/docs/tutorial-extras/translate-your-site.md
Files skipped from review due to trivial changes (4)
  • .idea/typed-api-spec.iml
  • docs/docs/05_server/category.json
  • docs/docs/06_validation/category.json
  • docs/docusaurus.config.ts
Additional context used
LanguageTool
docs/docs/06_validation/valibot.md

[uncategorized] ~7-~7: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... valibot is the open source schema library for TypeScript with bund...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

docs/docs/01_overview.md

[uncategorized] ~7-~7: Use the indefinite article “a” before nouns that start with a consonant sound.
Context: ...n: 1 --- # Overview typed-api-spec is an TypeScript based declarative API specif...

(AI_EN_LECTOR_REPLACEMENT_DETERMINER_AN_A)


[uncategorized] ~7-~7: This expression is usually spelled with a hyphen.
Context: ...1 --- # Overview typed-api-spec is an TypeScript based declarative API specification. ## Feat...

(BASED_HYPHEN)


[uncategorized] ~11-~11: This expression is usually spelled with a hyphen.
Context: ...ve API specification. ## Features ### TypeScript based API Specification You can define your A...

(BASED_HYPHEN)

docs/docs/02_getting-started.md

[uncategorized] ~52-~52: You might be missing the article “the” here.
Context: ... GITHUB_API_ORIGIN, Spec>; ### Use fetch function typescript {3} const GITHU...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~69-~69: Possible missing article found.
Context: ...ghlighted) lines have been changed from original, but now the fetch is type-safe.

(AI_HYDRA_LEO_MISSING_THE)

docs/docs/05_server/express.md

[uncategorized] ~38-~38: Possible missing article found.
Context: ...depended on validation library you use. Following example uses zod. ```typescript impor...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~71-~71: Possible missing article found.
Context: ... to handle errors of async handlers. If error is thrown in async handler of wrapped a...

(AI_HYDRA_LEO_MISSING_AN)


[uncategorized] ~71-~71: Possible missing article found.
Context: ...f async handlers. If error is thrown in async handler of wrapped app, it will be caug...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~71-~71: Possible missing article found.
Context: ... If error is thrown in async handler of wrapped app, it will be caught and passed to th...

(AI_HYDRA_LEO_MISSING_A)

docs/docs/03_api_specification.md

[grammar] ~81-~81: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: ...; }; }; }; }; }>; ``` ### Spec Spec have the following properties: - params: T...

(SINGULAR_NOUN_VERB_AGREEMENT)


[uncategorized] ~83-~83: Loose punctuation mark.
Context: ...ath parameters of the request. - query: The query parameters of the request. - ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~84-~84: Loose punctuation mark.
Context: ...y parameters of the request. - headers: The headers of the request. - body: T...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...s: The headers of the request. - body: The body of the request. - responses`:...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~86-~86: Loose punctuation mark.
Context: ...: The body of the request. - responses: The response schema of the request. -...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~87-~87: Loose punctuation mark.
Context: ...sponse schema of the request. - body: The body of the response. - headers...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~88-~88: Loose punctuation mark.
Context: ... The body of the response. - headers: The headers of the response. ```type...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~139-~139: Possible missing article found.
Context: ...nes the API specification. If you write wrong API specification, DefineApiEndpoints w...

(AI_HYDRA_LEO_MISSING_THE)

docs/docs/04_client.md

[grammar] ~42-~42: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: ...rNames: string[] } ``` If the response have multiple status codes, response type is...

(SINGULAR_NOUN_VERB_AGREEMENT)


[uncategorized] ~42-~42: Possible missing article found.
Context: ...he response have multiple status codes, response type is union of each status code type....

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~42-~42: Possible missing article found.
Context: ...multiple status codes, response type is union of each status code type. ```typescrip...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~159-~159: Possible missing article found.
Context: ... adds type information to native fetch. First generic parameter is the origin of the ...

(AI_HYDRA_LEO_MISSING_THE)

Markdownlint
docs/docs/06_validation/valibot.md

30-30: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

docs/docs/02_getting-started.md

23-23: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

docs/docs/03_api_specification.md

10-10: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Additional comments not posted (26)
docs/docs/06_validation/zod.md (1)

10-28: Great code example!

The code example is well-structured and demonstrates how to use Zod to define an API specification for a user endpoint. It covers all the necessary aspects of the endpoint, including:

  • Request parameters
  • Query parameters
  • Headers
  • Response structure

This example serves as a good reference for users to understand how to use Zod with typed-api-spec.

docs/docs/06_validation/valibot.md (1)

1-33: Excellent documentation for Valibot!

The documentation provides a clear and concise overview of Valibot and its features. The code example effectively demonstrates how to define an API specification using Valibot, making it easy for users to understand and get started with the library.

The mention of Express integration is also helpful for users looking to integrate Valibot with their server framework.

Overall, the documentation is well-structured, informative, and serves as a great resource for users interested in using Valibot for their API specifications.

Tools
LanguageTool

[uncategorized] ~7-~7: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... valibot is the open source schema library for TypeScript with bund...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

Markdownlint

30-30: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

docs/docs/05_server/fastify.md (4)

7-25: Great example of setting up a Fastify server with typed-api-spec and zod!

The code snippet provides a clear and concise example of:

  • Configuring a Fastify server with logging enabled
  • Setting up validation and serialization compilers
  • Using the toRoutes() function to convert the API specification schema to Fastify route objects
  • Defining a GET route for fetching user names based on a query parameter

The route handler demonstrates how to access the query parameter and return a response.


35-58: Great example of using the toRoutes() function!

The code snippet provides a clear example of:

  • Defining an API specification schema using zod
  • Using the toRoutes() function to convert the schema to Fastify route objects
  • Logging the output of the toRoutes() function to show the structure of the generated route object

This helps developers understand how to define the API specification schema and use the toRoutes() function effectively.


29-31: The API documentation for the toRoutes() function is clear and concise.

The description accurately states the purpose of the function, which is to convert the API specification schema to Fastify route objects. This helps developers understand the role of the toRoutes() function in the integration of typed-api-spec with Fastify.


60-62: The "Supported validation libraries" section is informative and helpful.

The section informs developers that zod is a supported validation library, which is useful information. It also provides a convenient link to the documentation for using zod with typed-api-spec, making it easy for developers to access further information if needed.

examples/github/github.ts (4)

1-9: LGTM!

The imports, constants, and types are correctly defined and used in the implementation.


11-38: Great work on the API specification!

The Spec type comprehensively defines the API specification for the endpoint /repos/:owner/:repo/topics, including the expected request structure and possible response formats. The specification is clear and well-structured.


39-39: Nice use of the FetchT utility type!

The fetchT constant is correctly defined as a typed fetch wrapper, ensuring that requests to the GitHub API conform to the defined specifications. This enhances type safety when making API calls.


41-54: Excellent implementation of the main function!

The main function correctly orchestrates the API call using the fetchT wrapper and handles the response appropriately. It demonstrates the usage of the typed API specification and fetch wrapper, ensuring type safety and clarity when interacting with the GitHub API.

docs/docs/01_overview.md (1)

1-46: Excellent overview of the typed-api-spec project!

The 01_overview.md file provides a clear and concise introduction to the typed-api-spec project. The code snippets are well-formatted and provide useful examples of how to define API endpoints and use the typed fetch function. The file is well-structured and easy to follow.

Great job on creating this comprehensive overview!

Tools
LanguageTool

[uncategorized] ~7-~7: Use the indefinite article “a” before nouns that start with a consonant sound.
Context: ...n: 1 --- # Overview typed-api-spec is an TypeScript based declarative API specif...

(AI_EN_LECTOR_REPLACEMENT_DETERMINER_AN_A)


[uncategorized] ~7-~7: This expression is usually spelled with a hyphen.
Context: ...1 --- # Overview typed-api-spec is an TypeScript based declarative API specification. ## Feat...

(BASED_HYPHEN)


[uncategorized] ~11-~11: This expression is usually spelled with a hyphen.
Context: ...ve API specification. ## Features ### TypeScript based API Specification You can define your A...

(BASED_HYPHEN)

src/express/zod.ts (1)

54-55: LGTM!

The destructuring assignment and subsequent error handling logic improve code readability and align with common practices in handling validation results. The change makes the error handling more explicit and reduces reliance on a success flag.

docs/docs/02_getting-started.md (4)

9-21: LGTM!

The code snippet effectively demonstrates the limitations of fetching data from the GitHub API without type safety. It sets the stage for introducing the benefits of using the @mpppk/typed-api-spec library.


31-43: LGTM!

The code snippet effectively demonstrates how to define the API specification using the DefineApiEndpoints type. The structured definition of the API endpoints, including the query parameters and response formats, enhances type safety and clarity.


54-67: LGTM!

The code snippet effectively demonstrates the usage of the fetchT function to make a type-safe API call. The type-safe response handling based on the success or failure of the request is a significant improvement over the non-type-safe approach. The code clearly illustrates the benefits of using the @mpppk/typed-api-spec library.


1-69: Excellent documentation!

The documentation provides a comprehensive and well-structured guide for integrating the @mpppk/typed-api-spec library into an npm project. The explanations are clear, and the code snippets effectively demonstrate each step of the process. The documentation successfully highlights the benefits of using the library for type-safe API interactions.

Tools
LanguageTool

[uncategorized] ~52-~52: You might be missing the article “the” here.
Context: ... GITHUB_API_ORIGIN, Spec>; ### Use fetch function typescript {3} const GITHU...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~69-~69: Possible missing article found.
Context: ...ghlighted) lines have been changed from original, but now the fetch is type-safe.

(AI_HYDRA_LEO_MISSING_THE)

Markdownlint

23-23: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

docs/docs/06_validation/concept.md (4)

12-34: LGTM!

The code segment demonstrates a clear and effective way to define an API specification using TypeScript types and the zod validation library. By separating runtime validation from API definition, it allows developers to use any validation library of their choice while still benefiting from the type safety provided by typed-api-spec. The code is well-structured and follows best practices.


39-44: Good example, but be cautious of using the correct schema.

The code segment demonstrates how to perform runtime validation of request parameters using the zod schema defined earlier. This is a good practice to validate incoming data and prevent potential errors or security vulnerabilities.

However, as mentioned in the document, there is no guarantee that the UsersQuery schema is actually the expected schema for the specific endpoint. Developers may accidentally use the wrong schema, leading to potential issues. It's important to ensure that the correct schema is used for each endpoint to maintain consistency and avoid validation errors.


51-62: Excellent approach to define API specification with integrated validation!

The code segment demonstrates an alternative approach to defining an API specification using zod schemas directly, without separating the validation from the API definition. By defining the Spec object using zod schemas for the query parameters and response body, it ensures that the API specification itself is validated against the expected structure.

This approach provides several benefits:

  • It is more concise and integrated, reducing the chances of using the wrong schema for a specific endpoint.
  • The satisfies ZodApiEndpoints statement ensures that the Spec object conforms to the expected structure, providing an additional layer of type safety.
  • The code is well-structured and follows best practices, making it easier to understand and maintain.

Overall, this approach is a great way to define API specifications with integrated validation, enhancing the reliability and maintainability of the application.


66-71: Great usage of the Spec object for runtime validation!

The code segment demonstrates how to utilize the Spec object defined earlier to perform runtime validation of request parameters in an Express route handler. By accessing the specific endpoint and HTTP method from the Spec object and using the parse method, it ensures that the query parameters conform to the expected structure and types defined in the API specification.

This approach provides several benefits:

  • It is more type-safe and integrated, as it directly uses the schemas defined in the API specification.
  • It reduces the chances of using the wrong schema and ensures consistency between the API specification and the actual validation performed in the route handler.
  • The code is clear and concise, making it easy to understand and maintain.

Overall, this approach showcases the power of using the Spec object for runtime validation, enhancing the reliability and maintainability of the application.

docs/docs/05_server/express.md (1)

1-83: Excellent documentation for integrating Express with typed-api-spec!

The guide provides a clear and comprehensive explanation of how to use the typed() function to apply strict types to an Express app, and how to use the validate() method to validate request parameters. The code snippets effectively demonstrate the usage and integration with validation libraries like zod.

The inclusion of the asAsync() function for handling async errors in Express 4 or lower is a helpful addition, with a clear note about its necessity and the upcoming support in Express 5.

Overall, this documentation file serves as a valuable resource for developers looking to implement type-safe APIs with Express and typed-api-spec. Great work!

Tools
LanguageTool

[uncategorized] ~38-~38: Possible missing article found.
Context: ...depended on validation library you use. Following example uses zod. ```typescript impor...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~71-~71: Possible missing article found.
Context: ... to handle errors of async handlers. If error is thrown in async handler of wrapped a...

(AI_HYDRA_LEO_MISSING_AN)


[uncategorized] ~71-~71: Possible missing article found.
Context: ...f async handlers. If error is thrown in async handler of wrapped app, it will be caug...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~71-~71: Possible missing article found.
Context: ... If error is thrown in async handler of wrapped app, it will be caught and passed to th...

(AI_HYDRA_LEO_MISSING_A)

docs/docs/03_api_specification.md (3)

38-56: LGTM!

The "Structure" section provides a clear explanation of the API specification structure and includes a relevant code example to illustrate the usage. The content is well-organized and easy to understand.


58-77: LGTM!

The "Method" section provides a complete list of supported HTTP methods and includes a clear code example to demonstrate defining endpoints with different methods. The content is well-structured and informative.


106-132: LGTM!

The "Validation library integration" section provides a clear explanation of how typed-api-spec can be integrated with validation libraries like Zod. The code example effectively demonstrates defining request and response schemas using Zod, ensuring type safety and validation. The content is well-structured and informative.

docs/docs/04_client.md (2)

1-178: Excellent documentation!

The documentation provides a clear and comprehensive guide on using zero-fetch for type-safe API interactions. The explanation of the "zero-runtime" concept and how zero-fetch adds type information to the native fetch without increasing the runtime footprint or bundle size is well-written and easy to understand.

The various type-safe features such as response, path, path parameters, query, headers, and body are thoroughly covered, and the TypeScript code examples effectively demonstrate the usage and features of zero-fetch.

The API section provides clear information on the usage of FetchT and JSONT types.

Overall, the documentation content is well-structured, informative, and easy to follow. Great job!

Tools
LanguageTool

[grammar] ~42-~42: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: ...rNames: string[] } ``` If the response have multiple status codes, response type is...

(SINGULAR_NOUN_VERB_AGREEMENT)


[uncategorized] ~42-~42: Possible missing article found.
Context: ...he response have multiple status codes, response type is union of each status code type....

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~42-~42: Possible missing article found.
Context: ...multiple status codes, response type is union of each status code type. ```typescrip...

(AI_HYDRA_LEO_MISSING_THE)


[uncategorized] ~159-~159: Possible missing article found.
Context: ... adds type information to native fetch. First generic parameter is the origin of the ...

(AI_HYDRA_LEO_MISSING_THE)


15-18: Code examples are accurate and effective!

The TypeScript code examples in the documentation are well-written and effectively demonstrate the usage and features of zero-fetch. The examples cover various scenarios such as defining API specifications, handling response types, path and path parameters, query parameters, headers, and request body.

The examples correctly use the FetchT and JSONT types to provide type safety, and they include error cases to showcase how zero-fetch enforces type safety at compile time.

The code examples follow best practices, are concise, and focused on demonstrating specific features. There are no apparent issues or errors in the code examples.

Great work on providing clear and accurate code examples to support the documentation!

Also applies to: 28-40, 44-70, 77-93, 99-112, 118-131, 138-153, 162-164, 171-176

Comment on lines +1 to +6
# Write your own integration

If you want to use a validation library which is not supported by `typed-api-spec`, you can write your own integration.
typed-api-spec provides a utility type `DefineApiSpec`, `DefineApiResponses`, and others for defining API specification schema with validation library.

TBW No newline at end of file
Copy link

Choose a reason for hiding this comment

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

Complete the documentation with more details and examples.

The documentation provides a good starting point for guiding developers on writing custom integrations for validation libraries. However, it is currently incomplete and lacks important details:

  1. Provide more information on the utility types (DefineApiSpec, DefineApiResponses, etc.):

    • Explain their purpose and how they facilitate defining API specification schemas.
    • Describe their usage and provide code examples.
  2. Expand the "TBW" section with the necessary content:

    • Provide step-by-step instructions on how to write a custom integration.
    • Include code snippets and examples to illustrate the process.
    • Explain how to use the utility types in conjunction with the validation library.
  3. Consider adding a section on best practices and common pitfalls to help developers avoid mistakes when writing custom integrations.

Completing the documentation with these details will greatly improve its usefulness and help developers effectively write custom integrations for validation libraries.

console.log(names); // => ["api-spec", "fetch", "typescript"]
```

### Installation
Copy link

Choose a reason for hiding this comment

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

Fix the heading level.

The heading level should only increment by one level at a time. Change the heading level of "### Installation" to "## Installation" to maintain a consistent heading hierarchy.

Tools
Markdownlint

23-23: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

Comment on lines 79 to 104
### Spec

Spec have the following properties:
- `params`: The path parameters of the request.
- `query`: The query parameters of the request.
- `headers`: The headers of the request.
- `body`: The body of the request.
- `responses`: The response schema of the request.
- `body`: The body of the response.
- `headers`: The headers of the response.

```typescript
type Spec = DefineApiEndpoints<{
"/users/:id": {
get: {
params: { id: string };
query: { page?: string };
headers: { "x-api-key": string };
responses: { 200: {
headers: {"content-type": "application/json"};
body: { userNames: string[] }; };
};
};
};
}>;
```
Copy link

Choose a reason for hiding this comment

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

Address grammatical and punctuation issues.

The "Spec" section provides a comprehensive explanation of the Spec properties and includes a relevant code example. However, there are a few issues that need attention:

  1. Line 81: There seems to be a noun/verb agreement error. Consider changing "have" to "has" to match the singular noun "Spec".
  2. Lines 83-88: The punctuation marks (backticks) before the property names appear to be loose. Consider removing the spaces before the backticks for consistency.

Apply the following changes to improve the clarity and readability of the content:

-Spec have the following properties:
+Spec has the following properties:
- `params`: The path parameters of the request.
+ `params`: The path parameters of the request.
- `query`: The query parameters of the request.
+ `query`: The query parameters of the request.
- `headers`: The headers of the request.
+ `headers`: The headers of the request.
- `body`: The body of the request.
+ `body`: The body of the request.
- `responses`: The response schema of the request.
+ `responses`: The response schema of the request.
  - `body`: The body of the response.
  - `headers`: The headers of the response.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Spec
Spec have the following properties:
- `params`: The path parameters of the request.
- `query`: The query parameters of the request.
- `headers`: The headers of the request.
- `body`: The body of the request.
- `responses`: The response schema of the request.
- `body`: The body of the response.
- `headers`: The headers of the response.
```typescript
type Spec = DefineApiEndpoints<{
"/users/:id": {
get: {
params: { id: string };
query: { page?: string };
headers: { "x-api-key": string };
responses: { 200: {
headers: {"content-type": "application/json"};
body: { userNames: string[] }; };
};
};
};
}>;
```
### Spec
Spec has the following properties:
`params`: The path parameters of the request.
`query`: The query parameters of the request.
`headers`: The headers of the request.
`body`: The body of the request.
`responses`: The response schema of the request.
- `body`: The body of the response.
- `headers`: The headers of the response.
```typescript
type Spec = DefineApiEndpoints<{
"/users/:id": {
get: {
params: { id: string };
query: { page?: string };
headers: { "x-api-key": string };
responses: { 200: {
headers: {"content-type": "application/json"};
body: { userNames: string[] }; };
};
};
};
}>;
```
Tools
LanguageTool

[grammar] ~81-~81: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: ...; }; }; }; }; }>; ``` ### Spec Spec have the following properties: - params: T...

(SINGULAR_NOUN_VERB_AGREEMENT)


[uncategorized] ~83-~83: Loose punctuation mark.
Context: ...ath parameters of the request. - query: The query parameters of the request. - ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~84-~84: Loose punctuation mark.
Context: ...y parameters of the request. - headers: The headers of the request. - body: T...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...s: The headers of the request. - body: The body of the request. - responses`:...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~86-~86: Loose punctuation mark.
Context: ...: The body of the request. - responses: The response schema of the request. -...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~87-~87: Loose punctuation mark.
Context: ...sponse schema of the request. - body: The body of the response. - headers...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~88-~88: Loose punctuation mark.
Context: ... The body of the response. - headers: The headers of the response. ```type...

(UNLIKELY_OPENING_PUNCTUATION)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
docs/docs/03_api_specification.md (1)

149-149: Reminder: Address the TODO comment.

The TODO comment indicates that a StackBlitz demo is planned to be added. This is a helpful addition to provide an interactive example for readers. Please ensure that the TODO comment is addressed in a timely manner.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7af0b64 and 57f9c27.

Files selected for processing (2)
  • docs/docs/02_getting-started.md (1 hunks)
  • docs/docs/03_api_specification.md (1 hunks)
Additional context used
LanguageTool
docs/docs/02_getting-started.md

[uncategorized] ~52-~52: You might be missing the article “the” here.
Context: ...f GITHUB_API_ORIGIN, Spec>; ## Use fetch function typescript {3} const GITHU...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~69-~69: You might be missing the article “a” here.
Context: ...h", "typescript"] ``` Notice that only few (highlighted) lines have been changed f...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[uncategorized] ~69-~69: You might be missing the article “the” here.
Context: ...ghlighted) lines have been changed from original, but now the fetch is type-safe.

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

docs/docs/03_api_specification.md

[uncategorized] ~83-~83: Loose punctuation mark.
Context: ...ath parameters of the request. - query: The query parameters of the request. - ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~84-~84: Loose punctuation mark.
Context: ...y parameters of the request. - headers: The headers of the request. - body: T...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...s: The headers of the request. - body: The body of the request. - responses`:...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~86-~86: Loose punctuation mark.
Context: ...: The body of the request. - responses: The response schema of the request. -...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~87-~87: Loose punctuation mark.
Context: ...sponse schema of the request. - body: The body of the response. - headers...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~88-~88: Loose punctuation mark.
Context: ... The body of the response. - headers: The headers of the response. ```type...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~139-~139: Possible missing article found.
Context: ...nes the API specification. If you write wrong API specification, DefineApiEndpoints w...

(AI_HYDRA_LEO_MISSING_THE)

Markdownlint
docs/docs/03_api_specification.md

10-10: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Additional comments not posted (6)
docs/docs/02_getting-started.md (2)

1-69: Excellent documentation!

The new "Getting Started" documentation file provides a comprehensive and easy-to-follow guide for integrating the @mpppk/typed-api-spec library into an npm project. The examples and explanations effectively demonstrate the benefits of using the library, particularly in terms of enhancing type safety in API interactions.

The file is well-structured, with clear sections covering installation, defining API specs, adding types to the fetch function, and using the typed fetch function. The code snippets and accompanying explanations are concise and informative, making it easy for developers to understand and apply the concepts.

Overall, this documentation serves as an essential resource for developers looking to leverage the @mpppk/typed-api-spec library in their projects. Great work!

Tools
LanguageTool

[uncategorized] ~52-~52: You might be missing the article “the” here.
Context: ...f GITHUB_API_ORIGIN, Spec>; ## Use fetch function typescript {3} const GITHU...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~69-~69: You might be missing the article “a” here.
Context: ...h", "typescript"] ``` Notice that only few (highlighted) lines have been changed f...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[uncategorized] ~69-~69: You might be missing the article “the” here.
Context: ...ghlighted) lines have been changed from original, but now the fetch is type-safe.

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


23-23: The heading level issue has been resolved.

The heading level for "Installation" has been correctly set to ##, maintaining a consistent heading hierarchy throughout the document. The past review comment regarding this issue is no longer applicable.

docs/docs/03_api_specification.md (4)

5-37: LGTM!

The "API Specification" section provides a clear and concise introduction to the API specification structure. The code example accurately demonstrates the structure of Path, Method, and Spec components.

Tools
Markdownlint

10-10: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


38-104: LGTM!

The "Structure" section provides a comprehensive explanation of the Path, Method, and Spec components. The code examples accurately demonstrate the usage of each component. The supported HTTP methods and the properties of the Spec component are clearly listed.

Tools
LanguageTool

[uncategorized] ~83-~83: Loose punctuation mark.
Context: ...ath parameters of the request. - query: The query parameters of the request. - ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~84-~84: Loose punctuation mark.
Context: ...y parameters of the request. - headers: The headers of the request. - body: T...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...s: The headers of the request. - body: The body of the request. - responses`:...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~86-~86: Loose punctuation mark.
Context: ...: The body of the request. - responses: The response schema of the request. -...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~87-~87: Loose punctuation mark.
Context: ...sponse schema of the request. - body: The body of the response. - headers...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~88-~88: Loose punctuation mark.
Context: ... The body of the response. - headers: The headers of the response. ```type...

(UNLIKELY_OPENING_PUNCTUATION)


106-132: LGTM!

The "Validation library integration" section provides a clear explanation of the integration with validation libraries. The code example accurately demonstrates the usage of Zod for schema validation. The reference to the "Validation" page is helpful for readers who want to learn more about the topic.


134-147: LGTM!

The "API" section provides a clear introduction to the DefineApiEndpoints utility type. The explanation of its purpose and behavior is accurate. The code example demonstrates the usage of DefineApiEndpoints correctly.

Tools
LanguageTool

[uncategorized] ~139-~139: Possible missing article found.
Context: ...nes the API specification. If you write wrong API specification, DefineApiEndpoints w...

(AI_HYDRA_LEO_MISSING_THE)

@mpppk mpppk merged commit 22c115d into main Sep 15, 2024
@mpppk mpppk deleted the update-doc branch September 15, 2024 13:59
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.

2 participants