Swagger-php: How can make swagger api documentation for multiple client in one project

Created on 27 Jun 2020  路  10Comments  路  Source: zircote/swagger-php

Hi!

I want to make api document for multiple client with the help of swagger

i have api's and want some api can access for public and some will private client and they will access only their api's endpoint and will use

Can you give me the best suggestion or example so that could solve my problem with the help of you

Thanks in advance

All 10 comments

you can select the files it scans to generate documentation yourself. See OpenApi\scan(): https://github.com/zircote/swagger-php/blob/master/src/functions.php#L34

So you could run the scan twice (or more) with different sets of files.

If you need more control and have public/private code mixed (model classes might be good candidate for that...) you could consider using tags and filtering the final document.

A full blown solution would be to:

  1. tag endpoints
  2. add a custom processor to filter by tag(s)
  3. potenitally add another processor to remove unused schema (models...) unless those are tagged too

Bro one more question can you help me i stuck in in last 1 days i want to upload a multipart/form-data file in application/json array can you help i have upload a code that i want to when generate then have not any error but not shown any file part in json array

you can see my code

/**
* @OA\Post(
*      path="/products/save",
*      tags={"Product"},
*      summary="Post bulk products",
*      description="Return bulk products",
*      @OA\RequestBody(
*       required=true,
*       description="Bulk products Body",
*       @OA\JsonContent(
*           @OA\Property(
*               property="products",
*               @OA\Items(
*                  @OA\Property(property="first_name", type="string"),
*                  @OA\Property(property="last_name", type="string"),
*                  @OA\Property(property="email", type="string"),
*                  @OA\Property(property="phone", type="string"),
*                  @OA\MediaType(
*                       mediaType="multipart/form-data",
*                       @OA\Schema(
*                           @OA\Property(
*                               property="resume",
*                               type="file",
*                               format="file"
*                           ),
*                       )
*                  )
*               ),
*           )
*       )
*     ),
* )
*/

That is not possible. Either the endpoint is application/json or multipart/form-data. If your body should contain the content of a file in JSON then you could put the base64 encoded binary source in the JSON.

That is not possible. Either the endpoint is application/json or multipart/form-data. If your body should contain the content of a file in JSON then you could put the base64 encoded binary source in the JSON.

Thanks @Doqnach bro .. for replying me Can you help me about this problem
How can send base64 format in application/json array i want to send a base64 format in application/json i have this code
you can see my code

/**
* @OA\Post(
*      path="/products/save",
*      tags={"Product"},
*      summary="Post bulk products",
*      description="Return bulk products",
*      @OA\RequestBody(
*       required=true,
*       description="Bulk products Body",
*       @OA\JsonContent(
*           @OA\Property(
*               property="products",
*               @OA\Items(
*                  @OA\Property(property="first_name", type="string"),
*                  @OA\Property(property="last_name", type="string"),
*                  @OA\Property(property="email", type="string"),
*                  @OA\Property(property="phone", type="string"),
*                  @OA\Property(property="resume", type="string", format="byte")
*               ),
*           )
*       )
*     ),
* )
*/

I'm using this code but not luck is not working for me can you give me an example from my code so that i could solve problem

I want to this type of array in swagger-ui
` { "products": [ { "first_name": "string", "last_name": "string", "email": "string", "phone": "string", "resume": "string" => here i will send base64 format of resume file } ] }

Not sure that is possible - string is string, in particular in a JSON object.

IIRC there is a JSON editor in swagger-ui but I am not sure if that would support this use case. If you are conviced this should work in the UI then maybe raise this with them to start with.

Should it be supported I'd be keen to see that in action. Having the actual JSON/YAML definition that would work in the UI might be the way to start and then we could work our way backwards to some annotations.

So, the annotation example result in a valid operation - how the UI interprets this is outside of the scope of swagger-php.

@jeff-cmyk what you are showing is not actual functioning "code". This is only documentation that SwaggerPHP will parse to generate a spec. It does not do any execution of any form, unless you have some other library that provides that functionality.

SwaggerUI does not have any support for uploading files as far as I am aware. But that would be a question for them and not here in this repo.

Not sure that is possible - string is string, in particular in a JSON object.

IIRC there is a JSON editor in swagger-ui but I am not sure if that would support this use case. If you are conviced this should work in the UI then maybe raise this with them to start with.

Should it be supported I'd be keen to see that in action. Having the actual JSON/YAML definition that would work in the UI might be the way to start and then we could work our way backwards to some annotations.

So, the annotation example result in a valid operation - how the UI interprets this is outside of the scope of swagger-php.

Thansk @DerManoMann brother for replying me ,
Bro i have a base64 format file which want to send in json array of product or any other sulotion which will help for this
becuase i have a base64 format in json array

@jeff-cmyk what you are showing is not actual functioning "code". This is only documentation that SwaggerPHP will parse to generate a spec. It does not do any execution of any form, unless you have some other library that provides that functionality.

SwaggerUI does not have any support for uploading files as far as I am aware. But that would be a question for them and not here in this repo.

Thanks @Doqnach for replying
I don't understand that we can't upload file swagger-php... bro we are upload files with the help of swagger-php and swagger-ui

My point is that you are exclusively showing documentation... you are not giving any actual code.

A client (e.g. browser, some server-to-server, etc) can send the contents of the file either using a multipart/form-data (https://swagger.io/docs/specification/describing-request-body/file-upload/) or by reading the content of the file and putting it as base64 into a JSON document. Swagger-UI supports the first one (form-data) but not the second one.

Another option could be multipart/mixed: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#encodingObject

I will reiterate again: SwaggerPHP only provides documentation for an API. It does not, in any way, provide any functional code for handling requests.

Was this page helpful?
0 / 5 - 0 ratings