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.json handle properties under 'allOf' #3

Open
MrBasque opened this issue Nov 25, 2020 · 7 comments
Open

swagger.json handle properties under 'allOf' #3

MrBasque opened this issue Nov 25, 2020 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@MrBasque
Copy link

Hi, thanks for this nice package.
However, we are currently unable to generate a form due to the following error:

node_modules\@verizonconnect\ngx-form-generator\dist\generator-lib.js:59
  const fields = Object.keys(definition.properties);
                        ^
TypeError: Cannot convert undefined or null to object

Our swagger.json contains several definitions that are structured like this:

"definitions":{
  "Trade": {
    "allOf": [{
        "$ref": "#/definitions/RootEntity"
      },
      {
        "type": "object",
        "properties": {
         "companyName": {
            "type": "string"
          },
          ....
        }
      }
    ]
  },
....
}

We did nothing special to the swagger configuration that I know of.
the generator-lib.js though, searches for "properties" as a direct child property which it cannot find in this case, because the properties are within an child under the "allOf" property.

anything we can do to resolve this?

@martinmcwhorter martinmcwhorter added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Nov 25, 2020
@martinmcwhorter
Copy link
Contributor

Thanks for this bug report.

Is this something you would want to try your hand at creating a PR?

It looks like we will need to do a few things:

  • If we are in an OAPI 3 spec, look for the allOf keyword in the definition

  • If the element of the allOf is a "$ref", follow the ref and generate the validators for that type

  • If the element of allOf is type "object", generate validators for the properties of that.

https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#discriminator-object

@MrBasque
Copy link
Author

Hi, Thanks for your quick response.
Would love to help out on this, but due to lack of time and other priorities I won't be able to at the moment. :-/

@martinmcwhorter martinmcwhorter added enhancement New feature or request and removed bug Something isn't working labels Nov 27, 2020
@martinmcwhorter
Copy link
Contributor

Fixed in version 1.1.0

@MrBasque
Copy link
Author

Thanks for the quick fix! 👌🏼

@dickinr
Copy link

dickinr commented Jun 7, 2021

This appears to still be broken in 1.1.2? First time using this package, but I'm getting this same exact error.

@MrBasque
Copy link
Author

MrBasque commented Jun 7, 2021

Affirmative, it also wasn't fixed in my case, but forgot to report that back.

@martinmcwhorter
Copy link
Contributor

martinmcwhorter commented Jun 7, 2021

Thanks.

Can the both of you provide me with a minimal openapi/swagger doc that reproduces the issue.

Are your documents OpenAPI 3 or 2 (Swagger)?

In 1.1.0 we changed to use @apidevtools/swagger-parser which can dereference types, including abstract types that use allOf.

We have a very simple test for this - but with the help of your minimal reproducing specs we should be able to:

  • Add additional tests based on real world usage
  • Fix our integration with @apidevtools/swagger-parser
  • Or if we determine the bug is in the parser, we can open a very descriptive bug report with that project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants