Ryan-Sin / swagger-nestjs-codegen

MIT License
20 stars 4 forks source link

Error: OperationId in undefined #2

Open d9k opened 1 year ago

d9k commented 1 year ago
> codegen -s openapi.yaml -p my-service
? Do you want to create a database module? not
? Do you want to create a kafka module? not
? Do you want to create a project? Yes
(node:1030607) UnhandledPromiseRejectionWarning: Error: /courses => OperationId in undefined
    at /home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/lib/codegen.js:201:15
    at /home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:3032:24)
    at /home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:4936:18
    at Function.forEach (/home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:9410:14)
    at /home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/lib/codegen.js:181:7
    at /home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lod
ash.js:3032:24)
    at /home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:4936:18
    at Function.forEach (/home/d9k/.nvm/versions/node/v14.16.1/lib/node_modules/@newko/swagger-nestjs-codegen/node_modules/lodash/lodash.js:9410:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1030607) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1030607) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
d9k commented 1 year ago

exceprts from openapi.yaml:

# . . . . .
paths:
  /courses:
    post:
      tags:
      - Courses
      summary: create course
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/courses_body'
      responses:
        "201":
          description: created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/course_serialized_item'
        "422":
          description: unprocessable_entity

# . . . . .

components:
  schemas:
# . . . . .
    course_serialized_item:
      type: object
      properties:
        id:
          type: integer
        status:
          type: string
        created_at:
          type: string
          format: date-time
          nullable: true
        updated_at:
          type: string
          format: date-time
          nullable: true
        context_id:
          type: integer
        source_file_id:
          type: string
          nullable: true
        start_resource_id:
          type: integer
          nullable: true
    courses_body:
      required:
      - context_id
      - source_file_id
      type: object
      properties:
        source_file_id:
          type: string
          description: GUID from FilesSerivce
        context_id:
          type: integer
d9k commented 1 year ago

https://swagger.io/docs/specification/paths-and-operations/

operationId is an optional unique string used to identify an operation.

It seems you break swagger standart because you require an operationId.

d9k commented 1 year ago

Under responses, each response definition starts with a status code, such as 200 or 404. An operation typically returns one successful status code and one or more error statuses.

I believe the swagger documentation doesn't say that you must provide HTTP 200 code response;

https://swagger.io/docs/specification/describing-responses/

Ryan-Sin commented 1 year ago

Yes, I need the operationId as you said.

Ryan-Sin commented 1 year ago

I also think that only 200 codes of HTTP response code do not exist.

d9k commented 1 year ago

Thanks for your project, honored @Ryan-Sin! The swagger-nestjs-codegen code is pretty well-written, that was easy to alter it in most cases.