question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Being able to create types on ApiModelProperty for complex nested arrays (eg. GeoJSON)

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[X ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Right now, it’s impossible to express deeply nested array structures, such as the one that is needed to define Polygon coordinates in GeoJSON. eg:

[
  [
    [-122.38005638122557, 37.60376025592665],
    [-122.37773895263672, 37.60593620261328],
    [-122.36555099487303, 37.600632221054056],
    [-122.34992980957031, 37.61858263247881],
    [-122.38417625427246, 37.6399950678721],
    [-122.39996910095215, 37.63809199009653],
    [-122.39705085754393, 37.63251841048015],
    [-122.39996910095215, 37.6315667819348],
    [-122.40159988403319, 37.62918765725775],
    [-122.3964500427246, 37.61416342563735],
    [-122.38005638122557, 37.60376025592665],
  ],
]

Expected behavior

I think it would work best if we were able to pass in a raw object to the type attribute of the ApiModelProperty decorator. Essentially something that allows us to define the raw type structure of something like the above. eg:

@ApiModelProperty({
    description:
      'A polygon shape that defines the geo fence. See "coordinates" key of the ' +
      'Polygon geometry here: https://en.wikipedia.org/wiki/GeoJSON#Geometries',
    type: {
      type: 'array',
      items: {
        type: 'array',
        items: {
          type: 'array',
          items: {
            type: 'number',
          },
        },
      },
    },
    required: true,
  })

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Oct 30, 2019

Added in the next version (to install run npm i @nestjs/swagger@next). Note: remember to update @nestjs/common, @nestjs/core and typescript as well to ensure that you’re using the latest versions.

Steps to migrate: https://github.com/nestjs/swagger/pull/355#issuecomment-547925879

1reaction
durocommented, Jun 28, 2019

@kamilmysliwiec I have submitted a PR for this, please give it a review.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Complex JSON nesting of objects and arrays - Stack Overflow
The first code is an example of Javascript code, which is similar, however not JSON. JSON would not have 1) comments and 2)...
Read more >
Swagger RESTful API Documentation Specification
The Swagger specification supports five data types: primitive (input/output); containers (as arrays/sets) (input/output); complex (as models ) ...
Read more >
Springfox Reference Documentation - GitHub Pages
Springfox works by examining an application, once, at runtime to infer API semantics based on spring configurations, class structure and various ...
Read more >
Querying arrays with complex types and nested structures
Your source data often contains arrays with complex data types and nested structures. Examples in this section show how to change element's data...
Read more >
Body - Nested Models - FastAPI
That's all standard Python syntax for type declarations. Use that same standard syntax for model attributes with internal types. So, in our example,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found