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

ArrayRef[HashRef] param #71

Open
slobo opened this issue Jul 26, 2019 · 7 comments
Open

ArrayRef[HashRef] param #71

slobo opened this issue Jul 26, 2019 · 7 comments

Comments

@slobo
Copy link
Contributor

slobo commented Jul 26, 2019

We would like an endpoint to to take a list of objects as an input, ex:

{
  entries: [
   { id: 1, title: 'Entry 1'},
   { id: 2, title: 'Entry 2'}
  ]
}

Naive approach, where we don't validate each object in list would be like this

  params(
    requires(
      entries => (
        type => ArrayRef[HashRef],
        desc => 'Entries',
      )
    ),
  );

This generates following bit in swagger:

{
  "parameters": [
    {
      "required": true,
      "description": "Entries",
      "items": {
        "$ref": "#/definitions/Entries-MD5Hash"
      },
      "in": "body",
      "type": "array",
      "name": "entries"
    }
  ]
}

But there is no definition of Entries-MD5Hash in definitions section in swagger, which makes the swagger.json out of spec.

Ideally, we would be able to define the structure of the HashRef too as part of the definition.

Any suggestions how to deal with this?

Thanks!

@slobo
Copy link
Contributor Author

slobo commented Jul 27, 2019

[[[egg on face]]] We were using old release, seems there is better behaviour in latest release. will experiment with that a bit first

@khrt
Copy link
Owner

khrt commented Jul 28, 2019

I can see the very same behaviour on current master.

@khrt
Copy link
Owner

khrt commented Jul 28, 2019

I assume the issue is in https://github.com/khrt/Raisin/blob/master/lib/Raisin/Plugin/Swagger.pm#L286 where everything which is not HashRef is ignored.

@slobo
Copy link
Contributor Author

slobo commented Jul 28, 2019 via email

khrt pushed a commit that referenced this issue Jul 28, 2019
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Sun Jul 28 20:34:28 2019 +0200
#
# On branch array-of
# Changes to be committed:
#	modified:   lib/Raisin/Plugin/Swagger.pm
#
# Untracked files:
#	examples/test.pl
#
khrt pushed a commit that referenced this issue Jul 28, 2019
* generate any-type items for ArrayRef w/o `using` (#71);
* fix `tags` object of spec to be compliant;
@khrt
Copy link
Owner

khrt commented Jul 28, 2019

I've kinda fixed it. The fix is that if type of a parameter is ArrayRef[.+] the plugin generates parameters of type array with items any-type. See https://swagger.io/docs/specification/data-models/data-types/

Not sure if it's what you want, but at least the spec is valid now.

@khrt
Copy link
Owner

khrt commented Jul 28, 2019

Released to CPAN to anyway, even if it doesn't solve your issue.

@slobo
Copy link
Contributor Author

slobo commented Jul 30, 2019

Thanks for such quick action, this helps! I'll keep the ticket open in hopes we can get more extensive ArrayRef[HashRef] support such that any deep nested JSON structure can be described eventually

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

2 participants