Generator: asyncapi.allSchemas() does no longer return all schemas!

Created on 4 Aug 2020  路  10Comments  路  Source: asyncapi/generator

Describe the bug

Version 1.0.0-rc.7 does not seem to return all the schemas when calling asyncapi.allSchemas().
It was still working in version 0.34.3.

How to Reproduce

  • install version 1.0.0-rc.7
  • use the yaml file below
asyncapi: 2.0.0
info:
  title: 'test - enums'
  version: 1.0.0
channels:
  testChannel:
    subscribe:
      message:
        oneOf:
          - $ref: '#/components/messages/testMessage'

components:
  messages:
    testMessage:
      contentType: application/json
      payload:
        $ref: '#/components/schemas/schemaA'

  schemas:

    schemaA:
      type: object
      properties:
        schemaCReference:
          $ref: '#/components/schemas/schemaC'
        schemaDReference:
          $ref: '#/components/schemas/schemaD'
        commonEnumName:
          type: string
          enum:
            - ENUM_1
            - ENUM_2
    schemaB:
      type: object
      properties:
        commonEnumName:
          type: string
          enum:
            - ENUM_3
            - ENUM_4
            - ENUM_5

    schemaC:
      type: string
      enum:
        - ENUM_A
        - ENUM_B
        - ENUM_C
        - ENUM_D

    schemaD:
      allOf:
        - $ref: '#/components/schemas/schemaC'
        - type: string
          enum:
            - ENUM_E
  • output all schemas (e.g. console.dir() in a custom filter)
Map {
      'schemaB' => Schema {
        _json: {
          type: 'object',
          properties: [Object],
          'x-parser-schema-id': 'schemaB'
        }
      },
      'schemaC' => Schema {
        _json: { type: 'string', enum: [Array], 'x-parser-schema-id': 'schemaC' }
      }
    }

Expected behavior

All schemas should be returned!

  • install version 0.34.3 (still working)
  • repeat process described above
Map {
  'schemaA' => Schema {
  _json:
   { type: 'object',
     properties: [Object],
     'x-parser-schema-id': 'schemaA' } },
  'schemaB' => Schema {
  _json:
   { type: 'object',
     properties: [Object],
     'x-parser-schema-id': 'schemaB' } },
  'schemaC' => Schema {
  _json:
   { type: 'string',
     enum: [Array],
     'x-parser-schema-id': 'schemaC' } },
  'schemaD' => Schema { _json: { allOf: [Array], 'x-parser-schema-id': 'schemaD' } } }
bug

All 10 comments

Welcome to AsyncAPI. Thanks a lot for reporting your first issue.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Hi @alexanderTilg,
Thanks for reporting this bug. Even if you would not add the ! we would still have a look as it is a bug and we are close to releasing major version 馃槃

allSchemas() is a parser function that I checked directly in parser with your schema and this is what I got:

Map {
  'schemaA' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaA'
    }
  },
  'schemaB' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaB'
    }
  },
  'schemaC' => Schema {
    _json: { type: 'string', enum: [Array], 'x-parser-schema-id': 'schemaC' }
  },
  'schemaD' => Schema { _json: { allOf: [Array], 'x-parser-schema-id': 'schemaD' } }
}

So the result is pretty good and we have pretty complex test for this function where we check more complex nested schema case: https://github.com/asyncapi/parser-js/blob/master/test/good/nested-schemas.json

But when I check with generator, updating to latest parser I get exactly what you get:

Map {
  'schemaB' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaB'
    }
  },
  'schemaC' => Schema {
    _json: { type: 'string', enum: [Array], 'x-parser-schema-id': 'schemaC' }
  }
}

and it is super weird, will investigate further

Thanks for the quick reply! ;) :)

@alexanderTilg oh man, this one gave me a headache 馃槃 looked like a magic first. Anyway, fix provided https://github.com/asyncapi/parser-js/pull/148, once parser is released I will bump generator release candidate and you will get:

Map {
  'schemaA' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaA'
    }
  },
  'schemaC' => Schema {
    _json: { type: 'string', enum: [Array], 'x-parser-schema-id': 'schemaC' }
  },
  'schemaD' => Schema { _json: { allOf: [Array], 'x-parser-schema-id': 'schemaD' } },
  '<anonymous-schema-1>' => Schema {
    _json: {
      type: 'string',
      enum: [Array],
      'x-parser-schema-id': '<anonymous-schema-1>'
    }
  },
  '<anonymous-schema-2>' => Schema {
    _json: {
      type: 'string',
      enum: [Array],
      'x-parser-schema-id': '<anonymous-schema-2>'
    }
  },
  'schemaB' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaB'
    }
  }
}

why not:

Map {
  'schemaA' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaA'
    }
  },
  'schemaB' => Schema {
    _json: {
      type: 'object',
      properties: [Object],
      'x-parser-schema-id': 'schemaB'
    }
  },
  'schemaC' => Schema {
    _json: { type: 'string', enum: [Array], 'x-parser-schema-id': 'schemaC' }
  },
  'schemaD' => Schema { _json: { allOf: [Array], 'x-parser-schema-id': 'schemaD' } }
}

because before you used a pretty old generator and since that time we added support for adding anonymous schema id to nested schemas

That was fast, thanks for looking into it and fixing it!
The extra anonymous schemas are not an issue, they can easily be filtered out if needed.

@alexanderTilg Parser with the fix is already released. I will make few other fixes today and should release generator tomorrow if nothing bad happens

just curious, what is your use case for the generator, do you have some custom template of yours?

Right now I'm working on generating Typescript typings out of asyncApi specs.
It is already in use in one micro service (lambda function; POC; that's the one running on 0.34.3.)
Now I'm putting it into its own npm package, so I can use it with the project I'm currently working on and then hopefully we will use it in all our services that use async communication.

I'm also considering to generate json schemas and we might create our own Java template in the future as well.

Sounds great. I recommend then to join our slack https://www.asyncapi.com/slack-invite/ and the #tooling channel where you can always ask for help or provide feedback if you see we're working on something for the generator.

Keep in mind template doesn't have to be on npm if you want to reuse it, but of course, it is a good practice to publish and version it on npm.

If you are mostly interested with generating only types and not entire service, you might be interested with this issue, https://github.com/asyncapi/generator/issues/216. Would love to hear your opinion there, in case this is interesting for ya.

what do you mean by generating json schemas?

@alexanderTilg new release candidate is finally out, can you please give it a try? https://github.com/asyncapi/generator/releases/tag/vv1.0.0-rc.8

closing as no followup was taken after 7 days

Was this page helpful?
0 / 5 - 0 ratings

Related issues

derberg picture derberg  路  8Comments

aravindajju picture aravindajju  路  9Comments

jonaslagoni picture jonaslagoni  路  5Comments

derberg picture derberg  路  8Comments

fmvilas picture fmvilas  路  8Comments