fastapi-code-generator icon indicating copy to clipboard operation
fastapi-code-generator copied to clipboard

$ref parameter prevents code generation

Open aktentasche opened this issue 3 years ago • 1 comments

I am trying to use $ref parameters in my openapi yaml, however as soon as I insert a $ref entry no code is generated (the folder is but it contains no files) and no error is thrown.

I took the code from #24, so my minimum working example is:

openapi.yaml

openapi: "3.0.0"
paths:
  /foo:
    parameters:
      - $ref: "#/components/parameters/MyParam"
components:
  parameters:
    MyParam:
      name: foo
      schema:
        type: string

But the same happens with my actual openapi definition. As soon as I add a $ref parameter, no code is generated.

command:

fastapi-codegen -i openapi.yaml -o app

I am using fastapi-code-generator version 0.3.5

Can someone help? Thanks!

aktentasche avatar Aug 11 '22 10:08 aktentasche

Ok so I found out I can use $refs in the schema but this not so clean if I really want to use the exact same parameter in several places, I would need to repeat it in every place.

So in below API definition the demo_pizza_factory_instance is part of every query.

 - name: demo_pizza_factory_instance
          in: query
          description: The service instance to address this request to.
          required: true
          schema:
            $ref: "#/components/schemas/DemoPizzaFactoryInstance" 
components:
  schemas:
    DemoPizzaFactoryInstance:
      type: string
      enum:
        - hawaii 
        - funghi   

aktentasche avatar Aug 13 '22 19:08 aktentasche