Skip to content

fix spacing on comment header #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { transformAll } from "./transform/index.js";
import { makeApiPathsEnum } from "./transform/paths.js";
export * from "./types.js"; // expose all types to consumers

export const WARNING_MESSAGE = `/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
export const COMMENT_HEADER = `/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
`;

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

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

// 2. generate raw output
let output = WARNING_MESSAGE;
let output = ctx.commentHeader;

// 2a. root schema
if (!options?.version && !ctx.rawSchema) ctx.version = swaggerVersion(rootSchema as any); // note: root version cascades down to all subschemas
Expand Down
17 changes: 11 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,26 @@ export interface SwaggerToTSOptions {
* (optional) Substitute path parameter names with their respective types.
*/
pathParamsAsTypes?: boolean;
/**
* (optional) Provide your own comment header that prefixes the generated file.
* Note this isn’t validated, so any string entered will be accepted as-is.
*/
commentHeader?: string;
}

/** Context passed to all submodules */
export interface GlobalContext {
additionalProperties: boolean;
auth?: string;
commentHeader: string;
defaultNonNullable: boolean;
formatter?: SchemaFormatter;
immutableTypes: boolean;
defaultNonNullable: boolean;
/** (optional) Should logging be suppressed? (necessary for STDOUT) */
silent?: boolean;
makePathsEnum: boolean;
namespace?: string;
pathParamsAsTypes?: boolean;
rawSchema: boolean;
makePathsEnum: boolean;
version: number;
silent?: boolean;
supportArrayLength?: boolean;
pathParamsAsTypes?: boolean;
version: number;
}