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

Use "Title" as model name if provided in swagger definition #2868

Closed
dmytrobr opened this issue May 14, 2016 · 1 comment
Closed

Use "Title" as model name if provided in swagger definition #2868

dmytrobr opened this issue May 14, 2016 · 1 comment

Comments

@dmytrobr
Copy link
Contributor

For inline object definitions, the generator uses "inline_response12323" as a model name which later ends up in a lot of Java classes with meaningless names like InlineResponse12323.

I propose to use "Title" attribute whenever provided. This attribute is part of Swagger definition (not specific to Swagger by comes from JSON schema) and could be added to any schema object.

Below is JSON example. For such example I would like to have Java class name for parameter be "ModifyCatRequest" (instead of "Data") and for response ModifyCatResponse instead of InlineResponse123.

I believe it is not specific for Java client, but should be a generic approach to use "title" as model name whenever provided. Other tools (e.g. Swagger UI) are using this approach too

Change is already working at my laptop, so if community supports this change I'll send pull request

    "/cat/{id}": {
      "put": {
        "summary": "Modify Cat",
        "operationId": "modifyCat",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "type": "string",
            "description": "ECM ID",
            "required": true
          },
          {
            "name": "data",
            "in": "body",
            "schema": {
              "type": "object",
              "title": "ModifyCatRequest",
              "properties": {
                "description": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                } 
                }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200 status response",
            "schema": {
              "type": "object",
              "title": "Status",
              "properties": {
                "status": {
                  "type": "object",
                  "title": "StatusItem",
                  "properties": {
                      "reqStatus": {
                      "type": "string",
                      "example": "sample reqStatus"
                    }, 
                  },
                  "required": [
                    "credentials",
                    "reqStatus"
                  ]
                },
                "data": {
                  "type": "object",
                  "title": "ModifyCatResponse",
                  "properties": {
                    "order": {
                      "type": "object",
                      "title": "order",
                      "properties": {                     
                        "id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
@dmytrobr dmytrobr changed the title Uses "Title" as model name if provided in swagger definition Use "Title" as model name if provided in swagger definition May 14, 2016
@wing328
Copy link
Contributor

wing328 commented Jun 20, 2016

PR merged. Issue closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants