question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Request body form parameters do not support complex composed schema use cases

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Request body form parameters do not support complex composed schema use cases When we handle request body form parameters here: https://github.com/OpenAPITools/openapi-generator/blob/fdb13c3e2e5fa96523102d7c92ae2a6b409c47d4/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L6001 Our code traverses composed schemas and pools all properties inside objects into the returned properties map. This will not work when:

  • two schemas define a property with the same name and different types
  • we have oneOf or anyOf schemas where some properties should be included and others shouldn’t

This code path is used when request bodies are content-type application/x-www-form-urlencoded, or content-type starts with multipart

openapi-generator version

5.2.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  version: '1.0.0'
  title: the title

paths:
  '/users/me':
    post:
      description: Change user password.
      operationId: changeCurrentUserPassword
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ChangePasswordRequest'
      responses:
        '200':
          description: Successful operation
          content: {}

components:
  schemas:
    CommonPasswordRequest:
      type: object
      required: [ password, passwordConfirmation ]
      properties:
        password:
          type: string
          format: password
        passwordConfirmation:
          type: string
          format: password

    ChangePasswordRequest:
      type: object
      allOf:
        - $ref: '#/components/schemas/CommonPasswordRequest'
        - type: object
          required: [ oldPassword ]
          properties:
            oldPassword:
              type: string
              format: password
Generation Details
Steps to reproduce
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/10396

Suggest a fix

Update this code to return a single CodegenParameter which represents the composed schema in these cases. Then the generator will require than an instance of the model that this refers to is passed in. This fix should only be done for generators which support full composition. For now our code only handles object schema and pure allOf with no colliding property definitions.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
sebastianblesgencommented, Dec 30, 2021

Same issue with 5.3.1 of the plugin (java). Models are not generated when ref$ is used. I got message like “Model XXX not generated since it’s marked as unused (due to form parameters) and skipFormModel (global property) set to true (default)” in my console"

Here is my workaround but this should not be the fix as skipFormModel should be true only for OA2 as I understand. The problem I think is related to the fact it’s “marked as unused (due to form parameters)”

                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                        ...
                            <globalProperties>
                                <skipFormModel>false</skipFormModel>
                            </globalProperties>
                        </configuration>
2reactions
spacethercommented, Mar 30, 2022

This has been fixed in the new python-experimental generator (added in 5.4.0) which supports Inline schemas anywhere. One can see it working in this PR in 6.0.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
HTTP GET with request body - Stack Overflow
Roy Fielding's comment about including a body with a GET request. Yes. In other words, any HTTP request message is allowed to contain...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >
Request Body - FastAPI
A request body is data sent by the client to your API. ... nevertheless, it is supported by FastAPI, only for very complex/extreme...
Read more >
Writing REST Services with RESTEasy Reactive - Quarkus
Obtain metadata about a resource, similar to GET with no body (HTTP docs). @POST ... See Parameter mapping for more advanced use-cases.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found