swagger-api / swagger-api/swagger-codegen

circular dependency in C++ when generate cpprest client

Open
#12,206 0 comments 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

I use the OpenAPI Spec files to generate cpprest client. Codes are generated successfully.
But the compilation failed because Teacher_instance.h is included in Student_instance.h and Student_instance.h is included in Teacher_instance.h.
How can I solve the problem?

{
  "swagger": "2.0",
  "info": {
    "title": "Test",
    "description": "Test",
    "version": "1.0.0.0",
    "license": {
      "name": "End User License Agreement",
      "url": "/branding/locales/en-US/eula.txt"
    }
  },
  "host": "127.0.0.1",
  "tags": [
    {
      "description": "student",
      "name": "student"
    },
    {
      "description": "teacher",
      "name": "teacher"
    }],
  "paths": {
    "/student": {
      "get": {
        "tags": [
          "student"
        ],
        "summary": "Find student",
        "description": "Query the student",
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/student_instance"
              }
            }
          }
        }
      }
    },
    "/teacher": {
      "get": {
        "tags": [
          "teacher"
        ],
        "summary": "Find teacher",
        "description": "Query the teacher",
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/teacher_instance"
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "student_instance" : {
     "description": "Properties of a student.",
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique identifier of the student.",
          "type": "string"
        },
        "name": {
          "description": "Name of the student.",
          "type": "string",
          "x-case-insensitive": true
        },
        "teacher": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/teacher_instance"
          },
          "description": "teachers of the student."
        }
      }
    },
    "teacher_instance" : {
      "description": "Properties of a teacher.",
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique identifier of the teacher.",
          "type": "string"
        },
        "name": {
          "description": "Name of the teacher.",
          "type": "string"
        },
        "student": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/student_instance"
          },
          "description": "students of the teacher."
        }
      }
    }
  }
}

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

Reproduce the generated cpprest client from the supplied OpenAPI document and inspect Student_instance.h and Teacher_instance.h, which include each other. Determine how the generator handles these mutually referenced models; done means the generated client compiles without the circular include failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.