Skip to content

Commit 9a11794

Browse files
committed
fix spacing on comment header
1 parent 22bf5da commit 9a11794

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { transformAll } from "./transform/index.js";
1010
import { makeApiPathsEnum } from "./transform/paths.js";
1111
export * from "./types.js"; // expose all types to consumers
1212

13-
export const WARNING_MESSAGE = `/**
14-
* This file was auto-generated by openapi-typescript.
15-
* Do not make direct changes to the file.
16-
*/
13+
export const COMMENT_HEADER = `/**
14+
* This file was auto-generated by openapi-typescript.
15+
* Do not make direct changes to the file.
16+
*/
1717
1818
1919
`;
2020

2121
/**
2222
* This function is the entry to the program and allows the user to pass in a remote schema and/or local schema.
23-
* The URL or schema and headers can be passed in either programtically and/or via the CLI.
23+
* The URL or schema and headers can be passed in either programmatically and/or via the CLI.
2424
* Remote schemas are fetched from a server that supplies JSON or YAML format via an HTTP GET request. File based schemas
2525
* are loaded in via file path, most commonly prefixed with the file:// format. Alternatively, the user can pass in
2626
* OpenAPI2 or OpenAPI3 schema objects that can be parsed directly by the function without reading the file system.
@@ -38,14 +38,15 @@ async function openapiTS(
3838
const ctx: GlobalContext = {
3939
additionalProperties: options.additionalProperties || false,
4040
auth: options.auth,
41+
commentHeader: typeof options.commentHeader === "string" ? options.commentHeader : COMMENT_HEADER,
4142
defaultNonNullable: options.defaultNonNullable || false,
4243
formatter: options && typeof options.formatter === "function" ? options.formatter : undefined,
4344
immutableTypes: options.immutableTypes || false,
44-
rawSchema: options.rawSchema || false,
4545
makePathsEnum: options.makePathsEnum || false,
46-
version: options.version || 3,
47-
supportArrayLength: options.supportArrayLength,
4846
pathParamsAsTypes: options.pathParamsAsTypes,
47+
rawSchema: options.rawSchema || false,
48+
supportArrayLength: options.supportArrayLength,
49+
version: options.version || 3,
4950
};
5051

5152
// note: we may be loading many large schemas into memory at once; take care to reuse references without cloning
@@ -76,7 +77,7 @@ async function openapiTS(
7677
}
7778

7879
// 2. generate raw output
79-
let output = WARNING_MESSAGE;
80+
let output = ctx.commentHeader;
8081

8182
// 2a. root schema
8283
if (!options?.version && !ctx.rawSchema) ctx.version = swaggerVersion(rootSchema as any); // note: root version cascades down to all subschemas

src/types.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,26 @@ export interface SwaggerToTSOptions {
165165
* (optional) Substitute path parameter names with their respective types.
166166
*/
167167
pathParamsAsTypes?: boolean;
168+
/**
169+
* (optional) Provide your own comment header that prefixes the generated file.
170+
* Note this isn’t validated, so any string entered will be accepted as-is.
171+
*/
172+
commentHeader?: string;
168173
}
169174

170175
/** Context passed to all submodules */
171176
export interface GlobalContext {
172177
additionalProperties: boolean;
173178
auth?: string;
179+
commentHeader: string;
180+
defaultNonNullable: boolean;
174181
formatter?: SchemaFormatter;
175182
immutableTypes: boolean;
176-
defaultNonNullable: boolean;
177-
/** (optional) Should logging be suppressed? (necessary for STDOUT) */
178-
silent?: boolean;
183+
makePathsEnum: boolean;
179184
namespace?: string;
185+
pathParamsAsTypes?: boolean;
180186
rawSchema: boolean;
181-
makePathsEnum: boolean;
182-
version: number;
187+
silent?: boolean;
183188
supportArrayLength?: boolean;
184-
pathParamsAsTypes?: boolean;
189+
version: number;
185190
}

0 commit comments

Comments
 (0)