Skip to content

Add TypeScript model generation for Pet Shop API #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pditommaso
Copy link
Contributor

@pditommaso pditommaso commented Aug 5, 2025

Summary

  • Add TypeScript model generation using OpenAPI Generator
  • Mirror Java model generation pattern: logic in app subproject, output in api directory
  • Generate type-safe TypeScript interfaces for all API models

Changes

  • Build Configuration: Add OpenAPI Generator plugin to app/build.gradle
  • Generation Task: Create generateTypeScriptModels task that depends on OpenAPI spec generation
  • Output Location: TypeScript models generated in api/typescript/ directory
  • Convenience Import: Create index.ts for easy model imports

Generated Models

  • Pet - Complete pet model with validation and date handling
  • CreatePetRequest/Response - Pet creation interfaces
  • UpdatePetRequest/Response - Pet update interfaces
  • GetPetResponse - Single pet retrieval
  • ListPetsResponse - Multiple pets response
  • ErrorResponse - Error handling model
  • ServiceInfo/Response - Service metadata models

Usage

import { Pet, CreatePetRequest, ErrorResponse } from 'api/typescript';

const newPet: CreatePetRequest = {
  name: 'Buddy',
  species: 'dog', 
  age: 3,
  breed: 'Golden Retriever' // optional
};

Generation Command

./gradlew :app:generateTypeScriptModels

- Add OpenAPI Generator plugin to app/build.gradle
- Configure TypeScript model generation task in app subproject
- Generate TypeScript models in api/typescript/ directory
- Create index.ts for convenient model imports
- Mirror Java model generation pattern: logic in app, output in api
- Support all API models: Pet, requests/responses, error handling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@pditommaso
Copy link
Contributor Author

Tagging @alvaromartmart for visibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant