@@ -58,39 +58,7 @@ primitives that aren't directly supported. However, there are two solutions to a
5858these challenges effectively. Click [ here] ( #list-of-supported-io-ts-primitives ) for the
5959list of supported primitives.
6060
61- ### Solution 1: Using a Custom Codec Configuration File
62-
63- ` openapi-generator ` supports importing codecs from other packages in ` node_modules ` , but
64- it struggles with primitives that need JavaScript interpretation, such as
65- ` new t.Type(...) ` . To work around this, you can define schemas for these codecs in a
66- configuration file within your downstream types package (where you generate the API
67- docs). This allows the generator to understand and use these schemas where necessary.
68- Follow these steps to create and use a custom codec configuration file:
69-
70- 1 . Create a JavaScript file with the following format:
71-
72- ``` javascript
73- module .exports = (E ) => {
74- return {
75- ' io-ts-bigint' : {
76- BigIntFromString : () => E .right ({ type: ' string' }),
77- NonZeroBigInt : () => E .right ({ type: ' number' }),
78- NonZeroBigIntFromString : () => E .right ({ type: ' string' }),
79- NegativeBigIntFromString : () => E .right ({ type: ' string' }),
80- NonNegativeBigIntFromString : () => E .right ({ type: ' string' }),
81- PositiveBigIntFromString : () => E .right ({ type: ' string' }),
82- },
83- // ... and so on for other packages
84- };
85- };
86- ```
87-
88- 2 . The input parameter ` E ` is the namespace import of ` fp-ts/Either ` , which avoids
89- issues with ` require ` . The return type should be a ` Record ` containing AST
90- definitions for external libraries. For more information on the structure, refer to
91- [ KNOWN_IMPORTS] ( ./src/knownImports.ts ) .
92-
93- ### Solution 2: Defining Custom Codec Schemas in the Types Package (recommended)
61+ ### Solution 1: Defining Custom Codec Schemas in the Types Package (recommended)
9462
9563` openapi-generator ` now offers the ability to define the schema of custom codecs
9664directly within the types package that defines them, rather than the downstream package
@@ -131,6 +99,38 @@ generated API docs for any endpoints that use the respective codecs. The input p
13199containing AST definitions for external libraries. For more details, see
132100[ KNOWN_IMPORTS] ( ./src/knownImports.ts ) .
133101
102+ ### Solution 2: Using a Custom Codec Configuration File
103+
104+ ` openapi-generator ` supports importing codecs from other packages in ` node_modules ` , but
105+ it struggles with ` io-ts ` primitives that need JavaScript interpretation, such as
106+ ` new t.Type(...) ` . To work around this, you can define schemas for these codecs in a
107+ configuration file within your downstream types package (where you generate the API
108+ docs). This allows the generator to understand and use these schemas where necessary.
109+ Follow these steps to create and use a custom codec configuration file:
110+
111+ 1 . Create a JavaScript file with the following format:
112+
113+ ``` javascript
114+ module .exports = (E ) => {
115+ return {
116+ ' io-ts-bigint' : {
117+ BigIntFromString : () => E .right ({ type: ' string' }),
118+ NonZeroBigInt : () => E .right ({ type: ' number' }),
119+ NonZeroBigIntFromString : () => E .right ({ type: ' string' }),
120+ NegativeBigIntFromString : () => E .right ({ type: ' string' }),
121+ NonNegativeBigIntFromString : () => E .right ({ type: ' string' }),
122+ PositiveBigIntFromString : () => E .right ({ type: ' string' }),
123+ },
124+ // ... and so on for other packages
125+ };
126+ };
127+ ```
128+
129+ 2 . The input parameter ` E ` is the namespace import of ` fp-ts/Either ` , which avoids
130+ issues with ` require ` . The return type should be a ` Record ` containing AST
131+ definitions for external libraries. For more information on the structure, refer to
132+ [ KNOWN_IMPORTS] ( ./src/knownImports.ts ) .
133+
134134## List of supported io-ts primitives
135135
136136- string
0 commit comments