swagger-api / swagger-api/swagger-codegen
[typescript-angular2] Suggestions for refactoring (baseUrl, url service, npm module)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I want to suggest a couple of change in the architecture distribution of the code generated by the typescript-angular2 version of the CLI. I know most of the changes I'm about to suggest are aesthetics, and you may find them useless in a code generator tool, but still.
Modulize generated code
In Angular way, and in npm way. This means the code generated should be able to be integrated as a regular Angular module, and be published in a repository to be manageable as a npm module, even if someone use npm private modules, can use this as well. This approach would generate more code, but their benefits should support the effort.
I think it's important to notice that the code generated by this tool it's not part of the client, but a piece of the server, and though, it should be updated only when the Swagger spec in the server gets updated.
The code that the Codegen should generate includes, but by any means I don't it limits to, package.json, tsconfig.json, .npmignore and Angular module file. The package.json should include a postinstall script preconfigured to compile all the ts code to regular, nodeable js, and a Typescript Definition file. The last, should also be added in the package.json. All the dependencies that are needed to build a regular Angular project should be added in the peerDependencies.
The definition file should export only the classes that will be consumed by public, and left inside all other Codegen generated code that are use inside those generated files.
The Angular module should only export the services that would be consumed. This is related to the previous point, but it's the way that Angular manages services.
Use index.ts in folders.
It's purely aesthetic, but I think it's better to request from index.ts than from a file name that's not even same casing than the others files.
Use a service for request the URL of the API.
I think this tool should generate a single file containing the URL of the API that the module would consume. This approach would allow to configure the URL of the API in the module importing. (The way that the module would be imported it's related to the last part of the first point).
basePath in api models should be readonly.
If there is a single service managing all the configuration of the URL, the api models should consume it and initialize a readonly basePath property, with the common URL of that API already prefixed.
Swagger-codegen version
v 2.2.1
Related issues
I think this has related issues, I'm trying to search them all. If you find any, pin me there, and I'll add it here. 👍
Suggest a Fix
I can and am willing to help this, if you find all those changes be reasonable. I know Java, Typescript and Angular (2 and up).
Thanks you.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test path is identified; begin by locating the typescript-angular2 generator templates or entry points that produce package.json, tsconfig.json, .npmignore, index.ts, the Angular module, and API models. Done would require an agreed scope and generated-output tests covering the selected packaging, URL configuration, and readonly basePath changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, node.js, typescript
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100