Skip to content

Commit

Permalink
Package dependencies cleanup (airtasker#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
lfportal authored Jan 22, 2020
1 parent bd8cf77 commit 9bc22d0
Show file tree
Hide file tree
Showing 28 changed files with 263 additions and 213 deletions.
11 changes: 6 additions & 5 deletions cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Command, flags } from "@oclif/command";
import { prompt } from "inquirer";
import YAML from "js-yaml";
import sortBy from "lodash/sortBy";
import path from "path";
import { Contract } from "../../../lib/src/definitions";
import { generateJsonSchema } from "../../../lib/src/generators/json-schema/json-schema";
Expand Down Expand Up @@ -52,7 +51,7 @@ export default class Generate extends Command {
}>({
name: "Generator",
type: "list",
choices: sortBy(availableGenerators())
choices: availableGenerators()
})
).Generator;
}
Expand All @@ -75,7 +74,7 @@ export default class Generate extends Command {
}>({
name: "Language",
type: "list",
choices: sortBy(availableFormats(generator))
choices: availableFormats(generator)
})
).Language;
}
Expand Down Expand Up @@ -118,11 +117,13 @@ export default class Generate extends Command {
}

function availableGenerators() {
return Object.keys(generators);
return Object.keys(generators).sort((a, b) => (a > b ? 1 : -1));
}

function availableFormats(generator: string) {
return Object.keys(generators[generator].formats);
return Object.keys(generators[generator].formats).sort((a, b) =>
a > b ? 1 : -1
);
}

interface Generators {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface Contract {
name: string;
description?: string;
config: Config;
types: Array<{ name: string; type: Type }>;
types: { name: string; type: Type }[];
security?: SecurityHeader;
endpoints: Endpoint[];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class ParserError extends Error {
readonly locations: Array<{ file: string; position: number }>;
readonly locations: { file: string; position: number }[];

constructor(
readonly message: string,
...locations: Array<{ file: string; position: number }>
...locations: { file: string; position: number }[]
) {
super(message); // 'Error' breaks prototype chain here
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ class EndpointWithArrayQueryParam {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class EndpointWithArrayQueryParam {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class Contract {}
})
class GetEndpoint {
@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class EndpointWithArrayQueryParam {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class EndpointWithQueryParams {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class EndpointWithRequestHeaders {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class Contract {
})
class GetEndpoint {
@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
10 changes: 5 additions & 5 deletions lib/src/generators/openapi2/openapi2-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface PathItemObject {
options?: OperationObject;
head?: OperationObject;
patch?: OperationObject;
parameters?: Array<ParameterObject | ReferenceObject>;
parameters?: (ParameterObject | ReferenceObject)[];
}

// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operationObject
Expand All @@ -67,7 +67,7 @@ export interface OperationObject {
operationId?: string;
consumes?: string[];
produces?: string[];
parameters?: Array<ParameterObject | ReferenceObject>;
parameters?: (ParameterObject | ReferenceObject)[];
responses: ResponsesObject;
schemes?: Schemes[];
deprecated?: boolean;
Expand Down Expand Up @@ -418,7 +418,7 @@ interface NumberSchemaObjectBase {
exclusiveMaximum?: boolean;
minimum?: number;
exclusiveMinimum?: boolean;
enum?: Array<number | null>;
enum?: (number | null)[];
}

export interface StringSchemaObject extends SchemaObjectBase {
Expand All @@ -432,12 +432,12 @@ export interface StringSchemaObject extends SchemaObjectBase {
*/
format?: "date" | "date-time" | "password" | "byte" | "binary";
pattern?: string;
enum?: Array<string | null>;
enum?: (string | null)[];
}

export interface BooleanSchemaObject extends SchemaObjectBase {
type: "boolean";
enum?: Array<boolean | null>;
enum?: (boolean | null)[];
default?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/generators/openapi2/openapi2-type-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function referenceObjectValue(referenceName: string): string {
function createEnum<T>(
values?: T[],
nullable?: boolean
): Array<T | null> | undefined {
): (T | null)[] | undefined {
if (!values) return;
return nullable ? [...values, null] : values;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ class EndpointWithArrayQueryParam {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class EndpointWithArrayQueryParam {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class Contract {}
})
class GetEndpoint {
@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class EndpointWithArrayQueryParam {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class EndpointWithQueryParams {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class EndpointWithRequestHeaders {
) {}

@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class Contract {
})
class GetEndpoint {
@response({ status: 200 })
successResponse(@body body: Array<{ id: String; name: String }>) {}
successResponse(@body body: { id: String; name: String }[]) {}
}
16 changes: 8 additions & 8 deletions lib/src/generators/openapi3/openapi3-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export interface PathItemObject {
patch?: OperationObject;
trace?: OperationObject;
servers?: ServerObject[];
parameters?: Array<ParameterObject | ReferenceObject>;
parameters?: (ParameterObject | ReferenceObject)[];
}

// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operationObject
Expand All @@ -76,7 +76,7 @@ export interface OperationObject {
description?: string;
externalDocs?: ExternalDocumentationObject;
operationId?: string;
parameters?: Array<ParameterObject | ReferenceObject>;
parameters?: (ParameterObject | ReferenceObject)[];
requestBody?: RequestBodyObject | ReferenceObject;
responses: ResponsesObject;
callbacks?: { [callback: string]: CallbackObject | ReferenceObject };
Expand Down Expand Up @@ -177,7 +177,7 @@ interface NumberSchemaObjectBase {
minimum?: number;
exclusiveMinimum?: boolean;
multipleOf?: number;
enum?: Array<number | null>;
enum?: (number | null)[];
default?: number;
}

Expand All @@ -191,13 +191,13 @@ export interface StringSchemaObject extends SchemaObjectBase {
*/
format?: "date" | "date-time" | "password" | "byte" | "binary";
pattern?: string;
enum?: Array<string | null>;
enum?: (string | null)[];
default?: string;
}

export interface BooleanSchemaObject extends SchemaObjectBase {
type: "boolean";
enum?: Array<boolean | null>;
enum?: (boolean | null)[];
default?: boolean;
}

Expand Down Expand Up @@ -237,17 +237,17 @@ export interface AnySchemaObject extends SchemaObjectBase {
}

export interface AllOfSchemaObject extends SchemaObjectBase {
allOf: Array<SchemaObject | ReferenceObject>;
allOf: (SchemaObject | ReferenceObject)[];
discriminator?: DiscriminatorObject;
}

export interface OneOfSchemaObject extends SchemaObjectBase {
oneOf: Array<SchemaObject | ReferenceObject>;
oneOf: (SchemaObject | ReferenceObject)[];
discriminator?: DiscriminatorObject;
}

export interface AnyOfSchemaObject extends SchemaObjectBase {
anyOf: Array<SchemaObject | ReferenceObject>;
anyOf: (SchemaObject | ReferenceObject)[];
discriminator?: DiscriminatorObject;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/generators/openapi3/openapi3-type-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function referenceObjectValue(referenceName: string): string {
function createEnum<T>(
values?: T[],
nullable?: boolean
): Array<T | null> | undefined {
): (T | null)[] | undefined {
if (!values) return;
return nullable ? [...values, null] : values;
}
2 changes: 1 addition & 1 deletion lib/src/linting/rules/has-response-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function hasResponsePayload(contract: Contract): LintingRuleViolation[] {
return violations;
}

function findResponses(endpoint: Endpoint): Array<DefaultResponse | Response> {
function findResponses(endpoint: Endpoint): (DefaultResponse | Response)[] {
return [
...endpoint.responses,
...(endpoint.defaultResponse ? [endpoint.defaultResponse] : [])
Expand Down
1 change: 1 addition & 0 deletions lib/src/parsers/__spec-examples__/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface TypeInterface {
propertyB?: boolean;
};
array: boolean[];
// tslint:disable-next-line: array-type
arrayConstructor: Array<{ a: boolean }>;
union: boolean | Date | null;
unionDiscriminated: DiscriminatedUnionElementA | DiscriminatedUnionElementB;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parsers/contract-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function extractEndpoints(
];
if (duplicateEndpointNames.length !== 0) {
const locations = duplicateEndpointNames.reduce<
Array<{ file: string; position: number }>
{ file: string; position: number }[]
>((acc, name) => {
const nameLocations = endpointClasses
.filter(k => k.getNameOrThrow() === name)
Expand Down
16 changes: 8 additions & 8 deletions lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ export interface DateTimeType {

export interface ObjectType {
kind: TypeKind.OBJECT;
properties: Array<{
properties: {
name: string;
description?: string;
optional: boolean;
type: Type;
}>;
}[];
}

export interface ArrayType {
Expand Down Expand Up @@ -224,12 +224,12 @@ export function dateTimeType(): DateTimeType {
}

export function objectType(
properties: Array<{
properties: {
name: string;
description?: string;
optional: boolean;
type: Type;
}>
}[]
): ObjectType {
return {
kind: TypeKind.OBJECT,
Expand Down Expand Up @@ -462,7 +462,7 @@ export function inferDiscriminator(

const possibleDiscriminators = new Map<
string,
Array<{ value: string; type: Type }>
{ value: string; type: Type }[]
>();

for (const type of concreteRootTypesExcludingNull) {
Expand Down Expand Up @@ -523,9 +523,9 @@ export class TypeTable {
return this.types.size;
}

static fromArray(types: Array<{ name: string; type: Type }>): TypeTable {
static fromArray(types: { name: string; type: Type }[]): TypeTable {
const entries = types.reduce(
(acc: Array<[string, Type]>, t: { name: string; type: Type }) => {
(acc: [string, Type][], t: { name: string; type: Type }) => {
acc.push([t.name, t.type]);
return acc;
},
Expand All @@ -544,7 +544,7 @@ export class TypeTable {
/**
* Return an object representation of the type table.
*/
toArray(): Array<{ name: string; type: Type }> {
toArray(): { name: string; type: Type }[] {
const arr = new Array<{ name: string; type: Type }>();
this.types.forEach((type, key, _) => {
arr.push({ name: key, type });
Expand Down
Loading

0 comments on commit 9bc22d0

Please sign in to comment.