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

Web Api interface generation #586

Merged

Conversation

bohdan-harniuk
Copy link
Collaborator

Description (*)
This PR adds the generation of a Web API interface for a service.

What was done:

  1. generation of a Web API interface for a service.
  2. added possibility to choose one or more methods to be included in an interface
  3. added possibility to choose interface name and change its description (default one is taken from the service)
  4. all methods short description taken from the service methods (or default TODO, that asks to add short description)
  5. implements added for a service
  6. implements class imported in use block for a service
  7. all included in interface methods annotations replaced with @inheritdoc annotations.
  8. added test case to test simple service with primitive types
  9. added test case to test simple service with Object types
  10. testing for inserting @inheritdoc annotations
  11. testing for an interface implemented by a service
  12. testing for interface FQN added in an import (use) block

Service to add Web Api interface:
Screenshot 2021-05-03 at 13 45 47

Open the context menu on it and choose Web API interface generation action:
Screenshot 2021-05-03 at 13 47 31

Choose methods to include in the interface, change default name and description:
Screenshot 2021-05-03 at 13 48 17
Screenshot 2021-05-03 at 13 48 56

Results:
Screenshot 2021-05-03 at 13 49 25
Screenshot 2021-05-03 at 13 50 09
Screenshot 2021-05-03 at 13 51 37

Questions or comments
To get generated Doc Annotations beautiful, go to the Preferences... > Editor > Code Style > PHP > PHPDoc > Blank lines around parameters and activate this configuration.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with integration/functional tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Copy link
Contributor

@eduard13 eduard13 left a comment

Choose a reason for hiding this comment

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

Hi @bohdan-harniuk, thank you for your contribution. Could you please rename all the visible text occurrences of Api to API, since API is an acronym and should be correctly used. Below you may see couple of places, but would be good to change it on every place that is visible to the user.

Also, can we exclude these API generators for Test/ or probably *Test.php files, in order to not overload the context menu? I don't see any use case, when we have to create an API for any kind of tests.

Thank you.

Comment on lines +266 to +267
<internalFileTemplate name="Magento Web Api XML"/>
<internalFileTemplate name="Web Api Interface"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<internalFileTemplate name="Magento Web Api XML"/>
<internalFileTemplate name="Web Api Interface"/>
<internalFileTemplate name="Magento Web API XML"/>
<internalFileTemplate name="Web API Interface"/>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Api For Class"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<text value="Api For Class"/>
<text value="API For Class"/>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@bohdan-harniuk
Copy link
Collaborator Author

Thank you, @eduard13, for the great findings! I've fixed them.

Screenshot 2021-05-05 at 10 57 38

Copy link
Contributor

@eduard13 eduard13 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 your contribution 👍

@eduard13 eduard13 merged commit 7540082 into magento:4.0.0-develop May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants