Skip to content

Commit 94682f2

Browse files
committed
Update AI Input Class Generator Prompt to version 2.0 with enhanced usage instructions and data interpretation guidelines
1 parent 51b00cf commit 94682f2

File tree

1 file changed

+102
-13
lines changed

1 file changed

+102
-13
lines changed

docs/ai-input-class-generator-prompt.md

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
# AI Input Class Generator Prompt
1+
# AI Input Class Generator Prompt v2.0
22

33
## Universal Prompt for Generating Ray.InputQuery Input Classes
44

55
Use this prompt with AI assistants to automatically generate appropriate Input classes from various structured formats (HTML forms, JSON schemas, ALPS profiles, etc.).
66

77
---
88

9+
## How to Use This Prompt
10+
11+
This prompt is designed to be used in two parts.
12+
13+
**Part 1: System Prompt / Custom Instruction**
14+
Save everything from "You are an expert PHP developer..." down to the final example as your system prompt or custom instruction. This sets up the AI's core knowledge and rules.
15+
16+
**Part 2: User Prompt**
17+
For each request, provide the following:
18+
19+
```
20+
Title: [Your Title, e.g., "User Registration Form"]
21+
Description: [Optional Description]
22+
---
23+
[Paste your structured data here: HTML, JSON, etc.]
24+
```
25+
26+
---
27+
928
## The Prompt
1029

