Skip to content

Minor docs change #1302

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 1 commit into from
Aug 17, 2023
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
16 changes: 8 additions & 8 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
},
"dependencies": {
"@algolia/client-search": "^4.19.1",
"@astrojs/preact": "^2.2.1",
"@astrojs/react": "^2.2.1",
"@astrojs/preact": "^2.2.2",
"@astrojs/react": "^2.2.2",
"@docsearch/css": "^3.5.1",
"@docsearch/react": "^3.5.1",
"@types/react": "^18.2.16",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"astro": "^2.9.2",
"preact": "^10.16.0",
"astro": "^2.10.9",
"preact": "^10.17.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.64.1"
"sass": "^1.65.1"
},
"devDependencies": {
"@astrojs/sitemap": "^2.0.1",
"@types/node": "^20.4.9",
"@astrojs/sitemap": "^2.0.2",
"@types/node": "^20.5.0",
"html-escaper": "^3.0.3",
"typescript": "^5.1.6"
}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ However, APIs are language-agnostic, and may contain a different syntax style fr

Instead, treat “consistency” in a more holistic sense, recognizing that preserving the API schema as-written is better than adhering to language-specific style conventions.

### Enable `noUncheckedIndexAccess` in your tsconfig.json
### Enable `noUncheckedIndexedAccess` in your tsconfig.json

openapi-typescript generates a `Record` for `additionalProperties` and tries to avoid adding a `undefined` union to the index signature. However, this may result in unsafe property access in TypeScript, **unless** the compiler flag `noUncheckedIndexAccess` is set. If set, TypeScript will error when you try to access a property that might not be set.
openapi-typescript generates a `Record` for `additionalProperties` and tries to avoid adding a `undefined` union to the index signature. However, this may result in unsafe property access in TypeScript, **unless** the compiler flag `noUncheckedIndexedAccess` is set ([docs](/advanced#enable-nouncheckedindexaccess-in-your-tsconfigjson)). If set, TypeScript will error when you try to access a property that might not be set.

### Be specific in your schema

Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ This library requires the latest version of <a href="https://nodejs.org/en" targ
npm i -D openapi-typescript
```

> ✨ **Tip**
>
> Enabling [noUncheckedIndexedAccess](https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess) in `tsconfig.json` can go along way to improve type safety ([read more](/advanced#enable-nouncheckedindexaccess-in-your-tsconfigjson))

## Basic usage

First, generate a local type file by running `npx openapi-typescript`:
Expand Down Expand Up @@ -62,10 +66,6 @@ type SuccessResponse = paths["/my/endpoint"]["get"]["responses"][200]["content"]
type ErrorResponse = paths["/my/endpoint"]["get"]["responses"][500]["content"]["application/json"]["schema"];
```

> ✨ **Tip**
>
> Using TypeScript’s bracket notation (`obj["property"]`) is a safe way to access all names in your OpenAPI schema, even the ones that aren’t “TypeScript-safe”

From here, you can use these types for any of the following (but not limited to):

- Using an OpenAPI-supported fetch client (like [openapi-fetch](/openapi-fetch))
Expand Down
18 changes: 15 additions & 3 deletions packages/openapi-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ openapi-typescript generates TypeScript types from static <a href="https://spec.

The code is [MIT-licensed](./LICENSE) and free for use.

**Features**
## Features

- ✅ Supports OpenAPI 3.0 and 3.1 (including advanced features like <a href="https://spec.openapis.org/oas/v3.1.0#discriminator-object" target="_blank" rel="noopener noreferrer">discriminators</a>)
- ✅ Generate **runtime-free types** that outperform old-school codegen
- ✅ Load schemas from YAML or JSON, locally or remotely
- ✅ Native Node.js code is fast and generates types within milliseconds

**Examples**
## Examples

👀 [See examples](./examples/)

## Usage
## Setup

This library requires the latest version of <a href="https://nodejs.org/en" target="_blank" rel="noopener noreferrer">Node.js</a> installed (20.x or higher recommended). With that present, run the following in your project:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 Just noticed this section was missing from the README.


```bash
npm i -D openapi-typescript
```

> ✨ **Tip**
>
> Enabling [noUncheckedIndexedAccess](https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess) in `tsconfig.json` can go along way to improve type safety ([read more](/advanced#enable-nouncheckedindexaccess-in-your-tsconfigjson))

## Basic usage

First, generate a local type file by running `npx openapi-typescript`:

Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"devDependencies": {
"@types/degit": "^2.8.3",
"@types/js-yaml": "^4.0.5",
"@types/node": "^20.4.9",
"@types/node": "^20.5.0",
"degit": "^2.8.4",
"del-cli": "^5.0.0",
"esbuild": "^0.19.2",
Expand Down
Loading