Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Creating an API as a 2nd level namespace #239

Open
str opened this issue Oct 31, 2014 · 10 comments
Open

Creating an API as a 2nd level namespace #239

str opened this issue Oct 31, 2014 · 10 comments

Comments

@str
Copy link

str commented Oct 31, 2014

I tried to create an API named "MyVendor\Api" so all files will be created inside the /module/MyVendor/Api/src folder, but calling the API that way, I get the following error message:

name: The API name must be a valid PHP namespace

@TomHAnderson
Copy link
Contributor

You, "Dr., it hurts when I do this"
Dr., "Then don't do that"

I prefer to name my 'main' module LikeThis and my API for the 'main api' LikeThisApi.

@str
Copy link
Author

str commented Nov 2, 2014

@TomHAnderson, I don't follow.You mean "then don't use vendor namespaces"? When you say "I prefer" it means one should be able to choose. Currently, I'm not able to choose.

@TomHAnderson
Copy link
Contributor

The file structure idea you're using of organizing modules as ModuleName/Subpart/src is incorrect. The proper way to handle this is ModuleName/src/ModuleName/Subpart/...

An excellent example of doing this is https://github.com/zfcampus/zf-apigility-doctrine where I use two modules in the same project namespace. See the /src directory for the bifurcation.

@TomHAnderson
Copy link
Contributor

See the Recommended Structure for modules here: http://framework.zend.com/manual/2.0/en/modules/zend.module-manager.intro.html

Take note there are not multiple instances of a /src directory for a module; just 1.

@str
Copy link
Author

str commented Nov 2, 2014

@TomHAnderson I'm not suggesting changing the module file structure, there is no "subpart", following your example, the src would be inside VendorName/ModuleName/src

The documentation for ZF says "The name of a module in a typical Zend Framework 2 application is simply a PHP namespace and must follow all of the same rules for naming." So, \Vendor\And\Any\Number\Of\Levels\Before\The\Module is a valid namespace. Even Apigility modules are inside the "ZF" vendor namespace ('ZF\Apigility', 'ZF\Apigility\Provider', 'ZF\Apigility\Documentation')

If I would like to have both your API and my API modules in the same proyect, it would be possible if they were in a different namespace, like having your's in /modules/TomHAnderson/MyApi and mine at /modules/Str/MyApi.

@basz
Copy link

basz commented Jun 9, 2015

Hello,

Today I performed some test showing namespaces API modules is possible - as far as I can tell the UI needs to be updated in a few places to support this. Ofcourse this was a quick test so perhaps it is more complicated than it seems. I'm using apigility 1.1.x

What I did was create an API called 'MyApi'. Added some REST stuff to it so I know it works, even configured some fields.

Then I manually moved the whole modules/MyApi to modules/My/Api and updated every class. Updated the application config to use the namespace module. And updated the configuration files in the MyApi module to reflect these changes.

Then I retested the API, which still worked as expected. (yee) I then reloaded the UI and the API showed up as 'My.Api' in the API list. The main settings page of it loaded fine - however accessing any TAB's such as fields gave me an error. The err is that it can't find the API 'My.Api' which could be expected as the endpoints' probably aren't capable of translating 'My.Api' into 'My/Api'.

I for one would love to see apigility capable of namespaced API's.

@viniciusgava
Copy link

Hello @basz, I am with the same problem, I did the same thing of you, I created the API and move it to the module, but when I tried create a new service the apigility does not follow the project struct.

In my case I need 3rd level namespace:

Bellow some examples:
ClientAPI/Customer/User
ClientAPI/Customer/Address
ClientAPI/Consumer/Checkout
BackStoreAPI/Customer/Consume
BackStoreAPI/Customer/User

Did you found a solution?

@merlindorin
Copy link

@basz thx for this introspection :D. FYI, I usually have sub namespace (in prod) and there is absolutely no pb (there are tested). So we let the ui down because in fact, it's a discovery tool ^^ :P

@snapshotpl
Copy link

Same issue here 😿

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-admin; a new issue has been opened at laminas-api-tools/api-tools-admin#40.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants