Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6979
Something went wrong while setting issue due date.
Closed
Open
Issue created 5 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

nodejs-express-server - Auto-populate URL_PORT, URL_PATH, BASE_VERSION from schema servers url

Closed

nodejs-express-server - Auto-populate URL_PORT, URL_PATH, BASE_VERSION from schema servers url

Created by: kmturley

Is your feature request related to a problem? Please describe.

Under the v3.0 spec, you can configure the server url, port and base API path, as shown here

openapi: 3.0.0
info:
  title: Sample title
  description: Sample description
  version: 0.1.9
servers:
  - url: http://0.0.0.0:5000/v3
    description: Local server

https://swagger.io/docs/specification/basic-structure/

However when generated using nodejs-express-server the settings are not used. They seem to be hardcoded:

const config = {
  ROOT_DIR: __dirname,
  URL_PORT: 3000,
  URL_PATH: 'http://localhost',
  BASE_VERSION: 'v2',
  CONTROLLER_DIRECTORY: path.join(__dirname, 'controllers'),
  PROJECT_DIR: __dirname,
};

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/nodejs-express-server/config.mustache#L5

However in other generators the settings are dynamic: http://localhost:{{serverPort}}{{contextPath}}/ui/ https://github.com/OpenAPITools/openapi-generator/search?l=HTML%2BDjango&p=2&q=serverPort

Describe the solution you'd like

Config to be generated using the yaml services url: http://0.0.0.0:5000/v3

const config = {
  ROOT_DIR: __dirname,
  URL_PORT: 5000,
  URL_PATH: 'http://0.0.0.0',
  BASE_VERSION: 'v3',
  CONTROLLER_DIRECTORY: path.join(__dirname, 'controllers'),
  PROJECT_DIR: __dirname,
};

It seems this can be achieve by modifying ./src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java

if (additionalProperties.containsKey(SERVER_HOST)) {
    host = additionalProperties.get(SERVER_HOST).toString();
}
this.additionalProperties.put(SERVER_HOST, host);

if (additionalProperties.containsKey(SERVER_PORT)) {
    port = additionalProperties.get(SERVER_PORT).toString();
}
this.additionalProperties.put(SERVER_PORT, port);

and also ./src/main/resources/nodejs-express-server/config.mustache

const config = {
  ROOT_DIR: __dirname,
  URL_PORT: {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}1234{{/serverPort}},
  URL_PATH: '{{#serverHost}}{{serverHost}}{{/serverHost}}{{^serverHost}}http://localhost{{/serverHost}}',
  BASE_VERSION: '{{#contextPath}}{{contextPath}}{{/contextPath}}{{^contextPath}}v2{{/contextPath}}',
  CONTROLLER_DIRECTORY: path.join(__dirname, 'controllers'),
  PROJECT_DIR: __dirname,
};

Describe alternatives you've considered

  1. Manually making the change after the template has been generated
  2. Using bash to update the string after the template has been created

These aren't ideal as every time the API spec changes we may want to regenerate the service, and have to repeat these steps manually. Also if we are generating multiple services they all have the same url/port settings...

An error occurred while loading designs. Please try again.
Tasks
0
server returned results with length 1, expected length of 9

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
No estimate or time spent
Confidentiality
Not confidential
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
0
0 participants
Reference:

Menu

Explore Projects Groups Snippets