Generated Swagger.json Does Not Validate with Swagger Editor

Created on 7 February 2021, over 3 years ago
Updated 3 March 2024, 4 months ago

Problem/Motivation

We have a fairly stock Drupal site that was just installed earlier today, and we are trying to get this module to generate Swagger/OpenAPI documentation for Drupal's JSON:API interface. We are finding that the swagger.json file that this module generates is not completely accepted by the Swagger Editor and related tools -- there are several sections that are flagged as errors, causing some generated code samples to similarly indicate errors.

Steps to reproduce

  1. Install Drupal 8 from 8.9.13 using the "Minimal" profile.
  2. Install and enable the following modules:
    1. JSON:API (in Core)
    2. OpenAPI 8.x-2.0-rc3
    3. OpenAPI UI 8.x-1.0-rc3
    4. ReDoc for OpenAPI UI 8.x-1.0-rc3
    5. Schemata 8.x-1.0-beta2
    6. Schemata in JSON Schema 8.x-1.0-beta2
    7. OpenAPI JSON:API 3.0.1
  3. Apply the patch from #5 in πŸ› Fix TypeError: Cannot read property 'anyOf' of undefined Needs work .
  4. Download the Swagger JSON file from /openapi/jsonapi?_format=json
  5. Open the Swagger Editor.
  6. Load the Swagger file that was downloaded into the Swagger Editor (File -> Import file).

Expected results

  • A OpenAPI-standards-compliant file is generated.
  • No errors or warnings appear in the Swagger editor.
  • The Swagger Editor generates code samples for all request types.

Actual results

  • The following file is generated: swagger.json β†’ .
  • When the file is loaded into the Swagger editor, the following errors appear:
    Structural error at security
    should be array
    Jump to line 16
    Structural error at definitions.file--file.properties.data.properties.attributes.properties.langcode.properties.language.type
    should be equal to one of the allowed values
    allowedValues: array, boolean, integer, number, object, string
    Jump to line 96
    Structural error at definitions.file--file.properties.data.properties.attributes.properties.uri.properties.value.type
    should be equal to one of the allowed values
    allowedValues: array, boolean, integer, number, object, string
    Jump to line 112
    Structural error at definitions.path_alias--path_alias.properties.data.properties.attributes.properties.langcode.properties.language.type
    should be equal to one of the allowed values
    allowedValues: array, boolean, integer, number, object, string
    Jump to line 288
    Structural error at definitions.user--user.properties.data.properties.attributes.properties.langcode.properties.language.type
    should be equal to one of the allowed values
    allowedValues: array, boolean, integer, number, object, string
    Jump to line 437
    Structural error at definitions.user--user.properties.data.properties.attributes.properties.preferred_langcode.properties.language.type
    should be equal to one of the allowed values
    allowedValues: array, boolean, integer, number, object, string
    Jump to line 451
    Structural error at definitions.user--user.properties.data.properties.attributes.properties.preferred_admin_langcode.properties.language.type
    should be equal to one of the allowed values
    allowedValues: array, boolean, integer, number, object, string
    Jump to line 467
    Structural error at paths./action/action.get.parameters.0.items
    should be object
    Jump to line 671
    Semantic error at paths./action/action.get.parameters.0.items
    `items` must be an object
    Jump to line 671
    Structural error at paths./action/action.get.parameters.1.items
    should be object
    Jump to line 681
    Semantic error at paths./action/action.get.parameters.1.items
    `items` must be an object
    Jump to line 681
    Structural error at paths./action/action.get.parameters.2.items
    should be object
    Jump to line 691
    Semantic error at paths./action/action.get.parameters.2.items
    `items` must be an object
    Jump to line 691
    Structural error at paths./action/action/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 722
    Structural error at paths./base_field_override/base_field_override.get.parameters.0.items
    should be object
    Jump to line 752
    Semantic error at paths./base_field_override/base_field_override.get.parameters.0.items
    `items` must be an object
    Jump to line 752
    Structural error at paths./base_field_override/base_field_override.get.parameters.1.items
    should be object
    Jump to line 762
    Semantic error at paths./base_field_override/base_field_override.get.parameters.1.items
    `items` must be an object
    Jump to line 762
    Structural error at paths./base_field_override/base_field_override.get.parameters.2.items
    should be object
    Jump to line 772
    Semantic error at paths./base_field_override/base_field_override.get.parameters.2.items
    `items` must be an object
    Jump to line 772
    Structural error at paths./base_field_override/base_field_override/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 803
    Structural error at paths./block/block.get.parameters.0.items
    should be object
    Jump to line 833
    Semantic error at paths./block/block.get.parameters.0.items
    `items` must be an object
    Jump to line 833
    Structural error at paths./block/block.get.parameters.1.items
    should be object
    Jump to line 843
    Semantic error at paths./block/block.get.parameters.1.items
    `items` must be an object
    Jump to line 843
    Structural error at paths./block/block.get.parameters.2.items
    should be object
    Jump to line 853
    Semantic error at paths./block/block.get.parameters.2.items
    `items` must be an object
    Jump to line 853
    Structural error at paths./block/block/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 884
    Structural error at paths./date_format/date_format.get.parameters.0.items
    should be object
    Jump to line 914
    Semantic error at paths./date_format/date_format.get.parameters.0.items
    `items` must be an object
    Jump to line 914
    Structural error at paths./date_format/date_format.get.parameters.1.items
    should be object
    Jump to line 924
    Semantic error at paths./date_format/date_format.get.parameters.1.items
    `items` must be an object
    Jump to line 924
    Structural error at paths./date_format/date_format.get.parameters.2.items
    should be object
    Jump to line 934
    Semantic error at paths./date_format/date_format.get.parameters.2.items
    `items` must be an object
    Jump to line 934
    Structural error at paths./date_format/date_format/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 965
    Structural error at paths./entity_form_display/entity_form_display.get.parameters.0.items
    should be object
    Jump to line 995
    Semantic error at paths./entity_form_display/entity_form_display.get.parameters.0.items
    `items` must be an object
    Jump to line 995
    Structural error at paths./entity_form_display/entity_form_display.get.parameters.1.items
    should be object
    Jump to line 1005
    Semantic error at paths./entity_form_display/entity_form_display.get.parameters.1.items
    `items` must be an object
    Jump to line 1005
    Structural error at paths./entity_form_display/entity_form_display.get.parameters.2.items
    should be object
    Jump to line 1015
    Semantic error at paths./entity_form_display/entity_form_display.get.parameters.2.items
    `items` must be an object
    Jump to line 1015
    Structural error at paths./entity_form_display/entity_form_display/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1046
    Structural error at paths./entity_form_mode/entity_form_mode.get.parameters.0.items
    should be object
    Jump to line 1076
    Semantic error at paths./entity_form_mode/entity_form_mode.get.parameters.0.items
    `items` must be an object
    Jump to line 1076
    Structural error at paths./entity_form_mode/entity_form_mode.get.parameters.1.items
    should be object
    Jump to line 1086
    Semantic error at paths./entity_form_mode/entity_form_mode.get.parameters.1.items
    `items` must be an object
    Jump to line 1086
    Structural error at paths./entity_form_mode/entity_form_mode.get.parameters.2.items
    should be object
    Jump to line 1096
    Semantic error at paths./entity_form_mode/entity_form_mode.get.parameters.2.items
    `items` must be an object
    Jump to line 1096
    Structural error at paths./entity_form_mode/entity_form_mode/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1127
    Structural error at paths./entity_view_display/entity_view_display.get.parameters.0.items
    should be object
    Jump to line 1157
    Semantic error at paths./entity_view_display/entity_view_display.get.parameters.0.items
    `items` must be an object
    Jump to line 1157
    Structural error at paths./entity_view_display/entity_view_display.get.parameters.1.items
    should be object
    Jump to line 1167
    Semantic error at paths./entity_view_display/entity_view_display.get.parameters.1.items
    `items` must be an object
    Jump to line 1167
    Structural error at paths./entity_view_display/entity_view_display.get.parameters.2.items
    should be object
    Jump to line 1177
    Semantic error at paths./entity_view_display/entity_view_display.get.parameters.2.items
    `items` must be an object
    Jump to line 1177
    Structural error at paths./entity_view_display/entity_view_display/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1208
    Structural error at paths./entity_view_mode/entity_view_mode.get.parameters.0.items
    should be object
    Jump to line 1238
    Semantic error at paths./entity_view_mode/entity_view_mode.get.parameters.0.items
    `items` must be an object
    Jump to line 1238
    Structural error at paths./entity_view_mode/entity_view_mode.get.parameters.1.items
    should be object
    Jump to line 1248
    Semantic error at paths./entity_view_mode/entity_view_mode.get.parameters.1.items
    `items` must be an object
    Jump to line 1248
    Structural error at paths./entity_view_mode/entity_view_mode.get.parameters.2.items
    should be object
    Jump to line 1258
    Semantic error at paths./entity_view_mode/entity_view_mode.get.parameters.2.items
    `items` must be an object
    Jump to line 1258
    Structural error at paths./entity_view_mode/entity_view_mode/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1289
    Structural error at paths./field_config/field_config.get.parameters.0.items
    should be object
    Jump to line 1319
    Semantic error at paths./field_config/field_config.get.parameters.0.items
    `items` must be an object
    Jump to line 1319
    Structural error at paths./field_config/field_config.get.parameters.1.items
    should be object
    Jump to line 1329
    Semantic error at paths./field_config/field_config.get.parameters.1.items
    `items` must be an object
    Jump to line 1329
    Structural error at paths./field_config/field_config.get.parameters.2.items
    should be object
    Jump to line 1339
    Semantic error at paths./field_config/field_config.get.parameters.2.items
    `items` must be an object
    Jump to line 1339
    Structural error at paths./field_config/field_config/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1370
    Structural error at paths./field_storage_config/field_storage_config.get.parameters.0.items
    should be object
    Jump to line 1400
    Semantic error at paths./field_storage_config/field_storage_config.get.parameters.0.items
    `items` must be an object
    Jump to line 1400
    Structural error at paths./field_storage_config/field_storage_config.get.parameters.1.items
    should be object
    Jump to line 1410
    Semantic error at paths./field_storage_config/field_storage_config.get.parameters.1.items
    `items` must be an object
    Jump to line 1410
    Structural error at paths./field_storage_config/field_storage_config.get.parameters.2.items
    should be object
    Jump to line 1420
    Semantic error at paths./field_storage_config/field_storage_config.get.parameters.2.items
    `items` must be an object
    Jump to line 1420
    Structural error at paths./field_storage_config/field_storage_config/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1451
    Structural error at paths./file/file.get.parameters.0.items
    should be object
    Jump to line 1481
    Semantic error at paths./file/file.get.parameters.0.items
    `items` must be an object
    Jump to line 1481
    Structural error at paths./file/file.get.parameters.1.items
    should be object
    Jump to line 1491
    Semantic error at paths./file/file.get.parameters.1.items
    `items` must be an object
    Jump to line 1491
    Structural error at paths./file/file.get.parameters.2.items
    should be object
    Jump to line 1501
    Semantic error at paths./file/file.get.parameters.2.items
    `items` must be an object
    Jump to line 1501
    Structural error at paths./file/file.post.description
    should be string
    Jump to line 1571
    Structural error at paths./file/file.post.responses
    should be object
    Jump to line 1581
    Structural error at paths./file/file/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1596
    Structural error at paths./file/file/{entity}.delete.description
    should be string
    Jump to line 1607
    Structural error at paths./file/file/{entity}.delete.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1612
    Structural error at paths./file/file/{entity}.patch.description
    should be string
    Jump to line 1621
    Structural error at paths./file/file/{entity}.patch.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1626
    Structural error at paths./file/file/{entity}.patch.responses
    should be object
    Jump to line 1636
    Structural error at paths./file/file/{entity}/uid.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1653
    Structural error at paths./file/file/{entity}/relationships/uid.delete.description
    should be string
    Jump to line 1665
    Structural error at paths./file/file/{entity}/relationships/uid.delete.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1670
    Structural error at paths./file/file/{entity}/relationships/uid.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1691
    Structural error at paths./file/file/{entity}/relationships/uid.patch.description
    should be string
    Jump to line 1727
    Structural error at paths./file/file/{entity}/relationships/uid.patch.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1732
    Structural error at paths./file/file/{entity}/relationships/uid.post.description
    should be string
    Jump to line 1799
    Structural error at paths./file/file/{entity}/relationships/uid.post.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1804
    Structural error at paths./filter_format/filter_format.get.parameters.0.items
    should be object
    Jump to line 1892
    Semantic error at paths./filter_format/filter_format.get.parameters.0.items
    `items` must be an object
    Jump to line 1892
    Structural error at paths./filter_format/filter_format.get.parameters.1.items
    should be object
    Jump to line 1902
    Semantic error at paths./filter_format/filter_format.get.parameters.1.items
    `items` must be an object
    Jump to line 1902
    Structural error at paths./filter_format/filter_format.get.parameters.2.items
    should be object
    Jump to line 1912
    Semantic error at paths./filter_format/filter_format.get.parameters.2.items
    `items` must be an object
    Jump to line 1912
    Structural error at paths./filter_format/filter_format/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 1943
    Structural error at paths./menu/menu.get.parameters.0.items
    should be object
    Jump to line 1973
    Semantic error at paths./menu/menu.get.parameters.0.items
    `items` must be an object
    Jump to line 1973
    Structural error at paths./menu/menu.get.parameters.1.items
    should be object
    Jump to line 1983
    Semantic error at paths./menu/menu.get.parameters.1.items
    `items` must be an object
    Jump to line 1983
    Structural error at paths./menu/menu.get.parameters.2.items
    should be object
    Jump to line 1993
    Semantic error at paths./menu/menu.get.parameters.2.items
    `items` must be an object
    Jump to line 1993
    Structural error at paths./menu/menu/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2024
    Structural error at paths./node_type/node_type.get.parameters.0.items
    should be object
    Jump to line 2054
    Semantic error at paths./node_type/node_type.get.parameters.0.items
    `items` must be an object
    Jump to line 2054
    Structural error at paths./node_type/node_type.get.parameters.1.items
    should be object
    Jump to line 2064
    Semantic error at paths./node_type/node_type.get.parameters.1.items
    `items` must be an object
    Jump to line 2064
    Structural error at paths./node_type/node_type.get.parameters.2.items
    should be object
    Jump to line 2074
    Semantic error at paths./node_type/node_type.get.parameters.2.items
    `items` must be an object
    Jump to line 2074
    Structural error at paths./node_type/node_type/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2105
    Structural error at paths./path_alias/path_alias.get.parameters.0.items
    should be object
    Jump to line 2135
    Semantic error at paths./path_alias/path_alias.get.parameters.0.items
    `items` must be an object
    Jump to line 2135
    Structural error at paths./path_alias/path_alias.get.parameters.1.items
    should be object
    Jump to line 2145
    Semantic error at paths./path_alias/path_alias.get.parameters.1.items
    `items` must be an object
    Jump to line 2145
    Structural error at paths./path_alias/path_alias.get.parameters.2.items
    should be object
    Jump to line 2155
    Semantic error at paths./path_alias/path_alias.get.parameters.2.items
    `items` must be an object
    Jump to line 2155
    Structural error at paths./path_alias/path_alias.post.description
    should be string
    Jump to line 2225
    Structural error at paths./path_alias/path_alias.post.responses
    should be object
    Jump to line 2235
    Structural error at paths./path_alias/path_alias/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2250
    Structural error at paths./path_alias/path_alias/{entity}.delete.description
    should be string
    Jump to line 2261
    Structural error at paths./path_alias/path_alias/{entity}.delete.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2266
    Structural error at paths./path_alias/path_alias/{entity}.patch.description
    should be string
    Jump to line 2275
    Structural error at paths./path_alias/path_alias/{entity}.patch.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2280
    Structural error at paths./path_alias/path_alias/{entity}.patch.responses
    should be object
    Jump to line 2290
    Structural error at paths./taxonomy_vocabulary/taxonomy_vocabulary.get.parameters.0.items
    should be object
    Jump to line 2314
    Semantic error at paths./taxonomy_vocabulary/taxonomy_vocabulary.get.parameters.0.items
    `items` must be an object
    Jump to line 2314
    Structural error at paths./taxonomy_vocabulary/taxonomy_vocabulary.get.parameters.1.items
    should be object
    Jump to line 2324
    Semantic error at paths./taxonomy_vocabulary/taxonomy_vocabulary.get.parameters.1.items
    `items` must be an object
    Jump to line 2324
    Structural error at paths./taxonomy_vocabulary/taxonomy_vocabulary.get.parameters.2.items
    should be object
    Jump to line 2334
    Semantic error at paths./taxonomy_vocabulary/taxonomy_vocabulary.get.parameters.2.items
    `items` must be an object
    Jump to line 2334
    Structural error at paths./taxonomy_vocabulary/taxonomy_vocabulary/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2365
    Structural error at paths./user/user.get.parameters.0.items
    should be object
    Jump to line 2395
    Semantic error at paths./user/user.get.parameters.0.items
    `items` must be an object
    Jump to line 2395
    Structural error at paths./user/user.get.parameters.1.items
    should be object
    Jump to line 2405
    Semantic error at paths./user/user.get.parameters.1.items
    `items` must be an object
    Jump to line 2405
    Structural error at paths./user/user.get.parameters.2.items
    should be object
    Jump to line 2415
    Semantic error at paths./user/user.get.parameters.2.items
    `items` must be an object
    Jump to line 2415
    Structural error at paths./user/user.post.description
    should be string
    Jump to line 2485
    Structural error at paths./user/user.post.responses
    should be object
    Jump to line 2495
    Structural error at paths./user/user/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2510
    Structural error at paths./user/user/{entity}.delete.description
    should be string
    Jump to line 2521
    Structural error at paths./user/user/{entity}.delete.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2526
    Structural error at paths./user/user/{entity}.patch.description
    should be string
    Jump to line 2535
    Structural error at paths./user/user/{entity}.patch.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2540
    Structural error at paths./user/user/{entity}.patch.responses
    should be object
    Jump to line 2550
    Structural error at paths./user/user/{entity}/roles.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2567
    Structural error at paths./user/user/{entity}/relationships/roles.delete.description
    should be string
    Jump to line 2577
    Structural error at paths./user/user/{entity}/relationships/roles.delete.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2582
    Structural error at paths./user/user/{entity}/relationships/roles.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2603
    Structural error at paths./user/user/{entity}/relationships/roles.patch.description
    should be string
    Jump to line 2645
    Structural error at paths./user/user/{entity}/relationships/roles.patch.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2650
    Structural error at paths./user/user/{entity}/relationships/roles.post.description
    should be string
    Jump to line 2729
    Structural error at paths./user/user/{entity}/relationships/roles.post.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2734
    Structural error at paths./user_role/user_role.get.parameters.0.items
    should be object
    Jump to line 2834
    Semantic error at paths./user_role/user_role.get.parameters.0.items
    `items` must be an object
    Jump to line 2834
    Structural error at paths./user_role/user_role.get.parameters.1.items
    should be object
    Jump to line 2844
    Semantic error at paths./user_role/user_role.get.parameters.1.items
    `items` must be an object
    Jump to line 2844
    Structural error at paths./user_role/user_role.get.parameters.2.items
    should be object
    Jump to line 2854
    Semantic error at paths./user_role/user_role.get.parameters.2.items
    `items` must be an object
    Jump to line 2854
    Structural error at paths./user_role/user_role/{entity}.get.parameters.0.type
    should be equal to one of the allowed values
    allowedValues: string, number, boolean, integer, array
    Jump to line 2885
     
  • The Swagger Editor generates code samples for most request types, but some samples contain errors. For example, when an entity contains a "language" field, it generates documentation like this:
            "langcode": {
              "value": "string",
              "language": "Unknown Type: language_reference"
            },
    

Proposed resolution

Revise the generated specification to comply with the OpenAPI Specification.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024