api-platform / api-platform/core

Custom openapi parameter defined in XML is not displayed in UI

Open
#8,166 0 comments 0 reactions 0 assignees View on GitHub
metadata OpenAPI
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 5h
Merged PRs (30d)
48

Description

**API Platform version(s) affected**: 4.1 (and probably some older versions as well)

**Description**

I define some custom parameters with `` XML element. This custom parameter is not being displayed in the OpenAPI UI under the desired operation.

Technical problem in the json:
OpenAPI parameter should not be indexed by its name but by integer index.

Such is described in [OpenAPI spec](https://swagger.io/docs/specification/v3_0/describing-parameters/) where parameters are array of objects, not object with fields (indexed by a string).

**How to reproduce**
I define custom parameter in XML like this:
```






string




```

Then I get this OpenAPI spec (reduced):
```
"\/api\/client\/auth\/economic-subjects": {
"get": {
"operationId": "api_clientautheconomic-subjects_get",
"parameters": {

// this string index
"businessTitle": {

"name": "businessTitle",
"in": "query",
"description": "The title of the business to search for.",
"required": true,
"deprecated": false,
"allowEmptyValue": false,
"schema": {
"type": "string"
},
"style": "form",
"explode": false,
"allowReserved": false
}
},
"deprecated": false
}
}
```
but this parameter indexed by string in the resulting json do not show up in the UI.

**Possible Solution**
When I make a change in the class [`metadata/Extractor/XmlResourceExtractor.php`](https://github.com/api-platform/core/blob/main/src/Metadata/Extractor/XmlResourceExtractor.php) such as
```
foreach ($openapi->parameters->parameter as $parameter) {
$data['parameters'][(string) $parameter->attributes()->name] = new OpenApiParameter(
name: $this->phpize($parameter, 'name', 'string'),
```
into
```
foreach ($openapi->parameters->parameter as $parameter) {
$data['parameters'][] = new OpenApiParameter(
name: $this->phpize($parameter, 'name', 'string'),
```
resulting json looks like this:
```
"\/api\/client\/auth\/economic-subjects": {
"get": {
"operationId": "api_clientautheconomic-subjects_get",
"summary": "Retrieves a AresEconomicSubject resource.",
"description": "Retrieves a AresEconomicSubject resource.",
"parameters": [

// no string index
{

"name": "businessTitle",
"in": "query",
"description": "The title of the business to search for.",
"required": true,
"deprecated": false,
"allowEmptyValue": false,
"schema": {
"type": "string"
},
"style": "form",
"explode": false,
"allowReserved": false
}
],
"deprecated": false
}
},
```
and the defined parameter (and others) is showing up in the UI.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.