miguelgrinberg / APIFairy

A minimalistic API framework built on top of Flask, Marshmallow and friends.
MIT License
323 stars 30 forks source link

Support for multiple server URL #65

Open hackzaid opened 2 years ago

hackzaid commented 2 years ago

Hi @miguelgrinberg I see in the core file there's support for multiple Server URLs or if I am mistaken with this line

# servers
        servers = [{'url': request.url_root}]

How do I set the second URL for instance if I want to set a sandbox and live server URL.

miguelgrinberg commented 2 years ago

You can manually edit the OpenAPI data blob in a process_apispec handler.

The documentation for the format is here. To add a server you will need to add your entry in the servers key. Something like this:

@apifairy.process_apispec
def my_apispec_processor(spec):
    spec['servers'][0]['description'] = 'Production server'
    spec['servers'].append({'url': 'https://staging.example.com', 'description': 'Staging server'})
    return spec

The first line adds a description to the main server (added by APIFairy automatically). The second line adds a second server, also with a description. The definition of what keys can be used to describe a server is here.

hackzaid commented 2 years ago

Thanks, this worked perfectly.

hackzaid commented 2 years ago

Allow me to reopen this.

So, I have set all the neccessary URL for the API.

What is required is that I want to serve the docs on a different URL and maintain the API on the set Server URLs.

According to the documentation, you can set to serve the /docs URL with this configuration APIFAIRY_UI_PATH?

miguelgrinberg commented 2 years ago

I'm sorry, but I don't understand what is the problem that needs addressing. Have you tried changing your docs URL? Is anything not working as documented?

hackzaid commented 2 years ago

Exactly, I am looking for a way on how to serve the docs on a different URL, e.g: Host the API on api.somedomain.com and then access the docs on developer.somedomain.com.

hackzaid commented 2 years ago

Not to forget, the FileField doesn't support multiple file uploads?

miguelgrinberg commented 2 years ago

You are going to have to serve your documentation yourself. Are you reading the documentation? This is all covered there: https://apifairy.readthedocs.io/en/latest/intro.html#using-a-custom-documentation-endpoint.

Not to forget, the FileField doesn't support multiple file uploads?

FileField represents one uploaded file.