api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 875 forks source link

Swagger: unable to render this definition #4531

Closed lermontex closed 2 years ago

lermontex commented 3 years ago

API Platform version(s) affected: dev/main

Description
After merging PR #4300, I got the following error when trying to open the UI:

Unable to render this definition

The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).

Config:

symfony console debug:config api_platform

Current configuration for extension with alias "api_platform"
=============================================================

api_platform:
    mapping:
        paths:
            - '***/api/src/Entity'
    patch_formats:
        json:
            mime_types:
                - application/merge-patch+json
    swagger:
        versions:
            - 3
        api_keys:
            apiKey:
                name: Authorization
                type: header
        swagger_ui_extra_configuration: {  }
    metadata_backward_compatibility_layer: false
    openapi:
        backward_compatibility_layer: false
        contact:
            name: null
            url: null
            email: null
        termsOfService: null
        license:
            name: null
            url: null
        swagger_ui_extra_configuration: {  }
    defaults:
        route_prefix: /api
        cache_headers:
            max_age: 1
            shared_max_age: 1
    title: ''
    description: ''
    version: 0.0.0
    show_webby: true
    default_operation_path_resolver: api_platform.operation_path_resolver.underscore
    name_converter: null
    asset_package: null
    path_segment_name_generator: api_platform.path_segment_name_generator.underscore
    allow_plain_identifiers: false
    validator:
        serialize_payload_fields: {  }
        query_parameter_validation: true
    eager_loading:
        enabled: true
        fetch_partial: false
        max_joins: 30
        force_eager: true
    enable_fos_user: false
    enable_nelmio_api_doc: false
    enable_swagger: true
    enable_swagger_ui: true
    enable_re_doc: true
    enable_entrypoint: true
    enable_docs: true
    enable_profiler: true
    collection:
        exists_parameter_name: exists
        order: ASC
        order_parameter_name: order
        order_nulls_comparison: null
        pagination:
            enabled: true
            partial: false
            client_enabled: false
            client_items_per_page: false
            client_partial: false
            items_per_page: 30
            maximum_items_per_page: null
            page_parameter_name: page
            enabled_parameter_name: pagination
            items_per_page_parameter_name: itemsPerPage
            partial_parameter_name: partial
    resource_class_directories: {  }
    doctrine:
        enabled: true
    doctrine_mongodb_odm:
        enabled: false
    oauth:
        enabled: false
        clientId: ''
        clientSecret: ''
        type: oauth2
        flow: application
        tokenUrl: ''
        authorizationUrl: ''
        refreshUrl: ''
        scopes: {  }
    graphql:
        enabled: true
        default_ide: graphiql
        graphiql:
            enabled: true
        graphql_playground:
            enabled: true
        nesting_separator: _
        collection:
            pagination:
                enabled: true
    http_cache:
        etag: true
        max_age: null
        shared_max_age: null
        vary:
            - Accept
        public: null
        invalidation:
            enabled: false
            varnish_urls: {  }
            max_header_length: 7500
            request_options: {  }
            xkey:
                enabled: false
                glue: ' '
            http_tags:
                enabled: true
    mercure:
        enabled: true
        hub_url: null
    messenger:
        enabled: true
    elasticsearch:
        enabled: false
        hosts: {  }
        mapping: {  }
    maker:
        enabled: true
    exception_to_status:
        Symfony\Component\Serializer\Exception\ExceptionInterface: 400
        ApiPlatform\Exception\InvalidArgumentException: 400
        ApiPlatform\Exception\FilterValidationException: 400
        Doctrine\ORM\OptimisticLockException: 409
    formats:
        jsonld:
            mime_types:
                - application/ld+json
        json:
            mime_types:
                - application/json
        html:
            mime_types:
                - text/html
    error_formats:
        jsonproblem:
            mime_types:
                - application/problem+json
        jsonld:
            mime_types:
                - application/ld+json

I tried to specify the version in the swagger_ui_extra_configuration section - unsuccessfully

How to reproduce

  1. Run symfony composer update api-platform/core
  2. Check config
  3. Go to UI

Additional Context

https://github.com/api-platform/core/blob/2625c8159c5eac1a2721299e106a1e354aadd862/src/Core/OpenApi/OpenApi.php#L26

lermontex commented 2 years ago

I tried updating to the last commit (main branch) - the problem still persists

@LoicBoursin, @soyuka

Could you comment on this issue? Is it a misconfiguration or is it something else?

Thanks!

alanpoulain commented 2 years ago

It's because Swagger-UI doesn't support OpenAPI 3.1 yet. See https://github.com/swagger-api/swagger-ui/issues/5891.

soyuka commented 2 years ago

in the meantime we could provide a way to patch our version as this is the only blocking thing