Skip to content

Developed web api xml file generation, web api xml declaration generation, improved action development experience, added PhpPsiElementsUtil #548

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

Merged

Conversation

bohdan-harniuk
Copy link
Collaborator

@bohdan-harniuk bohdan-harniuk commented Apr 15, 2021

Description (*)
The main purpose of this PR is to generate web api xml declaration for a service. Generation action is accessible from the context menu if you click on the public method name. Also, it is required for the class to have @api declaration in the annotation. Also, added test for testing this generation.

Screenshot 2021-04-15 at 10 38 15

Screenshot 2021-04-15 at 10 38 33

Screenshot 2021-04-15 at 10 39 25

Screenshot 2021-04-15 at 10 39 48

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)

final PhpDocComment classDocComment = method.getContainingClass().getDocComment();

if (!method.getAccess().isPublic()
|| method.getName().equals("__construct")
Copy link
Contributor

Choose a reason for hiding this comment

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

We have the same string literal here: com.magento.idea.magento2plugin.magento.files.Plugin#CONSTRUCT_METHOD_NAME
Could you please put them in some unified place?

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.

private final String aclResource;

/**
* Web Api xml declaration DTO constructor.
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
* Web Api xml declaration DTO constructor.
* Web API XML declaration DTO constructor.

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

for (final String method : HttpMethod.getHttpMethodList()) {
httpMethod.addItem(new ComboBoxItemData(method, method));
}
aclResource = new FilteredComboBox(new LinkedList<>(Arrays.asList("self", "anonymous")));
Copy link
Contributor

Choose a reason for hiding this comment

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

"self", "anonymous" should be moved to an enum

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.

public class NewWebApiDeclarationAction extends AnAction {

public static final String ACTION_NAME = "Create a new WebApi declaration for this method";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 WebApi XML declaration";
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
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 WebApi XML declaration";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Web API XML declaration";

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.


public class NewWebApiDeclarationAction extends AnAction {

public static final String ACTION_NAME = "Create a new WebApi declaration for this method";
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
public static final String ACTION_NAME = "Create a new WebApi declaration for this method";
public static final String ACTION_NAME = "Create a new Web API declaration for this method";

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.

}

/**
* Generate WEB API xml declaration.
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
* Generate WEB API xml declaration.
* Generate Web API XML declaration.

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 bohdan-harniuk force-pushed the entity-web-api-generation branch from 055c105 to 41abad4 Compare April 19, 2021 10:10
@bohdan-harniuk
Copy link
Collaborator Author

@VitaliyBoyko Requested changes implemented.

Thank you!

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, really good feature.
Additionally, I'm thinking if it worth having some more resource than anonymous an self. Since we create our own resources via EntityManager, maybe it also makes sense to list all the available resources?
cc. @VitaliyBoyko

@VitaliyBoyko
Copy link
Contributor

Hi @eduard13

I thought about it either.
Let's keep it as it is for the MVP and then extend it with all ACLs. To not overcomplicate this PR.

@bohdan-harniuk
Copy link
Collaborator Author

Hello, @VitaliyBoyko ! Thank you for your good suggestion about a useless mandatory requirement to have @api in the class doc. I removed it. Now it looks better.
Thank you!

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.

4 participants