Skip to content
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

[nodejs] Route defined in OpenAPI specification but there is no defined onGET operation #10254

Closed
NathanHazout opened this issue May 17, 2020 · 11 comments · Fixed by swagger-api/swagger-codegen-generators#816
Assignees
Milestone

Comments

@NathanHazout
Copy link

Description

I'm using codegen to generate a simple nodejs server. The Swagger UI gets generated just fine.

However if I try to run any of the API, I get Route defined in OpenAPI specification (/issue/{issueId}) but there is no defined onGET operation.

I've tried both in the swagger ui itself (Try it out), or postman (http://localhost:8080/issue/123).

Swagger-codegen version

swagger-codegen 3.0.19

Swagger declaration file content or url

I've simplified my api as much as possible for demo purposes.

openapi: 3.0.0
info:
  title: issue
  version: 1.0.0
servers:
  - url: http://localhost:8080
paths:
  '/issue/{issueId}':
    parameters:
      - schema:
          type: string
        name: issueId
        in: path
        required: true
    get:
      summary: GET Issue
      tags:
        - issue
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
      operationId: get-issue
Command line used for generation

I've tried both using the homebrew version, and the docker version.

swagger-codegen generate \
  -i api/issue.v1.json \
  -l nodejs-server \
  -o server/ 
Steps to reproduce

In an empty clean directory:

nathanh@Nathans-MBP Dev % rm -Rf server 
nathanh@Nathans-MBP Dev % swagger-codegen generate -i path/to/api.yaml -l nodejs-server -o server/
18:57:19.495 [main] DEBUG io.swagger.codegen.v3.cli.SwaggerCodegen - there are not options for command 'langs'
18:57:19.497 [main] DEBUG io.swagger.codegen.v3.cli.SwaggerCodegen - there are not options for command 'version'
18:57:19.571 [Thread-1] DEBUG io.swagger.v3.parser.OpenAPIV3Parser - Loaded raw data: openapi: 3.0.0
info:
  title: issue
  version: 1.0.0
servers:
  - url: http://localhost:8080
paths:
  '/issue/{issueId}':
    parameters:
      - schema:
          type: string
        name: issueId
        in: path
        required: true
    get:
      summary: GET Issue
      tags:
        - issue
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
      operationId: get-issue



18:57:19.575 [Thread-1] DEBUG io.swagger.v3.parser.OpenAPIV3Parser - Parsed rootNode: {"openapi":"3.0.0","info":{"title":"issue","version":"1.0.0"},"servers":[{"url":"http://localhost:8080"}],"paths":{"/issue/{issueId}":{"parameters":[{"schema":{"type":"string"},"name":"issueId","in":"path","required":true}],"get":{"summary":"GET Issue","tags":["issue"],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}},"operationId":"get-issue"}}}}
18:57:19.609 [Thread-1] DEBUG io.swagger.codegen.v3.config.CodegenConfigurator - getClientOptInput - parsed inputSpecURL /Users/nathanh/Git/data-quality/DQF-core/dqf-issue/api/api.yaml
18:57:19.613 [Thread-1] WARN io.swagger.codegen.v3.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.swagger-codegen-ignore) will be evaluated.
18:57:19.681 [Thread-1] DEBUG io.swagger.codegen.v3.generators.DefaultCodegenConfig - Property type is not primitive: Object
18:57:19.724 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/service.mustache
18:57:19.765 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.793 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.798 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.816 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/service/IssueService.js
18:57:19.817 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/controller.mustache
18:57:19.817 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.824 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.824 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.826 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/controllers/Issue.js
18:57:19.876 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/writer.mustache
18:57:19.876 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.881 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.881 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.882 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/utils/writer.js
18:57:19.883 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/swagger.mustache
18:57:19.883 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.884 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.884 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.885 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/api/openapi.yaml
18:57:19.885 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/index.mustache
18:57:19.886 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.888 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.889 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.889 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/index.js
18:57:19.890 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/package.mustache
18:57:19.890 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.893 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.893 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.894 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/package.json
18:57:19.895 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - About to parse: /handlebars/nodejs/README.mustache
18:57:19.895 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Building AST
18:57:19.900 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Applying Mustache spec
18:57:19.900 [Thread-1] DEBUG com.github.jknack.handlebars.internal.HbsParserFactory - Creating templates
18:57:19.901 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/README.md
18:57:19.905 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/.swagger-codegen-ignore
18:57:19.906 [Thread-1] INFO io.swagger.codegen.v3.AbstractGenerator - writing file /Users/nathanh/Dev/server/.swagger-codegen/VERSION
nathanh@Nathans-MBP Dev % cd server 
nathanh@Nathans-MBP server % npm start

