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

Swagger Parser Issues #9

Open
kleozzy opened this issue Nov 30, 2020 · 8 comments
Open

Swagger Parser Issues #9

kleozzy opened this issue Nov 30, 2020 · 8 comments

Comments

@kleozzy
Copy link

kleozzy commented Nov 30, 2020

I am always getting this error on runwhich i assume it has something to do with outdated parser?
Can you fix this?

0:36:05.376 [main] ERROR c.i.a.tests.ScenariosDataProvider - Failed to get httpRequestList, for file: site_staging.yaml
java.lang.NullPointerException: null
at com.imperva.apispecparser.parsers.swagger.Swagger2Parser.getEndpointModelList(Swagger2Parser.java:52)
at com.imperva.apiattacktool.tests.AbstractTestDriver.parseSwagger(AbstractTestDriver.java:85)
at com.imperva.apiattacktool.tests.SingleValueScenarioTestDriver.getHttpRequestList(SingleValueScenarioTestDriver.java:36)
at com.imperva.apiattacktool.tests.ScenariosDataProvider.getEndpointTestRequestData(ScenariosDataProvider.java:57)
at com.imperva.apiattacktool.tests.ScenariosDataProvider.positiveScenarioDataProvider(ScenariosDataProvider.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:77)
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:46)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:146)
at org.testng.internal.Parameters.handleParameters(Parameters.java:820)
at org.testng.internal.Parameters.handleParameters(Parameters.java:762)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:60)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:39)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:771)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at com.imperva.apiattacktool.cli.ApiAttackTool.call(ApiAttackTool.java:87)
at com.imperva.apiattacktool.cli.ApiAttackTool.call(ApiAttackTool.java:13)
at picocli.CommandLine.executeUserObject(CommandLine.java:1781)
at picocli.CommandLine.access$900(CommandLine.java:145)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2139)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2106)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1973)
at picocli.CommandLine.execute(CommandLine.java:1902)
at com.imperva.apiattacktool.ToolMain.main(ToolMain.java:17)
[Utils] [ERROR] [Error] org.testng.TestNGException:
Data Provider public static java.lang.Object[][] com.imperva.apiattacktool.tests.ScenariosDataProvider.positiveScenarioDataProvider() returned a null value
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:148)
at org.testng.internal.Parameters.handleParameters(Parameters.java:820)
at org.testng.internal.Parameters.handleParameters(Parameters.java:762)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:60)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:39)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:771)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at com.imperva.apiattacktool.cli.ApiAttackTool.call(ApiAttackTool.java:87)
at com.imperva.apiattacktool.cli.ApiAttackTool.call(ApiAttackTool.java:13)
at picocli.CommandLine.executeUserObject(CommandLine.java:1781)
at picocli.CommandLine.access$900(CommandLine.java:145)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2139)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2106)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1973)
at picocli.CommandLine.execute(CommandLine.java:1902)
at com.imperva.apiattacktool.ToolMain.main(ToolMain.java:17)

@thenorthernpole
Copy link
Contributor

Thanks for reaching out.
Could you please provide the yaml file you're using?

Thanks

@Lulztigre
Copy link

I got this same error as well, and i can't seem to find any .yaml

@mercutioviz
Copy link

I also get this. Here's the yaml file I am using:

swagger: '2.0'
info:
version: '1.0.0'
title: Swagger Petstore
description: >
This is a sample Petstore server. You can find

out more about Swagger at

