Skip to content
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
6 changes: 6 additions & 0 deletions packages/create_freestyle_fetch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# create-freestyle-fetch

## 1.2.1

### Patch Changes

- Handle strictNullChecks option correctly for model generation, handles nullable unions.

## 1.2.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create_freestyle_fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-freestyle-fetch",
"version": "1.2.0",
"version": "1.2.1",
"description": "Generate freestylejs fetch client from OpenAPI spec",
"author": "danpacho",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,65 @@
import { z } from 'zod';

export const Product = z.object({
// Helper types for schemas

export type ProductModel = {
'id': string;
'name': string;
'productType': string;
'price': number;
};

export type ElectronicsProductModel = ProductModel & {
'specs'?: {
[key: string]: string;
} | undefined;
};

export type ClothingProductModel = ProductModel & {
'size'?: 'S' | 'M' | 'L' | 'XL' | undefined;
'color'?: string | undefined;
};

export type OrderModel = {
'id'?: string | undefined;
'userId'?: string | undefined;
'products'?: ProductModel[] | undefined;
'total'?: number | undefined;
'status'?: 'pending' | 'shipped' | 'delivered' | undefined;
};

export type ErrorModel = {
'code'?: number | undefined;
'message'?: string | undefined;
};



export const Product: z.ZodType<ProductModel> = z.object({
'id': z.uuid(),
'name': z.string(),
'productType': z.string(),
'price': z.number().min(0)
});

export type ProductModel = z.infer<typeof Product>;

export const ElectronicsProduct = Product.and(z.object({
export const ElectronicsProduct: z.ZodType<ElectronicsProductModel> = Product.and(z.object({
'specs': z.record(z.string(), z.string()).optional()
}));

export type ElectronicsProductModel = z.infer<typeof ElectronicsProduct>;

export const ClothingProduct = Product.and(z.object({
export const ClothingProduct: z.ZodType<ClothingProductModel> = Product.and(z.object({
'size': z.enum(['S', 'M', 'L', 'XL']).optional(),
'color': z.string().optional()
}));

export type ClothingProductModel = z.infer<typeof ClothingProduct>;

export const Order = z.object({
export const Order: z.ZodType<OrderModel> = z.object({
'id': z.uuid().optional(),
'userId': z.string().optional(),
'products': z.array(Product).optional(),
'total': z.number().optional(),
'status': z.enum(['pending', 'shipped', 'delivered']).optional()
});

export type OrderModel = z.infer<typeof Order>;

export const Error = z.object({
export const Error: z.ZodType<ErrorModel> = z.object({
'code': z.number().int().optional(),
'message': z.string().optional()
});

export type ErrorModel = z.infer<typeof Error>;
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,73 @@
import { z } from 'zod';

export const User = z.object({
// Helper types for schemas

export type UserModel = {
'id': string;
'username': string;
'email': string;
'profile'?: {
'fullName'?: string | undefined;
'joinDate'?: string | undefined;
} | undefined;
'legacyId'?: number | undefined;
};

export type ProductInputModel = {
'name': string;
'description'?: string | undefined;
'price': number;
};

export type ProductModel = ProductInputModel & {
'id'?: string | undefined;
'imageUrl'?: string | undefined;
'stock'?: number | undefined;
};

export type PaginatedResponseModel = {
'page'?: number | undefined;
'pageSize'?: number | undefined;
'total'?: number | undefined;
'items'?: any[] | undefined;
};

export type PaginatedProductResponseModel = PaginatedResponseModel;

export type CreditCardModel = {
'methodType': 'card';
'cardNumber': string;
'expiry'?: string | undefined;
'cvv'?: string | undefined;
};

export type PayPalModel = {
'methodType': 'paypal_account';
'email': string;
};

export type PaymentMethodModel = CreditCardModel | PayPalModel;

export type CallbackPayloadModel = {
'orderId'?: string | undefined;
'status'?: 'PROCESSED' | 'FAILED' | undefined;
'detail'?: string | undefined;
};

export type InventoryUpdatePayloadModel = {
'productId'?: string | undefined;
'newStockLevel'?: number | undefined;
'timestamp'?: string | undefined;
};

export type ApiErrorModel = {
'errorCode'?: string | undefined;
'message'?: string | undefined;
};



export const User: z.ZodType<UserModel> = z.object({
'id': z.uuid(),
'username': z.string().regex(/^[a-zA-Z0-9_-]{3,16}$/),
'email': z.email(),
Expand All @@ -11,76 +78,54 @@ export const User = z.object({
'legacyId': z.number().int().optional()
});

export type UserModel = z.infer<typeof User>;

export const ProductInput = z.object({
export const ProductInput: z.ZodType<ProductInputModel> = z.object({
'name': z.string(),
'description': z.string().optional(),
'price': z.number().min(0)
});

export type ProductInputModel = z.infer<typeof ProductInput>;

export const Product = ProductInput.and(z.object({
export const Product: z.ZodType<ProductModel> = ProductInput.and(z.object({
'id': z.uuid().optional(),
'imageUrl': z.url().optional(),
'stock': z.number().int().optional()
}));

export type ProductModel = z.infer<typeof Product>;

export const PaginatedResponse = z.object({
export const PaginatedResponse: z.ZodType<PaginatedResponseModel> = z.object({
'page': z.number().int().optional(),
'pageSize': z.number().int().optional(),
'total': z.number().int().optional(),
'items': z.array(z.any()).optional()
});

export type PaginatedResponseModel = z.infer<typeof PaginatedResponse>;
export const PaginatedProductResponse: z.ZodType<PaginatedProductResponseModel> = PaginatedResponse;

export const PaginatedProductResponse = PaginatedResponse;

export type PaginatedProductResponseModel = z.infer<typeof PaginatedProductResponse>;

export const CreditCard = z.object({
export const CreditCard: z.ZodType<CreditCardModel> = z.object({
'methodType': z.enum(['card']),
'cardNumber': z.string(),
'expiry': z.string().optional(),
'cvv': z.string().optional()
});

export type CreditCardModel = z.infer<typeof CreditCard>;

export const PayPal = z.object({
export const PayPal: z.ZodType<PayPalModel> = z.object({
'methodType': z.enum(['paypal_account']),
'email': z.email()
});

export type PayPalModel = z.infer<typeof PayPal>;
export const PaymentMethod: z.ZodType<PaymentMethodModel> = z.discriminatedUnion('methodType', [CreditCard, PayPal]);

export const PaymentMethod = z.discriminatedUnion('methodType', [CreditCard, PayPal]);

export type PaymentMethodModel = z.infer<typeof PaymentMethod>;

export const CallbackPayload = z.object({
export const CallbackPayload: z.ZodType<CallbackPayloadModel> = z.object({
'orderId': z.uuid().optional(),
'status': z.enum(['PROCESSED', 'FAILED']).optional(),
'detail': z.string().optional()
});

export type CallbackPayloadModel = z.infer<typeof CallbackPayload>;

export const InventoryUpdatePayload = z.object({
export const InventoryUpdatePayload: z.ZodType<InventoryUpdatePayloadModel> = z.object({
'productId': z.uuid().optional(),
'newStockLevel': z.number().int().optional(),
'timestamp': z.iso.datetime().optional()
});

export type InventoryUpdatePayloadModel = z.infer<typeof InventoryUpdatePayload>;

export const ApiError = z.object({
export const ApiError: z.ZodType<ApiErrorModel> = z.object({
'errorCode': z.string().optional(),
'message': z.string().optional()
});

export type ApiErrorModel = z.infer<typeof ApiError>;
});
Original file line number Diff line number Diff line change
@@ -1,44 +1,67 @@
import { z } from 'zod';

export const HellObject = z.object({
// Helper types for schemas

export type HellObjectModel = {
'required-key': string;
'optional-key'?: string | undefined;
'spaced key': number;
'$special$'?: boolean | undefined;
};

export type DeepNestedModel = {
'level1'?: {
'level2'?: Array<{
'level3'?: 'deep' | undefined;
}> | undefined;
} | undefined;
};

export type IntersectionHellModel = HellObjectModel & {
'extra'?: string | undefined;
};

export type OptionAModel = {
'type': 'A';
'a'?: string | undefined;
};

export type OptionBModel = {
'type': 'B';
'b'?: number | undefined;
};

export type UnionHellModel = OptionAModel | OptionBModel;



export const HellObject: z.ZodType<HellObjectModel> = z.object({
'required-key': z.string(),
'optional-key': z.string().optional(),
'spaced key': z.number(),
'$special$': z.boolean().optional()
});

export type HellObjectModel = z.infer<typeof HellObject>;

export const DeepNested = z.object({
export const DeepNested: z.ZodType<DeepNestedModel> = z.object({
'level1': z.object({
'level2': z.array(z.object({
'level3': z.enum(['deep']).optional()
})).optional()
}).optional()
});

export type DeepNestedModel = z.infer<typeof DeepNested>;

export const IntersectionHell = HellObject.and(z.object({
export const IntersectionHell: z.ZodType<IntersectionHellModel> = HellObject.and(z.object({
'extra': z.string().optional()
}));

export type IntersectionHellModel = z.infer<typeof IntersectionHell>;

export const OptionA = z.object({
export const OptionA: z.ZodType<OptionAModel> = z.object({
'type': z.enum(['A']),
'a': z.string().optional()
});

export type OptionAModel = z.infer<typeof OptionA>;

export const OptionB = z.object({
export const OptionB: z.ZodType<OptionBModel> = z.object({
'type': z.enum(['B']),
'b': z.number().optional()
});

export type OptionBModel = z.infer<typeof OptionB>;

export const UnionHell = z.discriminatedUnion('type', [OptionA, OptionB]);

export type UnionHellModel = z.infer<typeof UnionHell>;
export const UnionHell: z.ZodType<UnionHellModel> = z.discriminatedUnion('type', [OptionA, OptionB]);
Loading
Loading