Forum Discussion

navyasaip's avatar
navyasaip
New Member
3 years ago

Swagger Spec Parsing | NodeJS library for example payload generation

Hi,

I have a requirement of programmatically parsing the YAML Swagger Spec files to get the request and response payload in the JSON format. I am looking for a NodeJS library with the functionality similar to swagger-node mock mode but where a mock of request and response can be generated from an external swagger file (refers to a github link to the swagger file). I tried using the swagger-parser with dereference() function but it doesn’t give the output I want.

Example swagger snippet:

requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
              - required:
                - org
              - $ref: '#/components/schemas/Write'
schemas:

    WriteID:
      type: object
      required:
      - ID
      - name
      properties:
        ID:
          $ref: '#/components/schemas/ID'
        name:
          $ref: '#/components/schemas/name'
        description:
          description:description
          type: string
          pattern: ^[A-Z0-9&\-\.' ]{1,17}$
          maxLength: 17
          example: truck
          
 
    Write:
      allOf:
      - description: |
          example 
      - $ref: '#/components/schemas/WriteID'
      - $ref: '#/components/schemas/ReadWrite'

Example of request payload I want programmatically generated using the library:

{  "ID": "876543210",  "name": {
"first": "xyz",
"last": "abc"
}
}

 

 

Any help I can get on this is greatly appreciated