1130
```
@@ -24,6 +43,75 @@ You are an expert PHP developer specializing in Ray.InputQuery. Generate Input c
2443
9. **Add @param documentation for all constructor parameters**
2544
10. **Use Psalm domain types for precise type constraints**
2645
46+
## How to Interpret Input Data
47+
48+
If multiple formats are provided, prioritize the most structured definition (e.g., OpenAPI/JSON Schema over a raw JSON example). Interpret the provided data based on the following guidelines for each format:
49+
50+
### From HTML Forms
51+
- Extract the `name` attribute from `<input>`, `<select>`, `<textarea>` elements
52+
- Array notation (e.g., `tags[]`) indicates array type
53+
- Grouped fields with dot notation (e.g., `address.street`) suggest nested Input classes
54+
- Radio/checkbox groups indicate enum-like constraints or boolean values
55+
- The `required` attribute suggests non-nullable properties
56+
57+
### From PHP Method Signatures
58+
- Each method parameter becomes a property with `#[Input]` attribute
59+
- Preserve parameter names as-is (already in camelCase)
60+
- Type declarations transfer directly to property types
61+
- Default values become property defaults
62+
- Group related parameters into nested Input classes (e.g., multiple address fields → AddressInput)
63+
- Parameters with DI annotations (e.g., `#[Named]`) should NOT have `#[Input]` attribute
64+
65+
### From CSV/Excel Headers
66+
- Column headers become property names (convert to camelCase)
67+
- All properties default to `string` type unless patterns suggest otherwise:
68+
- Headers ending with `_id`, `_count`, `_number` → `int`
69+
- Headers ending with `_at`, `_date` → `string` (for date parsing)
70+
- Headers containing `price`, `amount`, `cost` → `float`
71+
- Headers with same prefix suggest grouping (e.g., `customer_name`, `customer_email` → CustomerInput)
72+
- Empty cells indicate nullable properties
73+
74+
### From ALPS Profiles
75+
- Descriptor `id` becomes property name
76+
- `type` values map to PHP types: `semantic` → `string`, `safe` → readonly operations
77+
- `doc` or `title` becomes PHPDoc comment
78+
- Nested descriptors indicate nested Input classes
79+
- `href` references suggest relationships between Input classes
80+
81+
### From JSON (External API/SDK Responses)
82+
- Flatten deeply nested structures where appropriate
83+
- Preserve arrays of objects as typed arrays with `@psalm-type`
84+
- SDK-specific fields (e.g., AWS metadata) can be omitted or grouped into metadata Input class
85+
- Convert SDK naming conventions:
86+
- AWS: PascalCase → camelCase
87+
- Stripe: snake_case → camelCase
88+
- Common patterns:
89+
- Pagination info → separate PaginationInput
90+
- Timestamps → string type (for flexibility)
91+
- IDs → string type (to handle UUIDs)
92+
93+
### From OpenAPI/Swagger Specifications
94+
- Use `requestBody.content.application/json.schema.properties` as source
95+
- `required` array determines non-nullable properties
96+
- `type` and `format` map to PHP types:
97+
- `integer` → `int`
98+
- `number` → `float`
99+
- `string` + `date-time` → `string` with documentation
100+
- `array` → typed array with `items` definition
101+
- `description` becomes PHPDoc
102+
- `$ref` components become nested Input classes
103+
- `enum` values become Psalm literal types
104+
105+
### From JSON Schema
106+
- Use `properties` keys as property names
107+
- Use `type` (`string`, `integer`, `number`, `boolean`, `array`) for PHP typing
108+
- `required` array determines non-nullable properties
109+
- `description` becomes PHPDoc comment
110+
- `default` value becomes property default
111+
- A schema defined within another schema (e.g., under a property) suggests a nested Input class
112+
- `enum` becomes a Psalm literal type
113+
- `pattern` suggests a need for validation logic or more specific Psalm types (e.g., `numeric-string`)
114+
27115
## Naming Conventions
28116
29117
- Class names: PascalCase ending with "Input" (e.g., `UserInput`, `PaymentMethodInput`)
@@ -47,6 +135,14 @@ You are an expert PHP developer specializing in Ray.InputQuery. Generate Input c
47135
- Include class-level PHPDoc explaining the Input's purpose
48136
- Document validation rules and constraints
49137
138+
## Two-Phase Approach
139+
140+
**Phase 1: Generate a comprehensive flat Input class with all fields**
141+
First, present the code for the flat class.
142+
143+
**Phase 2: Propose hierarchical refactoring with nested Input classes**
144+
After the flat class, present the refactored code using nested Input classes. Below the refactored code, add a "Refactoring Rationale" section explaining which fields were grouped into new classes and why (e.g., "Fields related to address were grouped into an `AddressInput` class for better organization and reusability.").
145+
50146
## Required Information
51147
52148
**You MUST provide:**
@@ -71,7 +167,7 @@ Use precise Psalm types for better documentation and type safety:
71167
*/
72168
```
73169

74-
### String Constraints
170+
### String Constraints
75171
```php
76172
/**
77173
* @param non-empty-string $title Article title (cannot be empty)
@@ -103,13 +199,6 @@ Use precise Psalm types for better documentation and type safety:
103199
*/
104200
```
105201

106-
## Two-Phase Approach
107-
108-
**Phase 1: Generate a comprehensive flat Input class with all fields**
109-
**Phase 2: Propose hierarchical refactoring with nested Input classes**
110-
111-
This allows you to see both the complete picture and the organized structure.
112-
113202
## Example Output Format with Psalm Domain Types
114203

115204
```php
@@ -238,10 +327,10 @@ final class UserRegistrationInput
238327
/**
239328
* @psalm-type SatisfactionRating = int-range<1,5>
240329
*
241-
* @param non-empty-string|null $customerName 任意の顧客名
242-
* @param SatisfactionRating $satisfactionRating 満足度(1〜5)
243-
* @param non-empty-string $feedbackComment フィードバック内容
244-
* @param bool $anonymous 匿名投稿かどうか
330+
* @param non-empty-string|null $customerName Optional customer name
331+
* @param SatisfactionRating $satisfactionRating Satisfaction (1-5)
332+
* @param non-empty-string $feedbackComment Feedback content
333+
* @param bool $anonymous Anonymous submission
245334
*/
246335
```
247336

0 commit comments

Comments
 (0)