Skip to content
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

09 17 fourth commit #1681

Closed
wants to merge 4 commits into from
Closed
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
98 changes: 87 additions & 11 deletions packages/runtime/src/swagger/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,94 @@ export namespace Swagger {
description?: string;
}

export interface BaseParameter extends BaseSchema {
interface Item {
id: number;
name: string;
in: 'query' | 'header' | 'path' | 'formData' | 'body';
required?: boolean;
description?: string;
example?: unknown;
examples?: { [name: string]: Example3 | string };
schema: Schema;
type: DataType;
format?: DataFormat;
deprecated?: boolean;
}
quantity: number;
price: number;
}

class Inventory {
private items: Item[] = [];
private nextId: number = 1;

addItem(name: string, quantity: number, price: number): void {
const newItem: Item = {
id: this.nextId++,
name,
quantity,
price
};
this.items.push(newItem);
console.log(`Item added: ${JSON.stringify(newItem)}`);
}

updateItem(id: number, name?: string, quantity?: number, price?: number): void {
const item = this.items.find(item => item.id === id);
if (item) {
if (name !== undefined) item.name = name;
if (quantity !== undefined) item.quantity = quantity;
if (price !== undefined) item.price = price;
console.log(`Item updated: ${JSON.stringify(item)}`);
} else {
console.log(`Item with ID ${id} not found.`);
}
}

deleteItem(id: number): void {
const index = this.items.findIndex(item => item.id === id);
if (index !== -1) {
const deletedItem = this.items.splice(index, 1)[0];
console.log(`Item deleted: ${JSON.stringify(deletedItem)}`);
} else {
console.log(`Item with ID ${id} not found.`);
}
}

searchItem(name: string): Item[] {
const foundItems = this.items.filter(item => item.name.toLowerCase().includes(name.toLowerCase()));
console.log(`Items found: ${JSON.stringify(foundItems)}`);
return foundItems;
}

listItems(): void {
console.log('Inventory List:');
this.items.forEach(item => {
console.log(`ID: ${item.id}, Name: ${item.name}, Quantity: ${item.quantity}, Price: ${item.price}`);
});
}
}

// Example Usage
const inventory = new Inventory();

// Add items
inventory.addItem('Apple', 100, 1.0);
inventory.addItem('Banana', 150, 0.5);
inventory.addItem('Orange', 200, 0.8);

// List all items
inventory.listItems();
console.log('---');

// Update an item
inventory.updateItem(2, 'Banana', 180, 0.55);

// List all items
inventory.listItems();
console.log('---');

// Delete an item
inventory.deleteItem(3);

// List all items
inventory.listItems();
console.log('---');

// Search for items
inventory.searchItem('app');



export interface BodyParameter extends BaseParameter {
in: 'body';
Expand Down
2 changes: 1 addition & 1 deletion packages/tsoa/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OpenAPI-compliant REST APIs using TypeScript and Node

</div>

## Goal
## Goal (this is a test willy)

- TypeScript controllers and models as the single source of truth for your API
- A valid OpenAPI (formerly Swagger) spec (2.0 or 3.0 if you choose 😍) is generated from your controllers and models, including:
Expand Down