Skip to content

Some schemas are never iterated #229

Closed

Description

@jonaslagoni

Describe the bug

The following schemas are never iterated and therefore are never assigned ids.

  • Standalone component parameters
  • Standalone component traits with headers

How to Reproduce

The following yaml file should give parameters and headers uids.

asyncapi: 2.0.0
info:
  title: My API
  version: '1.0.0'
channels: {}
components:
  parameters:
    testParam:
      schema: 
        type: object
        properties:
          name:
            type: string
  messageTraits:
    extension:
      headers:
        type: object
        properties:
          some-common-header:
            type: string

Expected behavior

Expected schemas to iterated

Activity

  1. added
    bug
    on Jan 18, 2021
  2. jonaslagoni commented on Feb 27, 2021

    @jonaslagoni
    MemberAuthor

    After some research here are some other schemas keywords we need to add to the iterator:

    • patternProperties
    • definitions
    • dependencies

    Furthermore this check

    if (schema.type() !== undefined) {
    should be removed completely IMO. Since if properties have been defined (lets say they omit the type keyword) we still need to be able to iterate those properties.

    Also this check

    if (!schemaTypesToIterate.includes(SchemaTypesToIterate.arrays) && schema.type() === 'array') return;
    needs to be done at each of the property/array keywords instead, so it should be moved to
    if (schema.additionalProperties() !== undefined && typeof schema.additionalProperties() !== 'boolean') {
    if (schema.additionalItems() !== undefined) {
    and wrap the code.

    Furthermore

    traverseCombinedSchemas(schema, callback, schemaTypesToIterate);
    should not be wrapped in an else statement, it should always iterate combination schemas.

  3. jonaslagoni commented on Feb 27, 2021

    @jonaslagoni
    MemberAuthor

    If anyone is up for the task we are always ready to help you out in the implementation of the issue, if it needs more explaining, just let us know 👋

  4. arjungarg07 commented on Mar 16, 2021

    @arjungarg07

    I am getting familiar with the codebase of parser-js and will pick up this issue real soon.

  5. arjungarg07 commented on Mar 24, 2021

    @arjungarg07

    Hey @jonaslagoni, By standalone components you mean which do not have $ref (reference) to another type of schemas?
    Can you please clear this doubt on standalone components Thanks.

  6. jonaslagoni commented on Mar 24, 2021

    @jonaslagoni
    MemberAuthor

    @arjungarg07 Yes either that or directly referenced by the document such as for testParam is never referenced by a channel and therefore never given an id. Because it is a standalone parameter no one uses 😄

    asyncapi: 2.0.0
    info:
      title: My API
      version: '1.0.0'
    channels: {}
    components:
      parameters:
        testParam:
          schema: 
            type: object
            properties:
              name:
                type: string
    

    Did that make sense? 🤔

  7. arjungarg07 commented on Mar 24, 2021

    @arjungarg07

    Yeah, that makes sense. Thanks😀

  8. arjungarg07 commented on Mar 30, 2021

    @arjungarg07

    Hey @jonaslagoni , I parsed this doc, and on calling doc.allSchemas() I am getting the output as shown. I think patternProperties ,definitions, dependencies are already iteratable, Can you please tell why do we need to add these keywords in iterator?

    asyncapi: 2.0.0
    info:
      title: My API
      version: '1.0.0'
    channels: {}
    components:
      parameters:
        testParam:
          schema: 
            type: object
            properties:
              name:
                type: string
      messageTraits:
        extension:
          headers:
            type: object
            properties:
              some-common-header:
                type: string
      schemas: 
        dependencies:
          test: ['test']
        patternProperties:
          test:
            type: string
        definitions: 
          test: 
            type: string
    

    Screenshot 2021-03-30 at 3 10 40 PM

  9. jonaslagoni commented on Mar 30, 2021

    @jonaslagoni
    MemberAuthor

    @arjungarg07 In your example you have defined schemas called patternProperties ,definitions and dependencies. You need to use them as keywords in a schema. Such as:

    {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "credit_card": { "type": "number" },
        "billing_address": { "$ref": "#/definitions/address" }
      },
      "required": ["name"],
      "dependencies": {
        "credit_card": {
          "properties": {
            "billing_address_2": { "type": "string" }
          },
          "required": ["billing_address_2"]
        }
      }
      "patternProperties": {
        "^S_": { "type": "string" },
        "^I_": { "type": "integer" }
      },
      "definitions": {
        "address": {
          "type": "object",
          "properties": {
            "street_address": { "type": "string" },
            "city":           { "type": "string" },
            "state":          { "type": "string" }
          },
          "required": ["street_address", "city", "state"]
        }
      }
    }
  10. arjungarg07 commented on Mar 31, 2021

    @arjungarg07

    Thanks, @jonaslagoni for helping me out.

  11. arjungarg07 commented on May 10, 2021

    @arjungarg07

    Hey @jonaslagoni, really sorry for not being active on this issue, it's coz of the whole covid situation in India, but now all fine and am catching up to resolve this issue.

    {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "credit_card": { "type": "number" },
        "billing_address": { "$ref": "#/definitions/address" }
      },
      "required": ["name"],
      "dependencies": {
        "credit_card": {
          "properties": {
            "billing_address_2": { "type": "string" }
          },
          "required": ["billing_address_2"]
        }
      }
      "patternProperties": {
        "^S_": { "type": "string" },
        "^I_": { "type": "integer" }
      },
      "definitions": {
        "address": {
          "type": "object",
          "properties": {
            "street_address": { "type": "string" },
            "city":           { "type": "string" },
            "state":          { "type": "string" }
          },
          "required": ["street_address", "city", "state"]
        }
      }
    }

    Can you please share with me the whole doc of which this is a subset as I need to prepare a new doc for testing?
    Thanks!

  12. jonaslagoni commented on May 10, 2021

    @jonaslagoni
    MemberAuthor

    Hey @jonaslagoni, really sorry for not being active on this issue, it's coz of the whole covid situation in India, but now all fine and am catching up to resolve this issue.

    You don't have to apologize @arjungarg07, hope everything is well! You can spend as much time as you want on this, so don't stress about it 🙂

    Can you please share with me the whole doc of which this is a subset as I need to prepare a new doc for testing?

    I am assuming you want an AsyncAPI document example right? As the example schema is part of the payload, you can add the json to the following, replacing <Insert here> with the above example:

    {
      "asyncapi": "2.0.0",
      "info": {
        "title": "example",
        "version": "0.1.0"
      },
      "channels": {
        "example": {
          "publish": {
            "message": {
              "payload": <Insert here>
            }
          }
        }
      }
    }
    
  13. arjungarg07 commented on May 10, 2021

    @arjungarg07

    You don't have to apologize @arjungarg07, hope everything is well! You can spend as much time as you want on this, so don't stress about it 🙂

    Thanks, just have to prepare the test file😃

    I am assuming you want an AsyncAPI document example right? As the example schema is part of the payload, you can add the json to the following, replacing <Insert here> with the above example:

    Yeah! This will help a lot.

  14. github-actions commented on Jul 10, 2021

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴
    It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
    Thank you for your contributions ❤️

  15. github-actions commented on Sep 11, 2021

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴
    It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
    Thank you for your contributions ❤️

  16. derberg commented on Sep 13, 2021

    @derberg
    Member

    @arjungarg07 do you continue with this?

  17. arjungarg07 commented on Sep 14, 2021

    @arjungarg07

    I don't think so, coz now I would have to reiterate through the issue again. Would love it if anyone else could take this up or I will try to look into it again this week :)

  18. derberg commented on Sep 20, 2021

    @derberg
    Member

    @arjungarg07 I don't think anyone here will have time to look at it in next weeks anytime soon so I suggest you continue in October and you will have already one PR for the Hacktoberfest 😄

  19. magicmatatjahu commented on Oct 18, 2021

    @magicmatatjahu
    Member

    @arjungarg07 Are you still interesting with this task? The problem itself is much deeper and it is not only about iterating through all the schemes but also about detecting circular schemes in traverseSchema function - see for example this issue asyncapi/generator#666

    I would like to try to fix this problem because a lot of people have a problem with circular references and we should support them in html-template and markdown-template.

  20. arjungarg07 commented on Oct 23, 2021

    @arjungarg07

    I would like to try to fix this problem because a lot of people have a problem with circular references

    Yeah, sure. Please go ahead fixing this one. Thanks.

  21. asyncapi-bot commented on Nov 23, 2021

    @asyncapi-bot
    Contributor

    🎉 This issue has been resolved in version 1.12.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuereleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions