@@ -20,24 +20,20 @@ Options
2020 --headersObject, -h (optional) Provide a JSON object as string of HTTP headers for remote schema request
2121 --header, -x (optional) Provide an array of or singular headers as an alternative to a JSON object. Each header must follow the key: value pattern
2222 --httpMethod, -m (optional) Provide the HTTP Verb/Method for fetching a schema from a remote URL
23- --immutable-types , -it (optional) Generates immutable types (readonly properties and readonly array)
24- --content-never (optional) If supplied, an omitted reponse \`content\` property will be generated as \`never\` instead of \`unknown\`
25- --additional-properties, -ap (optional) Allow arbitrary properties for all schema objects without "additionalProperties: false"
23+ --export-type , -t (optional) Export "type" instead of "interface"
24+ --immutable-types (optional) Generates immutable types (readonly properties and readonly array)
25+ --additional-properties (optional) Allow arbitrary properties for all schema objects without "additionalProperties: false"
2626 --default-non-nullable (optional) If a schema object has a default value set, don’t mark it as nullable
27- --prettier-config, -c (optional) specify path to Prettier config file
28- --raw-schema (optional) Parse as partial schema (raw components)
29- --paths-enum, -pe (optional) Generate an enum containing all API paths.
30- --export-type (optional) Export type instead of interface
3127 --support-array-length (optional) Generate tuples using array minItems / maxItems
3228 --path-params-as-types (optional) Substitute path parameter names with their respective types
3329 --alphabetize (optional) Sort types alphabetically
34- --version (optional) Force schema parsing version
3530` ;
3631
3732const OUTPUT_FILE = "FILE" ;
3833const OUTPUT_STDOUT = "STDOUT" ;
3934const CWD = new URL ( `file://${ process . cwd ( ) } /` ) ;
4035const EXT_RE = / \. [ ^ . ] + $ / i;
36+ const HTTP_RE = / ^ h t t p s ? : \/ \/ / ;
4137
4238const timeStart = process . hrtime ( ) ;
4339
@@ -47,30 +43,28 @@ function errorAndExit(errorMessage) {
4743}
4844
4945const [ , , input , ...args ] = process . argv ;
46+ if ( args . includes ( "-ap" ) ) errorAndExit ( `The -ap alias has been deprecated. Use "--additional-properties" instead.` ) ;
47+ if ( args . includes ( "-it" ) ) errorAndExit ( `The -it alias has been deprecated. Use "--immutable-types" instead.` ) ;
48+
5049const flags = parser ( args , {
5150 array : [ "header" ] ,
5251 boolean : [
5352 "defaultNonNullable" ,
5453 "immutableTypes" ,
5554 "contentNever" ,
56- "rawSchema" ,
5755 "exportType" ,
5856 "supportArrayLength" ,
59- "makePathsEnum" ,
6057 "pathParamsAsTypes" ,
6158 "alphabetize" ,
6259 ] ,
6360 number : [ "version" ] ,
64- string : [ "auth" , "header" , "headersObject" , "httpMethod" , "prettierConfig" ] ,
61+ string : [ "auth" , "header" , "headersObject" , "httpMethod" ] ,
6562 alias : {
66- additionalProperties : [ "ap" ] ,
6763 header : [ "x" ] ,
64+ exportType : [ "t" ] ,
6865 headersObject : [ "h" ] ,
6966 httpMethod : [ "m" ] ,
70- immutableTypes : [ "it" ] ,
7167 output : [ "o" ] ,
72- prettierConfig : [ "c" ] ,
73- makePathsEnum : [ "pe" ] ,
7468 } ,
7569 default : {
7670 httpMethod : "GET" ,
@@ -103,9 +97,6 @@ async function generateSchema(pathToSpec) {
10397 auth : flags . auth ,
10498 defaultNonNullable : flags . defaultNonNullable ,
10599 immutableTypes : flags . immutableTypes ,
106- prettierConfig : flags . prettierConfig ,
107- rawSchema : flags . rawSchema ,
108- makePathsEnum : flags . makePathsEnum ,
109100 contentNever : flags . contentNever ,
110101 silent : output === OUTPUT_STDOUT ,
111102 version : flags . version ,
@@ -156,13 +147,8 @@ async function main() {
156147 console . info ( `✨ ${ BOLD } openapi-typescript ${ packageJSON . version } ${ RESET } ` ) ; // only log if we’re NOT writing to stdout
157148 }
158149
159- // error: --raw-schema
160- if ( flags . rawSchema && ! flags . version ) {
161- throw new Error ( `--raw-schema requires --version flag` ) ;
162- }
163-
164150 // handle remote schema, exit
165- if ( / ^ h t t p s ? : \/ \/ / . test ( pathToSpec ) ) {
151+ if ( HTTP_RE . test ( pathToSpec ) ) {
166152 if ( output !== "." && output === OUTPUT_FILE ) fs . mkdirSync ( outputDir , { recursive : true } ) ;
167153 await generateSchema ( pathToSpec ) ;
168154 return ;
0 commit comments