OpenAPITools / OpenAPITools/openapi-generator

[Python] not generating if query parameteres contain object

Open
#1,587 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the supplied YAML and the python-flask generation command. Trace DefaultGenerator.processOperation and DefaultCodegen.getParameterFromRef, where the stack trace reports the NullPointerException. Done means the object query parameter is accepted according to the OpenAPI declaration and generation completes without the exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, java, openapi, python
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.