Skip to content

OpenAPI document resolves custom configured REST path#1653

Merged
seantleonard merged 3 commits intomainfrom
dev/seleonar/openapi_restcustompath_patch
Aug 25, 2023
Merged

OpenAPI document resolves custom configured REST path#1653
seantleonard merged 3 commits intomainfrom
dev/seleonar/openapi_restcustompath_patch

Conversation

@seantleonard
Copy link
Copy Markdown
Contributor

Why make this change?

  • Closes [Bug]: Wrong REST path generated in OpenAPI spec #1633
    • The wrong 'path' value is generated in the OpenAPI description document created. This was observed when looking at the /swagger endpoint to see the REST endpoint documentation.
    • When an entity's REST path property is explicitly set AND includes a starting slash /, the openapidocumentor does not properly create the PATH used to access the entity in the REST endpoint.

What is this change?

  • Correctly process an entity's REST path configuration. Before this change, the method at fault was improperly calling Substring() on the wrong variable. Although the variable was previously restPath, the value at the time of calling substring was the top-level entity name which did not have a starting slash /.
  • The variable restPath is modified depending on whether the entity has explicit rest path config. If no explicit rest path is configured, the top level entity name is returned as the resolved rest path.
  • Now, calling entityRestSettings.Path.TrimStart('/') will correctly remove a starting slash IF one exists. This accommodates the following formatting of the explicit rest path:
  1. /customRestPath
  2. customRestPath
  3. //customRestPath -> while this option is not advisable to use in practice, we still support it and this PR is not meant to change that behavior. But for complete test coverage, this case is tested.

How was this tested?

  • Integration Tests

…umentor. Removed usage of substring and instead use Trim().
Comment thread src/Service.Tests/OpenApiDocumentor/StoredProcedureGeneration.cs
Comment thread src/Service.Tests/OpenApiDocumentor/OpenApiTestBootstrap.cs
Comment thread src/Core/Services/OpenAPI/OpenApiDocumentor.cs
Comment thread src/Service.Tests/OpenApiDocumentor/OpenApiTestBootstrap.cs Outdated
Comment thread src/Service.Tests/OpenApiDocumentor/PathValidation.cs
Comment thread src/Service.Tests/OpenApiDocumentor/PathValidation.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.

Thanks for the quick investigation and fix! Few questions, but otherwise LGTM.

…omments to reflect expected input and output of formatting the rest path in openapi documentor. Updated test variable name to more concisely reflect test parameter purpose -> `configuredRestPath`
Copy link
Copy Markdown
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@seantleonard seantleonard enabled auto-merge (squash) August 25, 2023 22:58
@seantleonard seantleonard merged commit 31a0e7d into main Aug 25, 2023
@seantleonard seantleonard deleted the dev/seleonar/openapi_restcustompath_patch branch August 25, 2023 23:11
seantleonard added a commit that referenced this pull request Aug 25, 2023
## Why make this change?

- Closes #1633
- The wrong 'path' value is generated in the OpenAPI description
document created. This was observed when looking at the `/swagger`
endpoint to see the REST endpoint documentation.
- When an entity's REST path property is explicitly set AND includes a
starting slash `/`, the openapidocumentor does not properly create the
PATH used to access the entity in the REST endpoint.

## What is this change?

- Correctly process an entity's REST path configuration. Before this
change, the method at fault was improperly calling `Substring()` on the
wrong variable. Although the variable was previously `restPath`, the
value at the time of calling substring was the top-level entity name
which did not have a starting slash `/`.
- The variable `restPath` is modified depending on whether the entity
has explicit rest path config. If no explicit rest path is configured,
the top level entity name is returned as the resolved rest path.
- Now, calling `entityRestSettings.Path.TrimStart('/')` will correctly
remove a starting slash IF one exists. This accommodates the following
formatting of the explicit rest path:

1. `/customRestPath`
2. `customRestPath`
3. `//customRestPath` -> while this option is not advisable to use in
practice, we still support it and this PR is not meant to change that
behavior. But for complete test coverage, this case is tested.

## How was this tested?

- [x] Integration Tests
seantleonard added a commit that referenced this pull request Aug 25, 2023
…or 0.8 release) (#1658)

Cherry Picks commit from #1653 to 0.8 release branch as a patch.
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]: Wrong REST path generated in OpenAPI spec

3 participants