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.

[openapi-jsonschema-parameters] No properties copied over for parameters of type object

See original GitHub issue

openapi-jsonschema-parameters strips the properties from the schema for things like query and path params.

I’m mostly interested in the former, as this is causing issues in my particular use case of validating the pagination query parameters for a JSON:API request (spec).

Please find the below snippet from our OAI3 schema for the page query parameter:

components:
  parameters:
    PageQueryParam:
      name: page
      in: query
      schema:
        description: |
          Although JSON:API doesn't enforce any specific pagination strategy, it does reserve the `page` query parameter
          and suggests using an object with fields corresponding to parameters relating to the selected pagination strategy.
        type: object
        externalDocs:
          description: JSON:API Pagination
          url: https://jsonapi.org/format/1.0/#auto-id--pagination
        properties:
          offset:
            type: integer
          limit:
            type: integer
            maximum: 100 # TODO: magic number

At the moment ajv in the request validator is not given the properties of the object, so it can only validate the type of the page query param, which in this case is object. This results in incorrect values for page[offset] or page[limit] passing the validation done by openapi-request-validator.

I will issue a PR later today once I have the chance, but my sort-of quickfix solution is to add properties to the VALIDATION_KEYWORDS array. See edit below.

https://github.com/kogosoftwarellc/open-api/blob/6323130dfe8e4c895ad88267333e20db20563860/packages/openapi-jsonschema-parameters/index.ts#L44-L65

Please share your thoughts.

EDIT:

Okay, yeah, just adding properties into the VALIDATION_KEYWORDS won’t suffice as it will just copy the properties without converting them to JSON Schema. Looking further into it.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
TomaszChrosniakcommented, Dec 12, 2019

Sorry for the long wait. I think the best advice for anyone using this project would be to just add middleware for validating object-type parameters by themselves, just to keep this project simple.

1reaction
TomaszChrosniakcommented, Nov 22, 2019

Hi again, I’ve been looking at a few things to make sure I don’t break anything, and I’ve noticed that the OAI2 spec doesn’t allow object-valued parameters in non-body parameters (link).

I’m gonna have to ponder on this some more, as I was approaching this from the perspective of OAI3, which is my use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is there no type error when using copy with spread
I make a copy of the array of objects through the map function. Why does not an error occur with a new property...
Read more >
Error when Object Type parameter is passed through another ...
I have a pipeline with object type parameter that is used to parameterize Additional columns property in Copy activity.
Read more >
Perspective Component Properties - Ignition User Manual 8.0
There are three property data types available in Perspective's components: value, object, and array. When you create a new custom property, ...
Read more >
Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
In an object literal, the spread syntax enumerates the properties of an object ... allows deep copying values of certain supported types.
Read more >
Data Objects - MATLAB & Simulink - MathWorks
You can create data objects to specify values, value ranges, data types, tunability, and other characteristics of signals, states, and block parameters.
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