LiveRamp / reslang

A language for describing resource-oriented APIs & turning them into Swagger or resource diagrams. Oriented around the concepts we want to expose in the APIs.
Apache License 2.0
23 stars 7 forks source link

Invalid AsyncAPI Spec if no Events are Described #81

Closed njaczko closed 4 years ago

njaczko commented 4 years ago

If a Reslang spec doesn't describe any events, the Reslang cli still attempts to generate an AsyncAPI spec when the --events flag is passed. The result is confusing, invalid AsyncAPI. Reslang probably shouldn't generate anything if no events are specified and the --events flag is passed.

For example:

➜  reslang git:(master) ✗ ./reslang ./models/direct2dist --events --stdout
# generated by Reslang v1.4.9
asyncapi: 2.0.0
info:
  title: 'Direct to Distribution API - BETA '
  description: API for accessing LiveRamp's Direct to Distribution Service
  version: 0.0.1
servers:
  production:
    url: 'pubsub.liveramp.com:{port}'
    protocol: Google Cloud Pub/Sub
    description: LiveRamp Production pubsub instance
    variables:
      port:
        description: Secure connection (TLS) is available through port 8883
        default: '1883'
defaultContentType: application/json
channels: {}
components:
  messages: {}
  schemas:
    VerbEnum:
      type: string
      enum:
        - POST
        - PUT
        - PATCH
        - GET
        - MULTIGET
        - DELETE
  messageTraits:
    RestHeader:
      headers:
        type: object
        properties:
          verb:
            description: ''
            $ref: '#/components/schemas/VerbEnum'
          location:
            description: ''
            type: string
            format: url
            example: 'https://www.domain.com (url)'
          ids:
            description: ''
            items:
              type: string
            type: array
        required:
          - verb
          - location
          - ids
liveandrew commented 4 years ago

now generates an error if you ask for --events but there are no events specified. btw this took my less time to fix than i bet it took to write the issue. perhaps we can just fix these minor things as we find them?

njaczko commented 4 years ago

Hi @liveandrew, I'm glad it was a quick fix. I'm surprised by your comment, though.

This was a trivial fix for you because of your deep understanding of the Reslang code. I would have had to spend a non-trivial amount of time source-diving to identify the fix. Then I would have spent some time figuring out how to run the tests (some documentation would help here) and reviewing all of the failed tests to make sure my changes did not introduce anything unexpected.

liveandrew commented 4 years ago

that's fair. pls ignore the tone of my comment, i was in a grumpy mood after returning from vacationing in cancun...

let's chat about how we can pair to fix some of these bugs. it doesn't have to be an all or nothing handover, it can be "let's work on this 1 defect together for an hour" as a way of getting into the code. it's only 3k lines of typescript, admittedly it's a transpiler so it's necessarily a bit complex, but it's a pretty simple system

liveandrew commented 4 years ago

and yes, you would have to spend some time figuring how to run the tests, or ask me ;-P part of this is the fact that typescript and npm development has well established norms - i'm presuming you are not necessarily from this dev world? e.g. yarn test