-
Notifications
You must be signed in to change notification settings - Fork 357
Description
Environment
- Package:
@omnigraph/openapi - GraphQL Mesh Version: latest
- Node Version: 20.16.0
Description
The OpenAPI handler fails to properly handle POST requests with application/x-www-form-urlencoded content type when the request body schema uses discriminator with oneOf structure. The API returns "missing required parameters" error even when all parameters are provided.
Steps to Reproduce
-
Use an OpenAPI spec with the following characteristics:
- POST endpoint with
application/x-www-form-urlencodedrequest body - Request body schema uses
oneOfwith discriminator - Example: USPS OAuth2 token endpoint
- POST endpoint with
-
Configure GraphQL Mesh with the spec:
{
sourceHandler: loadOpenAPISubgraph('USPS_Token', {
source: './openapi-spec.yaml',
operationHeaders: {
'Content-Type': 'application/x-www-form-urlencoded',
}
})
}- Call the generated mutation with required parameters
Example OpenAPI Spec Structure
paths:
/token:
post:
requestBody:
content:
application/x-www-form-urlencoded:
schema:
discriminator:
propertyName: grant_type
mapping:
client_credentials: '#/components/schemas/ClientCredentials'
oneOf:
- $ref: '#/components/schemas/ClientCredentials'Full spec available: oauth2_3_update.yaml
Expected Behavior
The handler should:
- Properly serialize form-urlencoded data even with discriminator/oneOf schemas
- Include all required parameters in the request body
- Successfully call the API endpoint
Actual Behavior
The API returns: "The request is missing one or more required parameters or is otherwise malformed"
This suggests the parameters are not being properly serialized or sent in the request body.
Workaround
Create a simplified OpenAPI spec without discriminator and oneOf:
paths:
/token:
post:
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
required:
- grant_type
- client_id
- client_secret
properties:
grant_type:
type: string
enum: [client_credentials]
client_id:
type: string
client_secret:
type: string
scope:
type: stringWith this simplified spec, the same mutation works correctly.
Additional Context
- The same OpenAPI spec works correctly with WunderGraph
- Issue specifically occurs with form-urlencoded content type + discriminator pattern
- This is a common pattern in OAuth 2.0 token endpoints
Possible Root Cause
The OpenAPI handler may not be correctly handling the discriminator + oneOf pattern when serializing to application/x-www-form-urlencoded format, possibly:
- Not flattening the discriminated union properties
- Not correctly mapping the discriminator value
- Sending JSON structure instead of form-encoded key-value pairs
Related
- OpenAPI Spec: https://github.com/USPS/api-examples
- OAuth 2.0 Token Endpoint Standard: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4