Skip to content

[Python] not generating if query parameteres contain object #1587

Open

Description

@tobuh
Description

I cannot generate python server (flask) or client if yaml contains query parameters based on an object.

Error thrown:

Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: default
    description: null
    externalDocs: null
}
[..]
  Exception: null
        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1039)
        at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:930)
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:511)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:891)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:355)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:62)
Caused by: java.lang.NullPointerException
        at org.openapitools.codegen.DefaultCodegen.getParameterFromRef(DefaultCodegen.java:4122)
        at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:2472)
        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1007)
        ... 5 more
openapi-generator version

3.3.3
openapi-generator-cli-3.3.4-20181130.143646-28.jar
openapi-generator-cli-3.4.0-20181108.104734-7.jar
openapi-generator-cli-4.0.0-20181129.104836-46.jar

with 3.3.1 generating didn't throw any errors, but I had to adjust the code a little bit

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: Test    
  version: 0.1.0
  title: "Test API"

paths:
  /objects:
    get:
      summary: "Get all available objects"
      operationId: getObjects
      parameters:
      - in: "query"
        name: "filterTime"
        description: "Time based filter"
        required: false
        schema:
          type: "object"
          properties:
            begin:
              type: "string"
              format: "date-time"
            end:
              type: "string"
              format: "date-time"
          minProperties: 1
        style: "form"
        explode: true
      responses:
        200:
          description: "List of available objects"
          content:
            application/json:
              schema:
                type: "array"
                items:
                  allOf:
                  - $ref: '#/components/schemas/AnotherObject'
        default:
          description: "standard error"

components:
  schemas:
    TestObject:
      type: "object"
      properties:
        name:
          type: "string"
          example: "Testname"
          
    AnotherObject:
      allOf:
        - $ref: '#/components/schemas/TestObject'
        - type: "object"
          properties:
            anotherproperty:
              type: "string"
Command line used for generation

java -jar openapi-generator-cli.jar generate -i testapispec.yaml -g python-flask -o out/

Steps to reproduce

use mentioned yaml and command line

Related issues/PRs

I didn't find any related issue

Suggest a fix/enhancement

Objects in query parameters should be accepted as it is a valid spec according to editor.swagger.io

Activity

  1. romantul commented on Dec 3, 2018

    @romantul

    Hello all.
    I have the same problem generating java server with openapi-generator-maven-plugin version=3.3.3

    I agree with @tobuh that it is valid spec also according to official "OpenAPI-Specification": https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#parameterObject

  2. yknx4 commented on Dec 14, 2018

    @yknx4
    Contributor

    +1

  3. mertsert commented on Aug 22, 2023

    @mertsert

    +1

    Hi,

    When utilizing the 'Try it out' button on the UI screen to generate a request, you might notice the display of the Bad request response. This behavior stems from the evaluation of object properties as individual parameters during request creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions