Skip to content

Commit

Permalink
fix(cli): fix type reference schemas (#4701)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Sep 19, 2024
1 parent 98f2147 commit 807b43e
Show file tree
Hide file tree
Showing 42 changed files with 498 additions and 7,449 deletions.
416 changes: 188 additions & 228 deletions fern.schema.dev.json

Large diffs are not rendered by default.

416 changes: 188 additions & 228 deletions fern.schema.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
- changelogEntry:
- summary: |
Previously, the OpenAPI converter would bring over `title` on every
single property. This field is extraneous, so now we ignore it.
type: fix
irVersion: 53
version: 0.42.10

- changelogEntry:
- summary: |
Previously, the OpenAPI importer would ignore skip parsing arbitrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,17 +743,13 @@ types:
docs: Four-digit number representing the card's expiration year.
address_line1:
type: optional<string>
display-name: Card
address_line2:
type: optional<string>
display-name: Card
address_city:
type: optional<string>
display-name: Card
address_country: string
address_post_code:
type: optional<string>
display-name: Card
source:
openapi: openapi/trains/openapi.yml
BookingPaymentSourceBankAccountAccountType:
Expand Down Expand Up @@ -781,7 +777,6 @@ types:
docs: >-
The sort code for the bank account, in string form. Must be a
six-digit number.
display-name: Bank Account
account_type:
type: BookingPaymentSourceBankAccountAccountType
docs: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,13 @@ types:
docs: Four-digit number representing the card's expiration year.
address_line1:
type: optional<string>
display-name: Card
address_line2:
type: optional<string>
display-name: Card
address_city:
type: optional<string>
display-name: Card
address_country: string
address_post_code:
type: optional<string>
display-name: Card
source:
openapi: openapi/trains/openapi.yml
BookingPaymentSourceBankAccountAccountType:
Expand Down Expand Up @@ -288,7 +284,6 @@ types:
docs: >-
The sort code for the bank account, in string form. Must be a
six-digit number.
display-name: Bank Account
account_type:
type: BookingPaymentSourceBankAccountAccountType
docs: >-
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/fern-definition/json-schema/.depcheckrc.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/fern-definition/json-schema/.prettierrc.cjs

This file was deleted.

47 changes: 0 additions & 47 deletions packages/cli/fern-definition/json-schema/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/fern-definition/json-schema/src/index.ts

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions packages/cli/fern-definition/json-schema/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { z } from "zod";
import { TypeReferenceWithDocsAndAvailabilitySchema } from "./TypeReferenceSchema";
import { TypeReferenceSchema } from "./TypeReferenceSchema";
import { VariableReferenceSchema } from "./VariableReferenceSchema";

export const HttpPathParameterSchema = z.union([
TypeReferenceWithDocsAndAvailabilitySchema,
TypeReferenceSchema,
// pathParam: $myVariable
z.string(),
VariableReferenceSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { DeclarationSchema } from "./DeclarationSchema";
import { DeclarationWithNameSchema } from "./DeclarationWithNameSchema";
import { EncodingSchema } from "./EncodingSchema";
import { ValidationSchema } from "./ValidationSchema";
import { WithDisplayNameSchema } from "./WithDisplayNameSchema";
import { WithDocsAndAvailabilitySchema } from "./WithDocsAndAvailability";
import { WithAvailabilitySchema } from "./WithAvailabilitySchema";
import { WithDocsSchema } from "./WithDocsSchema";

// This return type is too crazy to write explicitly!
Expand All @@ -19,28 +18,15 @@ export function extendTypeReferenceSchema<T extends z.ZodRawShape>(extension: T)
encoding: z.optional(EncodingSchema),
validation: z.optional(ValidationSchema)
})
.extend(WithAvailabilitySchema.shape)
.extend(WithDocsSchema.shape)
.extend(extension)
]);
}

export const TypeReferenceSchema = extendTypeReferenceSchema({});
export const TypeReferenceSchema = extendTypeReferenceSchema(z.object({}).shape);
export type TypeReferenceSchema = z.infer<typeof TypeReferenceSchema>;

