swagger-api / swagger-api/swagger-codegen
[Nodejs-server] Bug generating server - reference to service files
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When a nodejs-server code is generated, the generated code has incorrect reference to dependencies. Once the reference is corrected, the code works as is. (So should be an easy fix)
Swagger-codegen version
swagger-codegen-cli-2.3.1.jar
Swagger declaration file content or url
Note: This can be any working swagger 2.0 file. This is just an example
swagger: '2.0'
info:
title: User API
version: '1.0'
description: Manage users
host: 'localhost:8080'
paths:
/users:
get:
summary: List User
operationId: findUsers
responses:
'200':
description: ''
schema:
type: array
items:
$ref: '#/definitions/user-output'
tags:
- user
basePath: /v1
schemes:
- http
- https
consumes:
- application/json
produces:
- application/json
definitions:
user-common:
title: User Common
description: The properties that are shared amongst all versions of the User model.
type: object
properties:
name:
type: string
description: Name of the user
email:
type: string
description: email address
type:
type: string
enum:
- primary
- secondary
description: Whether Primary or Secondary user type
required:
- name
- email
- type
user-output:
title: User Output
description: The properties that are included when fetching a list of Users.
allOf:
- type: object
properties:
created:
type: string
format: date-time
id:
type: integer
required:
- created
- id
- $ref: '#/definitions/user-common'
tags:
- name: user
description: User related APIs
Command line used for generation
java -jar C:\swagger-codegen-cli-2.3.1.jar generate -l nodejs-server -o .\src -i .\specs\api.oas2.yaml
Steps to reproduce
- Generate nodejs-server code using the command above and any properly created yaml
- Go to
/srcand runnpm start - Npm install will fail as version in
package.jsonfile is unsupported <== Lower priority issue - Update the version in
package.jsonfile to 1.0.0 instead of 1.0 - Run
npm startagain. This time npm install will work, but the code will fail with the following error message:
Error: Cannot find module '../service/UserService' - To fix the issue, go to
controllers/User.jsand modify the import reference for UserService.js to the right file ('./UserService')
Related issues/PRs
Suggest a fix/enhancement
Fix the reference or create a new '/service' folder and move appropriate files into that folder while code generation.
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
Generate the nodejs-server output from the example command, then inspect src/controllers/User.js and the generated service file to confirm the incorrect reference. Search the generator templates for the corresponding UserService import and verify that npm start succeeds after the package.json version adjustment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100