Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Python] deepObject parameter style creates invalid code on 5.0.1 and raises exception on 5.1.1 #9603

Open
4 of 5 tasks
RonnyPfannschmidt opened this issue May 27, 2021 · 10 comments

Comments

@RonnyPfannschmidt
Copy link
Contributor

RonnyPfannschmidt commented May 27, 2021

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?
Description

when having a spec with deep objects parameter style, the python codegen creates invalid code on generator 5.0.x and fails altogether on generator 5.1.x

on 5.0.x the bad code generated looks like
api_50/api/hosts_api.py:from api_50.model.str_bool_date_datetime_dict_float_int_list_str_none_type import StrBoolDateDatetimeDictFloatIntListStrNoneType

on 5.1.x even considering them triggers

[main] ERROR o.o.codegen.DefaultCodegen - Undefined property/schema for `filter`. Default to type:string.
[main] ERROR o.o.codegen.DefaultCodegen - Undefined property/schema for `filter`. Default to type:string.
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
openapi-generator version
  • 5.1.1
  • 5.0.1
OpenAPI declaration file content or url

api spec

relevant item is a used

components:
  parameters:
    filter_param:
      in: query
      name: filter
      required: false
      style: deepObject
      explode: true
      schema:
       type: object
Generation Details/ steps to reproduce
Related issues/PRs

i haven't found anything quite related

Suggest a fix

my current workaround is to use 5.1.x templates , the 5.0.x codegen and to post-process the generated files dropping the bad lines
it would be nice if there was a configuration option to set a deep_object_hook so users can provide a own serialization/de-serialization for deep_objects

@spacether
Copy link
Contributor

How about instead implementing proper serialization/deserialization for deepobject?
Sadly, I don't think that our python generator has kept up with the openpapi options for parameter serialization.

@RonnyPfannschmidt
Copy link
Contributor Author

@spacether it's on the mid term agenda for me, as a starting point I want don't crash at gen time and a option to configure the serializer

We also need the sercer/connexion side at some point

@spacether
Copy link
Contributor

Doesn't openapi define what deepobject should do? Do you have a use case where you need to customize how it behaves?

@RonnyPfannschmidt
Copy link
Contributor Author

@spacether deepObject is an utterly painful "standard" left for implementations, there are some non-formal ones for php/ruby, but there is no implementation for python that's standardized, so is not something i will start soon as it will need a good setup to be sane

also i don't want to just put a parser hack into openapi-codegen sincei ts jsut going to be a mess then

@kevinkirkup
Copy link

Any update on this?

@spacether
Copy link
Contributor

spacether commented Jan 25, 2022

No one has written this feature yet. If you want it, please consider writing a PR adding it in python-experimental
QueryParameter.__serialize_deep_object

One could implement it the same way that other libraries do per here: OAI/OpenAPI-Specification#1706
@kevinkirkup I pointed you at the python-experimental generator, not the python generator because python-experimental has serialization/deserialization code much more cleanly structured.
You posted a python generator stack trace which is different.

@kevinkirkup
Copy link

I don't mind updating the template, but I don't have an environment to fix the exception being thrown:

1  Exception: null
2        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1159)
3        at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1050)
4        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:549)
5        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:891)
6        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
7        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
8        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
9  Caused by: java.lang.NullPointerException
10        at org.openapitools.codegen.languages.PythonClientCodegen.fromProperty(PythonClientCodegen.java:440)
11        at org.openapitools.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:4752)
12        at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:4113)
13        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1127)

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java#L440

@kevinkirkup
Copy link

Example OpenAPI.json schema that shows this issue.
https://gist.github.com/kevinkirkup/5820d8db926f07b6eaa833394a21504c

@kevinkirkup
Copy link

May also be related to #11234

@spacether
Copy link
Contributor

@kevinkirkup my PR will fix the NPE issue but does not add the deep object serialization

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

No branches or pull requests

3 participants