export const TypeReferenceWithDocsSchema = extendTypeReferenceSchema(WithDocsSchema.shape);
export type TypeReferenceWithDocsSchema = z.infer<typeof TypeReferenceWithDocsSchema>;

export const TypeReferenceWithDocsAndAvailabilitySchema = extendTypeReferenceSchema(
WithDocsAndAvailabilitySchema.shape
);
export type TypeReferenceWithDocsAndAvailabilitySchema = z.infer<typeof TypeReferenceWithDocsAndAvailabilitySchema>;

export const TypeReferenceWithDocsAndDisplayNameAndAvailabilitySchema = extendTypeReferenceSchema(
WithDocsAndAvailabilitySchema.extend(WithDisplayNameSchema.shape).shape
);
export type TypeReferenceWithDocsAndDisplayNameAndAvailabilitySchema = z.infer<
typeof TypeReferenceWithDocsAndDisplayNameAndAvailabilitySchema
>;

export const TypeReferenceDeclarationSchema = extendTypeReferenceSchema(DeclarationSchema.shape);
export type TypeReferenceDeclarationSchema = z.infer<typeof TypeReferenceDeclarationSchema>;

Expand All @@ -53,10 +39,3 @@ export const TypeReferenceDeclarationWithEnvOverride = extendTypeReferenceSchema
}).shape
);
export type TypeReferenceDeclarationWithEnvOverride = z.infer<typeof TypeReferenceDeclarationWithEnvOverride>;

export const TypeReferenceWithDefaultAndValidationSchema = z.strictObject({
type: z.string(),
default: z.unknown().optional(),
validation: z.optional(ValidationSchema)
});
export type TypeReferenceWithDefaultAndValidationSchema = z.infer<typeof TypeReferenceWithDefaultAndValidationSchema>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { z } from "zod";
import { TypeReferenceWithDocsSchema } from "./TypeReferenceSchema";
import { WithDocsSchema } from "./WithDocsSchema";

export const VariableDeclarationSchema = TypeReferenceWithDocsSchema;
export const VariableDeclarationSchema = z.union([
z.string(),
z
.strictObject({
type: z.string()
})
.extend(WithDocsSchema.shape)
]);

export type VariableDeclarationSchema = z.infer<typeof VariableDeclarationSchema>;
6 changes: 1 addition & 5 deletions packages/cli/fern-definition/schema/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ export { StatusCodeErrorDiscriminationSchema } from "./StatusCodeErrorDiscrimina
export { StringValidationSchema } from "./StringValidationSchema";
export { TransportSchema } from "./TransportSchema";
export { TypeDeclarationSchema } from "./TypeDeclarationSchema";
export {
TypeReferenceSchema,
TypeReferenceWithDocsSchema,
TypeReferenceWithDocsAndDisplayNameAndAvailabilitySchema
} from "./TypeReferenceSchema";
export { TypeReferenceSchema } from "./TypeReferenceSchema";
export { UndiscriminatedUnionSchema } from "./UndiscriminatedUnionSchema";
export { ValidationSchema } from "./ValidationSchema";
export { VariableDeclarationSchema } from "./VariableDeclarationSchema";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HttpPathParameterSchema } from "../schemas";
import { TypeReferenceWithDocsSchema } from "../schemas/TypeReferenceSchema";
import { TypeReferenceSchema } from "../schemas/TypeReferenceSchema";
import { VariableReferenceSchema } from "../schemas/VariableReferenceSchema";

export interface PathParameterDeclarationVisitor<R> {
nonVariable: (pathParameter: TypeReferenceWithDocsSchema) => R;
nonVariable: (pathParameter: TypeReferenceSchema) => R;
variable: (pathParameter: VariableReferenceSchema | string) => R;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function validatePropertyInRequest({
return validatePropertyInType({ path, typeResolver, file, resolvedType: resolvedBodyPropertyType, validate });
}

function getTypeFromTypeReference(typeReference: RawSchemas.TypeReferenceWithDocsSchema): string {
function getTypeFromTypeReference(typeReference: RawSchemas.TypeReferenceSchema): string {
if (typeof typeReference === "string") {
return typeReference;
}
Expand Down
Loading

0 comments on commit 807b43e

Please sign in to comment.