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

Produces the empty output for definitions with allOf #55

Open
ganqqwerty opened this issue May 28, 2018 · 1 comment
Open

Produces the empty output for definitions with allOf #55

ganqqwerty opened this issue May 28, 2018 · 1 comment

Comments

@ganqqwerty
Copy link

ganqqwerty commented May 28, 2018

If you use allOf in your definitions section of the swagger json object, the mock is empty.

This example works fine:

let Swagmock = require('swagmock');
let Mockgen = Swagmock(api);

Mockgen.responses({
        path: '/news/categories/{categoryId}/articles',
// operation: 'get',
        // response: 200,
        useExamples: true
    })
    .then(mock => {
        console.log('success');
        console.log(JSON.stringify(mock, null, 2));
    }).catch(error => {
    console.error(error);
});
{
    "swagger": "2.0",
    "info": {
        "description": "API managing all news content served to the portal",
        "version": "1.0.0",
        "title": "News API"
    },
    "host": "www.hauni.local",
    "basePath": "/o/api/news/v1",
    "tags": [
        {
            "name": "Article",
            "description": "Article Services"
        },
        {
            "name": "Category",
            "description": "Category Services"
        }
    ],
    "schemes": [
        "http"
    ],
    "paths": {
        "/news/categories/{categoryId}/articles": {
            "get": {
                "tags": [
                    "Article"
                ],
                "summary": "Find News by CategoryId",
                "description": "Returns a list of news of the required category",
                "operationId": "getArticlesByCategoryId",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "categoryId",
                        "in": "path",
                        "description": "Category ID required ",
                        "required": true,
                        "type": "integer",
                        "format": "int64"
                    },
                    {
                        "name": "pageSize",
                        "in": "query",
                        "description": "Expected page size",
                        "type": "integer"
                    },
                    {
                        "name": "pageNumber",
                        "in": "query",
                        "description": "Page number we want to be returned",
                        "type": "integer"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "successful operation",
                        "schema": {
                            "$ref": "#/definitions/PagedArticles"
                        }
                    },
                    "404": {
                        "description": "CategoryId not found"
                    }
                }
            }
        }
    },
    "definitions": {
        "PagedArticles": {
          "properties": {
            "totalItems": {
              "type": "number",
              "description": "Total items for this query"
            },
            "pageNumber": {
              "type": "number",
              "description": "Current page number"
            },
            "pageSize": {
              "type": "number",
              "description": "Page size used to provide this result"
            }
          },
          "example": {
            "totalItems": 2,
            "pageNumber": 1,
            "pageSize": 10
          }

        }
    }
}

With this json file it produces the following output, which is good and nice:

success
{
  "get": {
    "responses": {
      "200": {
        "totalItems": -151274603832.9344,
        "pageNumber": -120071625323.3152,
        "pageSize": -558157441846.4768
      }
    }
  }
}

However with the following json we get an empty object, which is a bug:

{
    "swagger": "2.0",
    "info": {
        "description": "API managing all news content served to the portal",
        "version": "1.0.0",
        "title": "News API"
    },
    "host": "www.hauni.local",
    "basePath": "/o/api/news/v1",
    "tags": [
        {
            "name": "Article",
            "description": "Article Services"
        },
        {
            "name": "Category",
            "description": "Category Services"
        }
    ],
    "schemes": [
        "http"
    ],
    "paths": {
        "/news/categories/{categoryId}/articles": {
            "get": {
                "tags": [
                    "Article"
                ],
                "summary": "Find News by CategoryId",
                "description": "Returns a list of news of the required category",
                "operationId": "getArticlesByCategoryId",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "categoryId",
                        "in": "path",
                        "description": "Category ID required ",
                        "required": true,
                        "type": "integer",
                        "format": "int64"
                    },
                    {
                        "name": "pageSize",
                        "in": "query",
                        "description": "Expected page size",
                        "type": "integer"
                    },
                    {
                        "name": "pageNumber",
                        "in": "query",
                        "description": "Page number we want to be returned",
                        "type": "integer"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "successful operation",
                        "schema": {
                            "$ref": "#/definitions/PagedArticles"
                        }
                    },
                    "404": {
                        "description": "CategoryId not found"
                    }
                }
            }
        }
    },
    "definitions": {
        "PagedArticles": {
            "allOf": [
                {
                    "$ref": "#/definitions/Pagination"
                }

            ]
        },
        "Pagination": {
            "properties": {
                "totalItems": {
                    "type": "number",
                    "description": "Total items for this query"
                },
                "pageNumber": {
                    "type": "number",
                    "description": "Current page number"
                },
                "pageSize": {
                    "type": "number",
                    "description": "Page size used to provide this result"
                }
            },
            "example": {
                "totalItems": 2,
                "pageNumber": 1,
                "pageSize": 10
            }
        }
    }
}

The output:

{
  "get": {
    "responses": {
      "200": {}
    }
  }
}
@ganqqwerty
Copy link
Author

I found that in function Generators/objectMock() we have nothing to process oneOf, anyOf, allOf or not keywords from swagger/openAPI specification. I can provide a relatively naïve implementation for this case, but I have to be sure that @subeeshcbabu is merging pull requests, and didn't abandon the repo.

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

No branches or pull requests

1 participant