oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Client With Responses cant reference external responses

Open amammay opened this issue 2 years ago • 4 comments

In the client-with-responses template if you have have

pkg b

components:
  responses:
    200:
      description: "OK"
      content:
        'application/json':
          schema:
            $ref: '#/components/schemas/Document'
  schemas:
    Document:
      type: object
      properties:
        fields:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Value'
    Value:
      type: object
      properties:
        stringValue:
          type: string
        arrayValue:
          $ref: '#/components/schemas/ArrayValue'
    ArrayValue:
      type: array
      items:
        $ref: '#/components/schemas/Value'

and in pkg a

paths:
  /example:
    get:
      operationId: exampleGet
      responses:
        200:
          $ref: "./pkgb/spec.yaml#/components/responses/200"

the codegen output doesnt include external refs

image

I will open a PR with a broken test to showcase an exact replica

amammay avatar Feb 10 '23 21:02 amammay

pr that shows issue -> https://github.com/deepmap/oapi-codegen/pull/959

amammay avatar Feb 10 '23 21:02 amammay

Proposed solution: #992

Rmarken5 avatar Mar 07 '23 19:03 Rmarken5

Issue is with the bump to kin-openapi v0.112.0 => V0.114.0.

Schema struct is loaded with Component as nil in new version. In root schema yaml, I added a component property and schema is loaded properly into memory.

Generated models now have correct package.

fixed with #1013

Rmarken5 avatar Mar 27 '23 20:03 Rmarken5

Hey folks, mind re-reviewing this in light of the v2.1.0 release, which made some significant changes (:crossed_fingers: and the fix for this) to external references?

jamietanna avatar Mar 04 '24 21:03 jamietanna