Generator: Mixed type array support

Created on 13 Oct 2020  路  14Comments  路  Source: asyncapi/generator

Describe the bug

If a mixed type array is declared, this is not correctly rendered in the HTML view it is rendered as _Array < Unknown >_

How to Reproduce

To reproduce it:

1) copy and paste the following spec in the generator

asyncapi: 2.0.0
info:
  title: Test MQTT API
  version: '1.0.0'
  description: |
    Test


defaultContentType: application/json

channels:  
  foo/bar:
    description: Test MQTT operation
    publish:

      message:
        $ref: '#/components/messages/testMessage'
components:
  messages:
    testMessage:
      contentType: application/json
      payload:
        $ref: "#/components/schemas/mainSchema"
  schemas:

    oneOfSchema:
      type: object
      properties:
        foo:
          type: number
          format: float 
    oneOfSchema2:
      type: object
      properties:
        foo:
          type: number
          format: float     


    mainSchema:
      type: object
      properties:
        mixedTypeArray:
          type: array
          items:
            oneOf:
            - $ref: "#/components/schemas/oneOfSchema"
            - $ref: "#/components/schemas/oneOfSchema2"

2) In the generated HTML code, see that the _Array < Unknown >_ is shown for the property mixedTypeArray and no types shown in the definition of the array in the drop down of the array

Expected behavior

The drop down of the array mixedTypeArray should show the list of possible items of the array [ oneOfSchema , oneOfSchema2 ]

bug

Most helpful comment

@derberg Thanks! And also uploaded to https://playground.asyncapi.io/ , perfect!

All 14 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.

@jonathanhuet this issue was reported a few days here.

PR with the fix is already opened https://github.com/asyncapi/html-template/pull/97

When I check my fix with your example, this is what I get
Screenshot 2020-10-14 at 10 05 37

So I guess this is also a fix for you. I'll wait for feedback from @CumminsMikeMattern one day more and if I get no response I'll look for a reviewer and merge/release, so this week it should go out

@derberg thanks for the fast reply!

Totally true about the issue #36. My bad!

About your PR result, it's totally ok for me. Thanks.

Just as a side note that probably is most a feature: As I'm familiar from Swagger/OAS, I'm missing the type name of the (referenced) object in the dropdown, as it is can be seen in OAS generator

@jonathanhuet no worries.

you mean that instead of 0 and 1 you would prefer oneOfSchema and oneOfSchema2?

yes, I think it is might be useful. OAS 3 HTML generator has it for each reference. In terms of coding I think it is useful to identify each parts and then having a specific handler/parser for that specific part of the message

I agree with @jonathanhuet

@jonathanhuet @CumminsMikeMattern I'll see what I can do. We already did it a few days ago in our react component https://github.com/asyncapi/asyncapi-react/pull/156 so this is definitely something that should be done here in the HTML template

Ok, I pushed fix that I think you are looking for

with such schema:

asyncapi: 2.0.0
info:
  title: Test MQTT API
  version: '1.0.0'
  description: |
    Test


defaultContentType: application/json

channels:  
  foo/bar:
    description: Test MQTT operation
    publish:

      message:
        $ref: '#/components/messages/testMessage'
components:
  messages:
    testMessage:
      contentType: application/json
      payload:
        $ref: "#/components/schemas/mainSchema"
  schemas:

    oneOfSchema:
      type: object
      properties:
        foo:
          type: number
          format: float 
    oneOfSchema2:
      type: object
      properties:
        foo:
          type: number
          format: float     


    mainSchema:
      type: object
      properties:
        mixedTypeArray:
          type: array
          items:
            oneOf:
            - $ref: "#/components/schemas/oneOfSchema"
            - $ref: "#/components/schemas/oneOfSchema2"
            - type: object
              properties:
                foo:
                  type: number
                  format: float   

you get this

Screenshot 2020-10-15 at 17 10 43

what do you think?

what do you think?

Looks great !

Yes, that's great!It will be very helpful! Thanks 馃憤

@jonathanhuet it is already released 馃槈 https://github.com/asyncapi/html-template/releases/tag/v0.15.0

@derberg Thanks! And also uploaded to https://playground.asyncapi.io/ , perfect!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uraala picture uraala  路  10Comments

fmvilas picture fmvilas  路  3Comments

jonaslagoni picture jonaslagoni  路  5Comments

alexanderTilg picture alexanderTilg  路  10Comments

derberg picture derberg  路  8Comments