> issue@1.0.0 prestart /Users/nathanh/Dev/server
> npm install


> deasync@0.1.20 install /Users/nathanh/Dev/server/node_modules/deasync
> node ./build.js

`darwin-x64-node-12` exists; testing
Binary is fine; exiting
npm notice created a lockfile as package-lock.json. You should commit this file.
added 110 packages from 116 contributors and audited 110 packages in 4.364s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities


> issue@1.0.0 start /Users/nathanh/Dev/server
> node index.js

body-parser deprecated undefined extended: provide extended option node_modules/oas3-tools/dist/middleware/express.app.config.js:20:33
Your server is listening on port 8080 (http://localhost:8080)
Swagger-ui is available on http://localhost:8080/docs
  Mock mode: disabled
handlerId: 
Issue_getIssue
handlerCache[handlerId]: 
[Function: getIssue]
GET /docs/ 304 3.450 ms - -
GET /docs/swagger-ui.css 304 0.640 ms - -
GET /docs/swagger-ui-standalone-preset.js 304 0.641 ms - -
GET /docs/swagger-ui-bundle.js 304 0.291 ms - -
GET /docs/swagger-ui-bundle.js.map 404 3.319 ms - 93
GET /docs/swagger-ui.css.map 304 0.302 ms - -
GET /docs/swagger-ui-standalone-preset.js.map 304 0.283 ms - -
HEAD /docs/ 304 0.289 ms - -
GET /api-docs 200 0.192 ms - -
GET /api-docs 200 0.073 ms - -
GET /issue/543 500 3.085 ms - 112
Suggest a fix/enhancement

Is codegen development still active?

@NathanHazout
Copy link
Author

Ah!
I got it!

It didn't like my operationId: get-issue. Replacing it with operationId: getIssue worked.

Is this a bug?

@vullankib
Copy link

Faced the same issue.
Dash case should be changed to camel case in the generator.

@MishaBindra
Copy link

MishaBindra commented Nov 19, 2020

Hi , I am also encountering the above issue.To rule out issues on my end I tried using the demo OAS3 spec pasted above by @nasht00 . The operatioId does not have any "-" and I see the function with the same name in the controllers directory as the operationId.

`'use strict';

var utils = require('../utils/writer.js');
var Issue = require('../service/IssueService');

module.exports.getIssue = function getIssue (req, res, next, issueId) {
Issue.getIssue(issueId)
.then(function (response) {
utils.writeJson(res, response);
})
.catch(function (response) {
utils.writeJson(res, response);
});
};`
Is there anything else that could possibly causing this issue?
{
"message": "Route defined in OpenAPI specification (/issue/{issueId}) but there is no defined onGET operation."
}

Do you think possibly the node version or any other package version?

Although I did try to download to node 10 but still have the same issue.

@bhumikVa-kore
Copy link

@MishaBindra did you get any workaround with your issue

@MishaBindra
Copy link

@bhumikVa-kore , actually the issue in my case seemed to be the package versions . I updated the package.json file to use exact versions and then it worked.I am pasting the dependencies below for which I am using the exact version:

"dependencies": {
"connect": "3.2.0",
"js-yaml": "3.3.0",
"oas3-tools": "2.0.2"
}

@bhumikVa-kore
Copy link

@MishaBindra how to determine which package version to use

@chainhead
Copy link

@MishaBindra I was able to resolve this issue using the exact versions you mention. Thanks!

@bhumikVa-kore suggest, you try setting the versions as pasted in @MishaBindra post above.

@jschaufele
Copy link

I used the petstore sample ootb and then exported and have not been able to resolve this issue - being my very experience w swagger this is disappointing - i would think their samples would work

@HugoMario HugoMario self-assigned this Nov 29, 2020
@salmarvasti2020
Copy link

is this problem resolved? I cant seem make it work even with the 3.2.0 version

@HugoMario HugoMario added this to the M11 milestone Dec 4, 2020
@HugoMario
Copy link
Contributor

hey guys, i know it's been a while.

I've been stucked in other issues, anyway. i took a time to check this and the problem is the name used for operationId

operationId: get-issue

@nasht00
I suggest avoid using this dash character in operation id meantime i add a solution. By the way, the solution needsa to be applied on https://github.com/bug-hunters/oas3-tools repo instead here.

@tjoudeh
Copy link

tjoudeh commented May 19, 2022

In my case, the operation id was named this "UnfreezeDoc", so I had to change it to "unfreezeDoc". It should be a camel case.

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 a pull request may close this issue.

9 participants