Search code examples
phpsymfonyyamlapi-platform.com

API Platfrom - disabling swagger UI


I was trying to disable Swagger UI or more precisely as I want us to provide it only for non-prod envs.

I was referencing THIS link but, nothing is happening.

My api_platform.yaml file:

api_platform:
  defaults:
    route_prefix: '/%env(API_ROUTE)%'
    enable_docs: false
    enable_entrypoint: false
    enable_swagger_ui: false
  swagger:
    api_keys:
      JWT:
        name: Authorization
        type: header
  collection:
    pagination:
      enabled: true

Solution

  • api_platform:
      defaults:
        route_prefix: '/%env(API_ROUTE)%'
      swagger:
        api_keys:
          JWT:
            name: Authorization
            type: header
      collection:
        pagination:
          enabled: true
        
    when@prod:
        api_platform:
            enable_docs: false
            enable_entrypoint: false
            enable_swagger_ui: false
    

    your api_platform.yaml has look like this. Then your swagger is disabled only on your prod environment, if you use the environment properly.