[BUG] python/python-experimental generator got NPE when handle object schema in query parameters
Created by: chanjarster
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
openapi-generator version
5.4.0
6.0.0-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: foo api
version: v1
description: 'bar'
paths:
'/users':
get:
summary: user list
operationId: userList
parameters:
- name: mapBean
in: query
required: false
description: mapBean
style: deepObject
explode: true
schema:
type: object
properties:
keyword:
title: keyword
type: string
responses:
'200':
description: ok
Generation Details
config:
projectName: foo-api
packageName: foo_api
Steps to reproduce
openapi-generator-cli generate \
--generator-name python \
--config foo-api-gen-config.yaml \
--output foo-api \
--input-spec foo-api.yaml
got error:
[main] INFO o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO o.o.codegen.DefaultGenerator - Generator 'python' is considered stable.
[main] INFO o.o.c.languages.PythonClientCodegen - generateAliasAsModel is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums
[main] INFO o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO o.o.codegen.TemplateManager - writing file /Users/qianjia/tmp/oas-gen/foo-api/foo_api/model/map_bean.py
[main] INFO o.o.codegen.TemplateManager - Skipped /Users/qianjia/tmp/oas-gen/foo-api/test/test_map_bean.py (Test files never overwrite an existing file of the same name.)
[main] INFO o.o.codegen.TemplateManager - writing file /Users/qianjia/tmp/oas-gen/foo-api/docs/MapBean.md
[main] ERROR o.o.codegen.DefaultCodegen - Undefined property/schema for `map_bean`. Default to type:string.
[main] ERROR o.o.codegen.DefaultCodegen - Undefined property/schema for `map_bean`. Default to type:string.
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
Tag: class Tag {
name: default
description: null
externalDocs: null
}
Operation: userList
Resource: get /users
Schemas: {mapBean=class ObjectSchema {
class Schema {
type: object
format: null
$ref: null
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: {keyword=class StringSchema {
class Schema {
type: string
format: null
$ref: null
description: null
title: keyword
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
}}
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
}}
Exception: null
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1163)
at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1054)
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:549)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:891)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException
at org.openapitools.codegen.languages.PythonClientCodegen.fromProperty(PythonClientCodegen.java:440)
at org.openapitools.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:4752)
at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:4113)
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1131)
... 6 more
Related issues/PRs
Suggest a fix
PythonClientCodegen#fromProperty
and PythonExperimentalClientCodegen#fromProperty
doesn't handle the situation that super.fromProperty may return null.