@@ -20,24 +20,20 @@ Options
20
20
--headersObject, -h (optional) Provide a JSON object as string of HTTP headers for remote schema request
21
21
--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
22
22
--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"
26
26
--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
31
27
--support-array-length (optional) Generate tuples using array minItems / maxItems
32
28
--path-params-as-types (optional) Substitute path parameter names with their respective types
33
29
--alphabetize (optional) Sort types alphabetically
34
- --version (optional) Force schema parsing version
35
30
` ;
36
31
37
32
const OUTPUT_FILE = "FILE" ;
38
33
const OUTPUT_STDOUT = "STDOUT" ;
39
34
const CWD = new URL ( `file://${ process . cwd ( ) } /` ) ;
40
35
const EXT_RE = / \. [ ^ . ] + $ / i;
36
+ const HTTP_RE = / ^ h t t p s ? : \/ \/ / ;
41
37
42
38
const timeStart = process . hrtime ( ) ;
43
39
@@ -47,30 +43,28 @@ function errorAndExit(errorMessage) {
47
43
}
48
44
49
45
const [ , , 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
+
50
49
const flags = parser ( args , {
51
50
array : [ "header" ] ,
52
51
boolean : [
53
52
"defaultNonNullable" ,
54
53
"immutableTypes" ,
55
54
"contentNever" ,
56
- "rawSchema" ,
57
55
"exportType" ,
58
56
"supportArrayLength" ,
59
- "makePathsEnum" ,
60
57
"pathParamsAsTypes" ,
61
58
"alphabetize" ,
62
59
] ,
63
60
number : [ "version" ] ,
64
- string : [ "auth" , "header" , "headersObject" , "httpMethod" , "prettierConfig" ] ,
61
+ string : [ "auth" , "header" , "headersObject" , "httpMethod" ] ,
65
62
alias : {
66
- additionalProperties : [ "ap" ] ,
67
63
header : [ "x" ] ,
64
+ exportType : [ "t" ] ,
68
65
headersObject : [ "h" ] ,
69
66
httpMethod : [ "m" ] ,
70
- immutableTypes : [ "it" ] ,
71
67
output : [ "o" ] ,
72
- prettierConfig : [ "c" ] ,
73
- makePathsEnum : [ "pe" ] ,
74
68
} ,
75
69
default : {
76
70
httpMethod : "GET" ,
@@ -103,9 +97,6 @@ async function generateSchema(pathToSpec) {
103
97
auth : flags . auth ,
104
98
defaultNonNullable : flags . defaultNonNullable ,
105
99
immutableTypes : flags . immutableTypes ,
106
- prettierConfig : flags . prettierConfig ,
107
- rawSchema : flags . rawSchema ,
108
- makePathsEnum : flags . makePathsEnum ,
109
100
contentNever : flags . contentNever ,
110
101
silent : output === OUTPUT_STDOUT ,
111
102
version : flags . version ,
@@ -156,13 +147,8 @@ async function main() {
156
147
console . info ( `✨ ${ BOLD } openapi-typescript ${ packageJSON . version } ${ RESET } ` ) ; // only log if we’re NOT writing to stdout
157
148
}
158
149
159
- // error: --raw-schema
160
- if ( flags . rawSchema && ! flags . version ) {
161
- throw new Error ( `--raw-schema requires --version flag` ) ;
162
- }
163
-
164
150
// handle remote schema, exit
165
- if ( / ^ h t t p s ? : \/ \/ / . test ( pathToSpec ) ) {
151
+ if ( HTTP_RE . test ( pathToSpec ) ) {
166
152
if ( output !== "." && output === OUTPUT_FILE ) fs . mkdirSync ( outputDir , { recursive : true } ) ;
167
153
await generateSchema ( pathToSpec ) ;
168
154
return ;
0 commit comments