- #2102
0cdfc47
Thanks @ViktorPontinen! - Support generating path params for flaky schemas using --generate-path-params option
- #2049
39f9b2f
Thanks @duncanbeevers! - Add schema to postTransform options
-
#2052
d2de5c7
Thanks @laurenz-glueck! - brings back --make-paths-enum option to generate ApiPaths enum -
#2059
9e4f61c
Thanks @gduliscouet-ubitransport! - Allow all types except UNKNOWN to be nullable
- #1873
c2c396d
Thanks @DanDeMicco! - Support for generating enums when enums definition has null value
- #1876
a9cd9aa
Thanks @BradHacker! - Add option to export all root component types
- #1877
94592a4
Thanks @phk422! - fix: replace special characters usingSPECIAL_CHARACTER_MAP
for duplicate-identifiers
- #1849
08bde72
Thanks @liangskyli! - fix: keyedParameters use unique key
- #1784
c2f8655
Thanks @yoshi2no! - Fix: Correct handling of identical minItems and maxItems in array schemas when arrayLength option is true
-
#1772
41cb9a2
Thanks @ashwin153! - fix: add explicit import of performance to fix bazel compatibility issues -
#1764
2793049
Thanks @michalfedyna! - Fix --properties-required-by-default flag not working -
#1763
19b9383
Thanks @nkt! - fix: schema.content might be omitted
- #1746
e705909
Thanks @phk422! - fix: Correct handling of default parameter values in referenced component schema
- #1761
8043c5d
Thanks @yoshi2no! - fix: Enum option cannot generate enums if values are not valid property names
-
6d1eb32
Thanks @drwpow! -⚠️ Breaking: The Node.js API now returns the TypeScript AST for the main method as well astransform()
andpostTransform()
. To migrate, you’ll have to use thetypescript
compiler API:+ import ts from "typescript"; + const DATE = ts.factory.createIdentifier("Date"); + const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull()); const ast = await openapiTS(mySchema, { transform(schemaObject, metadata) { if (schemaObject.format === "date-time") { - return schemaObject.nullable ? "Date | null" : "Date"; + return schemaObject.nullable + ? ts.factory.createUnionTypeNode([DATE, NULL]) + : DATE; } }, };
Though it’s more verbose, it’s also more powerful, as now you have access to additional properties of the generated code you didn’t before (such as injecting comments).
For example syntax, search this codebae to see how the TypeScript AST is used.
Also see AST Explorer’s
typescript
parser to inspect how TypeScript is interpreted as an AST. -
6d1eb32
Thanks @drwpow! -⚠️ Breaking: Changing of several CLI flags and Node.js API options- The
--auth
,--httpHeaders
,--httpMethod
, andfetch
(Node.js-only) options were all removed from the CLI and Node.js API- To migrate, you’ll need to create a redocly.yaml config that specifies your auth options in the http setting
- You can also set your fetch client in redocly.yaml as well.
--immutable-types
has been renamed to--immutable
--support-array-length
has been renamed to--array-length
- The
-
fbaf96d
Thanks @drwpow! -⚠️ Breaking: Remove globbing schemas in favor ofredocly.yaml
config. Specify multiple schemas with outputs in there instead. See Multiple schemas for more info. -
6d1eb32
Thanks @drwpow! -⚠️ Breaking: Most optional objects are now always present in types, just typed as:never
. This includes keys of the Components Object as well as HTTP methods. -
6d1eb32
Thanks @drwpow! -⚠️ Breaking: No moreexternal
export in schemas anymore. Everything gets flattened into thecomponents
object instead (if referencing a schema object from a remote partial, note it may have had a minor name change to avoid conflict). -
6d1eb32
Thanks @drwpow! -⚠️ BreakingdefaultNonNullable
option now defaults totrue
. You’ll now need to manually setfalse
to return to old behavior. -
799194d
Thanks @drwpow~ -⚠️ Breaking TypeScript is now a peerDependency and must be installed alongsideopenapi-typescript
-
6d1eb32
Thanks @drwpow! - ✨ Feature: automatically validate schemas with Redocly CLI (docs). No more need for external tools to report errors! 🎉- By default, it will only throw on actual schema errors (uses Redocly’s default settings)
- For stricter linting or custom rules, you can create a redocly.yaml config
-
312b7ba
Thanks @drwpow! - ✨ Feature: allow configuration of schemas viaapis
key in redocly.config.yaml. See docs for more info.- Any options passed into your redocly.yaml config are respected
-
6d1eb32
Thanks @drwpow! - ✨ Feature: addenum
option to export top-level enums from schemas -
6d1eb32
Thanks @drwpow! - ✨ Feature: addformatOptions
to allow formatting TS output -
6d1eb32
Thanks @drwpow! - ✨ Feature: header responses add[key: string]: unknown
index type to allow for additional untyped headers -
6d1eb32
Thanks @drwpow! - ✨ Feature: bundle schemas with Redocly CLI -
6d1eb32
Thanks @drwpow! - ✨ Feature: Added debugger that lets you profile performance and see more in-depth messages -
#1374
7ac5174
Thanks @ElForastero! - Add support for x-enum-varnames and x-enum-descriptions -
#1545
9158b81
Thanks @jaredLunde! - Replace # characters in operation IDs with a slash
-
6d1eb32
Thanks @drwpow! - Refactor internals to use TypeScript AST rather than string mashing -
6d1eb32
Thanks @drwpow! - 🧹 Cleaned up and reorganized all tests -
#1602
9da96cd
Thanks @JeanRemiDelteil! - Do not add readonly on Typescript enum when the --immutable option is used.
-
#1348
f6fdd2f
Thanks @drwpow! - Improve YAML vs JSON parsing -
#1345
6f078c1
Thanks @SchabaJo! - Mirror directory structure of input files if output is a directory to prevent overwriting the same file again and again.
- #1335
7cb02ac
Thanks @duncanbeevers! - Request parameters member is optional when all parameters are optional.
- #1320
3cf78b9
Thanks @duncanbeevers! - Wrap nested readonly types in parentheses, allowing for nested immutable arrays
- #1295
99a1648
Thanks @pvanagtmaal! - Avoid adding a undefined union to additionProperties
-
#1280
50441d0
Thanks @pvanagtmaal! - Fix invalid typescript for empty request bodies, fix headers being left out when response body is omitted -
#1289
7f452fa
Thanks @adamschoenemann! - Fixed a bug where references to types with discriminators with implicit mappings would generate incorrect types
- #1281
ebd31ff
Thanks @pvanagtmaal! - Refactor CLI path handling, fixing several bugs
- #1278
d7420e3
Thanks @pvanagtmaal! - Fix externalizing external refs
- #1269
e735ff2
Thanks @pimveldhuisen! - Stop trimming whitespace other than linebreaks in string values
-
#1248
c145f5f
Thanks @drwpow! - Fix Record<string, never> appearing in union -
#1248
c145f5f
Thanks @drwpow! - Improve oneOf generated types
-
#1231
e1ce2d6
Thanks @tkrotoff! - Do not append trailing spaces to JSDoc tags -
#1232
31c030d
Thanks @tkrotoff! - Remove unnecessary array parenthesis
- #1200
4fc8c20
Thanks @toomuchdesign! - Remove unexpected empty string in generated nullable polymophic enum types (["string", "null"])
- #1193
64decb7
Thanks @psychedelicious! - Add example forBlob
type transforms
- #1166
db37f3c
Thanks @pvanagtmaal! - Fix property escaping for discriminators
-
#1149
b82cffb
Thanks @duncanbeevers! - Stringify const values with no specified type -
#1156
ad017a9
Thanks @horaklukas! - Avoid index signature TS error for paths with empty params
- 7d09c3b: Support nested path parameters in
--path-params-as-types
(#1130). Thanks, barakalon!
- Fix remote
$ref
s to complete schemas (#1087) - Fix incorrect check for protocol by @happycollision (#1088)
- Fix missing parameters in operation object (#1090)
- Fix tuples type generation by @liangskyli (#1085)
- Fix path generation by @HiiiiD (#991)
- If no type is specified, type as
unknown
by @mitchell-merry (#1049) - Ensure not required parameters are created as optional properties by @AplusKminus (#1053)
- Fix missing type defs (#1072)
- Deduplicate unions by @mitchell-merry (#1069)
- Fix tuples type generation support by @liangskyli (#1011)
- Fix
$ref
’d parameters missing (#1061) - Fix
oneOf
number const (#1056) by @qnp
- New
--empty-objects-unknown
flag for better control over unspecified object types’ default shape by @duncanbeevers (#1032)
- JSDoc improvements by @mitchell-merry (#1029)
- Fix readonly nullable properties by @mtth (#1036)
- Tiny QoL improvements to invalid schema errors (#1043)
- Fix response key for HTTP ranges (#1010) @stefanmaric
- Escape constant string in generated schema (#1014) @mvdbeek
- Support fully-qualified refs as discriminator mapping values (#1017) @sgrimm
- Improve behavior of allOf + required properties (#1027) @Swiftwork
- Make params non-nullable even if all params are optional (#1022) @sgrimm
- Adds
webhook
typings by @yacinehmito (#1001) - Use undici’s
fetch()
instead ofrequest()
which can be overridden locally by @yacinehmito (#1002) - Adds type helpers only when used by @imagoiq (#992)
- Fixes bug in glob output by @BTMPL (#999)
- Fixes header casing by @HiiiiD (#990)
- Fixed multiple causes of bug #988 “cannot read properties of undefined” by @HiiiiD and @yacinehmito (#990 and #1002)
- Fixed
nullable: true
(#983) - Fixed
additionalProperties
bug (#983)
- Fixes #975 where
#/components/examples
were being parsed as schema objects
- Remove
postinstall
hook only meant for dev
- Dropped Prettier formatting and all formatting options. Now, simply format at your discretion (or not at all!)
- Dropped support for Swagger 2.0
- Dropped Node 14 support (it still works for now, but Node 14 bugs won’t be fixed if any arise)
--version
was changed to return the version of this library (also by dropping Swagger 2.0 support the old usage was no longer needed)- Dropped
--raw-schema
. Your entry schema MUST be valid and complete (however, your $refs to subschemas may be partials). - Dropped
--make-paths-enum
because it was incompatible with--path-params-as-types
- Dropped the CLI aliases
-it
and-ap
(specify the full --immutable-types
or--additional-properties
flag) - Empty content:
{}
now returnsnever
. Dropped the--content-never
flag as this is now the default behavior. - Renamed and upgraded the Node API’s
formatter()
function totransform()
andpostTransform()
. It’s an overall improvement on the original concept with even more power than before.
- Sped up type generation by 3× by dropping Prettier & optimizing deep-object crawl speed
- OpenAPI 3.1 support for
discriminator
and polymorphic types - Complete codebase rewrite and cleanup
- Now ships modern ESNext code rather than ES2018
- Improved internal types & documentation
- Test cleanup, now powered by Vitest
- New
transform()
andpostTransform()
hooks give you more control in overriding/extending generated types
- More accurate types for
oneOf
/anyOf
/allOf
(#894) --immutable-types
has a new-t
alias- Addition of path.default types
- Support
nullable
as type arrays for OpenAPI 3.1 (#898)
- Fixed multiple bugs with deep-linked remote schemas and complex
$ref
s - Fixed
anyOf
intersections resulting in unexpected type signatures - Fixed
[string, null]
generating asunknown
- Fixed
{ property: unknown; }
withallOf
union - Fixed
requestBody
missingcontent
property - Fixed headers missing remote
$ref
s
- New
--content-never
flag forces never response body by @duncanbeevers (#905)
- Empty strings are now allowed for properties like
@default
by @duncanbeevers (#906) - Throws friendlier error on bad
--prettier-config
path by @duncanbeevers (#909) - Objects are now allowed for properties like
@default
by @duncanbeevers (#910) - Fixes
enum
export of operation paths by @duncanbeevers (#912)
- New
--make-paths-enum
CLI flag by @berzi (#883) - New
--path-params-as-types
CLI flag by @Powell-v2 (#891) - Supports
/** @constant */
JSDoc comments by @PhilipTrauner (#896) - You can now add your own custom comment header at the top of every generated doc (#904)
- Fixes inconsistent comment title (#904)
- The
--export-type
flag was added to generate type instead of interface by @dominikdosoudil (#868) - Updated schemas & examples
- Tiny optimizations for a little speed boost (#881)
- Fixes CommonJS error for undici on older versions of Node (#879)
- Removes CJS version from npm (to use CJS, use
openapi-typescript@4
). Version 5 switched to ESM as default anyway, and since tests are now testing ESM, the reliability of CJS was dubious (and there were TypeScript problems as well) - Fixes type error when using TypeScript nightly (#847)
- Patches security vulnerability with node-fetch (by replacing with undici)
- Adds constants support by @sadfsdfdsa (#831)
- Fixes a syntax error caused by an empty
oneOf
by @sadfsdfdsa (#830)
- Adds missing types for CJS build (#861)
- 5.x drops support for Node 12. If you’re still on Node 12, be sure to lock your version to 4.x.
- Updates this library to full ESM! ✨ This is the future of JavaScript, and is now natively supported in Node 14+.
- Now supports a
URL()
as input to make ESM usage easier (see example)
- Significantly-enhanced JSDoc output by @sadfsdfdsa (#797)
- Adds TypeScript
@deprecated
comment to deprecated schema objects by @bunkscene
- In many areas, changed out
any
withunknown
(#769). See #554 for more explanation / context
- An old bug is now gone! openapi-typescript would incorrectly generate
{ [key: string]: unknown }
for a type when it may have been astring
ornumber
. Now it will generate a more genericunknown
type, unless it knows it’s dealing with an object for sure.
- Reference arbitrary data on generated types via the
properties
key by @Peteck (#626)
- Fixes the remote schema URL cache being too long-lived by @mbelsky (#708)
- New
--headersObject
and--headers
CLI flags by @ericzorn93 (#764)
"type": "file"
no longer generates unexpected results (#766)
- Loading in-memory schemas through the JS API resulted in broken
$ref
s (#689)
- Fixes
properties
+anyOf
with onlyrequired
properties by @gr2m (#643)
- The Node.js API now returns a promise, and can no longer be run synchronously (a necessity because resolving remote schemas can never be synchronous). Other than that, there are no other breaking changes. CLI users are unaffected, and the types generated are backwards-compatible with previous versions.
- Now supports remote references (
$ref: "remote.yaml#/components/schemas/User
) 🎉 (#602)!
- Fix glob accidentally generating empty folders alongside single-file schemas (#633)
- Adds glob support thanks to @sharmarajdaksh (#615)
- Reverts #613 and adds a
--default-non-nullable
flag (#631)
- Schema objects that have a
default:
property shouldn’t be marked as nullable (#613)
- Changes default behavior of #585 to require an opt-in
--additional-properties
flag (#607) - Adds
-c
shortcut alias for--prettier-config
(#607) - Adds
-it
shortcut alias for--immutable-types
(#607)
additionalProperties
now default totrue
per the OpenAPI 3.0 spec by @mehalter (#583)
- Fixed a parse error on
enum: []
(#563) - Fixed another parse error on responses missing schemas (#565)
- Fixed a bug with the latest version of Prettier and
options.prettierConfig
(#566)
- RequestBodies that had hyphens in their name would generate an error (#550). Thanks (again), @ashsmith!
- Fixed an issue where a comment within a schema definition would break type gen (#548). Thanks, @ashsmith!
- Added a new
--immutable-types
flag by @dnalborczyk (#522)
- The
operations
interface inherits parameters properly by @henhal (#530)
- Fixes package types for TypeScript projects (#520)
- Better handles remote schema content types (#516)
- Remote schema loading now follows redirects (#510)
- New
--auth
flag to access private schemas (#508) - npm version now ships with ESM package exports for better interop between ESM & CommonJS (#509)
- Fixes an OpenAPI V2 parameter bug by @yamacent (#489)
- If using OpenAPI 2.0, and you didn’t have
definitions
, an unexpected error was encountered. This is now fixed.
- Improves handling of complex
oneOf
by @gr2m (#491)
- Fixed generation bug where responseBodies that contained both a
$ref
andoperationId
generated invalid TypeScript (#464)
- This is marked as a breaking version for safety. Swagger v2 users should be able to migrate to
3.0.0
with no problems; OpenAPI v3 users will either experience no changes or minor changes that should be an overall improvement.
- Adds long-requested paths support to Swagger v2 schemas
- Adds more compact comments, resulting more readable generated types
- Fixes bugs in paths generation (missing $refs support in areas, inconsistent generation)
- Comments can now be single-line, saving some needed space in the specs (#443)
additionalProperties.oneOf
is now generating as expected (#442)
- Fixes
paths.requestBody.content
possibly missing by @robertmassaioli (#369) - Fix: check if path item is method operation by @rendall (#366)
- escape quotes in enum string values by @gr2m (#365)
- Add
operations
interface by @gr2m (#353)
- Allow
$ref: 'foo.yaml#bar'
syntax, but cast toany
type (TODO: full external schema support) (#354)
$refs
in paths now respect optional parameters (#352) by @gr2m
- Handle parameters on paths as well as methods by @samdbmg (#347)
- Set index type to all possible values (#348)
requestBody
and$ref
-type parameters added in response types by @gr2m
🐣 Minor Changes
- responses without content schemas changed from
any
tonever
orunknown
by @gr2m
- New name! Now published at
openapi-typescript
. - Added paths support (#328)
- Support for components.responses (#258)
- Adds tuple support (#293)
- Fix missing port bug (#252)
- additionalProperties interpolation, primitive enums (#266)
- bubble up the error message / improve error message when failing to parse the schema (#269)
- Improve error message when server is unreachable (#288)
- OpenAPI 3.0 support (#223)
- Schema names are no longer transformed (e.g.
UserRole
is nowdefinitions['user']['role']
). See README for migration instructions. (#223) - Flags with “deprecated” warnings in
1.x
were dropped and no longer work (#223)
- Adds support for JSDoc comments (#223)
- Support for null values (#223)
- Improves Prettier config resolution (#224)
- Improves array and object handling (#226)
- Now handles the
@
character in namespaces thanks to @sorin-davidoi 🎉 - Updates Prettier to
2.0
- Swagger v3 is no longer unsupported! 🎉 But it’s in beta. Which means errors will probably arise. Please test it out on your existing v3 schema, and file any bugs here.
- The
--swagger
flag is now deprecated; this library will automatically parse the version from the schema.
- Fixes a bug where
additionalProperties
weren’t respected for nestedproperties
(#92).
- Fixes an issue where
--camelcase
wouldn’t camelCase$ref
s properly
- Fixes a bug where a definition with a missing
type
would be skipped, rather than assume it’s anobject
like Swagger does by default.
- Adds Property mapper function (see README) that supports
x-nullable
and other properties by @atlefren (#118)
- Convert names containing spaces to use underscores (#75) thanks to @svnv
- Puts out JSDoc thanks to @lbenie
- Fix nested arrays (#54)
- The
--nowrapper
flag was added to the CLI, courtesy of @scvnathan (#33). Now you don’t have to wrap your interfaces if you don’t want to!
- This fixes underscores from accidentally appearing in some TypeScript interface names (#29)
- Swagger properties in
kebab-case
would break generation unless they were converted to--camelcase
(#13). This has been fixed! 🎉 You still have the option of converting to--camelcase
, but now you can keepkebab-case
too if needed
- Adds
--wrapper
option, letting you specify any namespace or module wrapper for exporting types. See the README for full description
--namespace
and--export
options are now deprecated, in favor of the more versatile--wrapper
- Now supports an
--export
option to export namespaces thanks to @tpdewolf
- No longer generates empty interfaces (caused by top-level definitions being array types, referencing other definitions)
- Improves enum generation to be simpler-to-use (values are now just hardcoded inline, rather than trying to use TypeScript enums).
- Changes default behavior to preserve
snake_case
properties (you can still convert with--camelcase
)
- Bundles & ships with @pika/pack
- Falls back to
object
if it can’t grab properties
- Different API, now requires
namespace
as 2nd parameter. Because namespacing is good.
- Maybe a bug; maybe not—if a Swagger spec had a common name like
Error
it would break your build if another type extended from it
- Fixes bug where number enums names could be generated.
- Supports TypeScript enums
- Exists