fastapi-code-generator: $refs in parameter is not processed

I expect

$refs in parameters to be processed, eg

paths:
  /foo:
    parameters:
    - $ref: '#/components/parameters/MyParam'
components:
  parameters:
    MyParam:
      name: foo
      schema:
        type: string

Instead

I get KeyError

  File "/usr/local/lib/python3.8/site-packages/fastapi_code_generator/parser.py", line 207, in get_parameter_type
    schema: JsonSchemaObject = JsonSchemaObject.parse_obj(parameter["schema"])
KeyError: 'schema'

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (17 by maintainers)

Most upvoted comments

@oktavlachs

I didn’t know it.

Do you know what the differences or (dis-)/advantages are from your project?

I guess openapi-generator-cli supports openapi features like multiple status codes of responses. (But, We can implement the features to fastapi-code-generator.) Also, the code-generator creates project files (tests, docker file, …)

However, openapi-generator-cli can generate only a simple model. https://github.com/OpenAPITools/openapi-generator/commit/0da409986889dcfab1420fb1410ae9509a5834c8#diff-b667e564efa49b2fa6b6d766c52b062dc73f3e6444046e34d9457d6e532e91e0

fastapi-code-generator use datamodel-code-generator to generate models. The datamodel-code-generator supports a lot of features. For example, allOf is created as an inherited class. I believe definitely this is the best advantage.

Btw, datamodel-code-generator is used in a lot of projects. It’s download about 100k per month. Famous tech compies convert complex and large Schema files to pydantic models by datamodel-code-generator . 😉

If fastapi-code-generator can call all features of datamodel-code-generator then I guess fastapi-code-generator becomes an awesome tool to generate fastapi and pydnatic code.

@koxudaxi yes, parameters can accept content in OAS3. It is the first time I see it though 😃 https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.1.md#parameterObject

Thanks! As it still does not support remote refs, I’ll close this and file another! Great work!

I confirm it is now working well with version 0.0.16 even with some nested refs. Great work ! Thanks.

@oktavlachs Thank you for posting the problem. I have not known that parameters can accept content. OK, I will fix it.