Skip to content

Development: Improve openapi generated code #5

Open
az108 wants to merge 5 commits intomainfrom
chore/backport-tum-apply-fixes
Open

Development: Improve openapi generated code #5
az108 wants to merge 5 commits intomainfrom
chore/backport-tum-apply-fixes

Conversation

@az108
Copy link
Copy Markdown
Collaborator

@az108 az108 commented Apr 6, 2026

Summary

Closes #4

Changes

  1. Path template generation — Use original OpenAPI paths instead of regex-parsing encodeParam (broke with openapi-generator 7.18.0+)
  2. GET methods in service classes — Services always include all HTTP methods as Observables, regardless of httpResource config
  3. Model-to-model imports — Added ./ relative path prefix
  4. API-to-model imports — Use tsImports with correct kebab-case model filenames
  5. Array-of-enum types — Wrap in Array<> when property is an array
  6. Void return types — Explicit <void> type parameter on HttpClient calls
  7. Duplicate HttpHeaders import — Static import instead of per-operation conditional
  8. Const enum objects — Runtime const objects for enum types (TypeScript type/value pattern)
  9. Blob response handlingresponseType: 'blob' + observe: 'response' for file downloads
  10. Array query paramsURLSearchParams.append() instead of join(',') for correct wire format
  11. Inline model filenames — Underscore-to-hyphen conversion in toKebabCase()
  12. Model output foldermodel/ instead of models/
  13. Configurable GET API stylegenerator-config.yaml with documented options for all CLI properties
  14. Inline resource supportuseHttpResource=true + separateResources=false renders httpResource GET functions inline in *-api.ts alongside Observable class methods (one file per tag)
  15. Required query params fix — httpResource functions with required query params now use non-optional params: Signal<T> instead of params?: Signal<T> with ?? {} fallback that lost type info

Architecture

Observable service classes are always generated with all HTTP methods. httpResource functions are generated alongside (not instead of) Observable methods when useHttpResource=true. This means:

  • Existing consumer code using .subscribe() / firstValueFrom() never breaks
  • New code can opt into signal-based httpResource functions for reactive patterns
  • No config change will ever remove methods from the service class

Configuration matrix

useHttpResource separateResources Result
false false One file: Observable class only
true false One file: Observable class + inline httpResource functions
true true Two files: Observable class (*-api.ts) + httpResource functions (*-resources.ts)
false true Same as false/false (no resource files to generate)

Files changed

File Changes
Angular21Generator.java Fixes 1, 2, 4, 8, 11, 12, 13, 14, 15 + comprehensive JavaDoc
api-service.mustache Fixes 2, 4, 6, 7, 9, 10, 13, 14
api-resource.mustache Fix 4, 15
model.mustache Fixes 3, 5, 8
generator-config.yaml Fix 13, 14 (new file)

Test plan

  • Build the generator: ./gradlew build
  • Run against a sample OpenAPI spec and verify generated output compiles
  • Verify model imports use ./ relative paths
  • Verify API imports reference ../model/ with correct filenames
  • Verify enum types generate both union types and const objects
  • Verify blob endpoints use responseType: 'blob'
  • Verify with useHttpResource=true, separateResources=true: Observable class in *-api.ts has all methods, *-resources.ts has httpResource GETs
  • Verify with useHttpResource=true, separateResources=false: Single file with Observable class + inline httpResource functions
  • Verify with useHttpResource=false: Observable class only, no httpResource functions
  • Verify GET-only tags still generate a service class (not skipped)
  • Verify httpResource functions with required query params use non-optional params: Signal<T>

🤖 Generated with Claude Code

az108 and others added 2 commits April 6, 2026 13:44
Brings the standalone generator in sync with the battle-tested version
from ls1intum/tum-apply. Key fixes:

1. Path template generation: use original OpenAPI paths instead of
   regex-parsing the parent's encodeParam format
2. Include GET methods in API service classes alongside mutations
3. Model-to-model imports: add ./ relative path prefix
4. API-to-model imports: use tsImports with correct model filenames
5. Array-of-enum types: wrap in Array<> when property is an array
6. Void return types: add explicit <void> type parameter to HttpClient
7. Duplicate HttpHeaders import: use static import instead of per-op
8. Const enum objects: generate runtime const objects for enum types
9. Blob response handling: use responseType/observe for file downloads
10. Array query params: use URLSearchParams.append() instead of join
11. Inline model filenames: convert underscores to hyphens in toKebabCase
12. Model output folder: use 'model/' instead of 'models/'

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace <h3> with <p><b> in class-level javadoc to satisfy strict
heading sequence checks, and add missing javadoc comments to all
public/protected fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@az108 az108 changed the title Backport all generator fixes from tum-apply Development: Improve openapi generated code Apr 6, 2026
When useHttpResource=true, GET operations are excluded from service
files and only appear in resource files. GET-only tags skip service
file generation entirely. Add generator-config.yaml with documented
options for all CLI properties.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@az108 az108 self-assigned this Apr 12, 2026
az108 and others added 2 commits April 12, 2026 15:39
- Fix bug where useHttpResource=true skipped *-api.ts for GET-only tags
  even when separateResources=false, causing GET clients to vanish
- Add x-inline-resource vendor extension for rendering httpResource
  functions inline in *-api.ts when separateResources=false
- Add hasServiceClass/hasInlineResources flags for conditional template
  rendering (no empty classes for GET-only tags)
- Update config comments to document all useHttpResource/separateResources
  combinations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Service class now always includes GET methods as Observables,
  regardless of useHttpResource/separateResources config
- httpResource functions are generated alongside (not instead of)
  Observable methods — existing consumer code never breaks
- Fix required query params typed as {} in httpResource functions
- Remove api file suppression for GET-only tags

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Backport generator fixes from tum-apply

1 participant