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

Implement Autocomplete of OAS3 with 3scale account data #1935

Merged
merged 7 commits into from
Jun 17, 2020

Conversation

damianpm
Copy link
Contributor

@damianpm damianpm commented May 29, 2020

What this PR does / why we need it:

Implements autocomplete of OAS 3 using 3scale account data

Which issue(s) this PR fixes

https://issues.redhat.com/browse/THREESCALE-4857

Notes

This PR is an alternative to #1863

#1863 uses the plugins system of swagger ui to wrap and modify the components.

This PR uses a different approach: intercepts the response, injects the data to autocomplete and leaves swagger-ui do the rendering.
See responseInterceptor in https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/

PROS:

  • Cleaner code
  • No DOM manipulation
  • No need to maintain wrapped components
  • It uses swagger default ui components

CONS:

  • If some examples are already in the specification, they will be overwritten.
    I don't think it's a great problem, as we are autocompleting only the parameters using 3scale acccount data (from /p/admin/api_docs/account_data.json endpoint.).

autocomplete

Steps to reproduce

  • Go to a Service's active docs section: apiconfig/services/2/api_docs
  • Create a new spec using OAS v3 (you can use this example)
  • Update the following templates at Dev Portal's Content section: /p/admin/cms/templates
    Documentation
<h1>Documentation</h1>

<p>Use our live documentation to learn about the Echo API</p>

{% content_for javascripts %}
    {{ 'active_docs.js' | javascript_include_tag }}
{% endcontent_for %}

{% include 'shared/swagger_ui' %}

shared/swagger_ui:

Replace the <script></script> section at the end of the document with:

<script type="text/javascript">
  (function () {
    var url = "{{provider.api_specs.first.url}}";
    var accountDataUrl = '/api_docs/account_data.json'


    SwaggerUI({
      url: url,
      responseInterceptor: function(response){return autocompleteOAS3(response, accountDataUrl)},
      dom_id: '#swagger-ui-container',
      supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
      apisSorter: 'alpha', // can also be a function
      operationsSorter: 'method', // can also be 'alpha' or a function
      docExpansion: 'list',
      transport: function (httpClient, obj) { ApiDocsProxy.execute(httpClient, obj) }
      });
  }());
</script>

@damianpm damianpm changed the base branch from master to THREESCALE-4212-OAS-ActiveDocs_features May 29, 2020 14:59
@damianpm damianpm changed the base branch from THREESCALE-4212-OAS-ActiveDocs_features to master May 29, 2020 15:00
@damianpm damianpm changed the title [POC] Autocomplete OAS3 with 3scale account data [POC] Autocomplete OAS3 with 3scale account data - 2 May 29, 2020
@damianpm damianpm changed the base branch from master to THREESCALE-4212-OAS-ActiveDocs_features June 1, 2020 09:00
@didierofrivia
Copy link
Member

Could you point this to master in order to see all the changes?

@damianpm damianpm changed the base branch from THREESCALE-4212-OAS-ActiveDocs_features to master June 3, 2020 07:29
@damianpm
Copy link
Contributor Author

damianpm commented Jun 3, 2020

Could you point this to master in order to see all the changes?

@didierofrivia
Done!

@damianpm
Copy link
Contributor Author

damianpm commented Jun 3, 2020

@josemigallas @didierofrivia
then you agree this is a better option than #1863 ?

@josemigallas
Copy link
Contributor

@josemigallas @didierofrivia
then you agree this is a better option than #1863 ?

It looks simpler and better

@didierofrivia
Copy link
Member

I think this is the right path to follow, you can close #1863 if you want 👍

@damianpm damianpm force-pushed the THREESCALE-4212-OAS-ActiveDocs_features-B branch 2 times, most recently from c9ffdd1 to c57cecc Compare June 4, 2020 13:04
Copy link
Member

@didierofrivia didierofrivia left a comment

Choose a reason for hiding this comment

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

I left a final minor comment, but the most important thing is that it matches the current behaviour 100%. If that's the case, it's good to go!

@damianpm damianpm force-pushed the THREESCALE-4212-OAS-ActiveDocs_features-B branch 3 times, most recently from 4b19b5a to 8d3a4ef Compare June 16, 2020 11:14
@damianpm damianpm force-pushed the THREESCALE-4212-OAS-ActiveDocs_features-B branch from 8d3a4ef to 0acec6a Compare June 16, 2020 17:36
Copy link
Member

@didierofrivia didierofrivia left a comment

Choose a reason for hiding this comment

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

Squash the commits before merging.

@thomasmaas
Copy link
Member

@damianpm be carefull to reference the correct jira in branch name. as now parent issue was moved to ready for testing

damianpm added a commit that referenced this pull request Jun 24, 2020
damianpm added a commit that referenced this pull request Jun 24, 2020
@damianpm damianpm added the javascript Pull requests that update Javascript code label Jan 25, 2021
@hallelujah hallelujah deleted the THREESCALE-4212-OAS-ActiveDocs_features-B branch September 2, 2021 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants