swagger-api / swagger-api/swagger-codegen

[Node.js server] Response entity is empty string when allOf is used

Open
#8,261 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The generated Node.js server responds with an empty response if allOf composition is used for defining response schemes.

Swagger-codegen version

2.3.1

Swagger declaration file content or url
  • Code below is simplified and sanitizied
  • Correct example response is created from original code in swagger-editor
paths:
  '/users':
    patch:
      summary: Patch some user
      # omitted parameters definition
      operationId: createUserUsingPATCH
      consumes:
        - application/json
      produces:
        - application/json
      responses:
        '200':
          description: Success
          schema:
            $ref: '#/definitions/CreateUserResponse'


definitions:
# omitted example" fields
  CreateUserResponse:
    type: object
    allOf:
      - $ref: '#/definitions/PartOne'
    properties:
      userId:
        type: integer
        format: int32
    required:
      - userId

  PartOne:
    type: object
    required:
      - foo
      - firstName
      - lastName
    properties:
      foo:
        allOf:
          - $ref: '#/definitions/PartTwo'
      firstName:
        type: string
      lastName:
        type: string
        
  PartTwo:
    type: object
    properties:
      bar:
        type: string
Command line used for generation
swagger-codegen generate -i api.spec.yaml -l nodejs-server -o generated-server
Steps to reproduce
  1. Execute command above.
  2. Start server via npm start
  3. Execute PATCH http://localhost:8082/api/v1/users/123

Expected response:
JSON object containing combined example content from CreateUserResponse, PartOne and PartTwo.

Actual response:
Empty string.

Related issues/PRs

According to the existing tracked issues, allOf seems to be unsupported. However, I would be glad to know if my particular issue is somehow related to my specs or my usage of YAML.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the nodejs-server output from the supplied YAML, then run it with npm start and reproduce the PATCH request. Inspect the generated server's response handling for the CreateUserResponse allOf schema. Done means the endpoint returns the expected combined JSON example instead of an empty string.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.