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

Custom examples not working when file is generated #1060

Closed
lenartgolob opened this issue Nov 6, 2023 · 4 comments
Closed

Custom examples not working when file is generated #1060

lenartgolob opened this issue Nov 6, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@lenartgolob
Copy link

Describe the bug

I defined custom payload example, but when I generate documentation from html template, the examples are generic ("string", 0, "timestamp").

How to Reproduce

I define my examples in messages like this:
HelpDeskTicketUserRaised:
name: HelpDeskTicketUserRaised
title: Help Desk Ticket User Raised
traits:
- $ref: './headers.yaml#/messageTraits/commonHeaders'
payload:
$ref: "./schemas.yaml#/UserRequestPayload"
example:
UserRequestId: 1
Number: T-2023/241
UserRequestMessage: '20'
ReportedBy:
User:
Id: 2
Email: john.doe@gmail.com
ExternalCode:

Expected behavior

Expected behaviour is that this data shows in generated html file instead of the generic examples. If I define the data in schema and for each attribute then it works, but in my case that is unacceptable since I have too much messages. Also I am using VS Code extension which uses the react-component and on the preview in VS Code the examples work fine. But once the html file is generated, only the generic examples show.

@lenartgolob lenartgolob added the bug Something isn't working label Nov 6, 2023
@derberg
Copy link
Member

derberg commented Nov 6, 2023

Hey there, please provide a full example, or at least a formatted message that can be copy/pasted

please use markdown code formatting

@lenartgolob
Copy link
Author

lenartgolob commented Nov 7, 2023

asyncapi: '2.6.0'
info:
  title: Message Queues Documentation
  version: '1.0.0'
  description: This is a documentation for message queues
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
servers:
  test:
    url: test.mykafkacluster.org:8092
    protocol: kafka-secure
    description: Test broker
    security:
      - saslScram: []
defaultContentType: application/json
channels:

  #  Session

  "{operatorId}.*.session.started":
    description: desc
    parameters:
      operatorId:
        $ref: '#/components/parameters/operatorId'
    publish:
      operationId: sessionStarted
      traits:
        - $ref: '#/components/operationTraits/kafka'
      message:
        $ref: '#/components/messages/SessionStarted'
      tags:
        - name:  Session

components:
  messages:
    SessionStarted:
      name: SessionStarted
      title: Session Started
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/commonHeaders'
      payload:
        $ref: "#/components/schemas/SessionPayload"   
        example:
          SessionId: 660427
          SessionNumber: "S-2023/2673"
          SessionSourceId: 1
          ParkingFrom: null
          ParkingTo: null
          ConnectedFrom: "2023-10-30T07: 53: 03.557Z"
          ConnectedTo: null
          From: "2023-10-30T07: 53: 03.557Z"
          To: null
          MeterStart: 6804.3 
          MeterEnd: null
          Consumption: null
          Power: null
          RoamingTypeId: 0
          RoamingSessionId: null
          InstanceRoamingPlatformId: null
          Object: 
            Id: 75691
            ObjectFriendlyCode: "1"                 
                                                                                                                              

  schemas:
    SessionPayload:
      type: object
      properties:
        SessionId:
          type: integer
          format: int64
          description: Unique ID of the  session
        SessionNumber:
          type: string
          description: Friendly ID of the  session
        SessionSourceId:
          type: integer
          format: int16
          description: 1 - Local charge point (CSO); 2 - Roaming CDR.
        ParkingFrom:
          type: string
          format: date-time
          description: Parking start time. Normally empty if charger is not able to detect parking time.
        ParkingTo:
          type: string
          format: date-time
          description: Parking end time. Normally empty if charger is not able to detect parking time.
        ConnectedFrom:
          type: string
          format: date-time
        ConnectedTo:
          type: string
          format: date-time
        From:
          type: string
          format: date-time
        To:
          type: string
          format: date-time
        MeterStart:
          type: string
          format: date-time
        MeterEnd:
          type: string
          format: date-time
        Consumption:
          type: number
          format: float
        Power:
          type: number
          format: float
        RoamingTypeId:
          type: integer
          format: int32
        RoamingSessionId:
          type: string
          description: Roaming session id, collected from roaming partner, used as reference when communicating with partner.
        InstanceRoamingPlatformId:
          type: integer
          format: int32
        Object:
          type: object
          properties:
            Id:
              type: integer
              format: int32
            ObjectFriendlyCode:
              type: string
  
  securitySchemes:
    saslScram:
      type: scramSha256
      description: Provide your username and password for SASL/SCRAM authentication
  parameters:
    operatorId:
      description: Instance ID. Every tenant has unique ID.
      schema:
        type: integer
        format: int32                
  messageTraits:
    commonHeaders:
      headers:
        type: object
        properties:
          my-app-header:
            type: integer
            minimum: 0
            maximum: 100
  operationTraits:
    kafka:
      bindings:
        kafka:
          clientId: my-app-id

@derberg This is the sample document (full document is too long). There are no error, the file gets generated, but the examples are generic instead of the examples I listed. I want the generated html file to have the example I listed. When I preview the async file with VS Code Extension the examples are the ones I defined and not generated ones, but once I generate html file the genric examples show up. Also defining example for each attribute is really not an option, because the file is so long and examples are also very long.

@derberg
Copy link
Member

derberg commented Jan 17, 2024

@derberg sorry for such a late response but we were in the middle of asyncapi v3 release and then also christmas break

the problem is that you provide example in not a valid asyncapi way

your message should look like:

    SessionStarted:
      name: SessionStarted
      title: Session Started
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/commonHeaders'
      payload:
        $ref: "#/components/schemas/SessionPayload"   
      examples:
        - payload:
            SessionId: 660427
            SessionNumber: "S-2023/2673"
            SessionSourceId: 1
            ParkingFrom: null
            ParkingTo: null
            ConnectedFrom: "2023-10-30T07: 53: 03.557Z"
            ConnectedTo: null
            From: "2023-10-30T07: 53: 03.557Z"
            To: null
            MeterStart: 6804.3 
            MeterEnd: null
            Consumption: null
            Power: null
            RoamingTypeId: 0
            RoamingSessionId: null
            InstanceRoamingPlatformId: null
            Object: 
              Id: 75691
              ObjectFriendlyCode: "1"      

since message can also have headers, then an example object has a structure that enable you to provide example of header and payload separately + you can have multiple examples -> https://v2.asyncapi.com/docs/reference/specification/v2.6.0#messageExampleObject

here you can see fixed document but still with errors as your example do not match provided AsyncAPI Schema

@derberg
Copy link
Member

derberg commented Jan 25, 2024

7 days passed. I think we can assume provided solution will work. Closing. Feel free to drop a comment in case it is not really resolved

@derberg derberg closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants