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

Swagger autogeneration has support for non primitive attributes? #350

Open
yossialush opened this issue Nov 29, 2017 · 2 comments
Open

Swagger autogeneration has support for non primitive attributes? #350

yossialush opened this issue Nov 29, 2017 · 2 comments

Comments

@yossialush
Copy link

While trying to generate swagger file for the following resource:

const jsonApi = require("jsonapi-server");

module.exports = function(handler) {
    return {
        resource: "SomeResource",
        handlers: handler,
        attributes: {
            objectProperty: jsonApi.Joi.object().keys({
                prop1: jsonApi.Joi.string().required(),
                prop2: jsonApi.Joi.string().required()
            }).required(),
            arrayProperty: jsonApi.Joi.array().items(jsonApi.Joi.object().keys({
                primitiveProp1: jsonApi.Joi.string(),
                primitiveProp2: jsonApi.Joi.string()
            }))
        }
    };
};

I got this definition in swagger file:

"definitions": {
    "SomeResource": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "attributes": {
          "type": "object",
          "properties": {
            "objectProperty": {
              "type": "object"
            },
            "arrayProperty": {
              "type": "array"
            }
          },
          "required": [
            "objectProperty"
          ]
        },
        "relationships": {
          "type": "object",
          "properties": {
            
          }
        },
        "links": {
          "type": "object",
          "properties": {
            "self": {
              "type": "string"
            }
          }
        },
        "meta": {
          "type": "object"
        }
      }
    }

Now, you can see that objectProperty is missing properties with definitions of its properties prop1 and prop2. And arrayProperty is missing items with its items definitions.

I'd expect it to look like this:

"definitions": {
    "SomeResource": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "attributes": {
          "type": "object",
          "properties": {
            "objectProperty": {
              "type": "object",
              "properties": {
                "prop1":{
                  "type":"string"
                },
                "prop2":{
                  "type":"string"
                }
              }
            },
            "arrayProperty": {
              "type": "array",
              "items": {
                "type":"object",
                "properties": {
                 "primitiveProp1":{
                  "type":"string"
                },
                "primitiveProp2":{
                  "type":"string"
                } 
                }
              }
            }
          },
          "required": [
            "objectProperty"
          ]
        },
        "relationships": {
          "type": "object",
          "properties": {
            
          }
        },
        "links": {
          "type": "object",
          "properties": {
            "self": {
              "type": "string"
            }
          }
        },
        "meta": {
          "type": "object"
        }
      }
    }

Is there any plan for swagger autogeneration to support array and object?

@championswimmer
Copy link
Contributor

we need to use swagger 3.0 (openapi 3.0) to support the full spec of JSON:API

@gboston
Copy link

gboston commented May 4, 2018

When is the switch to OpenAPI 3.0 planned? I know the support is limited at the moment....

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

3 participants