Skip to content

Fix REST behavior for Stored Procedures when methods property is absent in the config file #1548

Merged
severussundar merged 228 commits intomainfrom
dev/shyamsundarj/bugfix-sp-handle-rest-methods-unspecified-scenario
Jul 10, 2023
Merged

Fix REST behavior for Stored Procedures when methods property is absent in the config file #1548
severussundar merged 228 commits intomainfrom
dev/shyamsundarj/bugfix-sp-handle-rest-methods-unspecified-scenario

Conversation

@severussundar
Copy link
Copy Markdown
Contributor

@severussundar severussundar commented Jun 26, 2023

Why make this change?

Sample config:

   "rest": {           
        "path": "bus-near-position"        
   }
  • Unless otherwise configured, by default, REST POST requests should be enabled for stored procedures.

What is this change?

  • EntityRestOptions: DEFAULT_SUPPORTED_VERBS_FOR_SP is added to represent the default HTTP methods supported for stored procedures
  • EntityRestOptionsConverter: Logic is modified to always populate the REST Methods as an empty array when absent in the config file. This is because, at this point, the converter cannot be aware of the entity type and hence, cannot populate different default values for tables/views vs stored procedures. The right values are populated later during the deserialization process.
  • RuntimeEntities: ProcessRestDefaults method is modified to populate the right set of supported HTTP methods based on the entity type.
  • TestSPRestDefaultsForManuallyConstructedConfigs: Integration tests for validating the REST API behavior for stored procedures for various scenarios are added.

How was this tested?

  • Integration Tests

Manual Tests:

  • REST section is completely absent in the config file.

    POST requests should be supported on the default endpoint (/api/{entity's name})

  • REST section contains only enabled field: True

    POST requests should be supported on the default endpoint (/api/{entity's name})

  • REST section contains only enabled field : False

    REST APIs should be disabled for this entity.

  • REST section contains only path element

    POST requests should be supported on the specified endpoint (/api/{path})

  • REST section contains only methods element

    Specified list of HTTP actions should be supported on the default endpoint (/api/{entity's name})

  • REST section contains both methods and path element

    Specified list of HTTP actions should be supported on the specified endpoint (/api/{path})

Finding missing types
Refactoring some type names
Simplifying the GraphQL naming by doing that when building the config, rather than on demand
Added implementation of JsonConverter.Write methods to generate an initial pass on the config file using CLI
Removed some tests that weren't testing the CLI but dependencies (such as CommandLineParser or ILogger)
…them simpler and clearer with the new object structure
Moved logic for Entities defaults to RuntimeEntities rather than deserialiser, as that is a more logical place. We always pass that type around, so we can assume the ctor ran, but we aren't always assuming the deserialiser ran (such as what happens with tests)
Copy link
Copy Markdown
Contributor

@abhishekkumams abhishekkumams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing it. just one nit.

Comment thread src/Config/ObjectModel/RuntimeEntities.cs
Comment thread src/Config/Converters/EntityRestOptionsConverter.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the extensive manual testing, looking forward to more optimal way to have automated test.

Comment thread src/Service.Tests/TestHelper.cs
@severussundar severussundar requested a review from Aniruddh25 July 7, 2023 12:03
Comment thread src/Config/ObjectModel/RuntimeEntities.cs Outdated
Comment thread src/Config/ObjectModel/EntityRestOptions.cs Outdated
Copy link
Copy Markdown
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions. Would be worth identifying path forward based on Ani's comment: not using hard coded string config file values. Now that we have the new config system, you can create configs programmatically and in your case, only change the entity under test.

@severussundar
Copy link
Copy Markdown
Contributor Author

Few questions. Would be worth identifying path forward based on Ani's comment: not using hard coded string config file values. Now that we have the new config system, you can create configs programmatically and in your case, only change the entity under test.

I considered using InitMinimalRuntimeConfig helper method in ConfigurationTests for generating the config files. There are few reasons why I decided not to use that and chose to go with hard coded config files.

a) This bug was identified by constructing the config file by hand and not through CLI.
b) This PR modifies the deserialization logic for the rest element in the config file. A direct and cleaner way to test this would be to pass the various hard coded strings that are possible and see if the deserialization works as expected. This ensures that the serialization logic does not interfere with the way we would like our test config files to be (programmatically it is not possible to generate all the cases that are possible when editing the config by hand).
For example: The scenario of not having methods in the config file at all.
Even if an Entity object (backed by a SP) is created by populating the rest methods as an empty string, finally, in the config file, it gets written out as an array with a POST element.

Considering the way this particular bug was identified; to have an exact representation of that scenario in the tests - hard coding the config file would be the way to go IMHO.

There was scope to remove some duplication by re-using the common parts of the hard coded string across all the scenarios - I have incorporated this.

Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for removing as much duplication as possible, yet preserving to test the bug scenario.

@severussundar severussundar merged commit d840baf into main Jul 10, 2023
@severussundar severussundar deleted the dev/shyamsundarj/bugfix-sp-handle-rest-methods-unspecified-scenario branch July 10, 2023 04:47
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

Successfully merging this pull request may close these issues.

[Bug]: adding the rest object in an entity, remove the default value for the "method" property

6 participants