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

Wrong dynamic name/variable dependency in compiling output #910

Open
HangyiWang opened this issue Aug 23, 2024 · 2 comments
Open

Wrong dynamic name/variable dependency in compiling output #910

HangyiWang opened this issue Aug 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@HangyiWang
Copy link

HangyiWang commented Aug 23, 2024

Description

When I run restler compile to generate grammar files, it creates a wrong dynamic dependency on one of the API requests so restler has to create another unrelated resource before that request.

Steps to reproduce

This is the partial resource definitions for my PUT /api/assets/{assetName}.

AssetProperties:
    properties:
      assetEndpointProfileRef:
        type: string
      attributes:
        additionalProperties: {}
        type: object
      datasets:
        items:
          $ref: '#/definitions/AssetDataset'
        type: array
      defaultDatasetsConfiguration:
        type: string
      defaultEventsConfiguration:
        type: string
      defaultTopic:
        $ref: '#/definitions/Topic'
...
AssetDataset:
    properties:
      dataPoints:
        items:
          $ref: '#/definitions/AssetDataPoint'
        type: array
      datasetConfiguration:
        type: string
      name:
        type: string
      topic:
        $ref: '#/definitions/Topic'
    type: object
AssetDataPoint:
    properties:
      capabilityId:
        type: string
      dataPointConfiguration:
        type: string
      dataSource:
        type: string
      name:
        type: string
      observabilityMode:
        type: string
    type: object

I also have another path called PUT /api/datasets/{datasetName}, which does nothing with the assets API.

But in assets request in grammar.py, I saw _api_datasets__datasetName__put_name.reader() which comes from the dataset creation API. Look at the name under datasetConfiguration. It should be a simple string.

primitives.restler_static_string(""",
            "datasets":
            [
                {
                    "dataPoints":
                    [
                        {
                            "capabilityId":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
                            "dataPointConfiguration":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
                            "dataSource":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
                            "name":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
                            "observabilityMode":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string("""
                        }
                    ],
                    "datasetConfiguration":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
                    "name":"""),
    primitives.restler_static_string(_api_datasets__datasetName__put_name.reader(), quoted=True),
    primitives.restler_static_string(""",
                    "topic":
                        {
                            "path":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
                            "retain":"""),
    primitives.restler_fuzzable_bool("true"),
    primitives.restler_static_string("""
                        }
                }
            ],
            "defaultDatasetsConfiguration":"""),
    primitives.restler_fuzzable_string("fuzzstring", quoted=True),
    primitives.restler_static_string(""",
            "defaultEventsConfiguration":"""),

If I remove /api/datasets/{datasetName} in my swagger input, restler generates correct file.

And I didn't set any producer/consumer relationships in my annotation file.

Expected results

_api_datasets__datasetName__put_name.reader() should be a simple fuzz string.

Actual results

_api_datasets__datasetName__put_name.reader() comes from a wrong restler logic?

Environment details

  • OS: WSL Ubuntu
  • Python 3.10.12
  • 8.0.108
  • RESTler version: 9.2.4
@HangyiWang HangyiWang changed the title Wrong dynamic dependency in compiling output Wrong dynamic name/variable dependency in compiling output Aug 23, 2024
@marina-p marina-p self-assigned this Aug 26, 2024
@marina-p marina-p added the bug Something isn't working label Aug 26, 2024
@marina-p
Copy link
Contributor

Hello @HangyiWang,

This issue is due to imprecision in one of the heuristics in RESTler for identifying dependencies. If these names should simply be arbitrary strings, adding the following to the dictionary should resolve the incorrect dependencies in the grammar (or adding a custom payload generator for the strings if the names must be unique):

  "restler_custom_payload": {

    "/properties/datasets/[0]/name": ["any", "string"],
    "/properties/status/datasets/[0]/name": ["any", "string"]

  },

Unfortunately, this same imprecision could impact new APIs with a similar naming pattern in the body and those new properties would need to be added similarly to the above. (Please keep this issue open to track improving the dependency analysis to fix the root cause).

Thanks,

Marina

@HangyiWang
Copy link
Author

Thanks!

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