[http://swagger.io](http://swagger.io) or on

[irc.freenode.net, #swagger](http://swagger.io/irc/).

contact:
email: apiteam@swagger.io
host: '*'
basePath: /api/petstore/1.0.0
securityDefinitions:
api_key:
type: apiKey
description: ''
name: api_key
in: header
schemes:

  • http
  • https
    consumes:
  • application/json
    produces:
  • application/json
    paths:
    /pet:
    put:
    description: Update an existing pet
    summary: update_pet
    tags:
    - pet
    operationId: update_pet
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: body
    in: body
    required: false
    description: Pet object that needs to be added to the store
    schema:
    $ref: '#/definitions/Pet'
    responses:
    '400':
    description: Invalid ID supplied
    headers: {}
    '404':
    description: Pet not found
    headers: {}
    '405':
    description: Validation exception
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    post:
    description: Add a new pet to the store
    summary: add_pet
    tags:
    - pet
    operationId: add_pet
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: body
    in: body
    required: false
    description: Pet object that needs to be added to the store
    schema:
    $ref: '#/definitions/Pet'
    responses:
    '405':
    description: Invalid input
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    /pet/findByStatus:
    get:
    description: Multiple status values can be provided with comma separated strings
    summary: find_pets_by_status
    tags:
    - pet
    operationId: find_pets_by_status
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: status
    in: query
    required: true
    type: array
    items:
    type: string
    enum:
    - available
    - pending
    - sold
    description: Status values that need to be considered for filter
    responses:
    '200':
    description: successful operation
    schema:
    type: array
    items:
    $ref: '#/definitions/Pet'
    headers: {}
    '400':
    description: Invalid status value
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    /pet/findByTags:
    get:
    description: Muliple tags can be provided with comma separated strings. Use\ \ tag1, tag2, tag3 for testing.
    summary: find_pets_by_tags
    tags:
    - pet
    operationId: find_pets_by_tags
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: tags
    in: query
    required: true
    type: array
    items:
    type: string
    description: Tags to filter by
    responses:
    '200':
    description: successful operation
    schema:
    type: array
    items:
    $ref: '#/definitions/Pet'
    headers: {}
    '400':
    description: Invalid tag value
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    /pet/{petId}:
    get:
    description: Returns a single pet
    summary: get_pet_by_id
    tags:
    - pet
    operationId: get_pet_by_id
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: petId
    in: path
    required: true
    type: integer
    format: int64
    description: ID of pet to return
    responses:
    '200':
    description: successful operation
    schema:
    $ref: '#/definitions/Pet'
    headers: {}
    '400':
    description: Invalid ID supplied
    headers: {}
    '404':
    description: Pet not found
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    post:
    description: Updates a pet in the store with form data
    summary: update_pet_with_form
    tags:
    - pet
    operationId: update_pet_with_form
    deprecated: false
    produces:
    - application/json
    consumes:
    - application/x-www-form-urlencoded
    parameters:
    - name: petId
    in: path
    required: true
    type: integer
    format: int64
    description: ID of pet that needs to be updated
    - name: name
    in: formData
    required: false
    type: string
    description: Updated name of the pet
    - name: status
    in: formData
    required: false
    type: string
    description: Updated status of the pet
    responses:
    '405':
    description: Invalid input
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    delete:
    description: Deletes a pet
    summary: delete_pet
    tags:
    - pet
    operationId: delete_pet
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: api_key
    in: header
    required: false
    type: string
    description: ''
    - name: petId
    in: path
    required: true
    type: integer
    format: int64
    description: Pet id to delete
    responses:
    '400':
    description: Invalid ID supplied
    headers: {}
    '404':
    description: Pet not found
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    /pet/{petId}/uploadImage:
    post:
    description: uploads an image
    summary: upload_file
    tags:
    - pet
    operationId: upload_file
    deprecated: false
    produces:
    - application/json
    consumes:
    - multipart/form-data
    parameters:
    - name: petId
    in: path
    required: true
    type: integer
    format: int64
    description: ID of pet to update
    - name: body
    in: formData
    required: false
    type: file
    format: file
    description: ''
    responses:
    '200':
    description: successful operation
    schema:
    $ref: '#/definitions/ApiResponse'
    headers: {}
    security:
    - api_key:
    - ''
    - ''
    /store/inventory:
    get:
    description: Returns a map of status codes to quantities
    summary: get_inventory
    tags:
    - store
    operationId: get_inventory
    deprecated: false
    produces:
    - application/json
    parameters: []
    responses:
    '200':
    description: successful operation
    schema:
    type: object
    additionalProperties:
    type: integer
    format: int32
    headers: {}
    /store/order:
    post:
    description: Place an order for a pet
    summary: place_order
    tags:
    - store
    operationId: place_order
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: body
    in: body
    required: true
    description: order placed for purchasing the pet
    schema:
    $ref: '#/definitions/Order'
    responses:
    '200':
    description: successful operation
    schema:
    $ref: '#/definitions/Order'
    headers: {}
    '400':
    description: Invalid Order
    headers: {}
    /store/order/{orderId}:
    get:
    description: For valid response try integer IDs with value >= 1 and <= 10.\ \ Other values will generated exceptions
    summary: get_order_by_id
    tags:
    - store
    operationId: get_order_by_id
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: orderId
    in: path
    required: true
    type: integer
    format: int64
    minimum: 1
    maximum: 10
    exclusiveMaximum: false
    exclusiveMinimum: false
    description: ID of pet that needs to be fetched
    responses:
    '200':
    description: successful operation
    schema:
    $ref: '#/definitions/Order'
    headers: {}
    '400':
    description: Invalid ID supplied
    headers: {}
    '404':
    description: Order not found
    headers: {}
    delete:
    description: For valid response try integer IDs with positive integer value.\ \ Negative or non-integer values will generate API errors
    summary: delete_order
    tags:
    - store
    operationId: delete_order
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: orderId
    in: path
    required: true
    type: integer
    format: int64
    minimum: 1
    exclusiveMinimum: false
    description: ID of the order that needs to be deleted
    responses:
    '400':
    description: Invalid ID supplied
    headers: {}
    '404':
    description: Order not found
    headers: {}
    /user:
    post:
    description: This can only be done by the logged in user.
    summary: create_user
    tags:
    - user
    operationId: create_user
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: body
    in: body
    required: true
    description: Created user object
    schema:
    $ref: '#/definitions/User'
    responses:
    '200':
    description: successful operation
    headers: {}
    /user/createWithArray:
    post:
    description: Creates list of users with given input array
    summary: create_users_with_array_input
    tags:
    - user
    operationId: create_users_with_array_input
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: body
    in: body
    required: true
    description: List of user object
    schema:
    type: array
    items:
    $ref: '#/definitions/User'
    responses:
    '200':
    description: successful operation
    headers: {}
    /user/createWithList:
    post:
    description: Creates list of users with given input array
    summary: create_users_with_list_input
    tags:
    - user
    operationId: create_users_with_list_input
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: body
    in: body
    required: true
    description: List of user object
    schema:
    type: array
    items:
    $ref: '#/definitions/User'
    responses:
    '200':
    description: successful operation
    headers: {}
    /user/login:
    get:
    description: Logs user into the system
    summary: login_user
    tags:
    - user
    operationId: login_user
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: username
    in: query
    required: true
    type: string
    description: The user name for login
    - name: password
    in: query
    required: true
    type: string
    description: The password for login in clear text
    responses:
    '200':
    description: successful operation
    schema:
    type: string
    headers:
    X-Rate-Limit:
    description: calls per hour allowed by the user
    type: string
    X-Expires-After:
    description: date in UTC when token expires
    type: string
    '400':
    description: Invalid username/password supplied
    headers: {}
    /user/logout:
    get:
    description: Logs out current logged in user session
    summary: logout_user
    tags:
    - user
    operationId: logout_user
    deprecated: false
    produces:
    - application/json
    parameters: []
    responses:
    '200':
    description: successful operation
    headers: {}
    /user/{username}:
    get:
    description: Get user by user name
    summary: get_user_by_name
    tags:
    - user
    operationId: get_user_by_name
    deprecated: false
    produces:
    - application/json
    - application/xml
    parameters:
    - name: username
    in: path
    required: true
    type: string
    description: The name that needs to be fetched. Use user1 for testing.
    responses:
    '200':
    description: successful operation
    schema:
    $ref: '#/definitions/User'
    headers: {}
    '400':
    description: Invalid username supplied
    headers: {}
    '404':
    description: User not found
    headers: {}
    put:
    description: This can only be done by the logged in user.
    summary: update_user
    tags:
    - user
    operationId: update_user
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: username
    in: path
    required: true
    type: string
    description: name that need to be updated
    - name: body
    in: body
    required: true
    description: Updated user object
    schema:
    $ref: '#/definitions/User'
    responses:
    '400':
    description: Invalid user supplied
    headers: {}
    '404':
    description: User not found
    headers: {}
    delete:
    description: This can only be done by the logged in user.
    summary: delete_user
    tags:
    - user
    operationId: delete_user
    deprecated: false
    produces:
    - application/json
    parameters:
    - name: username
    in: path
    required: true
    type: string
    description: The name that needs to be deleted
    responses:
    '400':
    description: Invalid username supplied
    headers: {}
    '404':
    description: User not found
    headers: {}
    definitions:
    Order:
    title: Order
    type: object
    properties:
    id:
    type: integer
    format: int64
    petId:
    type: integer
    format: int64
    transactionDetailsId:
    type: integer
    format: int64
    username:
    type: string
    shipDate:
    type: string
    format: date-time
    status:
    $ref: '#/definitions/Status'
    complete:
    example: false
    type: boolean
    default: false
    Category:
    title: Category
    type: object
    properties:
    id:
    type: integer
    format: int64
    name:
    type: string
    User:
    title: User
    type: object
    properties:
    id:
    type: integer
    format: int64
    username:
    type: string
    firstName:
    type: string
    lastName:
    type: string
    email:
    type: string
    password:
    type: string
    phone:
    type: string
    userStatus:
    description: User Status
    type: integer
    format: int32
    Tag:
    title: Tag
    type: object
    properties:
    id:
    type: integer
    format: int64
    name:
    type: string
    Pet:
    title: Pet
    type: object
    properties:
    id:
    type: integer
    format: int64
    category:
    $ref: '#/definitions/Category'
    name:
    type: string
    photoUrls:
    xml:
    name: photoUrl
    attribute: false
    wrapped: true
    type: array
    items:
    type: string
    tags:
    xml:
    name: tag
    attribute: false
    wrapped: true
    type: array
    items:
    $ref: '#/definitions/Tag'
    status:
    $ref: '#/definitions/Status1'
    required:
    • name
    • photoUrls
      ApiResponse:
      title: ApiResponse
      example:
      code: 0
      type: type
      message: message
      type: object
      properties:
      code:
      type: integer
      format: int32
      type:
      type: string
      message:
      type: string
      body:
      title: body
      type: object
      properties:
      name:
      description: Updated name of the pet
      type: string
      status:
      description: Updated status of the pet
      type: string
      Status:
      title: Status
      description: Order Status
      type: string
      enum:
    • placed
    • approved
    • delivered
      Status1:
      title: Status1
      description: pet status in the store
      type: string
      enum:
    • available
    • pending
    • sold
      status2:
      title: status2
      type: string
      enum:
    • available
    • pending
    • sold
      security:
  • api_key: []
    tags:
  • name: pet
    description: Everything about your Pets
    externalDocs:
    url: http://swagger.io
    description: Find out more
  • name: store
    description: Access to Petstore orders
  • name: user
    description: Operations about user
    externalDocs:
    url: http://swagger.io
    description: Find out more about our store
    externalDocs:
    url: http://swagger.io
    description: Find out more about Swagger

@0xabdi
Copy link

0xabdi commented Jul 29, 2021

Getting the same error. How did fix this?

@HeyThisHaku
Copy link

I got same error, but I was fix with this converter: https://editor.swagger.io/

Import ur swagger.json or yaml .json
after u import, try to export to yaml
after that, check your yaml file make sure first line is:

'swagger: [version]' because my problem the first line is not swagger but 'openfile:[version]'

@AnjiB
Copy link

AnjiB commented Jun 1, 2023

I am getting the same issue even after I added the first line as swagger: 3.0.1

@thenorthernpole
Copy link
Contributor

@AnjiB and all, the parser currently supports only Swagger 2.

@sertal70
Copy link

@thenorthernpole Maybe it could be worth spending 2 mins to add this valuable information in the README, just to help people to avoid wasting time to download, compile and run the tool on an unsupported OpenAPI specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants